| OLD | NEW | 
 | (Empty) | 
|   1 <!DOCTYPE html> |  | 
|   2 <html> |  | 
|   3 <body> |  | 
|   4 <script src="../../../resources/testharness.js"></script> |  | 
|   5 <script src="../../../resources/testharnessreport.js"></script> |  | 
|   6 <script> |  | 
|   7  |  | 
|   8 var changeTest = async_test("Test that orientationchange event is fired when the
     orientation changes."); |  | 
|   9 var noChangeTest = async_test("Test that orientationchange event is not fired wh
    en the orientation does not change."); |  | 
|  10  |  | 
|  11 var orientations = [ |  | 
|  12   'portrait-primary', |  | 
|  13   'portrait-secondary', |  | 
|  14   'landscape-primary', |  | 
|  15   'landscape-secondary' |  | 
|  16 ]; |  | 
|  17  |  | 
|  18 var currentIndex = orientations.indexOf(window.screen.orientation.type); |  | 
|  19 // Count the number of calls received from the EventHandler set on screen.orient
    ation.onchange. |  | 
|  20 var orientationChangeEventHandlerCalls = 0; |  | 
|  21 // Count the number of calls received from the listener set with screen.orientat
    ion.addEventListene(). |  | 
|  22 var orientationChangeEventListenerCalls = 0; |  | 
|  23  |  | 
|  24 var orientationChangeContinuation = null; |  | 
|  25  |  | 
|  26 function getNextIndex() { |  | 
|  27   return (currentIndex + 1) % orientations.length; |  | 
|  28 } |  | 
|  29  |  | 
|  30 window.screen.orientation.onchange = function() { |  | 
|  31   orientationChangeEventHandlerCalls++; |  | 
|  32   if (orientationChangeEventContinuation) { |  | 
|  33     setTimeout(orientationChangeEventContinuation); |  | 
|  34     orientationChangeEventContinuation = null; |  | 
|  35   } |  | 
|  36 }; |  | 
|  37  |  | 
|  38 window.screen.orientation.addEventListener('change', function() { |  | 
|  39   orientationChangeEventListenerCalls++; |  | 
|  40 }); |  | 
|  41  |  | 
|  42 function runNoChangeTest() { |  | 
|  43   screen.orientation.lock(orientations[currentIndex]).then(function() {}, functi
    on() {}); |  | 
|  44  |  | 
|  45   noChangeTest.step(function() { |  | 
|  46     assert_equals(screen.orientation.type, orientations[currentIndex]); |  | 
|  47     assert_equals(orientationChangeEventHandlerCalls, orientations.length); |  | 
|  48     assert_equals(orientationChangeEventListenerCalls, orientations.length); |  | 
|  49   }); |  | 
|  50  |  | 
|  51   noChangeTest.done(); |  | 
|  52 } |  | 
|  53  |  | 
|  54 var i = 0; |  | 
|  55 function runChangeTest() { |  | 
|  56   screen.orientation.lock(orientations[getNextIndex()]).then(function() {}, func
    tion() {}); |  | 
|  57   currentIndex = getNextIndex(); |  | 
|  58  |  | 
|  59   orientationChangeEventContinuation = function() { |  | 
|  60     changeTest.step(function() { |  | 
|  61       assert_equals(screen.orientation.type, orientations[currentIndex]); |  | 
|  62       assert_equals(orientationChangeEventHandlerCalls, i + 1); |  | 
|  63       assert_equals(orientationChangeEventListenerCalls, i + 1); |  | 
|  64     }); |  | 
|  65  |  | 
|  66     ++i; |  | 
|  67     if (i == orientations.length) { |  | 
|  68       changeTest.done(); |  | 
|  69       runNoChangeTest(); |  | 
|  70     } else { |  | 
|  71       runChangeTest(); |  | 
|  72     } |  | 
|  73   }; |  | 
|  74 } |  | 
|  75  |  | 
|  76 runChangeTest(); |  | 
|  77  |  | 
|  78 </script> |  | 
|  79 </body> |  | 
|  80 </html> |  | 
| OLD | NEW |