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

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

Issue 1158673006: Replace various ScrollableArea scroll methods with setScrollPosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Build fix Created 5 years, 6 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
« no previous file with comments | « Source/web/tests/ScrollAnimatorNoneTest.cpp ('k') | Source/web/tests/TouchActionTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 193
194 // Scrolling up after previous scroll downs should cause top controls to be 194 // Scrolling up after previous scroll downs should cause top controls to be
195 // shown only after all previously scrolled down amount is compensated. 195 // shown only after all previously scrolled down amount is compensated.
196 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp)) 196 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp))
197 { 197 {
198 WebViewImpl* webView = initialize(); 198 WebViewImpl* webView = initialize();
199 // initialize top controls to be shown and position page at 100px. 199 // initialize top controls to be shown and position page at 100px.
200 webView->setTopControlsHeight(50.f, true); 200 webView->setTopControlsHeight(50.f, true);
201 webView->topControls().setShownRatio(1); 201 webView->topControls().setShownRatio(1);
202 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100)); 202 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100), Progr ammaticScroll);
203 203
204 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 204 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
205 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 205 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
206 206
207 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page. 207 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page.
208 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f)); 208 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f));
209 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 209 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
210 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition()); 210 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition());
211 211
212 // Scroll up and ensure the top controls does not move until we recover 100p x previously scrolled. 212 // Scroll up and ensure the top controls does not move until we recover 100p x previously scrolled.
(...skipping 17 matching lines...) Expand all
230 } 230 }
231 231
232 // Scrolling down should always cause visible top controls to start hiding even 232 // Scrolling down should always cause visible top controls to start hiding even
233 // if we have been scrolling up previously. 233 // if we have been scrolling up previously.
234 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown)) 234 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown))
235 { 235 {
236 WebViewImpl* webView = initialize(); 236 WebViewImpl* webView = initialize();
237 // initialize top controls to be hidden and position page at 100px. 237 // initialize top controls to be hidden and position page at 100px.
238 webView->setTopControlsHeight(50.f, false); 238 webView->setTopControlsHeight(50.f, false);
239 webView->topControls().setShownRatio(0); 239 webView->topControls().setShownRatio(0);
240 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100)); 240 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100), Progr ammaticScroll);
241 241
242 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 242 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
243 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 243 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
244 244
245 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page. 245 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page.
246 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f)); 246 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f));
247 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 247 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
248 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 248 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
249 249
250 // Scroll down and ensure only top controls is scrolled 250 // Scroll down and ensure only top controls is scrolled
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, -10) ); 344 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, -10) );
345 EXPECT_EQ(0, remainingDelta.height()); 345 EXPECT_EQ(0, remainingDelta.height());
346 } 346 }
347 347
348 // Scrollable subregions should scroll before top controls 348 // Scrollable subregions should scroll before top controls
349 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst)) 349 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
350 { 350 {
351 WebViewImpl* webView = initialize("overflow-scrolling.html"); 351 WebViewImpl* webView = initialize("overflow-scrolling.html");
352 webView->setTopControlsHeight(50.f, true); 352 webView->setTopControlsHeight(50.f, true);
353 webView->topControls().setShownRatio(1); 353 webView->topControls().setShownRatio(1);
354 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 50)); 354 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 50), Progra mmaticScroll);
355 355
356 // Test scroll down 356 // Test scroll down
357 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll. 357 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll.
358 verticalScroll(-800.f); 358 verticalScroll(-800.f);
359 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 359 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
360 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 360 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
361 361
362 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 362 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
363 verticalScroll(-40.f); 363 verticalScroll(-40.f);
364 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 364 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
(...skipping 21 matching lines...) Expand all
386 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 386 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
387 } 387 }
388 388
389 389
390 // Scrollable iframes should scroll before top controls 390 // Scrollable iframes should scroll before top controls
391 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst)) 391 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
392 { 392 {
393 WebViewImpl* webView = initialize("iframe-scrolling.html"); 393 WebViewImpl* webView = initialize("iframe-scrolling.html");
394 webView->setTopControlsHeight(50.f, true); 394 webView->setTopControlsHeight(50.f, true);
395 webView->topControls().setShownRatio(1); 395 webView->topControls().setShownRatio(1);
396 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 50)); 396 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 50), Progra mmaticScroll);
397 397
398 // Test scroll down 398 // Test scroll down
399 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll. 399 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll.
400 verticalScroll(-800.f); 400 verticalScroll(-800.f);
401 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 401 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
402 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 402 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
403 403
404 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 404 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
405 verticalScroll(-40.f); 405 verticalScroll(-40.f);
406 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 406 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 webView->setTopControlsHeight(30.f, false); 449 webView->setTopControlsHeight(30.f, false);
450 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); 450 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
451 } 451 }
452 452
453 // Zero delta should not have any effect on top controls. 453 // Zero delta should not have any effect on top controls.
454 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect)) 454 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect))
455 { 455 {
456 WebViewImpl* webView = initialize(); 456 WebViewImpl* webView = initialize();
457 webView->setTopControlsHeight(0, false); 457 webView->setTopControlsHeight(0, false);
458 webView->topControls().setShownRatio(0); 458 webView->topControls().setShownRatio(0);
459 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100)); 459 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100), Progr ammaticScroll);
460 460
461 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 461 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
462 462
463 verticalScroll(20.f); 463 verticalScroll(20.f);
464 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 464 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
465 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition()); 465 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition());
466 466
467 verticalScroll(-30.f); 467 verticalScroll(-30.f);
468 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 468 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
469 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition()); 469 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 // Top controls should not move because neither frameview nor pinch viewport 503 // Top controls should not move because neither frameview nor pinch viewport
504 // are scrollable 504 // are scrollable
505 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 505 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
506 } 506 }
507 507
508 // Top controls should honor its constraints 508 // Top controls should honor its constraints
509 TEST_F(TopControlsTest, MAYBE(StateConstraints)) 509 TEST_F(TopControlsTest, MAYBE(StateConstraints))
510 { 510 {
511 WebViewImpl* webView = initialize(); 511 WebViewImpl* webView = initialize();
512 webView->setTopControlsHeight(50.f, false); 512 webView->setTopControlsHeight(50.f, false);
513 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100)); 513 frame()->view()->scrollableArea()->setScrollPosition(IntPoint(0, 100), Progr ammaticScroll);
514 514
515 // Setting permitted state should not change content offset 515 // Setting permitted state should not change content offset
516 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse); 516 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse);
517 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 517 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
518 518
519 // Showing is permitted 519 // Showing is permitted
520 webView->topControls().setShownRatio(1); 520 webView->topControls().setShownRatio(1);
521 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); 521 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset());
522 522
523 // Only shown state is permitted so controls cannot hide 523 // Only shown state is permitted so controls cannot hide
(...skipping 22 matching lines...) Expand all
546 verticalScroll(50.f); 546 verticalScroll(50.f);
547 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); 547 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset());
548 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 548 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
549 549
550 verticalScroll(-50.f); 550 verticalScroll(-50.f);
551 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); 551 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset());
552 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 552 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
553 } 553 }
554 554
555 } // namespace 555 } // namespace
OLDNEW
« no previous file with comments | « Source/web/tests/ScrollAnimatorNoneTest.cpp ('k') | Source/web/tests/TouchActionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698