Index: LayoutTests/screen_orientation/orientationchange-event.html |
diff --git a/LayoutTests/screen_orientation/orientationchange-event.html b/LayoutTests/screen_orientation/orientationchange-event.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..54d387f6bafd57bba3d049a38888268b11bfade6 |
--- /dev/null |
+++ b/LayoutTests/screen_orientation/orientationchange-event.html |
@@ -0,0 +1,62 @@ |
+<!DOCTYPE html> |
+<html> |
+<body> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script> |
+ |
+var orientations = [ |
+ 'portrait-primary', |
+ 'portrait-secondary', |
+ 'landscape-primary', |
+ 'landscape-secondary' |
+]; |
+ |
+var currentIndex = orientations.indexOf(window.screen.orientation); |
+// Count the number of calls received from the EventHandler set on window.onorientationchange. |
+var orientationChangeEventHandlerCalls = 0; |
+// Count the number of calls received from the listener set with window.addEventListene(). |
+var orientationChangeEventListenerCalls = 0; |
+ |
+// TODO: window.onorientationchange is enabled on Android only. We will enable |
+// it with ScreenOrientation later, at which point this test will fail. We will |
+// then have to fix it. |
+function todo_equals(actual, expected) { |
+ assert_not_equals(actual, expected, "TODO: if this fails, it means that something got fixed."); |
+} |
+ |
+function getNextIndex() { |
+ return (currentIndex + 1) % orientations.length; |
+} |
+ |
+window.onorientationchange = function() { |
+ orientationChangeEventHandlerCalls++; |
+}; |
+ |
+window.addEventListener('orientationchange', function() { |
+ orientationChangeEventListenerCalls++; |
+}); |
+ |
+for (var i = 0; i < 4; ++i) { |
+ test(function() { |
+ window.testRunner.setMockScreenOrientation(orientations[getNextIndex()]); |
+ |
+ currentIndex = getNextIndex(); |
+ assert_equals(screen.orientation, orientations[currentIndex]); |
+ |
+ todo_equals(orientationChangeEventHandlerCalls, i + 1); |
+ assert_equals(orientationChangeEventListenerCalls, i + 1); |
+ }, "Test that orientationchange event is fired when the orientation changes"); |
+} |
+ |
+test(function() { |
+ window.testRunner.setMockScreenOrientation(orientations[currentIndex]); |
+ assert_equals(screen.orientation, orientations[currentIndex]); |
+ |
+ todo_equals(orientationChangeEventHandlerCalls, 4); |
+ assert_equals(orientationChangeEventListenerCalls, 4); |
+}, "Test that orientationchange event is not fired when the orientation does not change"); |
+ |
+</script> |
+</body> |
+</html> |