1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
2 <script src=
"../../../resources/js-test.js"></script>
19 <script language=
"JavaScript" type=
"text/javascript">
20 if (window
.testRunner
&& window
.internals
) {
21 window
.internals
.setPageScaleFactorLimits(0.5, 4.0);
22 window
.jsTestIsAsync
= true;
23 testRunner
.dumpAsText();
24 testRunner
.waitUntilDone();
27 description("This test makes sure the window properties related to the\
28 viewport remain correct under pinch-to-zoom.");
30 debug('===Unscaled===');
32 shouldBe('window.innerWidth', '800');
33 shouldBe('window.innerHeight', '600');
35 function testPinchedIn() {
37 debug('===Pinch Zoom in to 2X===');
39 window
.internals
.setPageScaleFactor(2.0);
40 shouldBe('window.innerWidth', '400');
41 shouldBe('window.innerHeight', '300');
42 shouldBe('window.scrollX', '0');
43 shouldBe('window.scrollY', '0');
45 window
.scrollBy(10, 20);
46 shouldBe('window.scrollX', '10');
47 shouldBe('window.scrollY', '20');
48 window
.scrollBy(1590, 1180);
49 shouldBe('window.scrollX', '1600');
50 shouldBe('window.scrollY', '1200');
51 window
.scrollBy(-1600, -1200);
52 shouldBe('window.scrollX', '0');
53 shouldBe('window.scrollY', '0');
54 window
.scrollTo(1600, 1200);
55 shouldBe('window.scrollX', '1600');
56 shouldBe('window.scrollY', '1200');
57 window
.scrollTo(0, 0);
58 shouldBe('window.scrollX', '0');
59 shouldBe('window.scrollY', '0');
62 function testMaximallyPinchedOut() {
64 debug('===Pinch Out to 0.5X===');
66 window
.internals
.setPageScaleFactor(0.5);
67 shouldBe('window.innerWidth', '1600');
68 shouldBe('window.innerHeight', '1200');
69 shouldBe('window.scrollX', '0');
70 shouldBe('window.scrollY', '0');
72 window
.scrollBy(10, 20);
73 shouldBe('window.scrollX', '10');
74 shouldBe('window.scrollY', '20');
75 window
.scrollBy(390, 280);
76 shouldBe('window.scrollX', '400');
77 shouldBe('window.scrollY', '300');
78 window
.scrollBy(-400, -300);
79 shouldBe('window.scrollX', '0');
80 shouldBe('window.scrollY', '0');
81 window
.scrollTo(400, 300);
82 shouldBe('window.scrollX', '400');
83 shouldBe('window.scrollY', '300');
84 window
.scrollTo(0, 0);
85 shouldBe('window.scrollX', '0');
86 shouldBe('window.scrollY', '0');
89 function testOnScroll() {
91 debug('===Test OnScroll===');
93 window
.internals
.setPageScaleFactor(1.0);
94 shouldBe('window.innerWidth', '800');
95 shouldBe('window.innerHeight', '600');
96 shouldBe('window.scrollX', '0');
97 shouldBe('window.scrollY', '0');
99 // First scroll scrolls only the outer viewport.
100 // Second scrolls the outer and the inner.
101 // Third scrolls only the inner.
102 var scrolls
= [100, 400, 100];
103 var numScrollsReceived
= 0;
106 document
.onscroll = function() {
107 if (numRAFCalls
== 0)
110 ++numScrollsReceived
;
111 debug('PASS OnScroll called for scroll #' + numScrollsReceived
);
112 if (numScrollsReceived
< scrolls
.length
) {
113 var scrollAmount
= scrolls
[numScrollsReceived
];
114 window
.scrollBy(scrollAmount
, 0);
115 } else if (numScrollsReceived
== scrolls
.length
) {
116 // Make sure scrollTo that moves only the inner viewport also
117 // triggers a scroll event.
118 window
.scrollTo(1200, 0);
125 // Scroll events are fired right before RAF so this is a good place to
126 // make sure event was handled.
127 var failureSentinel = function() {
128 if (numRAFCalls
== 0) {
129 window
.scrollBy(scrolls
[0], 0);
130 }else if (numRAFCalls
> numScrollsReceived
) {
131 testFailed("Failed to receive scroll event #" + (numScrollsReceived
+1));
135 window
.requestAnimationFrame(failureSentinel
);
138 window
.requestAnimationFrame(failureSentinel
);
141 function forceLayout() {
142 window
.scrollTo(0, 0);
145 function runTests() {
146 if (window
.testRunner
&& window
.internals
) {
149 testMaximallyPinchedOut();
156 <div class=
"spacer"></div>