diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /testing/web-platform/tests/screen-orientation | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/web-platform/tests/screen-orientation')
11 files changed, 509 insertions, 0 deletions
diff --git a/testing/web-platform/tests/screen-orientation/OWNERS b/testing/web-platform/tests/screen-orientation/OWNERS new file mode 100644 index 000000000..bbdded8ff --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/OWNERS @@ -0,0 +1 @@ +@haoxli diff --git a/testing/web-platform/tests/screen-orientation/lock-bad-argument.html b/testing/web-platform/tests/screen-orientation/lock-bad-argument.html new file mode 100644 index 000000000..df27ac21d --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/lock-bad-argument.html @@ -0,0 +1,73 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +var test = async_test("Test that screen.orientation.lock() throws when the input isn't valid."); + +function onOrientationChangeEvent(ev) { + assert_unreached('Unexpected orientation change'); +} + +window.screen.orientation.addEventListener('change', test.step_func(onOrientationChangeEvent)); + +test.step(function() { + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock('invalid-orientation'); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(null); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(undefined); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(undefined); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(123); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(window); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(['portrait-primary']); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(['portrait-primary', 'landscape-primary']); + }); + + assert_equals(screen.orientation.type, 'portrait-primary'); + assert_throws(new TypeError(), function() { + screen.orientation.lock(); + }); +}); + +// Finish asynchronously to give events a chance to fire. +setTimeout(test.step_func(function() { + assert_equals(screen.orientation.type, 'portrait-primary'); + screen.orientation.unlock(); + test.done(); +})); + +</script> +</body> +</html> + diff --git a/testing/web-platform/tests/screen-orientation/lock-basic.html b/testing/web-platform/tests/screen-orientation/lock-basic.html new file mode 100644 index 000000000..022d24be3 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/lock-basic.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +var previousOrientation = screen.orientation; + +test(function() { + screen.orientation.unlock(); +}, "Test that screen.orientation.unlock() doesn't throw when there is no lock"); + +async_test(function(t) { + var orientations = ['any', 'portrait', 'landscape', 'portrait-secondary', + 'landscape-primary', 'landscape-secondary', 'portrait-primary']; + + setOrientation = function(idx) { + if( idx == orientations.length) { + screen.orientation.unlock(); + t.done(); + return; + } + (function(i) { + screen.orientation.lock(orientations[i]).then(function() { + setOrientation(i+1); + },function() {}); + })(idx); + }; + + setOrientation(0); + +}, "Test that screen.orientation.lock returns a pending promise."); + +test(function() { + assert_equals(screen.orientation, previousOrientation); +}, "Test that screen.orientation.lock() is actually async"); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/lock-sandboxed-iframe.html b/testing/web-platform/tests/screen-orientation/lock-sandboxed-iframe.html new file mode 100644 index 000000000..1c4f5294c --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/lock-sandboxed-iframe.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<iframe id="allowedIframe" sandbox="allow-scripts allow-same-origin allow-orientation-lock" style="display:none"> +</iframe> + +<iframe id="disallowedIframe" sandbox="allow-scripts allow-same-origin" style="display:none"> +</iframe> +<script> + var testNotAllowed = async_test("Test without 'allow-orientation-lock' sandboxing directive"); + var testAllowed = async_test("Test with 'allow-orientation-lock' sandboxing directive"); + + function runTestAllowed() { + window.onmessage = testAllowed.step_func(function (ev) { + assert_equals(ev.data, "portrait-primary", "screen.orientation lock to portrait-primary"); + screen.orientation.unlock(); + testAllowed.done(); + }); + var allowedIframe = document.getElementById("allowedIframe"); + allowedIframe.src = "resources/sandboxed-iframe-locking.html"; + } + + function runTestNotAllowed() { + window.onmessage = testNotAllowed.step_func(function (ev) { + assert_equals(ev.data, "SecurityError", "screen.lockOrientation() throws a SecurityError"); + testNotAllowed.done(); + runTestAllowed(); + }); + var disallowedIframe = document.getElementById("disallowedIframe"); + disallowedIframe.src = "resources/sandboxed-iframe-locking.html"; + } + runTestNotAllowed(); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html b/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html new file mode 100644 index 000000000..87b0e9fe7 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/onchange-event-subframe.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> + +<iframe id="testIframe" sandbox="allow-scripts allow-same-origin" style="display:none"> +</iframe> + +<script> + var test = async_test("Test subframes receive orientation change events"); + + var orientations = [ + 'portrait-primary', + 'portrait-secondary', + 'landscape-primary', + 'landscape-secondary' + ]; + + var currentIndex = orientations.indexOf(window.screen.orientation.type); + var eventsReceived = 0; + + function getNextIndex() { + return (currentIndex + 1) % orientations.length; + } + + function changeOrientation() { + screen.orientation.lock(orientations[getNextIndex()]).then(function () {}, function () {}); + currentIndex = getNextIndex(); + } + + window.onmessage = test.step_func(function (ev) { + assert_equals(ev.data, orientations[currentIndex], "subframe receives orientation change event"); + ++eventsReceived; + if (eventsReceived < orientations.length) + changeOrientation() + else + test.done(); + }); + + var testIframe = document.getElementById("testIframe"); + testIframe.src = "resources/iframe-listen-orientation-change.html"; + testIframe.onload = changeOrientation; +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/onchange-event.html b/testing/web-platform/tests/screen-orientation/onchange-event.html new file mode 100644 index 000000000..be39efc32 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/onchange-event.html @@ -0,0 +1,80 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +var changeTest = async_test("Test that orientationchange event is fired when the orientation changes."); +var noChangeTest = async_test("Test that orientationchange event is not fired when the orientation does not change."); + +var orientations = [ + 'portrait-primary', + 'portrait-secondary', + 'landscape-primary', + 'landscape-secondary' +]; + +var currentIndex = orientations.indexOf(window.screen.orientation.type); +// Count the number of calls received from the EventHandler set on screen.orientation.onchange. +var orientationChangeEventHandlerCalls = 0; +// Count the number of calls received from the listener set with screen.orientation.addEventListene(). +var orientationChangeEventListenerCalls = 0; + +var orientationChangeContinuation = null; + +function getNextIndex() { + return (currentIndex + 1) % orientations.length; +} + +window.screen.orientation.onchange = function() { + orientationChangeEventHandlerCalls++; + if (orientationChangeEventContinuation) { + setTimeout(orientationChangeEventContinuation); + orientationChangeEventContinuation = null; + } +}; + +window.screen.orientation.addEventListener('change', function() { + orientationChangeEventListenerCalls++; +}); + +function runNoChangeTest() { + screen.orientation.lock(orientations[currentIndex]).then(function() {}, function() {}); + + noChangeTest.step(function() { + assert_equals(screen.orientation.type, orientations[currentIndex]); + assert_equals(orientationChangeEventHandlerCalls, orientations.length); + assert_equals(orientationChangeEventListenerCalls, orientations.length); + }); + + noChangeTest.done(); +} + +var i = 0; +function runChangeTest() { + screen.orientation.lock(orientations[getNextIndex()]).then(function() {}, function() {}); + currentIndex = getNextIndex(); + + orientationChangeEventContinuation = function() { + changeTest.step(function() { + assert_equals(screen.orientation.type, orientations[currentIndex]); + assert_equals(orientationChangeEventHandlerCalls, i + 1); + assert_equals(orientationChangeEventListenerCalls, i + 1); + }); + + ++i; + if (i == orientations.length) { + changeTest.done(); + runNoChangeTest(); + } else { + runChangeTest(); + } + }; +} + +runChangeTest(); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/orientation-api.html b/testing/web-platform/tests/screen-orientation/orientation-api.html new file mode 100644 index 000000000..80910a3a0 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/orientation-api.html @@ -0,0 +1,35 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +test(function() { + assert_true('orientation' in window.screen); + assert_true('angle' in window.screen.orientation); + assert_true('type' in window.screen.orientation); + assert_true('lock' in window.screen.orientation); + assert_true('unlock' in window.screen.orientation); + assert_true('onchange' in window.screen.orientation); +}, "Test that the Screen Orientation API is present.") + +test(function() { + assert_equals(typeof(screen.orientation), "object"); + assert_equals(typeof(screen.orientation.angle), "number"); + assert_equals(typeof(screen.orientation.type), "string"); + assert_equals(typeof(screen.orientation.lock), "function"); + assert_equals(typeof(screen.orientation.unlock), "function"); + assert_equals(typeof(screen.orientation.onchange), "object"); +}, "Test Screen Orientation API property types."); + +test(function() { + assert_true('addEventListener' in screen.orientation); + assert_true('removeEventListener' in screen.orientation); + assert_true('dispatchEvent' in screen.orientation); + assert_true(screen.orientation instanceof EventTarget) +}, "Test that screen.orientation is an EventTarget."); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/orientation-reading.html b/testing/web-platform/tests/screen-orientation/orientation-reading.html new file mode 100644 index 000000000..4b1d0b838 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/orientation-reading.html @@ -0,0 +1,61 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +test(function() { + assert_true('type' in screen.orientation); + assert_true('angle' in screen.orientation); +}, "Test screen.orientation properties"); + +test(function() { + assert_equals(screen.orientation.type, "portrait-primary"); + assert_equals(screen.orientation.angle, 0); +}, "Test screen.orientation default values."); + +test(function() { + var type = screen.orientation.type; + var angle = screen.orientation.angle; + + screen.orientation.type = 'foo'; + screen.orientation.angle = 42; + + assert_equals(screen.orientation.type, type); + assert_equals(screen.orientation.angle, angle); +}, "Test that screen.orientation properties are not writable"); + +test(function() { + assert_equals(screen.orientation, screen.orientation); +}, "Test that screen.orientation is always the same object"); + +async_test(function(t) { + var orientation = screen.orientation; + var orientationType = screen.orientation.type; + var orientationAngle = screen.orientation.angle; + + screen.orientation.unlock(); + screen.orientation.lock('landscape-primary').then(function () { + t.step(function () { + assert_equals(screen.orientation, orientation); + assert_equals(screen.orientation.type, orientation.type); + assert_equals(screen.orientation.angle, orientation.angle); + assert_not_equals(screen.orientation.type, orientationType); + assert_not_equals(screen.orientation.angle, orientationAngle); + }); + t.done(); + screen.orientation.unlock(); + }, function () { + t.step(function () { + assert_unreached('Unexpected orientation change'); + }); + t.done(); + screen.orientation.unlock(); + }); + +}, "Test that screen.orientation values change if the orientation changes"); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/page-visibility-manual.html b/testing/web-platform/tests/screen-orientation/page-visibility-manual.html new file mode 100644 index 000000000..95633ba12 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/page-visibility-manual.html @@ -0,0 +1,110 @@ +<!DOCTYPE html> +<html> +<body> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<meta name='flags' content='interact'> +<meta name="timeout" content="long"> +<p>Switch the page to background, then switch back in a minute.</p> +<iframe src='about:blank'></iframe> +<script> + +var eventVisibleTest = async_test("Test that a change event is fired when the page is visible."); +var noEventHiddenTest = async_test("Test that change event is not fired when the page is not visible."); +var orientationUnchangeHiddenTest = async_test("Test that screen.orientation keeps returning the same orientation when the page is not visible."); +var orientationUpdateVisibleTest = async_test("Test that screen.orientation is updated once the page is visible again."); +var frameEventsTest = async_test("Test that the iframe got as many events as the main frame."); + +var orientationChangeContinuation = null; +var orientationChangeEventListenerCalls = 0; +var orientationChangeEventListenerCallsForFrame = 0; + +screen.orientation.addEventListener('change', function() { + orientationChangeEventListenerCalls++; + if (orientationChangeEventContinuation) { + setTimeout(orientationChangeEventContinuation); + orientationChangeEventContinuation = null; + } +}); + +window.frames[0].screen.orientation.addEventListener('change', function() { + orientationChangeEventListenerCallsForFrame++; +}); + +document.addEventListener("visibilitychange", function () { + if(document.hidden) + runNoEventHiddenTest(); + else + runOrientationUpdateVisibleTest(); +}); + +function runEventVisibleTest() { + eventVisibleTest.step(function() { + assert_false(document.hidden); + }); + + screen.orientation.lock("landscape-primary").then(function() {}, function() {}); + + orientationChangeEventContinuation = function() { + eventVisibleTest.step(function() { + assert_equals(orientationChangeEventListenerCalls, 1); + assert_equals(screen.orientation.type, "landscape-primary"); + }); + eventVisibleTest.done(); + + }; +} + +function runNoEventHiddenTest() { + + noEventHiddenTest.step(function() { + assert_true(document.hidden); + }); + + screen.orientation.lock("portrait-primary").then(function() {}, function() {}); + + noEventHiddenTest.step(function() { + assert_equals(orientationChangeEventListenerCalls, 1); + }); + noEventHiddenTest.done(); + + runOrientationUnchangeHiddenTest(); +} + +function runOrientationUnchangeHiddenTest() { + orientationUnchangeHiddenTest.step(function() { + assert_equals(screen.orientation.type, "landscape-primary"); + }); + orientationUnchangeHiddenTest.done(); + +} + +function runOrientationUpdateVisibleTest() { + + orientationChangeEventContinuation = function() { + orientationUpdateVisibleTest.step(function() { + assert_false(document.hidden); + // A change event should have been fired. + assert_equals(orientationChangeEventListenerCalls, 2); + // Should keep returning the start returning the orientation value. + assert_equals(screen.orientation.type, "portrait-primary"); + }); + + orientationUpdateVisibleTest.done(); + + runFrameEventsTest(); + }; +} + +function runFrameEventsTest() { + frameEventsTest.step(function() { + assert_equals(orientationChangeEventListenerCallsForFrame, orientationChangeEventListenerCalls); + }); + frameEventsTest.done(); +} + +runEventVisibleTest(); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html b/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html new file mode 100644 index 000000000..760d95248 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/iframe-listen-orientation-change.html @@ -0,0 +1,6 @@ +<!DOCTYPE html> +<script> + window.screen.orientation.addEventListener('change', function() { + parent.window.postMessage(screen.orientation.type, "*"); + }); +</script> diff --git a/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html b/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html new file mode 100644 index 000000000..74dac82a5 --- /dev/null +++ b/testing/web-platform/tests/screen-orientation/resources/sandboxed-iframe-locking.html @@ -0,0 +1,18 @@ +<!DOCTYPE html> +<html> +<script> + var msg = ""; + screen.orientation.lock("portrait-primary").then(function() { + msg = screen.orientation.type; + }, function(error) { + msg = error.name; + }); + + // FIXME: for the moment, tests gets notified when there is a failure but + // not a success, this hack should allow us to still have the test running. + // That should be removed as soon as we get a resolved promise in tests. + setTimeout(function() { + parent.window.postMessage(msg, "*"); + }) +</script> +</html> |