|
| 1 | +/* global assert, process, setup, suite, test */ |
| 2 | +var entityFactory = require('../../helpers').entityFactory; |
| 3 | + |
| 4 | +suite('auto-enter-vr', function () { |
| 5 | + suite('no getVRDisplay', function () { |
| 6 | + setup(function (done) { |
| 7 | + this.entityEl = entityFactory(); |
| 8 | + var el = this.el = this.entityEl.parentNode; |
| 9 | + var resolvePromise = function () { return Promise.resolve(); }; |
| 10 | + el.setAttribute('auto-enter-vr', ''); |
| 11 | + el.effect = { |
| 12 | + requestPresent: resolvePromise, |
| 13 | + exitPresent: resolvePromise |
| 14 | + }; |
| 15 | + var self = this; |
| 16 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 17 | + el.addEventListener('loaded', function () { |
| 18 | + self.enterVRSpy = self.sinon.spy(autoEnterVR, 'enterVR'); |
| 19 | + self.exitVRSpy = self.sinon.spy(autoEnterVR, 'exitVR'); |
| 20 | + done(); |
| 21 | + }); |
| 22 | + }); |
| 23 | + |
| 24 | + test('if no getVRDisplay, then !shouldAutoEnterVR and !enterVR', function () { |
| 25 | + var el = this.el; |
| 26 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 27 | + assert.notOk(el.effect.getVRDisplay); |
| 28 | + assert.notOk(autoEnterVR.shouldAutoEnterVR()); |
| 29 | + process.nextTick(function () { |
| 30 | + assert.notOk(this.enterVRSpy.called); |
| 31 | + }); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + suite('!getVRDisplay()', function () { |
| 36 | + setup(function (done) { |
| 37 | + this.entityEl = entityFactory(); |
| 38 | + var el = this.el = this.entityEl.parentNode; |
| 39 | + var resolvePromise = function () { return Promise.resolve(); }; |
| 40 | + el.setAttribute('auto-enter-vr', ''); |
| 41 | + el.effect = { |
| 42 | + getVRDisplay: function () { return null; }, |
| 43 | + requestPresent: resolvePromise, |
| 44 | + exitPresent: resolvePromise |
| 45 | + }; |
| 46 | + var self = this; |
| 47 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 48 | + el.addEventListener('loaded', function () { |
| 49 | + self.enterVRSpy = self.sinon.spy(autoEnterVR, 'enterVR'); |
| 50 | + self.exitVRSpy = self.sinon.spy(autoEnterVR, 'exitVR'); |
| 51 | + done(); |
| 52 | + }); |
| 53 | + }); |
| 54 | + |
| 55 | + test('if !getVRDisplay(), then !shouldAutoEnterVR and !enterVR', function () { |
| 56 | + var el = this.el; |
| 57 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 58 | + assert.ok(el.effect.getVRDisplay); |
| 59 | + assert.notOk(el.effect.getVRDisplay()); |
| 60 | + assert.notOk(autoEnterVR.shouldAutoEnterVR()); |
| 61 | + process.nextTick(function () { |
| 62 | + assert.notOk(this.enterVRSpy.called); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + suite('no getVRDisplay() displayName', function () { |
| 68 | + setup(function (done) { |
| 69 | + this.entityEl = entityFactory(); |
| 70 | + var el = this.el = this.entityEl.parentNode; |
| 71 | + var resolvePromise = function () { return Promise.resolve(); }; |
| 72 | + el.setAttribute('auto-enter-vr', ''); |
| 73 | + el.effect = { |
| 74 | + getVRDisplay: function () { return {}; }, |
| 75 | + requestPresent: resolvePromise, |
| 76 | + exitPresent: resolvePromise |
| 77 | + }; |
| 78 | + var self = this; |
| 79 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 80 | + el.addEventListener('loaded', function () { |
| 81 | + self.enterVRSpy = self.sinon.spy(autoEnterVR, 'enterVR'); |
| 82 | + self.exitVRSpy = self.sinon.spy(autoEnterVR, 'exitVR'); |
| 83 | + done(); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + test('if no getVRDisplay().displayName, then !shouldAutoEnterVR and !enterVR', function () { |
| 88 | + var el = this.el; |
| 89 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 90 | + assert.ok(el.effect.getVRDisplay); |
| 91 | + assert.notOk(el.effect.getVRDisplay().displayName); |
| 92 | + assert.notOk(autoEnterVR.shouldAutoEnterVR()); |
| 93 | + process.nextTick(function () { |
| 94 | + assert.notOk(this.enterVRSpy.called); |
| 95 | + }); |
| 96 | + }); |
| 97 | + }); |
| 98 | + |
| 99 | + suite('getVRDisplay() displayName something else', function () { |
| 100 | + setup(function (done) { |
| 101 | + this.entityEl = entityFactory(); |
| 102 | + var el = this.el = this.entityEl.parentNode; |
| 103 | + var resolvePromise = function () { return Promise.resolve(); }; |
| 104 | + el.setAttribute('auto-enter-vr', ''); |
| 105 | + el.effect = { |
| 106 | + getVRDisplay: function () { return {displayName: 'something else'}; }, |
| 107 | + requestPresent: resolvePromise, |
| 108 | + exitPresent: resolvePromise |
| 109 | + }; |
| 110 | + var self = this; |
| 111 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 112 | + el.addEventListener('loaded', function () { |
| 113 | + self.enterVRSpy = self.sinon.spy(autoEnterVR, 'enterVR'); |
| 114 | + self.exitVRSpy = self.sinon.spy(autoEnterVR, 'exitVR'); |
| 115 | + done(); |
| 116 | + }); |
| 117 | + }); |
| 118 | + |
| 119 | + test('if getVRDisplay().displayName something else, then !shouldAutoEnterVR and !enterVR', function () { |
| 120 | + var el = this.el; |
| 121 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 122 | + assert.ok(el.effect.getVRDisplay); |
| 123 | + assert.ok(el.effect.getVRDisplay().displayName); |
| 124 | + assert.notOk(el.effect.getVRDisplay().displayName.indexOf('GearVR') >= 0); |
| 125 | + assert.notOk(autoEnterVR.shouldAutoEnterVR()); |
| 126 | + process.nextTick(function () { |
| 127 | + assert.notOk(this.enterVRSpy.called); |
| 128 | + }); |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + suite('getVRDisplay() displayName GearVR something', function () { |
| 133 | + setup(function (done) { |
| 134 | + this.entityEl = entityFactory(); |
| 135 | + var el = this.el = this.entityEl.parentNode; |
| 136 | + var resolvePromise = function () { return Promise.resolve(); }; |
| 137 | + el.setAttribute('auto-enter-vr', ''); |
| 138 | + el.effect = { |
| 139 | + getVRDisplay: function () { return {displayName: 'GearVR something'}; }, |
| 140 | + requestPresent: resolvePromise, |
| 141 | + exitPresent: resolvePromise |
| 142 | + }; |
| 143 | + var self = this; |
| 144 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 145 | + el.addEventListener('loaded', function () { |
| 146 | + self.enterVRSpy = self.sinon.spy(autoEnterVR, 'enterVR'); |
| 147 | + self.exitVRSpy = self.sinon.spy(autoEnterVR, 'exitVR'); |
| 148 | + done(); |
| 149 | + }); |
| 150 | + }); |
| 151 | + |
| 152 | + test('if getVRDisplay().displayName has GearVR, then shouldAutoEnterVR and enterVR', function () { |
| 153 | + var el = this.el; |
| 154 | + var autoEnterVR = el.components['auto-enter-vr']; |
| 155 | + assert.ok(el.effect.getVRDisplay); |
| 156 | + assert.ok(el.effect.getVRDisplay().displayName); |
| 157 | + assert.ok(el.effect.getVRDisplay().displayName.indexOf('GearVR') >= 0); |
| 158 | + assert.ok(autoEnterVR.shouldAutoEnterVR()); |
| 159 | + process.nextTick(function () { |
| 160 | + assert.ok(this.enterVRSpy.called); |
| 161 | + }); |
| 162 | + }); |
| 163 | + }); |
| 164 | +}); |
0 commit comments