OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <body> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script> |
| 6 description("Validates that screen orientation can be unlocked"); |
| 7 window.jsTestIsAsync = true; |
| 8 |
| 9 var orientationChangeEventCount = 0; |
| 10 var locked = false; |
| 11 |
| 12 function checkNoOrientationChangeThenContinue() { |
| 13 shouldBeEqualToString("screen.orientation", "portrait-primary"); |
| 14 shouldBe("orientationChangeEventCount", "0"); |
| 15 debug("Unlocking orientation..."); |
| 16 locked = false; |
| 17 screen.unlockOrientation(); |
| 18 } |
| 19 |
| 20 function completeTest() { |
| 21 screen.removeEventListener("orientationchange", onOrientationChangeEvent); |
| 22 internals.setScreenOrientation(document, "portrait-primary"); |
| 23 finishJSTest(); |
| 24 } |
| 25 |
| 26 var testEvent; |
| 27 function onOrientationChangeEvent(ev) { |
| 28 ++orientationChangeEventCount; |
| 29 testEvent = ev; |
| 30 debug("Received an 'orientationchange' event."); |
| 31 shouldBeFalse('locked'); |
| 32 shouldBe("orientationChangeEventCount", "1"); |
| 33 shouldBeEqualToString("testEvent.type", "orientationchange"); |
| 34 shouldBeEqualToString("screen.orientation", "landscape-primary"); |
| 35 completeTest(); |
| 36 } |
| 37 |
| 38 function setScreenOrientationtoLandscapePrimary() { |
| 39 debug("Faking device screen orientation change to 'landscape-primary'..."); |
| 40 internals.setScreenOrientation(document, "landscape-primary"); |
| 41 setTimeout(checkNoOrientationChangeThenContinue, 0); |
| 42 } |
| 43 |
| 44 internals.setScreenOrientationClientMock(document); |
| 45 screen.addEventListener("orientationchange", onOrientationChangeEvent); |
| 46 |
| 47 shouldBeEqualToString("screen.orientation", "portrait-primary"); |
| 48 debug("locking orientation to 'portrait-primary'."); |
| 49 locked = true; |
| 50 shouldBeTrue("screen.lockOrientation('portrait-primary')"); |
| 51 // Doing this asynchronously as lockOrientation() is asynchronous. |
| 52 setTimeout(setScreenOrientationtoLandscapePrimary, 0); |
| 53 </script> |
| 54 </body> |
| 55 </html> |
OLD | NEW |