Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: third_party/WebKit/Source/web/tests/TopControlsTest.cpp

Issue 1844013002: Fix main thread top controls scrolling to mirror CC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@propertyTreesBoundsDelta
Patch Set: Override top controls resize() in classes that override resize() Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 #define MAYBE(test) DISABLED_##test 149 #define MAYBE(test) DISABLED_##test
150 #else 150 #else
151 #define MAYBE(test) test 151 #define MAYBE(test) test
152 #endif 152 #endif
153 153
154 // Scrolling down should hide top controls. 154 // Scrolling down should hide top controls.
155 TEST_F(TopControlsTest, MAYBE(HideOnScrollDown)) 155 TEST_F(TopControlsTest, MAYBE(HideOnScrollDown))
156 { 156 {
157 WebViewImpl* webView = initialize(); 157 WebViewImpl* webView = initialize();
158 // initialize top controls to be shown. 158 // initialize top controls to be shown.
159 webView->setTopControlsHeight(50.f, true); 159 webView->resize(webView->size(), 50.f, true);
160 webView->topControls().setShownRatio(1); 160 webView->topControls().setShownRatio(1);
161 161
162 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 162 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
163 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 163 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
164 164
165 // Top controls should be scrolled partially and page should not scroll. 165 // Top controls should be scrolled partially and page should not scroll.
166 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f)); 166 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f));
167 EXPECT_FLOAT_EQ(25.f, webView->topControls().contentOffset()); 167 EXPECT_FLOAT_EQ(25.f, webView->topControls().contentOffset());
168 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 168 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
169 169
170 // Top controls should consume 25px and become hidden. Excess scroll should be consumed by the page. 170 // Top controls should consume 25px and become hidden. Excess scroll should be consumed by the page.
171 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); 171 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f));
172 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 172 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
173 EXPECT_POINT_EQ(IntPoint(0, 15), frame()->view()->scrollPosition()); 173 EXPECT_POINT_EQ(IntPoint(0, 15), frame()->view()->scrollPosition());
174 174
175 // Only page should consume scroll 175 // Only page should consume scroll
176 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); 176 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f));
177 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 177 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
178 EXPECT_POINT_EQ(IntPoint(0, 35), frame()->view()->scrollPosition()); 178 EXPECT_POINT_EQ(IntPoint(0, 35), frame()->view()->scrollPosition());
179 } 179 }
180 180
181 // Scrolling up should show top controls. 181 // Scrolling up should show top controls.
182 TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp)) 182 TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp))
183 { 183 {
184 WebViewImpl* webView = initialize(); 184 WebViewImpl* webView = initialize();
185 // initialize top controls to be hidden. 185 // initialize top controls to be hidden.
186 webView->setTopControlsHeight(50.f, false); 186 webView->resize(webView->size(), 50.f, false);
187 webView->topControls().setShownRatio(0); 187 webView->topControls().setShownRatio(0);
188 188
189 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 189 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
190 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 190 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
191 191
192 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); 192 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f));
193 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 193 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
194 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 194 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
195 195
196 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); 196 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f));
197 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 197 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
198 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 198 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
199 } 199 }
200 200
201 // Scrolling up after previous scroll downs should cause top controls to be 201 // Scrolling up after previous scroll downs should cause top controls to be
202 // shown only after all previously scrolled down amount is compensated. 202 // shown only after all previously scrolled down amount is compensated.
203 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp)) 203 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp))
204 { 204 {
205 WebViewImpl* webView = initialize(); 205 WebViewImpl* webView = initialize();
206 // initialize top controls to be shown and position page at 100px. 206 // initialize top controls to be shown and position page at 100px.
207 webView->setTopControlsHeight(50.f, true); 207 webView->resize(webView->size(), 50.f, true);
208 webView->topControls().setShownRatio(1); 208 webView->topControls().setShownRatio(1);
209 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 209 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
210 210
211 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 211 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
212 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 212 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
213 213
214 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page. 214 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page.
215 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f)); 215 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f));
216 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 216 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
217 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition()); 217 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition());
(...skipping 17 matching lines...) Expand all
235 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 235 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
236 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 236 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
237 } 237 }
238 238
239 // Scrolling down should always cause visible top controls to start hiding even 239 // Scrolling down should always cause visible top controls to start hiding even
240 // if we have been scrolling up previously. 240 // if we have been scrolling up previously.
241 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown)) 241 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown))
242 { 242 {
243 WebViewImpl* webView = initialize(); 243 WebViewImpl* webView = initialize();
244 // initialize top controls to be hidden and position page at 100px. 244 // initialize top controls to be hidden and position page at 100px.
245 webView->setTopControlsHeight(50.f, false); 245 webView->resize(webView->size(), 50.f, false);
246 webView->topControls().setShownRatio(0); 246 webView->topControls().setShownRatio(0);
247 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 247 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
248 248
249 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 249 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
250 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 250 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
251 251
252 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page. 252 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page.
253 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f)); 253 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f));
254 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 254 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
255 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 255 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
256 256
257 // Scroll down and ensure only top controls is scrolled 257 // Scroll down and ensure only top controls is scrolled
258 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); 258 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f));
259 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 259 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
260 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 260 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
261 261
262 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f)); 262 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f));
263 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 263 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
264 EXPECT_POINT_EQ(IntPoint(0, 100), frame()->view()->scrollPosition()); 264 EXPECT_POINT_EQ(IntPoint(0, 100), frame()->view()->scrollPosition());
265 } 265 }
266 266
267 // Top controls should not consume horizontal scroll. 267 // Top controls should not consume horizontal scroll.
268 TEST_F(TopControlsTest, MAYBE(HorizontalScroll)) 268 TEST_F(TopControlsTest, MAYBE(HorizontalScroll))
269 { 269 {
270 WebViewImpl* webView = initialize(); 270 WebViewImpl* webView = initialize();
271 // initialize top controls to be shown. 271 // initialize top controls to be shown.
272 webView->setTopControlsHeight(50.f, true); 272 webView->resize(webView->size(), 50.f, true);
273 webView->topControls().setShownRatio(1); 273 webView->topControls().setShownRatio(1);
274 274
275 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 275 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
276 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 276 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
277 277
278 // Top controls should not consume horizontal scroll. 278 // Top controls should not consume horizontal scroll.
279 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f)); 279 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f));
280 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 280 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
281 EXPECT_POINT_EQ(IntPoint(110, 50), frame()->view()->scrollPosition()); 281 EXPECT_POINT_EQ(IntPoint(110, 50), frame()->view()->scrollPosition());
282 282
283 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0)); 283 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0));
284 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 284 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
285 EXPECT_POINT_EQ(IntPoint(150, 50), frame()->view()->scrollPosition()); 285 EXPECT_POINT_EQ(IntPoint(150, 50), frame()->view()->scrollPosition());
286 } 286 }
287 287
288 // Page scale should not impact top controls scrolling 288 // Page scale should not impact top controls scrolling
289 TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact)) 289 TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact))
290 { 290 {
291 WebViewImpl* webView = initialize(); 291 WebViewImpl* webView = initialize();
292 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); 292 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5);
293 webView->setPageScaleFactor(2.0); 293 webView->setPageScaleFactor(2.0);
294 294
295 // Initialize top controls to be shown. 295 // Initialize top controls to be shown.
296 webView->setTopControlsHeight(50.f, true); 296 webView->resize(webView->size(), 50.f, true);
297 webView->topControls().setShownRatio(1); 297 webView->topControls().setShownRatio(1);
298 298
299 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 299 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
300 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 300 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
301 301
302 // Top controls should be scrolled partially and page should not scroll. 302 // Top controls should be scrolled partially and page should not scroll.
303 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); 303 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f));
304 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); 304 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
305 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->getScrollableArea()->scroll PositionDouble()); 305 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->getScrollableArea()->scroll PositionDouble());
306 306
(...skipping 25 matching lines...) Expand all
332 // floating-point number. Make sure that if the top controls aren't fully 332 // floating-point number. Make sure that if the top controls aren't fully
333 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no 333 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no
334 // slippage between the content and top controls. 334 // slippage between the content and top controls.
335 TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage)) 335 TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
336 { 336 {
337 WebViewImpl* webView = initialize(); 337 WebViewImpl* webView = initialize();
338 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); 338 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5);
339 webView->setPageScaleFactor(2.0); 339 webView->setPageScaleFactor(2.0);
340 340
341 // Initialize top controls to be shown. 341 // Initialize top controls to be shown.
342 webView->setTopControlsHeight(50.f, true); 342 webView->resize(webView->size(), 50.f, true);
343 webView->topControls().setShownRatio(1); 343 webView->topControls().setShownRatio(1);
344 344
345 webView->topControls().scrollBegin(); 345 webView->topControls().scrollBegin();
346 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 346 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
347 347
348 // This will result in a 20px scroll to the top controls so the show ratio 348 // This will result in a 20px scroll to the top controls so the show ratio
349 // will be 30/50 == 0.6 which is not representible in a float. Make sure 349 // will be 30/50 == 0.6 which is not representible in a float. Make sure
350 // that scroll still consumes the whole delta. 350 // that scroll still consumes the whole delta.
351 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, 10)) ; 351 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, 10)) ;
352 EXPECT_EQ(0, remainingDelta.height()); 352 EXPECT_EQ(0, remainingDelta.height());
353 } 353 }
354 354
355 // Scrollable subregions should scroll before top controls 355 // Scrollable subregions should scroll before top controls
356 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst)) 356 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
357 { 357 {
358 WebViewImpl* webView = initialize("overflow-scrolling.html"); 358 WebViewImpl* webView = initialize("overflow-scrolling.html");
359 webView->setTopControlsHeight(50.f, true); 359 webView->resize(webView->size(), 50.f, true);
360 webView->topControls().setShownRatio(1); 360 webView->topControls().setShownRatio(1);
361 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll); 361 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll);
362 362
363 // Test scroll down 363 // Test scroll down
364 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll. 364 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll.
365 verticalScroll(-800.f); 365 verticalScroll(-800.f);
366 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 366 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
367 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 367 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
368 368
369 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 369 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
(...skipping 21 matching lines...) Expand all
391 verticalScroll(40.f); 391 verticalScroll(40.f);
392 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 392 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
393 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 393 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
394 } 394 }
395 395
396 396
397 // Scrollable iframes should scroll before top controls 397 // Scrollable iframes should scroll before top controls
398 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst)) 398 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
399 { 399 {
400 WebViewImpl* webView = initialize("iframe-scrolling.html"); 400 WebViewImpl* webView = initialize("iframe-scrolling.html");
401 webView->setTopControlsHeight(50.f, true); 401 webView->resize(webView->size(), 50.f, true);
402 webView->topControls().setShownRatio(1); 402 webView->topControls().setShownRatio(1);
403 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll); 403 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll);
404 404
405 // Test scroll down 405 // Test scroll down
406 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll. 406 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll.
407 verticalScroll(-800.f); 407 verticalScroll(-800.f);
408 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 408 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
409 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 409 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
410 410
411 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 411 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
(...skipping 20 matching lines...) Expand all
432 // Continued scroll down up scroll up the main frame 432 // Continued scroll down up scroll up the main frame
433 verticalScroll(40.f); 433 verticalScroll(40.f);
434 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 434 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
435 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 435 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
436 } 436 }
437 437
438 // Top controls visibility should remain consistent when height is changed. 438 // Top controls visibility should remain consistent when height is changed.
439 TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility)) 439 TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
440 { 440 {
441 WebViewImpl* webView = initialize(); 441 WebViewImpl* webView = initialize();
442 webView->setTopControlsHeight(20.f, false); 442 webView->resize(webView->size(), 20.f, false);
443 webView->topControls().setShownRatio(0); 443 webView->topControls().setShownRatio(0);
444 444
445 webView->setTopControlsHeight(20.f, false); 445 webView->resize(webView->size(), 20.f, false);
446 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 446 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
447 447
448 webView->setTopControlsHeight(40.f, false); 448 webView->resize(webView->size(), 40.f, false);
449 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 449 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
450 450
451 // Scroll up to show top controls. 451 // Scroll up to show top controls.
452 verticalScroll(40.f); 452 verticalScroll(40.f);
453 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset()); 453 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset());
454 454
455 // Changing height of a fully shown top controls should correctly adjust con tent offset 455 // Changing height of a fully shown top controls should correctly adjust con tent offset
456 webView->setTopControlsHeight(30.f, false); 456 webView->resize(webView->size(), 30.f, false);
457 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); 457 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
458 } 458 }
459 459
460 // Zero delta should not have any effect on top controls. 460 // Zero delta should not have any effect on top controls.
461 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect)) 461 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect))
462 { 462 {
463 WebViewImpl* webView = initialize(); 463 WebViewImpl* webView = initialize();
464 webView->setTopControlsHeight(0, false); 464 webView->resize(webView->size(), 0, false);
465 webView->topControls().setShownRatio(0); 465 webView->topControls().setShownRatio(0);
466 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 466 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
467 467
468 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 468 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
469 469
470 verticalScroll(20.f); 470 verticalScroll(20.f);
471 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 471 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
472 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition()); 472 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition());
473 473
474 verticalScroll(-30.f); 474 verticalScroll(-30.f);
475 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 475 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
476 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition()); 476 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition());
477 477
478 webView->topControls().setShownRatio(1); 478 webView->topControls().setShownRatio(1);
479 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 479 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
480 } 480 }
481 481
482 // Top controls should not hide when scrolling up past limit 482 // Top controls should not hide when scrolling up past limit
483 TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide)) 483 TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
484 { 484 {
485 WebViewImpl* webView = initialize(); 485 WebViewImpl* webView = initialize();
486 // Initialize top controls to be shown 486 // Initialize top controls to be shown
487 webView->setTopControlsHeight(50.f, true); 487 webView->resize(webView->size(), 50.f, true);
488 webView->topControls().setShownRatio(1); 488 webView->topControls().setShownRatio(1);
489 // Use 2x scale so that both visual viewport and frameview are scrollable 489 // Use 2x scale so that both visual viewport and frameview are scrollable
490 webView->setPageScaleFactor(2.0); 490 webView->setPageScaleFactor(2.0);
491 491
492 // Fully scroll frameview but visualviewport remains scrollable 492 // Fully scroll frameview but visualviewport remains scrollable
493 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); 493 webView->mainFrame()->setScrollOffset(WebSize(0, 10000));
494 visualViewport().setLocation(FloatPoint(0, 0)); 494 visualViewport().setLocation(FloatPoint(0, 0));
495 verticalScroll(-10.f); 495 verticalScroll(-10.f);
496 EXPECT_FLOAT_EQ(40, webView->topControls().contentOffset()); 496 EXPECT_FLOAT_EQ(40, webView->topControls().contentOffset());
497 497
(...skipping 11 matching lines...) Expand all
509 verticalScroll(-30.f); 509 verticalScroll(-30.f);
510 // Top controls should not move because neither frameview nor visual viewpor t 510 // Top controls should not move because neither frameview nor visual viewpor t
511 // are scrollable 511 // are scrollable
512 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 512 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
513 } 513 }
514 514
515 // Top controls should honor its constraints 515 // Top controls should honor its constraints
516 TEST_F(TopControlsTest, MAYBE(StateConstraints)) 516 TEST_F(TopControlsTest, MAYBE(StateConstraints))
517 { 517 {
518 WebViewImpl* webView = initialize(); 518 WebViewImpl* webView = initialize();
519 webView->setTopControlsHeight(50.f, false); 519 webView->resize(webView->size(), 50.f, false);
520 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 520 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
521 521
522 // Setting permitted state should not change content offset 522 // Setting permitted state should not change content offset
523 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse); 523 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse);
524 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 524 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
525 525
526 // Showing is permitted 526 // Showing is permitted
527 webView->topControls().setShownRatio(1); 527 webView->topControls().setShownRatio(1);
528 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); 528 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset());
529 529
(...skipping 28 matching lines...) Expand all
558 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); 558 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset());
559 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 559 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
560 } 560 }
561 561
562 // Ensure that top controls do not affect the layout by showing and hiding 562 // Ensure that top controls do not affect the layout by showing and hiding
563 // except for position: fixed elements. 563 // except for position: fixed elements.
564 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight)) 564 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
565 { 565 {
566 // Initialize with the top controls showing. 566 // Initialize with the top controls showing.
567 WebViewImpl* webView = initialize("percent-height.html"); 567 WebViewImpl* webView = initialize("percent-height.html");
568 webView->setTopControlsHeight(100.f, true); 568 webView->resize(webView->size(), 100.f, true);
569 webView->updateTopControlsState( 569 webView->updateTopControlsState(
570 WebTopControlsBoth, WebTopControlsShown, false); 570 WebTopControlsBoth, WebTopControlsShown, false);
571 webView->topControls().setShownRatio(1); 571 webView->topControls().setShownRatio(1);
572 webView->resize(WebSize(400, 300)); 572 webView->resize(WebSize(400, 300));
573 webView->updateAllLifecyclePhases(); 573 webView->updateAllLifecyclePhases();
574 574
575 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 575 ASSERT_EQ(100.f, webView->topControls().contentOffset());
576 576
577 // When the top controls are showing, there's 300px for the layout height so 577 // When the top controls are showing, there's 300px for the layout height so
578 // 50% should result in both the position:fixed and position: absolute divs 578 // 50% should result in both the position:fixed and position: absolute divs
579 // having 150px of height. 579 // having 150px of height.
580 RawPtr<Element> absPos = 580 RawPtr<Element> absPos =
581 getElementById(WebString::fromUTF8("abs")); 581 getElementById(WebString::fromUTF8("abs"));
582 RawPtr<Element> fixedPos = 582 RawPtr<Element> fixedPos =
583 getElementById(WebString::fromUTF8("fixed")); 583 getElementById(WebString::fromUTF8("fixed"));
584 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); 584 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
585 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height()); 585 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height());
586 586
587 // The layout size on the FrameView should not include the top controls. 587 // The layout size on the FrameView should not include the top controls.
588 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); 588 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
589 589
590 // Hide the top controls. 590 // Hide the top controls.
591 verticalScroll(-100.f); 591 verticalScroll(-100.f);
592 webView->setTopControlsHeight(100.f, false); 592 webView->resize(WebSize(400, 400), 100.f, false);
593 webView->resize(WebSize(400, 400));
594 webView->updateAllLifecyclePhases(); 593 webView->updateAllLifecyclePhases();
595 594
596 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 595 ASSERT_EQ(0.f, webView->topControls().contentOffset());
597 596
598 // Hiding the top controls shouldn't change the height of the initial 597 // Hiding the top controls shouldn't change the height of the initial
599 // containing block for non-position: fixed. Position: fixed however should 598 // containing block for non-position: fixed. Position: fixed however should
600 // use the entire height of the viewport however. 599 // use the entire height of the viewport however.
601 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); 600 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
602 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 601 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
603 602
604 // The layout size should not change as a result of top controls hiding. 603 // The layout size should not change as a result of top controls hiding.
605 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); 604 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
606 } 605 }
607 606
608 // Ensure that top controls do not affect vh units. 607 // Ensure that top controls do not affect vh units.
609 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits)) 608 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
610 { 609 {
611 // Initialize with the top controls showing. 610 // Initialize with the top controls showing.
612 WebViewImpl* webView = initialize("vh-height.html"); 611 WebViewImpl* webView = initialize("vh-height.html");
613 webView->setTopControlsHeight(100.f, true); 612 webView->resize(WebSize(400, 300), 100.f, true);
614 webView->updateTopControlsState( 613 webView->updateTopControlsState(
615 WebTopControlsBoth, WebTopControlsShown, false); 614 WebTopControlsBoth, WebTopControlsShown, false);
616 webView->topControls().setShownRatio(1); 615 webView->topControls().setShownRatio(1);
617 webView->resize(WebSize(400, 300));
618 webView->updateAllLifecyclePhases(); 616 webView->updateAllLifecyclePhases();
619 617
620 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 618 ASSERT_EQ(100.f, webView->topControls().contentOffset());
621 619
622 // 'vh' units should be based on the viewport when the top controls are 620 // 'vh' units should be based on the viewport when the top controls are
623 // hidden. 621 // hidden.
624 RawPtr<Element> absPos = 622 RawPtr<Element> absPos =
625 getElementById(WebString::fromUTF8("abs")); 623 getElementById(WebString::fromUTF8("abs"));
626 RawPtr<Element> fixedPos = 624 RawPtr<Element> fixedPos =
627 getElementById(WebString::fromUTF8("fixed")); 625 getElementById(WebString::fromUTF8("fixed"));
628 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); 626 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
629 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 627 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
630 628
631 // The size used for viewport units should not be reduced by the top 629 // The size used for viewport units should not be reduced by the top
632 // controls. 630 // controls.
633 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); 631 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
634 632
635 // Hide the top controls. 633 // Hide the top controls.
636 verticalScroll(-100.f); 634 verticalScroll(-100.f);
637 webView->setTopControlsHeight(100.f, false); 635 webView->resize(WebSize(400, 400), 100.f, false);
638 webView->resize(WebSize(400, 400));
639 webView->updateAllLifecyclePhases(); 636 webView->updateAllLifecyclePhases();
640 637
641 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 638 ASSERT_EQ(0.f, webView->topControls().contentOffset());
642 639
643 // vh units should be static with respect to the top controls so neighter 640 // vh units should be static with respect to the top controls so neighter
644 // <div> should change size are a result of the top controls hiding. 641 // <div> should change size are a result of the top controls hiding.
645 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); 642 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
646 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 643 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
647 644
648 // The viewport size used for vh units should not change as a result of top 645 // The viewport size used for vh units should not change as a result of top
649 // controls hiding. 646 // controls hiding.
650 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); 647 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
651 } 648 }
652 649
653 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill 650 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill
654 // the viewport, with top controls hidden, when the viewport encompasses the 651 // the viewport, with top controls hidden, when the viewport encompasses the
655 // layout width. 652 // layout width.
656 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale)) 653 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale))
657 { 654 {
658 // Initialize with the top controls showing. 655 // Initialize with the top controls showing.
659 WebViewImpl* webView = initialize("vh-height-width-800.html"); 656 WebViewImpl* webView = initialize("vh-height-width-800.html");
660 webView->setTopControlsHeight(100.f, true); 657 webView->resize(WebSize(400, 300), 100.f, true);
661 webView->updateTopControlsState( 658 webView->updateTopControlsState(
662 WebTopControlsBoth, WebTopControlsShown, false); 659 WebTopControlsBoth, WebTopControlsShown, false);
663 webView->topControls().setShownRatio(1); 660 webView->topControls().setShownRatio(1);
664 webView->resize(WebSize(400, 300));
665 webView->updateAllLifecyclePhases(); 661 webView->updateAllLifecyclePhases();
666 662
667 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 663 ASSERT_EQ(100.f, webView->topControls().contentOffset());
668 664
669 // Device viewport is 400px but the page is width=800 so minimum-scale 665 // Device viewport is 400px but the page is width=800 so minimum-scale
670 // should be 0.5. This is also the scale at which the viewport fills the 666 // should be 0.5. This is also the scale at which the viewport fills the
671 // layout width. 667 // layout width.
672 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor()); 668 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor());
673 669
674 // We should size vh units so that 100vh fills the viewport at min-scale so 670 // We should size vh units so that 100vh fills the viewport at min-scale so
675 // we have to account for the minimum page scale factor. Since both boxes 671 // we have to account for the minimum page scale factor. Since both boxes
676 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 80 0 672 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 80 0
677 // so we expect 50vh to be 400px. 673 // so we expect 50vh to be 400px.
678 RawPtr<Element> absPos = 674 RawPtr<Element> absPos =
679 getElementById(WebString::fromUTF8("abs")); 675 getElementById(WebString::fromUTF8("abs"));
680 RawPtr<Element> fixedPos = 676 RawPtr<Element> fixedPos =
681 getElementById(WebString::fromUTF8("fixed")); 677 getElementById(WebString::fromUTF8("fixed"));
682 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); 678 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height());
683 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); 679 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height());
684 680
685 // The size used for viewport units should not be reduced by the top 681 // The size used for viewport units should not be reduced by the top
686 // controls. 682 // controls.
687 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 683 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
688 684
689 // Hide the top controls. 685 // Hide the top controls.
690 verticalScroll(-100.f); 686 verticalScroll(-100.f);
691 webView->setTopControlsHeight(100.f, false); 687 webView->resize(WebSize(400, 400), 100.f, false);
692 webView->resize(WebSize(400, 400));
693 webView->updateAllLifecyclePhases(); 688 webView->updateAllLifecyclePhases();
694 689
695 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 690 ASSERT_EQ(0.f, webView->topControls().contentOffset());
696 691
697 // vh units should be static with respect to the top controls so neighter 692 // vh units should be static with respect to the top controls so neighter
698 // <div> should change size are a result of the top controls hiding. 693 // <div> should change size are a result of the top controls hiding.
699 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); 694 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height());
700 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); 695 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height());
701 696
702 // The viewport size used for vh units should not change as a result of top 697 // The viewport size used for vh units should not change as a result of top
703 // controls hiding. 698 // controls hiding.
704 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 699 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
705 } 700 }
706 701
707 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport 702 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport
708 // at minimum-scale is larger than the layout size, 100vh units fill the 703 // at minimum-scale is larger than the layout size, 100vh units fill the
709 // viewport, with top controls hidden, when the viewport is scaled such that 704 // viewport, with top controls hidden, when the viewport is scaled such that
710 // its width equals the layout width. 705 // its width equals the layout width.
711 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize)) 706 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize))
712 { 707 {
713 // Initialize with the top controls showing. 708 // Initialize with the top controls showing.
714 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html"); 709 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html");
715 webView->setTopControlsHeight(100.f, true); 710 webView->resize(WebSize(400, 300), 100.f, true);
716 webView->updateTopControlsState( 711 webView->updateTopControlsState(
717 WebTopControlsBoth, WebTopControlsShown, false); 712 WebTopControlsBoth, WebTopControlsShown, false);
718 webView->topControls().setShownRatio(1); 713 webView->topControls().setShownRatio(1);
719 webView->resize(WebSize(400, 300));
720 webView->updateAllLifecyclePhases(); 714 webView->updateAllLifecyclePhases();
721 715
722 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 716 ASSERT_EQ(100.f, webView->topControls().contentOffset());
723 717
724 // Device viewport is 400px and page is width=800 but there's an element 718 // Device viewport is 400px and page is width=800 but there's an element
725 // that's 1600px wide so the minimum scale is 0.25 to encompass that. 719 // that's 1600px wide so the minimum scale is 0.25 to encompass that.
726 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor()); 720 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor());
727 721
728 // The viewport will match the layout width at scale=0.5 so the height used 722 // The viewport will match the layout width at scale=0.5 so the height used
729 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top 723 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top
730 // controls = 800. 724 // controls = 800.
731 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 725 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
732 } 726 }
733 727
728 // This tests that the viewport remains anchored when top controls are brought
729 // in while the document is fully scrolled. This normally causes clamping of the
730 // visual viewport to keep it bounded by the layout viewport so we're testing
731 // that the viewport anchoring logic is working to keep the view unchanged.
732 TEST_F(TopControlsTest, MAYBE(AnchorViewportDuringIncreasingAdjustment))
733 {
734 int contentHeight = 1016;
735 int layoutViewportHeight = 500;
736 int visualViewportHeight = 500;
737 int topControlsHeight = 100;
738 int pageScale = 2;
739 int minScale = 1;
740
741 // Initialize with the top controls showing.
742 WebViewImpl* webView = initialize("large-div.html");
743 webViewImpl()->setDefaultPageScaleLimits(minScale, 5);
744 webView->updateTopControlsState(
745 WebTopControlsBoth, WebTopControlsShown, false);
746 webView->topControls().setShownRatio(1);
747 webView->resize(
748 WebSize(800, layoutViewportHeight),
749 topControlsHeight,
750 true);
751 webView->updateAllLifecyclePhases();
752
753 FrameView* view = frame()->view();
754 ScrollableArea* rootViewport = frame()->view()->getScrollableArea();
755
756 int expectedVisualOffset =
757 ((layoutViewportHeight + topControlsHeight / minScale) * pageScale
758 - (visualViewportHeight + topControlsHeight))
759 / pageScale;
760 int expectedLayoutOffset =
761 contentHeight - (layoutViewportHeight + topControlsHeight / minScale);
762 int expectedRootOffset = expectedVisualOffset + expectedLayoutOffset;
763
764 // Zoom in to 2X and fully scroll both viewports.
765 webView->setPageScaleFactor(pageScale);
766 {
767 webView->handleInputEvent(
768 generateEvent(WebInputEvent::GestureScrollBegin));
769 webView->handleInputEvent(
770 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -10000));
771
772 ASSERT_EQ(0.f, webView->topControls().contentOffset());
773
774 EXPECT_EQ(expectedVisualOffset, visualViewport().location().y());
775 EXPECT_EQ(expectedLayoutOffset,
776 view->layoutViewportScrollableArea()->scrollPosition().y());
777 EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
778
779 webView->handleInputEvent(
780 generateEvent(WebInputEvent::GestureScrollEnd));
781 }
782
783 // Commit the top controls resize so that the top controls do not shrink the
784 // layout size. This should not have moved any of the viewports.
785 webView->resize(
786 WebSize(800, layoutViewportHeight + topControlsHeight),
787 topControlsHeight,
788 false);
789 webView->updateAllLifecyclePhases();
790 ASSERT_EQ(expectedVisualOffset, visualViewport().location().y());
791 ASSERT_EQ(expectedLayoutOffset,
792 view->layoutViewportScrollableArea()->scrollPosition().y());
793 ASSERT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
794
795 // Now scroll back up just enough to show the top controls. The top controls
796 // should shrink both viewports but the layout viewport by a greater amount.
797 // This means the visual viewport's offset must be clamped to keep it within
798 // the layout viewport. Make sure we adjust the scroll position to account
799 // for this and keep the visual viewport at the same location relative to
800 // the document (i.e. the user shouldn't see a movement).
801 {
802 webView->handleInputEvent(
803 generateEvent(WebInputEvent::GestureScrollBegin));
804 webView->handleInputEvent(
805 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 80));
806
807 visualViewport().clampToBoundaries();
808 view->setScrollPosition(view->scrollPosition(), ProgrammaticScroll);
809
810 ASSERT_EQ(80.f, webView->topControls().contentOffset());
811 EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
812
813 webView->handleInputEvent(
814 generateEvent(WebInputEvent::GestureScrollEnd));
815 }
816 }
817
734 } // namespace blink 818 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698