OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2015 Google Inc. All rights reserved. | 2 * Copyright (C) 2015 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 #include "core/frame/TopControls.h" | 30 #include "core/frame/BrowserControls.h" |
31 | 31 |
32 #include "core/dom/ClientRect.h" | 32 #include "core/dom/ClientRect.h" |
33 #include "core/frame/FrameHost.h" | 33 #include "core/frame/FrameHost.h" |
34 #include "core/frame/FrameView.h" | 34 #include "core/frame/FrameView.h" |
35 #include "core/frame/LocalFrame.h" | 35 #include "core/frame/LocalFrame.h" |
36 #include "core/frame/VisualViewport.h" | 36 #include "core/frame/VisualViewport.h" |
37 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
38 #include "platform/testing/URLTestHelpers.h" | 38 #include "platform/testing/URLTestHelpers.h" |
39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
40 #include "public/platform/WebURLLoaderMockFactory.h" | 40 #include "public/platform/WebURLLoaderMockFactory.h" |
41 #include "public/web/WebCache.h" | 41 #include "public/web/WebCache.h" |
42 #include "public/web/WebElement.h" | 42 #include "public/web/WebElement.h" |
43 #include "public/web/WebSettings.h" | 43 #include "public/web/WebSettings.h" |
44 #include "testing/gmock/include/gmock/gmock.h" | 44 #include "testing/gmock/include/gmock/gmock.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
46 #include "web/WebLocalFrameImpl.h" | 46 #include "web/WebLocalFrameImpl.h" |
47 #include "web/tests/FrameTestHelpers.h" | 47 #include "web/tests/FrameTestHelpers.h" |
48 | 48 |
49 namespace blink { | 49 namespace blink { |
50 | 50 |
51 // These tests cover top controls scrolling on main-thread. | 51 // These tests cover browser controls scrolling on main-thread. |
52 // The animation for completing a partial show/hide is done in compositor so | 52 // The animation for completing a partial show/hide is done in compositor so |
53 // it is not covered here. | 53 // it is not covered here. |
54 class TopControlsTest : public testing::Test { | 54 class BrowserControlsTest : public testing::Test { |
55 public: | 55 public: |
56 TopControlsTest() : m_baseURL("http://www.test.com/") { | 56 BrowserControlsTest() : m_baseURL("http://www.test.com/") { |
57 registerMockedHttpURLLoad("large-div.html"); | 57 registerMockedHttpURLLoad("large-div.html"); |
58 registerMockedHttpURLLoad("overflow-scrolling.html"); | 58 registerMockedHttpURLLoad("overflow-scrolling.html"); |
59 registerMockedHttpURLLoad("iframe-scrolling.html"); | 59 registerMockedHttpURLLoad("iframe-scrolling.html"); |
60 registerMockedHttpURLLoad("iframe-scrolling-inner.html"); | 60 registerMockedHttpURLLoad("iframe-scrolling-inner.html"); |
61 registerMockedHttpURLLoad("percent-height.html"); | 61 registerMockedHttpURLLoad("percent-height.html"); |
62 registerMockedHttpURLLoad("vh-height.html"); | 62 registerMockedHttpURLLoad("vh-height.html"); |
63 registerMockedHttpURLLoad("vh-height-width-800.html"); | 63 registerMockedHttpURLLoad("vh-height-width-800.html"); |
64 registerMockedHttpURLLoad("vh-height-width-800-extra-wide.html"); | 64 registerMockedHttpURLLoad("vh-height-width-800-extra-wide.html"); |
65 } | 65 } |
66 | 66 |
67 ~TopControlsTest() override { | 67 ~BrowserControlsTest() override { |
68 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); | 68 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); |
69 WebCache::clear(); | 69 WebCache::clear(); |
70 } | 70 } |
71 | 71 |
72 WebViewImpl* initialize(const std::string& pageName = "large-div.html") { | 72 WebViewImpl* initialize(const std::string& pageName = "large-div.html") { |
73 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); | 73 RuntimeEnabledFeatures::setInertTopControlsEnabled(true); |
74 | 74 |
75 // Load a page with large body and set viewport size to 400x400 to ensure | 75 // Load a page with large body and set viewport size to 400x400 to ensure |
76 // main frame is scrollable. | 76 // main frame is scrollable. |
77 m_helper.initializeAndLoad(m_baseURL + pageName, true, nullptr, nullptr, | 77 m_helper.initializeAndLoad(m_baseURL + pageName, true, nullptr, nullptr, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 }; | 141 }; |
142 | 142 |
143 #define EXPECT_SIZE_EQ(expected, actual) \ | 143 #define EXPECT_SIZE_EQ(expected, actual) \ |
144 do { \ | 144 do { \ |
145 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ | 145 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ |
146 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ | 146 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ |
147 } while (false) | 147 } while (false) |
148 | 148 |
149 // Disable these tests on Mac OSX until further investigation. | 149 // Disable these tests on Mac OSX until further investigation. |
150 // Local build on Mac is OK but the bot fails. This is not an issue as | 150 // Local build on Mac is OK but the bot fails. This is not an issue as |
151 // Top Controls are currently only used on Android. | 151 // Browser Controls are currently only used on Android. |
152 #if OS(MACOSX) | 152 #if OS(MACOSX) |
153 #define MAYBE(test) DISABLED_##test | 153 #define MAYBE(test) DISABLED_##test |
154 #else | 154 #else |
155 #define MAYBE(test) test | 155 #define MAYBE(test) test |
156 #endif | 156 #endif |
157 | 157 |
158 // Scrolling down should hide top controls. | 158 // Scrolling down should hide browser controls. |
159 TEST_F(TopControlsTest, MAYBE(HideOnScrollDown)) { | 159 TEST_F(BrowserControlsTest, MAYBE(HideOnScrollDown)) { |
160 WebViewImpl* webView = initialize(); | 160 WebViewImpl* webView = initialize(); |
161 // initialize top controls to be shown. | 161 // initialize browser controls to be shown. |
162 webView->resizeWithTopControls(webView->size(), 50.f, true); | 162 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
163 webView->topControls().setShownRatio(1); | 163 webView->browserControls().setShownRatio(1); |
164 | 164 |
165 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 165 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
166 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 166 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
167 | 167 |
168 // Top controls should be scrolled partially and page should not scroll. | 168 // Browser controls should be scrolled partially and page should not scroll. |
169 webView->handleInputEvent( | 169 webView->handleInputEvent( |
170 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f)); | 170 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f)); |
171 EXPECT_FLOAT_EQ(25.f, webView->topControls().contentOffset()); | 171 EXPECT_FLOAT_EQ(25.f, webView->browserControls().contentOffset()); |
172 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); | 172 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); |
173 | 173 |
174 // Top controls should consume 25px and become hidden. Excess scroll should be | 174 // Browser controls should consume 25px and become hidden. Excess scroll |
| 175 // should be |
175 // consumed by the page. | 176 // consumed by the page. |
176 webView->handleInputEvent( | 177 webView->handleInputEvent( |
177 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); | 178 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); |
178 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 179 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
179 EXPECT_SIZE_EQ(ScrollOffset(0, 15), frame()->view()->scrollOffset()); | 180 EXPECT_SIZE_EQ(ScrollOffset(0, 15), frame()->view()->scrollOffset()); |
180 | 181 |
181 // Only page should consume scroll | 182 // Only page should consume scroll |
182 webView->handleInputEvent( | 183 webView->handleInputEvent( |
183 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); | 184 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); |
184 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 185 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
185 EXPECT_SIZE_EQ(ScrollOffset(0, 35), frame()->view()->scrollOffset()); | 186 EXPECT_SIZE_EQ(ScrollOffset(0, 35), frame()->view()->scrollOffset()); |
186 } | 187 } |
187 | 188 |
188 // Scrolling up should show top controls. | 189 // Scrolling up should show browser controls. |
189 TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp)) { | 190 TEST_F(BrowserControlsTest, MAYBE(ShowOnScrollUp)) { |
190 WebViewImpl* webView = initialize(); | 191 WebViewImpl* webView = initialize(); |
191 // initialize top controls to be hidden. | 192 // initialize browser controls to be hidden. |
192 webView->resizeWithTopControls(webView->size(), 50.f, false); | 193 webView->resizeWithBrowserControls(webView->size(), 50.f, false); |
193 webView->topControls().setShownRatio(0); | 194 webView->browserControls().setShownRatio(0); |
194 | 195 |
195 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 196 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
196 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 197 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
197 | 198 |
198 webView->handleInputEvent( | 199 webView->handleInputEvent( |
199 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); | 200 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); |
200 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); | 201 EXPECT_FLOAT_EQ(10.f, webView->browserControls().contentOffset()); |
201 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); | 202 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); |
202 | 203 |
203 webView->handleInputEvent( | 204 webView->handleInputEvent( |
204 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); | 205 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); |
205 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 206 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
206 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); | 207 EXPECT_SIZE_EQ(ScrollOffset(0, 0), frame()->view()->scrollOffset()); |
207 } | 208 } |
208 | 209 |
209 // Scrolling up after previous scroll downs should cause top controls to be | 210 // Scrolling up after previous scroll downs should cause browser controls to be |
210 // shown only after all previously scrolled down amount is compensated. | 211 // shown only after all previously scrolled down amount is compensated. |
211 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp)) { | 212 TEST_F(BrowserControlsTest, MAYBE(ScrollDownThenUp)) { |
212 WebViewImpl* webView = initialize(); | 213 WebViewImpl* webView = initialize(); |
213 // initialize top controls to be shown and position page at 100px. | 214 // initialize browser controls to be shown and position page at 100px. |
214 webView->resizeWithTopControls(webView->size(), 50.f, true); | 215 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
215 webView->topControls().setShownRatio(1); | 216 webView->browserControls().setShownRatio(1); |
216 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), | 217 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), |
217 ProgrammaticScroll); | 218 ProgrammaticScroll); |
218 | 219 |
219 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 220 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
220 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 221 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
221 | 222 |
222 // Scroll down to completely hide top controls. Excess deltaY (100px) should | 223 // Scroll down to completely hide browser controls. Excess deltaY (100px) |
223 // be consumed by the page. | 224 // should be consumed by the page. |
224 webView->handleInputEvent( | 225 webView->handleInputEvent( |
225 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f)); | 226 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f)); |
226 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 227 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
227 EXPECT_SIZE_EQ(ScrollOffset(0, 200), frame()->view()->scrollOffset()); | 228 EXPECT_SIZE_EQ(ScrollOffset(0, 200), frame()->view()->scrollOffset()); |
228 | 229 |
229 // Scroll up and ensure the top controls does not move until we recover 100px | 230 // Scroll up and ensure the browser controls does not move until we recover |
230 // previously scrolled. | 231 // 100px previously scrolled. |
231 webView->handleInputEvent( | 232 webView->handleInputEvent( |
232 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 40.f)); | 233 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 40.f)); |
233 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 234 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
234 EXPECT_SIZE_EQ(ScrollOffset(0, 160), frame()->view()->scrollOffset()); | 235 EXPECT_SIZE_EQ(ScrollOffset(0, 160), frame()->view()->scrollOffset()); |
235 | 236 |
236 webView->handleInputEvent( | 237 webView->handleInputEvent( |
237 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 60.f)); | 238 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 60.f)); |
238 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 239 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
239 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); | 240 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); |
240 | 241 |
241 // Now we have hit the threshold so further scroll up should be consumed by | 242 // Now we have hit the threshold so further scroll up should be consumed by |
242 // top controls. | 243 // browser controls. |
243 webView->handleInputEvent( | 244 webView->handleInputEvent( |
244 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 30.f)); | 245 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 30.f)); |
245 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); | 246 EXPECT_FLOAT_EQ(30.f, webView->browserControls().contentOffset()); |
246 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); | 247 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); |
247 | 248 |
248 // Once top control is fully shown then page should consume any excess scroll. | 249 // Once top control is fully shown then page should consume any excess scroll. |
249 webView->handleInputEvent( | 250 webView->handleInputEvent( |
250 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 70.f)); | 251 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 70.f)); |
251 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 252 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
252 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 253 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
253 } | 254 } |
254 | 255 |
255 // Scrolling down should always cause visible top controls to start hiding even | 256 // Scrolling down should always cause visible browser controls to start hiding |
256 // if we have been scrolling up previously. | 257 // even if we have been scrolling up previously. |
257 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown)) { | 258 TEST_F(BrowserControlsTest, MAYBE(ScrollUpThenDown)) { |
258 WebViewImpl* webView = initialize(); | 259 WebViewImpl* webView = initialize(); |
259 // initialize top controls to be hidden and position page at 100px. | 260 // initialize browser controls to be hidden and position page at 100px. |
260 webView->resizeWithTopControls(webView->size(), 50.f, false); | 261 webView->resizeWithBrowserControls(webView->size(), 50.f, false); |
261 webView->topControls().setShownRatio(0); | 262 webView->browserControls().setShownRatio(0); |
262 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), | 263 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), |
263 ProgrammaticScroll); | 264 ProgrammaticScroll); |
264 | 265 |
265 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 266 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
266 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 267 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
267 | 268 |
268 // Scroll up to completely show top controls. Excess deltaY (50px) should be | 269 // Scroll up to completely show browser controls. Excess deltaY (50px) should |
269 // consumed by the page. | 270 // be consumed by the page. |
270 webView->handleInputEvent( | 271 webView->handleInputEvent( |
271 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f)); | 272 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f)); |
272 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 273 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
273 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 274 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
274 | 275 |
275 // Scroll down and ensure only top controls is scrolled | 276 // Scroll down and ensure only browser controls is scrolled |
276 webView->handleInputEvent( | 277 webView->handleInputEvent( |
277 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); | 278 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); |
278 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); | 279 EXPECT_FLOAT_EQ(10.f, webView->browserControls().contentOffset()); |
279 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 280 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
280 | 281 |
281 webView->handleInputEvent( | 282 webView->handleInputEvent( |
282 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f)); | 283 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f)); |
283 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 284 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
284 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); | 285 EXPECT_SIZE_EQ(ScrollOffset(0, 100), frame()->view()->scrollOffset()); |
285 } | 286 } |
286 | 287 |
287 // Top controls should not consume horizontal scroll. | 288 // Browser controls should not consume horizontal scroll. |
288 TEST_F(TopControlsTest, MAYBE(HorizontalScroll)) { | 289 TEST_F(BrowserControlsTest, MAYBE(HorizontalScroll)) { |
289 WebViewImpl* webView = initialize(); | 290 WebViewImpl* webView = initialize(); |
290 // initialize top controls to be shown. | 291 // initialize browser controls to be shown. |
291 webView->resizeWithTopControls(webView->size(), 50.f, true); | 292 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
292 webView->topControls().setShownRatio(1); | 293 webView->browserControls().setShownRatio(1); |
293 | 294 |
294 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 295 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
295 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 296 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
296 | 297 |
297 // Top controls should not consume horizontal scroll. | 298 // Browser controls should not consume horizontal scroll. |
298 webView->handleInputEvent( | 299 webView->handleInputEvent( |
299 generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f)); | 300 generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f)); |
300 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 301 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
301 EXPECT_SIZE_EQ(ScrollOffset(110, 50), frame()->view()->scrollOffset()); | 302 EXPECT_SIZE_EQ(ScrollOffset(110, 50), frame()->view()->scrollOffset()); |
302 | 303 |
303 webView->handleInputEvent( | 304 webView->handleInputEvent( |
304 generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0)); | 305 generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0)); |
305 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 306 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
306 EXPECT_SIZE_EQ(ScrollOffset(150, 50), frame()->view()->scrollOffset()); | 307 EXPECT_SIZE_EQ(ScrollOffset(150, 50), frame()->view()->scrollOffset()); |
307 } | 308 } |
308 | 309 |
309 // Page scale should not impact top controls scrolling | 310 // Page scale should not impact browser controls scrolling |
310 TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact)) { | 311 TEST_F(BrowserControlsTest, MAYBE(PageScaleHasNoImpact)) { |
311 WebViewImpl* webView = initialize(); | 312 WebViewImpl* webView = initialize(); |
312 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); | 313 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); |
313 webView->setPageScaleFactor(2.0); | 314 webView->setPageScaleFactor(2.0); |
314 | 315 |
315 // Initialize top controls to be shown. | 316 // Initialize browser controls to be shown. |
316 webView->resizeWithTopControls(webView->size(), 50.f, true); | 317 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
317 webView->topControls().setShownRatio(1); | 318 webView->browserControls().setShownRatio(1); |
318 | 319 |
319 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 320 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
320 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 321 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
321 | 322 |
322 // Top controls should be scrolled partially and page should not scroll. | 323 // Browser controls should be scrolled partially and page should not scroll. |
323 webView->handleInputEvent( | 324 webView->handleInputEvent( |
324 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); | 325 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); |
325 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); | 326 EXPECT_FLOAT_EQ(30.f, webView->browserControls().contentOffset()); |
326 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 327 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
327 frame()->view()->getScrollableArea()->scrollOffset()); | 328 frame()->view()->getScrollableArea()->scrollOffset()); |
328 | 329 |
329 // Top controls should consume 30px and become hidden. Excess scroll should be | 330 // Browser controls should consume 30px and become hidden. Excess scroll |
330 // consumed by the page at 2x scale. | 331 // should be consumed by the page at 2x scale. |
331 webView->handleInputEvent( | 332 webView->handleInputEvent( |
332 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -70.f)); | 333 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -70.f)); |
333 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 334 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
334 EXPECT_SIZE_EQ(ScrollOffset(0, 20), | 335 EXPECT_SIZE_EQ(ScrollOffset(0, 20), |
335 frame()->view()->getScrollableArea()->scrollOffset()); | 336 frame()->view()->getScrollableArea()->scrollOffset()); |
336 | 337 |
337 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); | 338 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); |
338 | 339 |
339 // Change page scale and test. | 340 // Change page scale and test. |
340 webView->setPageScaleFactor(0.5); | 341 webView->setPageScaleFactor(0.5); |
341 | 342 |
342 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 343 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
343 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 344 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
344 EXPECT_SIZE_EQ(ScrollOffset(0, 20), | 345 EXPECT_SIZE_EQ(ScrollOffset(0, 20), |
345 frame()->view()->getScrollableArea()->scrollOffset()); | 346 frame()->view()->getScrollableArea()->scrollOffset()); |
346 | 347 |
347 webView->handleInputEvent( | 348 webView->handleInputEvent( |
348 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); | 349 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); |
349 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 350 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
350 EXPECT_SIZE_EQ(ScrollOffset(0, 20), | 351 EXPECT_SIZE_EQ(ScrollOffset(0, 20), |
351 frame()->view()->getScrollableArea()->scrollOffset()); | 352 frame()->view()->getScrollableArea()->scrollOffset()); |
352 | 353 |
353 // At 0.5x scale scrolling 10px should take us to the top of the page. | 354 // At 0.5x scale scrolling 10px should take us to the top of the page. |
354 webView->handleInputEvent( | 355 webView->handleInputEvent( |
355 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); | 356 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); |
356 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 357 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
357 EXPECT_SIZE_EQ(ScrollOffset(0, 0), | 358 EXPECT_SIZE_EQ(ScrollOffset(0, 0), |
358 frame()->view()->getScrollableArea()->scrollOffset()); | 359 frame()->view()->getScrollableArea()->scrollOffset()); |
359 } | 360 } |
360 | 361 |
361 // Some scroll deltas result in a shownRatio that can't be realized in a | 362 // Some scroll deltas result in a shownRatio that can't be realized in a |
362 // floating-point number. Make sure that if the top controls aren't fully | 363 // floating-point number. Make sure that if the browser controls aren't fully |
363 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no | 364 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no |
364 // slippage between the content and top controls. | 365 // slippage between the content and browser controls. |
365 TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage)) { | 366 TEST_F(BrowserControlsTest, MAYBE(FloatingPointSlippage)) { |
366 WebViewImpl* webView = initialize(); | 367 WebViewImpl* webView = initialize(); |
367 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); | 368 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); |
368 webView->setPageScaleFactor(2.0); | 369 webView->setPageScaleFactor(2.0); |
369 | 370 |
370 // Initialize top controls to be shown. | 371 // Initialize browser controls to be shown. |
371 webView->resizeWithTopControls(webView->size(), 50.f, true); | 372 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
372 webView->topControls().setShownRatio(1); | 373 webView->browserControls().setShownRatio(1); |
373 | 374 |
374 webView->topControls().scrollBegin(); | 375 webView->browserControls().scrollBegin(); |
375 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 376 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
376 | 377 |
377 // This will result in a 20px scroll to the top controls so the show ratio | 378 // This will result in a 20px scroll to the browser controls so the show ratio |
378 // will be 30/50 == 0.6 which is not representible in a float. Make sure | 379 // will be 30/50 == 0.6 which is not representible in a float. Make sure |
379 // that scroll still consumes the whole delta. | 380 // that scroll still consumes the whole delta. |
380 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, 10)); | 381 FloatSize remainingDelta = |
| 382 webView->browserControls().scrollBy(FloatSize(0, 10)); |
381 EXPECT_EQ(0, remainingDelta.height()); | 383 EXPECT_EQ(0, remainingDelta.height()); |
382 } | 384 } |
383 | 385 |
384 // Scrollable subregions should scroll before top controls | 386 // Scrollable subregions should scroll before browser controls |
385 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst)) { | 387 TEST_F(BrowserControlsTest, MAYBE(ScrollableSubregionScrollFirst)) { |
386 WebViewImpl* webView = initialize("overflow-scrolling.html"); | 388 WebViewImpl* webView = initialize("overflow-scrolling.html"); |
387 webView->resizeWithTopControls(webView->size(), 50.f, true); | 389 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
388 webView->topControls().setShownRatio(1); | 390 webView->browserControls().setShownRatio(1); |
389 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 50), | 391 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 50), |
390 ProgrammaticScroll); | 392 ProgrammaticScroll); |
391 | 393 |
392 // Test scroll down | 394 // Test scroll down |
393 // Scroll down should scroll the overflow div first but top controls and main | 395 // Scroll down should scroll the overflow div first but browser controls and |
394 // frame should not scroll. | 396 // main frame should not scroll. |
395 verticalScroll(-800.f); | 397 verticalScroll(-800.f); |
396 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 398 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
397 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 399 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
398 | 400 |
399 // Continued scroll down should start hiding top controls but main frame | 401 // Continued scroll down should start hiding browser controls but main frame |
400 // should not scroll. | 402 // should not scroll. |
401 verticalScroll(-40.f); | 403 verticalScroll(-40.f); |
402 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); | 404 EXPECT_FLOAT_EQ(10.f, webView->browserControls().contentOffset()); |
403 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 405 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
404 | 406 |
405 // Continued scroll down should scroll down the main frame | 407 // Continued scroll down should scroll down the main frame |
406 verticalScroll(-40.f); | 408 verticalScroll(-40.f); |
407 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 409 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
408 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 410 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
409 | 411 |
410 // Test scroll up | 412 // Test scroll up |
411 // scroll up should scroll overflow div first | 413 // scroll up should scroll overflow div first |
412 verticalScroll(800.f); | 414 verticalScroll(800.f); |
413 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 415 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
414 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 416 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
415 | 417 |
416 // Continued scroll up should start showing top controls but main frame should | 418 // Continued scroll up should start showing browser controls but main frame |
417 // not scroll. | 419 // should not scroll. |
418 verticalScroll(40.f); | 420 verticalScroll(40.f); |
419 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset()); | 421 EXPECT_FLOAT_EQ(40.f, webView->browserControls().contentOffset()); |
420 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 422 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
421 | 423 |
422 // Continued scroll down up scroll up the main frame | 424 // Continued scroll down up scroll up the main frame |
423 verticalScroll(40.f); | 425 verticalScroll(40.f); |
424 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 426 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
425 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 427 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
426 } | 428 } |
427 | 429 |
428 // Scrollable iframes should scroll before top controls | 430 // Scrollable iframes should scroll before browser controls |
429 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst)) { | 431 TEST_F(BrowserControlsTest, MAYBE(ScrollableIframeScrollFirst)) { |
430 WebViewImpl* webView = initialize("iframe-scrolling.html"); | 432 WebViewImpl* webView = initialize("iframe-scrolling.html"); |
431 webView->resizeWithTopControls(webView->size(), 50.f, true); | 433 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
432 webView->topControls().setShownRatio(1); | 434 webView->browserControls().setShownRatio(1); |
433 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 50), | 435 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 50), |
434 ProgrammaticScroll); | 436 ProgrammaticScroll); |
435 | 437 |
436 // Test scroll down | 438 // Test scroll down |
437 // Scroll down should scroll the iframe first but top controls and main frame | 439 // Scroll down should scroll the iframe first but browser controls and main |
438 // should not scroll. | 440 // frame should not scroll. |
439 verticalScroll(-800.f); | 441 verticalScroll(-800.f); |
440 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 442 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
441 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 443 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
442 | 444 |
443 // Continued scroll down should start hiding top controls but main frame | 445 // Continued scroll down should start hiding browser controls but main frame |
444 // should not scroll. | 446 // should not scroll. |
445 verticalScroll(-40.f); | 447 verticalScroll(-40.f); |
446 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); | 448 EXPECT_FLOAT_EQ(10.f, webView->browserControls().contentOffset()); |
447 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 449 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
448 | 450 |
449 // Continued scroll down should scroll down the main frame | 451 // Continued scroll down should scroll down the main frame |
450 verticalScroll(-40.f); | 452 verticalScroll(-40.f); |
451 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 453 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
452 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 454 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
453 | 455 |
454 // Test scroll up | 456 // Test scroll up |
455 // scroll up should scroll iframe first | 457 // scroll up should scroll iframe first |
456 verticalScroll(800.f); | 458 verticalScroll(800.f); |
457 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 459 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
458 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 460 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
459 | 461 |
460 // Continued scroll up should start showing top controls but main frame should | 462 // Continued scroll up should start showing browser controls but main frame |
461 // not scroll. | 463 // should not scroll. |
462 verticalScroll(40.f); | 464 verticalScroll(40.f); |
463 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset()); | 465 EXPECT_FLOAT_EQ(40.f, webView->browserControls().contentOffset()); |
464 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 466 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
465 | 467 |
466 // Continued scroll down up scroll up the main frame | 468 // Continued scroll down up scroll up the main frame |
467 verticalScroll(40.f); | 469 verticalScroll(40.f); |
468 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 470 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
469 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); | 471 EXPECT_SIZE_EQ(ScrollOffset(0, 50), frame()->view()->scrollOffset()); |
470 } | 472 } |
471 | 473 |
472 // Top controls visibility should remain consistent when height is changed. | 474 // Browser controls visibility should remain consistent when height is changed. |
473 TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility)) { | 475 TEST_F(BrowserControlsTest, MAYBE(HeightChangeMaintainsVisibility)) { |
474 WebViewImpl* webView = initialize(); | 476 WebViewImpl* webView = initialize(); |
475 webView->resizeWithTopControls(webView->size(), 20.f, false); | 477 webView->resizeWithBrowserControls(webView->size(), 20.f, false); |
476 webView->topControls().setShownRatio(0); | 478 webView->browserControls().setShownRatio(0); |
477 | 479 |
478 webView->resizeWithTopControls(webView->size(), 20.f, false); | 480 webView->resizeWithBrowserControls(webView->size(), 20.f, false); |
479 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 481 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
480 | 482 |
481 webView->resizeWithTopControls(webView->size(), 40.f, false); | 483 webView->resizeWithBrowserControls(webView->size(), 40.f, false); |
482 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 484 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
483 | 485 |
484 // Scroll up to show top controls. | 486 // Scroll up to show browser controls. |
485 verticalScroll(40.f); | 487 verticalScroll(40.f); |
486 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset()); | 488 EXPECT_FLOAT_EQ(40.f, webView->browserControls().contentOffset()); |
487 | 489 |
488 // Changing height of a fully shown top controls should correctly adjust | 490 // Changing height of a fully shown browser controls should correctly adjust |
489 // content offset | 491 // content offset |
490 webView->resizeWithTopControls(webView->size(), 30.f, false); | 492 webView->resizeWithBrowserControls(webView->size(), 30.f, false); |
491 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); | 493 EXPECT_FLOAT_EQ(30.f, webView->browserControls().contentOffset()); |
492 } | 494 } |
493 | 495 |
494 // Zero delta should not have any effect on top controls. | 496 // Zero delta should not have any effect on browser controls. |
495 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect)) { | 497 TEST_F(BrowserControlsTest, MAYBE(ZeroHeightMeansNoEffect)) { |
496 WebViewImpl* webView = initialize(); | 498 WebViewImpl* webView = initialize(); |
497 webView->resizeWithTopControls(webView->size(), 0, false); | 499 webView->resizeWithBrowserControls(webView->size(), 0, false); |
498 webView->topControls().setShownRatio(0); | 500 webView->browserControls().setShownRatio(0); |
499 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), | 501 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), |
500 ProgrammaticScroll); | 502 ProgrammaticScroll); |
501 | 503 |
502 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 504 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
503 | 505 |
504 verticalScroll(20.f); | 506 verticalScroll(20.f); |
505 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 507 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
506 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); | 508 EXPECT_SIZE_EQ(ScrollOffset(0, 80), frame()->view()->scrollOffset()); |
507 | 509 |
508 verticalScroll(-30.f); | 510 verticalScroll(-30.f); |
509 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 511 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
510 EXPECT_SIZE_EQ(ScrollOffset(0, 110), frame()->view()->scrollOffset()); | 512 EXPECT_SIZE_EQ(ScrollOffset(0, 110), frame()->view()->scrollOffset()); |
511 | 513 |
512 webView->topControls().setShownRatio(1); | 514 webView->browserControls().setShownRatio(1); |
513 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); | 515 EXPECT_FLOAT_EQ(0.f, webView->browserControls().contentOffset()); |
514 } | 516 } |
515 | 517 |
516 // Top controls should not hide when scrolling up past limit | 518 // Browser controls should not hide when scrolling up past limit |
517 TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide)) { | 519 TEST_F(BrowserControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide)) { |
518 WebViewImpl* webView = initialize(); | 520 WebViewImpl* webView = initialize(); |
519 // Initialize top controls to be shown | 521 // Initialize browser controls to be shown |
520 webView->resizeWithTopControls(webView->size(), 50.f, true); | 522 webView->resizeWithBrowserControls(webView->size(), 50.f, true); |
521 webView->topControls().setShownRatio(1); | 523 webView->browserControls().setShownRatio(1); |
522 // Use 2x scale so that both visual viewport and frameview are scrollable | 524 // Use 2x scale so that both visual viewport and frameview are scrollable |
523 webView->setPageScaleFactor(2.0); | 525 webView->setPageScaleFactor(2.0); |
524 | 526 |
525 // Fully scroll frameview but visualviewport remains scrollable | 527 // Fully scroll frameview but visualviewport remains scrollable |
526 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); | 528 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); |
527 visualViewport().setLocation(FloatPoint(0, 0)); | 529 visualViewport().setLocation(FloatPoint(0, 0)); |
528 verticalScroll(-10.f); | 530 verticalScroll(-10.f); |
529 EXPECT_FLOAT_EQ(40, webView->topControls().contentOffset()); | 531 EXPECT_FLOAT_EQ(40, webView->browserControls().contentOffset()); |
530 | 532 |
531 webView->topControls().setShownRatio(1); | 533 webView->browserControls().setShownRatio(1); |
532 // Fully scroll visual veiwport but frameview remains scrollable | 534 // Fully scroll visual veiwport but frameview remains scrollable |
533 webView->mainFrame()->setScrollOffset(WebSize(0, 0)); | 535 webView->mainFrame()->setScrollOffset(WebSize(0, 0)); |
534 visualViewport().setLocation(FloatPoint(0, 10000)); | 536 visualViewport().setLocation(FloatPoint(0, 10000)); |
535 verticalScroll(-20.f); | 537 verticalScroll(-20.f); |
536 EXPECT_FLOAT_EQ(30, webView->topControls().contentOffset()); | 538 EXPECT_FLOAT_EQ(30, webView->browserControls().contentOffset()); |
537 | 539 |
538 webView->topControls().setShownRatio(1); | 540 webView->browserControls().setShownRatio(1); |
539 // Fully scroll both frameview and visual viewport | 541 // Fully scroll both frameview and visual viewport |
540 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); | 542 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); |
541 visualViewport().setLocation(FloatPoint(0, 10000)); | 543 visualViewport().setLocation(FloatPoint(0, 10000)); |
542 verticalScroll(-30.f); | 544 verticalScroll(-30.f); |
543 // Top controls should not move because neither frameview nor visual viewport | 545 // Browser controls should not move because neither frameview nor visual |
| 546 // viewport |
544 // are scrollable | 547 // are scrollable |
545 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 548 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
546 } | 549 } |
547 | 550 |
548 // Top controls should honor its constraints | 551 // Browser controls should honor its constraints |
549 TEST_F(TopControlsTest, MAYBE(StateConstraints)) { | 552 TEST_F(BrowserControlsTest, MAYBE(StateConstraints)) { |
550 WebViewImpl* webView = initialize(); | 553 WebViewImpl* webView = initialize(); |
551 webView->resizeWithTopControls(webView->size(), 50.f, false); | 554 webView->resizeWithBrowserControls(webView->size(), 50.f, false); |
552 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), | 555 frame()->view()->getScrollableArea()->setScrollOffset(ScrollOffset(0, 100), |
553 ProgrammaticScroll); | 556 ProgrammaticScroll); |
554 | 557 |
555 // Setting permitted state should change the content offset to match the | 558 // Setting permitted state should change the content offset to match the |
556 // constraint. | 559 // constraint. |
557 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, | 560 webView->updateBrowserControlsState(WebBrowserControlsShown, |
558 false); | 561 WebBrowserControlsShown, false); |
559 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); | 562 EXPECT_FLOAT_EQ(50.f, webView->browserControls().contentOffset()); |
560 | 563 |
561 // Only shown state is permitted so controls cannot hide | 564 // Only shown state is permitted so controls cannot hide |
562 verticalScroll(-20.f); | 565 verticalScroll(-20.f); |
563 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); | 566 EXPECT_FLOAT_EQ(50, webView->browserControls().contentOffset()); |
564 EXPECT_SIZE_EQ(ScrollOffset(0, 120), frame()->view()->scrollOffset()); | 567 EXPECT_SIZE_EQ(ScrollOffset(0, 120), frame()->view()->scrollOffset()); |
565 | 568 |
566 // Setting permitted state should change content offset to match the | 569 // Setting permitted state should change content offset to match the |
567 // constraint. | 570 // constraint. |
568 webView->updateTopControlsState(WebTopControlsHidden, WebTopControlsHidden, | 571 webView->updateBrowserControlsState(WebBrowserControlsHidden, |
569 false); | 572 WebBrowserControlsHidden, false); |
570 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); | 573 EXPECT_FLOAT_EQ(0, webView->browserControls().contentOffset()); |
571 | 574 |
572 // Only hidden state is permitted so controls cannot show | 575 // Only hidden state is permitted so controls cannot show |
573 verticalScroll(30.f); | 576 verticalScroll(30.f); |
574 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); | 577 EXPECT_FLOAT_EQ(0, webView->browserControls().contentOffset()); |
575 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); | 578 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); |
576 | 579 |
577 // Setting permitted state to "both" should not change content offset. | 580 // Setting permitted state to "both" should not change content offset. |
578 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsBoth, | 581 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
579 false); | 582 WebBrowserControlsBoth, false); |
580 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); | 583 EXPECT_FLOAT_EQ(0, webView->browserControls().contentOffset()); |
581 | 584 |
582 // Both states are permitted so controls can either show or hide | 585 // Both states are permitted so controls can either show or hide |
583 verticalScroll(50.f); | 586 verticalScroll(50.f); |
584 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); | 587 EXPECT_FLOAT_EQ(50, webView->browserControls().contentOffset()); |
585 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); | 588 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); |
586 | 589 |
587 verticalScroll(-50.f); | 590 verticalScroll(-50.f); |
588 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); | 591 EXPECT_FLOAT_EQ(0, webView->browserControls().contentOffset()); |
589 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); | 592 EXPECT_SIZE_EQ(ScrollOffset(0, 90), frame()->view()->scrollOffset()); |
590 | 593 |
591 // Setting permitted state to "both" should not change an in-flight offset. | 594 // Setting permitted state to "both" should not change an in-flight offset. |
592 verticalScroll(20.f); | 595 verticalScroll(20.f); |
593 EXPECT_FLOAT_EQ(20, webView->topControls().contentOffset()); | 596 EXPECT_FLOAT_EQ(20, webView->browserControls().contentOffset()); |
594 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsBoth, | 597 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
595 false); | 598 WebBrowserControlsBoth, false); |
596 EXPECT_FLOAT_EQ(20, webView->topControls().contentOffset()); | 599 EXPECT_FLOAT_EQ(20, webView->browserControls().contentOffset()); |
597 | 600 |
598 // An animated state change shouldn't cause a change to the content offset | 601 // An animated state change shouldn't cause a change to the content offset |
599 // since it'll be driven from the compositor. | 602 // since it'll be driven from the compositor. |
600 webView->updateTopControlsState(WebTopControlsHidden, WebTopControlsHidden, | 603 webView->updateBrowserControlsState(WebBrowserControlsHidden, |
601 true); | 604 WebBrowserControlsHidden, true); |
602 EXPECT_FLOAT_EQ(20, webView->topControls().contentOffset()); | 605 EXPECT_FLOAT_EQ(20, webView->browserControls().contentOffset()); |
603 | 606 |
604 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, | 607 webView->updateBrowserControlsState(WebBrowserControlsShown, |
605 true); | 608 WebBrowserControlsShown, true); |
606 EXPECT_FLOAT_EQ(20, webView->topControls().contentOffset()); | 609 EXPECT_FLOAT_EQ(20, webView->browserControls().contentOffset()); |
607 | 610 |
608 // Setting just the constraint should affect the content offset. | 611 // Setting just the constraint should affect the content offset. |
609 webView->updateTopControlsState(WebTopControlsHidden, WebTopControlsBoth, | 612 webView->updateBrowserControlsState(WebBrowserControlsHidden, |
610 false); | 613 WebBrowserControlsBoth, false); |
611 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); | 614 EXPECT_FLOAT_EQ(0, webView->browserControls().contentOffset()); |
612 | 615 |
613 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsBoth, | 616 webView->updateBrowserControlsState(WebBrowserControlsShown, |
614 false); | 617 WebBrowserControlsBoth, false); |
615 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); | 618 EXPECT_FLOAT_EQ(50, webView->browserControls().contentOffset()); |
616 } | 619 } |
617 | 620 |
618 // Ensure that top controls do not affect the layout by showing and hiding | 621 // Ensure that browser controls do not affect the layout by showing and hiding |
619 // except for position: fixed elements. | 622 // except for position: fixed elements. |
620 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight)) { | 623 TEST_F(BrowserControlsTest, MAYBE(DontAffectLayoutHeight)) { |
621 // Initialize with the top controls showing. | 624 // Initialize with the browser controls showing. |
622 WebViewImpl* webView = initialize("percent-height.html"); | 625 WebViewImpl* webView = initialize("percent-height.html"); |
623 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true); | 626 webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true); |
624 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, | 627 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
625 false); | 628 WebBrowserControlsShown, false); |
626 webView->topControls().setShownRatio(1); | 629 webView->browserControls().setShownRatio(1); |
627 webView->updateAllLifecyclePhases(); | 630 webView->updateAllLifecyclePhases(); |
628 | 631 |
629 ASSERT_EQ(100.f, webView->topControls().contentOffset()); | 632 ASSERT_EQ(100.f, webView->browserControls().contentOffset()); |
630 | 633 |
631 // When the top controls are showing, there's 300px for the layout height so | 634 // When the browser controls are showing, there's 300px for the layout height |
| 635 // so |
632 // 50% should result in both the position:fixed and position: absolute divs | 636 // 50% should result in both the position:fixed and position: absolute divs |
633 // having 150px of height. | 637 // having 150px of height. |
634 Element* absPos = getElementById(WebString::fromUTF8("abs")); | 638 Element* absPos = getElementById(WebString::fromUTF8("abs")); |
635 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); | 639 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); |
636 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); | 640 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); |
637 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height()); | 641 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height()); |
638 | 642 |
639 // The layout size on the FrameView should not include the top controls. | 643 // The layout size on the FrameView should not include the browser controls. |
640 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); | 644 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); |
641 | 645 |
642 // Hide the top controls. | 646 // Hide the browser controls. |
643 verticalScroll(-100.f); | 647 verticalScroll(-100.f); |
644 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false); | 648 webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false); |
645 webView->updateAllLifecyclePhases(); | 649 webView->updateAllLifecyclePhases(); |
646 | 650 |
647 ASSERT_EQ(0.f, webView->topControls().contentOffset()); | 651 ASSERT_EQ(0.f, webView->browserControls().contentOffset()); |
648 | 652 |
649 // Hiding the top controls shouldn't change the height of the initial | 653 // Hiding the browser controls shouldn't change the height of the initial |
650 // containing block for non-position: fixed. Position: fixed however should | 654 // containing block for non-position: fixed. Position: fixed however should |
651 // use the entire height of the viewport however. | 655 // use the entire height of the viewport however. |
652 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); | 656 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); |
653 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); | 657 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); |
654 | 658 |
655 // The layout size should not change as a result of top controls hiding. | 659 // The layout size should not change as a result of browser controls hiding. |
656 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); | 660 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); |
657 } | 661 } |
658 | 662 |
659 // Ensure that top controls do not affect vh units. | 663 // Ensure that browser controls do not affect vh units. |
660 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits)) { | 664 TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnits)) { |
661 // Initialize with the top controls showing. | 665 // Initialize with the browser controls showing. |
662 WebViewImpl* webView = initialize("vh-height.html"); | 666 WebViewImpl* webView = initialize("vh-height.html"); |
663 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true); | 667 webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true); |
664 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, | 668 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
665 false); | 669 WebBrowserControlsShown, false); |
666 webView->topControls().setShownRatio(1); | 670 webView->browserControls().setShownRatio(1); |
667 webView->updateAllLifecyclePhases(); | 671 webView->updateAllLifecyclePhases(); |
668 | 672 |
669 ASSERT_EQ(100.f, webView->topControls().contentOffset()); | 673 ASSERT_EQ(100.f, webView->browserControls().contentOffset()); |
670 | 674 |
671 // 'vh' units should be based on the viewport when the top controls are | 675 // 'vh' units should be based on the viewport when the browser controls are |
672 // hidden. | 676 // hidden. |
673 Element* absPos = getElementById(WebString::fromUTF8("abs")); | 677 Element* absPos = getElementById(WebString::fromUTF8("abs")); |
674 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); | 678 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); |
675 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); | 679 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); |
676 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); | 680 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); |
677 | 681 |
678 // The size used for viewport units should not be reduced by the top | 682 // The size used for viewport units should not be reduced by the top |
679 // controls. | 683 // controls. |
680 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); | 684 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); |
681 | 685 |
682 // Hide the top controls. | 686 // Hide the browser controls. |
683 verticalScroll(-100.f); | 687 verticalScroll(-100.f); |
684 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false); | 688 webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false); |
685 webView->updateAllLifecyclePhases(); | 689 webView->updateAllLifecyclePhases(); |
686 | 690 |
687 ASSERT_EQ(0.f, webView->topControls().contentOffset()); | 691 ASSERT_EQ(0.f, webView->browserControls().contentOffset()); |
688 | 692 |
689 // vh units should be static with respect to the top controls so neighter | 693 // vh units should be static with respect to the browser controls so neighter |
690 // <div> should change size are a result of the top controls hiding. | 694 // <div> should change size are a result of the browser controls hiding. |
691 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); | 695 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); |
692 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); | 696 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); |
693 | 697 |
694 // The viewport size used for vh units should not change as a result of top | 698 // The viewport size used for vh units should not change as a result of top |
695 // controls hiding. | 699 // controls hiding. |
696 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); | 700 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); |
697 } | 701 } |
698 | 702 |
699 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill | 703 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill |
700 // the viewport, with top controls hidden, when the viewport encompasses the | 704 // the viewport, with browser controls hidden, when the viewport encompasses the |
701 // layout width. | 705 // layout width. |
702 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale)) { | 706 TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnitsWithScale)) { |
703 // Initialize with the top controls showing. | 707 // Initialize with the browser controls showing. |
704 WebViewImpl* webView = initialize("vh-height-width-800.html"); | 708 WebViewImpl* webView = initialize("vh-height-width-800.html"); |
705 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true); | 709 webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true); |
706 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, | 710 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
707 false); | 711 WebBrowserControlsShown, false); |
708 webView->topControls().setShownRatio(1); | 712 webView->browserControls().setShownRatio(1); |
709 webView->updateAllLifecyclePhases(); | 713 webView->updateAllLifecyclePhases(); |
710 | 714 |
711 ASSERT_EQ(100.f, webView->topControls().contentOffset()); | 715 ASSERT_EQ(100.f, webView->browserControls().contentOffset()); |
712 | 716 |
713 // Device viewport is 400px but the page is width=800 so minimum-scale | 717 // Device viewport is 400px but the page is width=800 so minimum-scale |
714 // should be 0.5. This is also the scale at which the viewport fills the | 718 // should be 0.5. This is also the scale at which the viewport fills the |
715 // layout width. | 719 // layout width. |
716 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor()); | 720 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor()); |
717 | 721 |
718 // We should size vh units so that 100vh fills the viewport at min-scale so | 722 // We should size vh units so that 100vh fills the viewport at min-scale so |
719 // we have to account for the minimum page scale factor. Since both boxes | 723 // we have to account for the minimum page scale factor. Since both boxes |
720 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 800 | 724 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 800 |
721 // so we expect 50vh to be 400px. | 725 // so we expect 50vh to be 400px. |
722 Element* absPos = getElementById(WebString::fromUTF8("abs")); | 726 Element* absPos = getElementById(WebString::fromUTF8("abs")); |
723 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); | 727 Element* fixedPos = getElementById(WebString::fromUTF8("fixed")); |
724 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); | 728 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); |
725 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); | 729 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); |
726 | 730 |
727 // The size used for viewport units should not be reduced by the top | 731 // The size used for viewport units should not be reduced by the top |
728 // controls. | 732 // controls. |
729 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); | 733 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); |
730 | 734 |
731 // Hide the top controls. | 735 // Hide the browser controls. |
732 verticalScroll(-100.f); | 736 verticalScroll(-100.f); |
733 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false); | 737 webView->resizeWithBrowserControls(WebSize(400, 400), 100.f, false); |
734 webView->updateAllLifecyclePhases(); | 738 webView->updateAllLifecyclePhases(); |
735 | 739 |
736 ASSERT_EQ(0.f, webView->topControls().contentOffset()); | 740 ASSERT_EQ(0.f, webView->browserControls().contentOffset()); |
737 | 741 |
738 // vh units should be static with respect to the top controls so neighter | 742 // vh units should be static with respect to the browser controls so neighter |
739 // <div> should change size are a result of the top controls hiding. | 743 // <div> should change size are a result of the browser controls hiding. |
740 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); | 744 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); |
741 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); | 745 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); |
742 | 746 |
743 // The viewport size used for vh units should not change as a result of top | 747 // The viewport size used for vh units should not change as a result of top |
744 // controls hiding. | 748 // controls hiding. |
745 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); | 749 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); |
746 } | 750 } |
747 | 751 |
748 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport | 752 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport |
749 // at minimum-scale is larger than the layout size, 100vh units fill the | 753 // at minimum-scale is larger than the layout size, 100vh units fill the |
750 // viewport, with top controls hidden, when the viewport is scaled such that | 754 // viewport, with browser controls hidden, when the viewport is scaled such that |
751 // its width equals the layout width. | 755 // its width equals the layout width. |
752 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize)) { | 756 TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize)) { |
753 // Initialize with the top controls showing. | 757 // Initialize with the browser controls showing. |
754 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html"); | 758 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html"); |
755 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true); | 759 webView->resizeWithBrowserControls(WebSize(400, 300), 100.f, true); |
756 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, | 760 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
757 false); | 761 WebBrowserControlsShown, false); |
758 webView->topControls().setShownRatio(1); | 762 webView->browserControls().setShownRatio(1); |
759 webView->updateAllLifecyclePhases(); | 763 webView->updateAllLifecyclePhases(); |
760 | 764 |
761 ASSERT_EQ(100.f, webView->topControls().contentOffset()); | 765 ASSERT_EQ(100.f, webView->browserControls().contentOffset()); |
762 | 766 |
763 // Device viewport is 400px and page is width=800 but there's an element | 767 // Device viewport is 400px and page is width=800 but there's an element |
764 // that's 1600px wide so the minimum scale is 0.25 to encompass that. | 768 // that's 1600px wide so the minimum scale is 0.25 to encompass that. |
765 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor()); | 769 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor()); |
766 | 770 |
767 // The viewport will match the layout width at scale=0.5 so the height used | 771 // The viewport will match the layout width at scale=0.5 so the height used |
768 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top | 772 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top |
769 // controls = 800. | 773 // controls = 800. |
770 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); | 774 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); |
771 } | 775 } |
772 | 776 |
773 // This tests that the viewport remains anchored when top controls are brought | 777 // This tests that the viewport remains anchored when browser controls are |
774 // in while the document is fully scrolled. This normally causes clamping of the | 778 // brought in while the document is fully scrolled. This normally causes |
775 // visual viewport to keep it bounded by the layout viewport so we're testing | 779 // clamping of the visual viewport to keep it bounded by the layout viewport |
776 // that the viewport anchoring logic is working to keep the view unchanged. | 780 // so we're testing that the viewport anchoring logic is working to keep the |
777 TEST_F(TopControlsTest, MAYBE(AnchorViewportDuringTopControlsAdjustment)) { | 781 // view unchanged. |
| 782 TEST_F(BrowserControlsTest, |
| 783 MAYBE(AnchorViewportDuringbrowserControlsAdjustment)) { |
778 int contentHeight = 1016; | 784 int contentHeight = 1016; |
779 int layoutViewportHeight = 500; | 785 int layoutViewportHeight = 500; |
780 int visualViewportHeight = 500; | 786 int visualViewportHeight = 500; |
781 int topControlsHeight = 100; | 787 int browserControlsHeight = 100; |
782 int pageScale = 2; | 788 int pageScale = 2; |
783 int minScale = 1; | 789 int minScale = 1; |
784 | 790 |
785 // Initialize with the top controls showing. | 791 // Initialize with the browser controls showing. |
786 WebViewImpl* webView = initialize("large-div.html"); | 792 WebViewImpl* webView = initialize("large-div.html"); |
787 webViewImpl()->setDefaultPageScaleLimits(minScale, 5); | 793 webViewImpl()->setDefaultPageScaleLimits(minScale, 5); |
788 webView->resizeWithTopControls(WebSize(800, layoutViewportHeight), | 794 webView->resizeWithBrowserControls(WebSize(800, layoutViewportHeight), |
789 topControlsHeight, true); | 795 browserControlsHeight, true); |
790 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, | 796 webView->updateBrowserControlsState(WebBrowserControlsBoth, |
791 false); | 797 WebBrowserControlsShown, false); |
792 webView->topControls().setShownRatio(1); | 798 webView->browserControls().setShownRatio(1); |
793 webView->updateAllLifecyclePhases(); | 799 webView->updateAllLifecyclePhases(); |
794 | 800 |
795 FrameView* view = frame()->view(); | 801 FrameView* view = frame()->view(); |
796 ScrollableArea* rootViewport = frame()->view()->getScrollableArea(); | 802 ScrollableArea* rootViewport = frame()->view()->getScrollableArea(); |
797 | 803 |
798 int expectedVisualOffset = | 804 int expectedVisualOffset = |
799 ((layoutViewportHeight + topControlsHeight / minScale) * pageScale - | 805 ((layoutViewportHeight + browserControlsHeight / minScale) * pageScale - |
800 (visualViewportHeight + topControlsHeight)) / | 806 (visualViewportHeight + browserControlsHeight)) / |
801 pageScale; | 807 pageScale; |
802 int expectedLayoutOffset = | 808 int expectedLayoutOffset = |
803 contentHeight - (layoutViewportHeight + topControlsHeight / minScale); | 809 contentHeight - (layoutViewportHeight + browserControlsHeight / minScale); |
804 int expectedRootOffset = expectedVisualOffset + expectedLayoutOffset; | 810 int expectedRootOffset = expectedVisualOffset + expectedLayoutOffset; |
805 | 811 |
806 // Zoom in to 2X and fully scroll both viewports. | 812 // Zoom in to 2X and fully scroll both viewports. |
807 webView->setPageScaleFactor(pageScale); | 813 webView->setPageScaleFactor(pageScale); |
808 { | 814 { |
809 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 815 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
810 webView->handleInputEvent( | 816 webView->handleInputEvent( |
811 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -10000)); | 817 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -10000)); |
812 | 818 |
813 ASSERT_EQ(0.f, webView->topControls().contentOffset()); | 819 ASSERT_EQ(0.f, webView->browserControls().contentOffset()); |
814 | 820 |
815 EXPECT_EQ(expectedVisualOffset, visualViewport().scrollOffset().height()); | 821 EXPECT_EQ(expectedVisualOffset, visualViewport().scrollOffset().height()); |
816 EXPECT_EQ(expectedLayoutOffset, | 822 EXPECT_EQ(expectedLayoutOffset, |
817 view->layoutViewportScrollableArea()->scrollOffset().height()); | 823 view->layoutViewportScrollableArea()->scrollOffset().height()); |
818 EXPECT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); | 824 EXPECT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); |
819 | 825 |
820 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); | 826 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); |
821 } | 827 } |
822 | 828 |
823 // Commit the top controls resize so that the top controls do not shrink the | 829 // Commit the browser controls resize so that the browser controls do not |
824 // layout size. This should not have moved any of the viewports. | 830 // shrink the layout size. This should not have moved any of the viewports. |
825 webView->resizeWithTopControls( | 831 webView->resizeWithBrowserControls( |
826 WebSize(800, layoutViewportHeight + topControlsHeight), topControlsHeight, | 832 WebSize(800, layoutViewportHeight + browserControlsHeight), |
827 false); | 833 browserControlsHeight, false); |
828 webView->updateAllLifecyclePhases(); | 834 webView->updateAllLifecyclePhases(); |
829 ASSERT_EQ(expectedVisualOffset, visualViewport().scrollOffset().height()); | 835 ASSERT_EQ(expectedVisualOffset, visualViewport().scrollOffset().height()); |
830 ASSERT_EQ(expectedLayoutOffset, | 836 ASSERT_EQ(expectedLayoutOffset, |
831 view->layoutViewportScrollableArea()->scrollOffset().height()); | 837 view->layoutViewportScrollableArea()->scrollOffset().height()); |
832 ASSERT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); | 838 ASSERT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); |
833 | 839 |
834 // Now scroll back up just enough to show the top controls. The top controls | 840 // Now scroll back up just enough to show the browser controls. The browser |
835 // should shrink both viewports but the layout viewport by a greater amount. | 841 // controls should shrink both viewports but the layout viewport by a greater |
836 // This means the visual viewport's offset must be clamped to keep it within | 842 // amount. This means the visual viewport's offset must be clamped to keep it |
837 // the layout viewport. Make sure we adjust the scroll position to account | 843 // within the layout viewport. Make sure we adjust the scroll position to |
838 // for this and keep the visual viewport at the same location relative to | 844 // account for this and keep the visual viewport at the same location relative |
839 // the document (i.e. the user shouldn't see a movement). | 845 // to the document (i.e. the user shouldn't see a movement). |
840 { | 846 { |
841 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); | 847 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); |
842 webView->handleInputEvent( | 848 webView->handleInputEvent( |
843 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 80)); | 849 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 80)); |
844 | 850 |
845 visualViewport().clampToBoundaries(); | 851 visualViewport().clampToBoundaries(); |
846 view->setScrollOffset(view->scrollOffset(), ProgrammaticScroll); | 852 view->setScrollOffset(view->scrollOffset(), ProgrammaticScroll); |
847 | 853 |
848 ASSERT_EQ(80.f, webView->topControls().contentOffset()); | 854 ASSERT_EQ(80.f, webView->browserControls().contentOffset()); |
849 EXPECT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); | 855 EXPECT_EQ(expectedRootOffset, rootViewport->scrollOffset().height()); |
850 | 856 |
851 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); | 857 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd)); |
852 } | 858 } |
853 } | 859 } |
854 | 860 |
855 } // namespace blink | 861 } // namespace blink |
OLD | NEW |