OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <style> | |
3 body { | |
4 width: 600px; | |
5 height: 1000px; | |
6 } | |
7 </style> | |
8 <script src="../../resources/js-test.js"></script> | |
9 | |
10 <script type="text/javascript"> | |
11 var testScrolls = []; | |
12 var currentTest = -1; | |
13 | |
14 setPrintTestResultsLazily(); | |
15 jsTestIsAsync = true; | |
16 | |
17 description("Test that when the scrollLayoutViewport setting is on, the scroll " + | |
18 "from window.scrollTo is applied to the layout viewport. Note that this test is " + | |
19 "pertaining to crbug.com/489206, where we want all APIs to reflect the layou t viewport."); | |
20 | |
21 function finishTest() { | |
22 var testCase = testScrolls[currentTest]; | |
23 if(window.scrollX == testCase.expectedX && window.scrollY == testCase.expect edY) { | |
24 testPassed("Scroll destination reached."); | |
25 startNextTestCase(); | |
26 } else { | |
27 testFailed("Scroll destination not reached."); | |
28 startNextTestCase(); | |
29 } | |
30 } | |
31 | |
32 function startNextTestCase() { | |
33 currentTest++; | |
34 if (currentTest >= testScrolls.length) { | |
35 finishJSTest(); | |
36 return; | |
37 } | |
38 | |
39 var testCase = testScrolls[currentTest]; | |
40 internals.settings.setScrollLayoutViewport(testScrolls[currentTest].scrollLa youtViewport); | |
41 window.scrollTo(testCase.x, testCase.y); | |
42 window.requestAnimationFrame(finishTest); | |
43 } | |
44 | |
45 window.onload = function () { | |
46 if (!window.internals) { | |
47 testFailed('This test requires window.internals'); | |
bokan
2015/09/21 16:49:12
should you return after this?
ymalik (do not use)
2015/09/21 20:35:50
Absolutely!
| |
48 } | |
49 | |
50 internals.settings.setScrollLayoutViewport(false); | |
51 // The height of the layout viewport is innerHeight of the window when no | |
52 // pinch-zoom is applied. | |
53 var layoutInnerHeight = window.innerHeight; | |
54 // The height of the visual viewport is innerHeight of the window when | |
55 // pinch-zoom is applied. | |
56 internals.setPageScaleFactor(2.0); | |
57 var visualInnerHeight = window.innerHeight; | |
bokan
2015/09/21 16:49:12
Please also add a case for verifying the innerWidt
ymalik (do not use)
2015/09/21 20:35:49
Acknowledged.
That's fair. I was trying to follow
bokan
2015/09/21 20:59:56
Good, consistency is usually the trump card.
| |
58 | |
59 // The maximum scrollTop when the visual viewport is scrolled. | |
60 var maxScrollHeightScrollVisual = document.scrollingElement.scrollHeight - v isualInnerHeight; | |
61 // The maximum scrollTop when the layout viewport is scrolled. | |
62 var maxScrollHeightScrollLayout = document.scrollingElement.scrollHeight - l ayoutInnerHeight; | |
63 | |
64 // First scrollTo is called with the scrollLayoutViewport setting off, in wh ich | |
65 // case, window.scrollY should return the position of the visual viewport. T hen | |
66 // the setting is turned on, and this time, window.scrollY should return the | |
67 // position of the layoutViewport. | |
68 testScrolls = [ | |
69 {x: 0, y: 2000, expectedX: 0, expectedY:maxScrollHeightScrollVisual, scrol lLayoutViewport:false}, | |
bokan
2015/09/21 16:49:12
Please also test the horizontal axis
ymalik (do not use)
2015/09/21 20:35:49
Done.
| |
70 {x: 0, y: 2000, expectedX: 0, expectedY:maxScrollHeightScrollLayout, scrol lLayoutViewport:true}, | |
71 ]; | |
72 startNextTestCase(); | |
73 } | |
74 </script> | |
OLD | NEW |