Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <script src="../../../resources/js-test.js"></script> | 2 <script src="../../../resources/js-test.js"></script> |
| 3 <style> | 3 <style> |
| 4 body { | 4 body { |
| 5 padding: 0px; | 5 padding: 0px; |
| 6 margin: 0px; | 6 margin: 0px; |
| 7 /* Overflow hidden so that the size of the scrollbar is not added to | |
| 8 the innerHeight/Width properties. */ | |
| 9 overflow: hidden; | |
| 7 } | 10 } |
| 8 | 11 |
| 9 .spacer { | 12 .spacer { |
| 10 position: absolute; | 13 position: absolute; |
| 11 left: 0px; | 14 left: 0px; |
| 12 top: 0px; | 15 top: 0px; |
| 13 margin: 0px; | 16 margin: 0px; |
| 14 padding: 0px; | 17 padding: 0px; |
| 15 width: 2000px; | 18 width: 2000px; |
| 16 height: 1500px; | 19 height: 1500px; |
| 17 } | 20 } |
| 18 </style> | 21 </style> |
| 19 <script language="JavaScript" type="text/javascript"> | 22 <script language="JavaScript" type="text/javascript"> |
| 20 if (window.testRunner && window.internals) { | 23 if (window.testRunner && window.internals) { |
| 24 // Note that the layout viewport is based on the minimum page scale. | |
| 25 // Thus, the minimum scale of 0.5 causes the layout viewport to become | |
| 26 // twice of what we would normally expect. | |
| 21 window.internals.setPageScaleFactorLimits(0.5, 4.0); | 27 window.internals.setPageScaleFactorLimits(0.5, 4.0); |
| 22 window.jsTestIsAsync = true; | 28 window.jsTestIsAsync = true; |
| 23 testRunner.dumpAsText(); | 29 testRunner.dumpAsText(); |
| 24 testRunner.waitUntilDone(); | 30 testRunner.waitUntilDone(); |
| 31 setPrintTestResultsLazily(); | |
| 25 } | 32 } |
| 26 | 33 |
| 27 description("This test makes sure the window properties related to the\ | 34 description("This test makes sure the window properties related to the\ |
| 28 viewport remain correct under pinch-to-zoom."); | 35 viewport remain correct under pinch-to-zoom."); |
| 29 | 36 |
| 30 debug('===Unscaled==='); | 37 |
| 31 debug(''); | 38 function testUnscaled () { |
| 32 shouldBe('window.innerWidth', '800'); | 39 debug('===Unscaled==='); |
|
bokan
2015/10/21 13:32:14
This is misleading since it's actually at 0.5 scal
ymalik
2015/10/21 15:14:08
Done.
| |
| 33 shouldBe('window.innerHeight', '600'); | 40 debug(''); |
| 41 shouldBe('window.innerWidth', '1600'); | |
| 42 shouldBe('window.innerHeight', '1200'); | |
| 43 shouldBe('internals.visualViewportWidth()', '1600'); | |
| 44 shouldBe('internals.visualViewportHeight()', '1200'); | |
| 45 } | |
| 46 | |
| 47 function jsScrollTo(x, y) { | |
| 48 window.scrollTo(x, y); | |
| 49 } | |
| 50 | |
| 51 function jsScrollBy(x, y) { | |
| 52 window.scrollBy(x, y); | |
| 53 } | |
| 54 | |
| 55 function testScrolls(jsScroll) { | |
| 56 // Test that the layout and visual viewport viewport scroll. | |
| 57 jsScroll(100, 200); | |
| 58 shouldBe('window.scrollX', '100'); | |
| 59 shouldBe('window.scrollY', '200'); | |
| 60 shouldBe('internals.visualViewportScrollX()', '100'); | |
| 61 shouldBe('internals.visualViewportScrollY()', '200'); | |
| 62 | |
| 63 // Test that the scroll doesn't bubble to the visual viewport. | |
| 64 jsScroll(1500, 1100); | |
| 65 shouldBe('window.scrollX', '400'); | |
| 66 shouldBe('window.scrollY', '300'); | |
| 67 shouldBe('internals.visualViewportScrollX()', '400'); | |
| 68 shouldBe('internals.visualViewportScrollY()', '300'); | |
| 69 | |
| 70 // Reset. | |
| 71 window.scrollTo(0, 0); | |
| 72 shouldBe('window.scrollX', '0'); | |
| 73 shouldBe('window.scrollY', '0'); | |
| 74 } | |
| 34 | 75 |
| 35 function testPinchedIn() { | 76 function testPinchedIn() { |
| 36 debug(''); | 77 debug(''); |
| 37 debug('===Pinch Zoom in to 2X==='); | 78 debug('===Pinch Zoom in to 2X==='); |
| 38 debug(''); | 79 debug(''); |
| 39 window.internals.setPageScaleFactor(2.0); | 80 window.internals.setPageScaleFactor(2.0); |
| 40 shouldBe('window.innerWidth', '400'); | 81 // Test that the innerWidth, innerHeight, scrollX, scrollY are relative |
| 41 shouldBe('window.innerHeight', '300'); | 82 // to the layout viewport after page scale. |
| 83 shouldBe('window.innerWidth', '1600'); | |
| 84 shouldBe('window.innerHeight', '1200'); | |
| 42 shouldBe('window.scrollX', '0'); | 85 shouldBe('window.scrollX', '0'); |
| 43 shouldBe('window.scrollY', '0'); | 86 shouldBe('window.scrollY', '0'); |
| 44 | 87 |
| 45 window.scrollBy(10, 20); | 88 // Test that the visual viewport size changes after page scale. |
| 46 shouldBe('window.scrollX', '10'); | 89 shouldBe('internals.visualViewportWidth()', '400'); |
| 47 shouldBe('window.scrollY', '20'); | 90 shouldBe('internals.visualViewportHeight()', '300'); |
| 48 window.scrollBy(1590, 1180); | 91 |
| 49 shouldBe('window.scrollX', '1600'); | 92 debug('===ScrollBy==='); |
| 50 shouldBe('window.scrollY', '1200'); | 93 testScrolls(jsScrollBy); |
| 51 window.scrollBy(-1600, -1200); | 94 debug('===ScrollTo==='); |
| 52 shouldBe('window.scrollX', '0'); | 95 testScrolls(jsScrollTo); |
| 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'); | |
| 60 } | 96 } |
| 61 | 97 |
| 62 function testMaximallyPinchedOut() { | 98 function testMaximallyPinchedOut() { |
| 63 debug(''); | 99 debug(''); |
| 64 debug('===Pinch Out to 0.5X==='); | 100 debug('===Pinch Out to 0.5X==='); |
| 65 debug(''); | 101 debug(''); |
| 66 window.internals.setPageScaleFactor(0.5); | 102 window.internals.setPageScaleFactor(0.5); |
| 67 shouldBe('window.innerWidth', '1600'); | 103 shouldBe('window.innerWidth', '1600'); |
| 68 shouldBe('window.innerHeight', '1200'); | 104 shouldBe('window.innerHeight', '1200'); |
| 69 shouldBe('window.scrollX', '0'); | 105 shouldBe('window.scrollX', '0'); |
| 70 shouldBe('window.scrollY', '0'); | 106 shouldBe('window.scrollY', '0'); |
| 107 shouldBe('internals.visualViewportWidth()', '1600'); | |
| 108 shouldBe('internals.visualViewportHeight()', '1200'); | |
| 71 | 109 |
| 72 window.scrollBy(10, 20); | 110 debug('===ScrollBy==='); |
| 73 shouldBe('window.scrollX', '10'); | 111 testScrolls(jsScrollBy); |
| 74 shouldBe('window.scrollY', '20'); | 112 debug('===ScrollTo==='); |
| 75 window.scrollBy(390, 280); | 113 testScrolls(jsScrollTo); |
| 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'); | |
| 87 } | 114 } |
| 88 | 115 |
| 89 function testOnScroll() { | 116 function testOnScroll() { |
| 90 debug(''); | 117 debug(''); |
| 91 debug('===Test OnScroll==='); | 118 debug('===Test OnScroll==='); |
| 92 debug(''); | 119 debug(''); |
| 93 window.internals.setPageScaleFactor(1.0); | 120 window.internals.setPageScaleFactor(1.0); |
| 94 shouldBe('window.innerWidth', '800'); | 121 shouldBe('window.innerWidth', '1600'); |
| 95 shouldBe('window.innerHeight', '600'); | 122 shouldBe('window.innerHeight', '1200'); |
| 96 shouldBe('window.scrollX', '0'); | 123 shouldBe('window.scrollX', '0'); |
| 97 shouldBe('window.scrollY', '0'); | 124 shouldBe('window.scrollY', '0'); |
| 98 | 125 |
| 99 // First scroll scrolls only the outer viewport. | 126 // First scroll scrolls the layout viewport fully. This should trigger |
| 100 // Second scrolls the outer and the inner. | 127 // a call to onscroll. The second scroll attempts to scroll a fully |
| 101 // Third scrolls only the inner. | 128 // scrolled page and should not trigger onscroll. |
| 102 var scrolls = [100, 400, 100]; | 129 var scrolls = [400, 100]; |
| 103 var numScrollsReceived = 0; | 130 var numScrollsReceived = 0; |
| 104 var numRAFCalls = 0; | 131 var numRAFCalls = 0; |
| 105 | 132 |
| 106 document.onscroll = function() { | 133 document.onscroll = function() { |
| 107 if (numRAFCalls == 0) | 134 if (numRAFCalls == 0) |
| 108 return; | 135 return; |
| 109 | 136 |
| 110 ++numScrollsReceived; | 137 ++numScrollsReceived; |
| 111 debug('PASS OnScroll called for scroll #' + numScrollsReceived); | 138 debug('PASS OnScroll called for scroll #' + numScrollsReceived); |
| 112 if (numScrollsReceived < scrolls.length) { | 139 if (numScrollsReceived < scrolls.length) { |
| 113 var scrollAmount = scrolls[numScrollsReceived]; | 140 var scrollAmount = scrolls[numScrollsReceived]; |
| 114 window.scrollBy(scrollAmount, 0); | 141 window.scrollBy(scrollAmount, 0); |
| 115 } else if (numScrollsReceived == scrolls.length) { | 142 } else if (numScrollsReceived == scrolls.length) { |
| 116 // Make sure scrollTo that moves only the inner viewport also | 143 testFailed("Received visual viewport scroll event"); |
|
bokan
2015/10/21 13:32:14
The failure message is wrong (and success message
ymalik
2015/10/21 15:14:08
Done.
| |
| 117 // triggers a scroll event. | 144 finishJSTest(); |
| 118 window.scrollTo(1200, 0); | |
| 119 } else { | 145 } else { |
| 120 debug(''); | 146 debug(''); |
| 121 finishJSTest(); | 147 finishJSTest(); |
| 122 } | 148 } |
| 123 } | 149 } |
| 124 | 150 |
| 125 // Scroll events are fired right before RAF so this is a good place to | 151 // Scroll events are fired right before RAF so this is a good place to |
| 126 // make sure event was handled. | 152 // make sure event was handled. |
| 127 var failureSentinel = function() { | 153 var failureSentinel = function() { |
| 128 if (numRAFCalls == 0) { | 154 if (numRAFCalls == 0) { |
| 129 window.scrollBy(scrolls[0], 0); | 155 window.scrollBy(scrolls[0], 0); |
|
bokan
2015/10/21 13:32:14
On second thought, this has nothing to do with pag
ymalik
2015/10/21 15:14:08
Removed test.
| |
| 130 }else if (numRAFCalls > numScrollsReceived) { | 156 } else if (numRAFCalls == scrolls.length && numScrollsReceived < num RAFCalls) { |
| 131 testFailed("Failed to receive scroll event #" + (numScrollsRecei ved+1)); | 157 testPassed("Did not receive visual viewport scroll event"); |
| 158 debug(''); | |
| 159 finishJSTest(); | |
| 160 } else if (numRAFCalls > numScrollsReceived) { | |
| 161 testFailed("Did not receive scroll event #" + (numScrollsReceive d+1)); | |
| 132 finishJSTest(); | 162 finishJSTest(); |
| 133 } | 163 } |
| 134 ++numRAFCalls; | 164 ++numRAFCalls; |
| 135 window.requestAnimationFrame(failureSentinel); | 165 window.requestAnimationFrame(failureSentinel); |
| 136 } | 166 } |
| 137 | 167 |
| 138 window.requestAnimationFrame(failureSentinel); | 168 window.requestAnimationFrame(failureSentinel); |
| 139 } | 169 } |
| 140 | 170 |
| 141 function forceLayout() { | 171 function forceLayout() { |
| 142 window.scrollTo(0, 0); | 172 window.scrollX; |
| 143 } | 173 } |
| 144 | 174 |
| 145 function runTests() { | 175 function runTests() { |
| 146 if (window.testRunner && window.internals) { | 176 if (window.testRunner && window.internals) { |
| 177 // TODO(ymalik): The call to setPageScaleFactorLimits should force | |
| 178 // layout. Fix that instead of forcing layout here. | |
| 147 forceLayout(); | 179 forceLayout(); |
| 180 testUnscaled(); | |
| 148 testPinchedIn(); | 181 testPinchedIn(); |
| 149 testMaximallyPinchedOut(); | 182 testMaximallyPinchedOut(); |
| 150 testOnScroll(); | 183 testOnScroll(); |
| 151 } | 184 } |
| 152 } | 185 } |
| 153 | 186 |
| 154 onload = runTests; | 187 onload = runTests; |
| 155 </script> | 188 </script> |
| 156 <div class="spacer"></div> | 189 <div class="spacer"></div> |
| OLD | NEW |