OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <style> | 2 <style> |
3 ::-webkit-scrollbar { | 3 ::-webkit-scrollbar { |
4 width: 0px; | 4 width: 0px; |
5 height: 0px; | 5 height: 0px; |
6 } | 6 } |
7 | 7 |
8 body, html { | 8 body, html { |
9 width: 100%; | 9 width: 100%; |
10 height: 100%; | 10 height: 100%; |
11 } | 11 } |
12 | 12 |
13 body { | 13 body { |
14 margin: 0px; | 14 margin: 0px; |
15 } | 15 } |
16 | 16 |
17 #container { | 17 #container { |
18 width: 1000px; | 18 width: 100%; |
19 height: 1000px; | 19 height: 100%; |
20 overflow: auto; | 20 overflow: auto; |
21 } | 21 } |
22 | 22 |
23 #spacer { | 23 #spacer { |
24 width: 2000px; | 24 width: 2000px; |
25 height: 1900px; | 25 height: 2000px; |
| 26 } |
| 27 |
| 28 #rootspacer { |
| 29 width: 1000px; |
| 30 height: 1000px; |
| 31 position: absolute; |
| 32 top: 0px; |
| 33 left: 0px; |
| 34 z-index: -1; |
26 } | 35 } |
27 </style> | 36 </style> |
28 | 37 |
29 <div id="container"> | 38 <div id="container"> |
30 <div id="spacer"> | 39 <div id="spacer"> |
31 <span id="spanner">TEST</span> | 40 <span id="spanner">TEST</span> |
32 </div> | 41 </div> |
33 </div> | 42 </div> |
| 43 <div id="rootspacer"></div> |
34 | 44 |
35 <script src="../../resources/testharness.js"></script> | 45 <script src="../../resources/testharness.js"></script> |
36 <script src="../../resources/testharnessreport.js"></script> | 46 <script src="../../resources/testharnessreport.js"></script> |
37 | 47 |
38 <script> | 48 <script> |
39 test(function() { | 49 test(function() { |
40 assert_false(typeof document.setRootScroller === 'undefined'); | 50 assert_false(typeof document.rootScroller === 'undefined'); |
41 }, 'setRootScroller API enabled'); | 51 }, 'setRootScroller API enabled'); |
| 52 |
| 53 // TODO(bokan): Break this test up, failing asserts are hard to find. |
42 test(function() { | 54 test(function() { |
43 // Setting the container object should succeed. | 55 // Setting the container object should succeed. |
44 assert_equals(document.rootScroller, document.documentElement); | 56 assert_equals(document.rootScroller, null); |
45 var container = document.querySelector('#container'); | 57 var container = document.querySelector('#container'); |
46 document.setRootScroller(container); | 58 document.rootScroller = container; |
47 assert_equals(document.rootScroller, container); | 59 assert_equals(document.rootScroller, container); |
48 | 60 |
49 // Trying to set the <span> should fail with an exception thrown since a | 61 // Trying to set the <span> should succeed even though it's not a valid |
50 // span is not a valid scroller. | 62 // scroller. |
51 assert_throws( | 63 var spanner = document.querySelector('#spanner'); |
52 'InvalidStateError', | 64 document.rootScroller = spanner; |
53 function() { | 65 assert_equals(document.rootScroller, spanner); |
54 document.setRootScroller(document.querySelector('#spanner')); | |
55 }, | |
56 'Trying to set a non-block flow element should throw'); | |
57 assert_equals(document.rootScroller, container); | |
58 | 66 |
59 // Scroll the container <div> past the end. The scrolls should not chain | 67 // Scroll the container <div> past the end. The scrolls should not chain |
60 // past the rootScroller to the scrollingElement. | 68 // past the rootScroller to the scrollingElement. |
| 69 document.rootScroller = container; |
61 if (typeof eventSender !== 'undefined') { | 70 if (typeof eventSender !== 'undefined') { |
62 eventSender.gestureScrollBegin(500, 500); | 71 eventSender.gestureScrollBegin(500, 500); |
63 eventSender.gestureScrollUpdate(-300, -300); | 72 eventSender.gestureScrollUpdate(-300, -300); |
64 eventSender.gestureScrollEnd(0, 0); | 73 eventSender.gestureScrollEnd(0, 0); |
65 eventSender.gestureScrollBegin(500, 500); | 74 eventSender.gestureScrollBegin(500, 500); |
66 eventSender.gestureScrollUpdate(-300, -300); | 75 eventSender.gestureScrollUpdate(-300, -300); |
67 eventSender.gestureScrollEnd(0, 0); | 76 eventSender.gestureScrollEnd(0, 0); |
68 eventSender.gestureScrollBegin(500, 500); | 77 eventSender.gestureScrollBegin(500, 500); |
69 eventSender.gestureScrollUpdate(-300, -300); | 78 eventSender.gestureScrollUpdate(-300, -300); |
70 eventSender.gestureScrollEnd(0, 0); | 79 eventSender.gestureScrollEnd(0, 0); |
71 eventSender.gestureScrollBegin(500, 500); | 80 eventSender.gestureScrollBegin(500, 500); |
72 eventSender.gestureScrollUpdate(-300, -300); | 81 eventSender.gestureScrollUpdate(-300, -300); |
| 82 eventSender.gestureScrollUpdate(-300, -300); |
| 83 eventSender.gestureScrollUpdate(-300, -300); |
73 eventSender.gestureScrollEnd(0, 0); | 84 eventSender.gestureScrollEnd(0, 0); |
74 | 85 |
75 assert_equals(container.scrollTop, 900); | 86 assert_equals(container.scrollTop, 2000 - 600); |
76 assert_equals(container.scrollLeft, 1000); | 87 assert_equals(container.scrollLeft, 2000 - 800); |
77 assert_equals(document.scrollingElement.scrollTop, 0); | 88 assert_equals(document.scrollingElement.scrollTop, 0); |
78 assert_equals(document.scrollingElement.scrollLeft, 0); | 89 assert_equals(document.scrollingElement.scrollLeft, 0); |
79 } | 90 } |
80 | 91 |
81 // Making the current rootScroller an invalid scroller should reset the | 92 // Making the current rootScroller an invalid scroller should fallback to |
82 // rootScroller to the default, the documentElement. | 93 // the default element, the documentElement, but the rootScroller property |
83 container.style.display = "none"; | 94 // should remain the same. |
84 newRootScroller = document.rootScroller; | 95 container.style.width = "95%"; |
85 assert_equals(newRootScroller, document.documentElement); | 96 assert_equals(document.rootScroller, container); |
86 | 97 |
87 container.style.display = "block"; | 98 // Now scrolling over the <div> should scroll the scrollingElement since the |
88 assert_equals(newRootScroller, document.documentElement); | 99 // rootElement is invalid (doesn't fill the viewport). |
89 | |
90 // Now scrolling over the <div> should scroll the scrollingElement. | |
91 if (typeof eventSender !== 'undefined') { | 100 if (typeof eventSender !== 'undefined') { |
92 eventSender.gestureScrollBegin(500, 500); | 101 eventSender.gestureScrollBegin(500, 500); |
93 eventSender.gestureScrollUpdate(-300, -300); | 102 eventSender.gestureScrollUpdate(-300, -300); |
94 eventSender.gestureScrollEnd(0, 0); | 103 eventSender.gestureScrollEnd(0, 0); |
95 eventSender.gestureScrollBegin(500, 500); | 104 eventSender.gestureScrollBegin(500, 500); |
96 eventSender.gestureScrollUpdate(-300, -300); | 105 eventSender.gestureScrollUpdate(-300, -300); |
97 eventSender.gestureScrollEnd(0, 0); | 106 eventSender.gestureScrollEnd(0, 0); |
98 eventSender.gestureScrollBegin(500, 500); | 107 eventSender.gestureScrollBegin(500, 500); |
99 eventSender.gestureScrollUpdate(-300, -300); | 108 eventSender.gestureScrollUpdate(-300, -300); |
100 eventSender.gestureScrollEnd(0, 0); | 109 eventSender.gestureScrollEnd(0, 0); |
101 eventSender.gestureScrollBegin(500, 500); | 110 eventSender.gestureScrollBegin(500, 500); |
102 eventSender.gestureScrollUpdate(-300, -300); | 111 eventSender.gestureScrollUpdate(-300, -300); |
103 eventSender.gestureScrollEnd(0, 0); | 112 eventSender.gestureScrollEnd(0, 0); |
104 | 113 |
105 assert_equals(document.scrollingElement.scrollTop, 400); | 114 assert_equals(document.scrollingElement.scrollTop, 400); |
106 assert_equals(document.scrollingElement.scrollLeft, 200); | 115 assert_equals(document.scrollingElement.scrollLeft, 200); |
107 } | 116 } |
108 | 117 |
109 // Don't output the text in spanner. | 118 // Don't output the text in spanner. |
110 document.querySelector('#spanner').style.display = 'none'; | 119 document.querySelector('#spanner').style.display = 'none'; |
111 | 120 |
112 }, 'Test the setRootScroller API basic functionality'); | 121 }, 'Test the setRootScroller API basic functionality'); |
113 </script> | 122 </script> |
OLD | NEW |