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

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: Whitespace 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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 // Device viewport is 400px and page is width=800 but there's an element 724 // 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. 725 // that's 1600px wide so the minimum scale is 0.25 to encompass that.
726 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor()); 726 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor());
727 727
728 // The viewport will match the layout width at scale=0.5 so the height used 728 // 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 729 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top
730 // controls = 800. 730 // controls = 800.
731 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 731 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
732 } 732 }
733 733
734 // This tests that the viewport remains anchored when top controls are brought
735 // in while the document is fully scrolled. This normally causes clamping of the
736 // visual viewport to keep it bounded by the layout viewport so we're testing
737 // that the viewport anchoring logic is working to keep the view unchanged.
738 TEST_F(TopControlsTest, MAYBE(AnchorViewportDuringTopControlsAdjustment))
739 {
740 int contentHeight = 1016;
741 int layoutViewportHeight = 500;
742 int visualViewportHeight = 500;
743 int topControlsHeight = 100;
744 int pageScale = 2;
745 int minScale = 1;
746
747 // Initialize with the top controls showing.
748 WebViewImpl* webView = initialize("large-div.html");
749 webViewImpl()->setDefaultPageScaleLimits(minScale, 5);
750 webView->setTopControlsHeight(topControlsHeight, true);
751 webView->updateTopControlsState(
752 WebTopControlsBoth, WebTopControlsShown, false);
753 webView->topControls().setShownRatio(1);
754 webView->resize(WebSize(800, layoutViewportHeight));
755 webView->updateAllLifecyclePhases();
756
757 FrameView* view = frame()->view();
758 ScrollableArea* rootViewport = frame()->view()->getScrollableArea();
759
760 int expectedVisualOffset =
761 ((layoutViewportHeight + topControlsHeight / minScale) * pageScale
762 - (visualViewportHeight + topControlsHeight))
763 / pageScale;
764 int expectedLayoutOffset =
765 contentHeight - (layoutViewportHeight + topControlsHeight / minScale);
766
767 // Zoom in to 2X and fully scroll both viewports.
768 webView->setPageScaleFactor(pageScale);
769 {
770 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegi n));
771 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpda te, 0, -10000));
772
773 ASSERT_EQ(0.f, webView->topControls().contentOffset());
774
775 EXPECT_EQ(expectedVisualOffset, visualViewport().location().y());
776 EXPECT_EQ(expectedLayoutOffset, view->layoutViewportScrollableArea()->sc rollPosition().y());
777 EXPECT_EQ(expectedVisualOffset + expectedLayoutOffset, rootViewport->scr ollPosition().y());
majidvp 2016/04/01 17:09:36 s/expectedVisualOffset + expectedLayoutOffset/expe
bokan 2016/04/05 17:11:40 Done.
778
779 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd) );
780 }
781
782 webView->setTopControlsHeight(topControlsHeight, false);
783 webView->resize(WebSize(800, 600));
majidvp 2016/04/01 17:09:36 600? did you mean layoutViewportHeight + topContro
bokan 2016/04/05 17:11:40 Done.
784 webView->updateAllLifecyclePhases();
785
786 // Commit the top controls resize so that the top controls do not shrink the
787 // layout size. This should not have moved any of the viewports.
788 int previousRootOffset = expectedVisualOffset + expectedLayoutOffset;
majidvp 2016/04/01 17:09:36 You can use expectedRootOffset which should be def
bokan 2016/04/05 17:11:40 Done.
789 ASSERT_EQ(expectedVisualOffset, visualViewport().location().y());
790 ASSERT_EQ(expectedLayoutOffset,
791 view->layoutViewportScrollableArea()->scrollPosition().y());
792 ASSERT_EQ(previousRootOffset, rootViewport->scrollPosition().y());
793
794 // Now scroll back up just enough to show the top controls. The top controls
795 // should shrink both viewports but the layout viewport by a greater amount.
796 // This means the visual viewport's offset must be clamped to keep it within
797 // the layout viewport. Make sure we adjust the scroll position to account
798 // for this and keep the visual viewport at the same location relative to
799 // the document (i.e. the user shouldn't see a movement).
800 {
801 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegi n));
802 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpda te, 0, 100));
majidvp 2016/04/01 17:09:36 100 is the same as topControlsHeight which may be
bokan 2016/04/05 17:11:40 Changed to 80.
803
804 visualViewport().clampToBoundaries();
805 view->setScrollPosition(view->scrollPosition(), ProgrammaticScroll);
majidvp 2016/04/01 17:09:36 Why are these clamps required?
bokan 2016/04/05 17:11:40 If we don't run the anchoring logic, the viewport
806
807 ASSERT_EQ(100.f, webView->topControls().contentOffset());
808 EXPECT_EQ(previousRootOffset, rootViewport->scrollPosition().y());
809
810 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollEnd) );
811 }
812 }
813
734 } // namespace blink 814 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698