|
20 | 20 | */
|
21 | 21 |
|
22 | 22 | exports.defineAutoTests = function () {
|
| 23 | + var isLockable = false; |
| 24 | + |
| 25 | + beforeAll(function () { |
| 26 | + // Mobile devices are expected to have a lockable orientation, while |
| 27 | + // desktop devices does not |
| 28 | + // (Chrome on desktop will return: |
| 29 | + // DOMException: screen.orientation.lock() is not available on this device) |
| 30 | + // Using an user agent check sucks, but this is a unit test, |
| 31 | + // - using browser window size is unreliable cause the browser can be resized. |
| 32 | + // - Using max touch support is unreliable cause some laptops will have touch support |
| 33 | + // but still lack support for locking the orientation. |
| 34 | + isLockable = /Android|iPhone|iPad|iPod/gi.test(window.navigator.userAgent); |
| 35 | + }); |
| 36 | + |
23 | 37 | describe('window.screen', function () {
|
24 | 38 | it('should be defined', function () {
|
25 | 39 | expect(window.screen).toBeDefined();
|
@@ -108,12 +122,22 @@ exports.defineAutoTests = function () {
|
108 | 122 | // test addEventListener('change') works
|
109 | 123 | // test onchange works
|
110 | 124 | describe('window.screen.orientation', function () {
|
111 |
| - it('should successfully lock and unlock screen orientation', function () { |
112 |
| - return window.screen.orientation.lock('portrait').then(function () { |
113 |
| - expect(window.screen.orientation.type).toMatch(/^portrait-/); |
114 |
| - expect(window.screen.orientation.unlock).not.toThrow(); |
| 125 | + if (isLockable) { |
| 126 | + it('should successfully lock and unlock screen orientation', function () { |
| 127 | + return window.screen.orientation.lock('portrait').then(function () { |
| 128 | + expect(window.screen.orientation.type).toMatch(/^portrait-/); |
| 129 | + expect(window.screen.orientation.unlock).not.toThrow(); |
| 130 | + }); |
115 | 131 | });
|
116 |
| - }); |
| 132 | + } |
| 133 | + // We do not test "not isLockable" states because it isn't testable. |
| 134 | + // The error stating it's not supported is not actually passed to the |
| 135 | + // promise reject function, so the error is not catchable. The error |
| 136 | + // is only ever printed to the JS console if nothing catches errors. |
| 137 | + // The promise itself is fulfilled successfully, despite the action |
| 138 | + // not doing what is expected. |
| 139 | + // I believe this might be a privacy security mechanism to avoid device |
| 140 | + // fingerprinting. |
117 | 141 | });
|
118 | 142 | };
|
119 | 143 | exports.defineManualTests = function (contentEl, createActionButton) {
|
|
0 commit comments