OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <body> |
| 4 <script src="../resources/js-test.js"></script> |
| 5 <script> |
| 6 description("Validates that orientationchange events can fired when several orie
ntations are locked."); |
| 7 window.jsTestIsAsync = true; |
| 8 |
| 9 var orientationChangeCount = 0; |
| 10 var currentTestOrientation = 0; |
| 11 var testOrientations = [ |
| 12 "portrait-secondary", |
| 13 "landscape-primary", |
| 14 "landscape-secondary", |
| 15 "portrait-primary" |
| 16 ]; |
| 17 |
| 18 function testComplete() { |
| 19 screen.unlockOrientation(); |
| 20 finishJSTest(); |
| 21 } |
| 22 |
| 23 var testEvent; |
| 24 function onOrientationChangeEvent(ev) { |
| 25 ++orientationChangeCount; |
| 26 testEvent = ev; |
| 27 if (screen.orientation != "portrait-primary" && screen.orientation != "portr
ait-secondary") { |
| 28 ++orientationChangeCount; |
| 29 testFailed("Unexpected 'orientationchange' event for " + screen.orientat
ion); |
| 30 testComplete(); |
| 31 } |
| 32 testPassed("Received an 'orientationchange' event."); |
| 33 shouldBeEqualToString("testEvent.type", "orientationchange"); |
| 34 if (orientationChangeCount == 1) { |
| 35 shouldBeEqualToString("screen.orientation", "portrait-secondary"); |
| 36 } else { |
| 37 shouldBe("orientationChangeCount", "2"); |
| 38 shouldBeEqualToString("screen.orientation", "portrait-primary"); |
| 39 testComplete(); |
| 40 } |
| 41 } |
| 42 |
| 43 function changeOrientation() { |
| 44 internals.setScreenOrientation(document, testOrientations[currentTestOrienta
tion++]); |
| 45 if (currentTestOrientation < testOrientations.length) |
| 46 setTimeout(changeOrientation, 0); |
| 47 } |
| 48 |
| 49 internals.setScreenOrientationClientMock(document); |
| 50 screen.addEventListener("orientationchange", onOrientationChangeEvent); |
| 51 |
| 52 shouldBeEqualToString("screen.orientation", "portrait-primary"); |
| 53 debug("locking orientation to 'portrait'."); |
| 54 shouldBeTrue("screen.lockOrientation('portrait')"); |
| 55 setTimeout(changeOrientation, 0); |
| 56 </script> |
| 57 </body> |
| 58 </html> |
OLD | NEW |