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

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

Issue 1573283002: Don't change layout size due to top control show/hide (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 11 matching lines...) Expand all
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/TopControls.h"
31 31
32 #include "core/dom/ClientRect.h"
32 #include "core/frame/FrameHost.h" 33 #include "core/frame/FrameHost.h"
33 #include "core/frame/FrameView.h" 34 #include "core/frame/FrameView.h"
34 #include "core/frame/LocalFrame.h" 35 #include "core/frame/LocalFrame.h"
35 #include "core/layout/LayoutView.h" 36 #include "core/layout/LayoutView.h"
36 #include "core/page/Page.h" 37 #include "core/page/Page.h"
37 #include "platform/testing/URLTestHelpers.h" 38 #include "platform/testing/URLTestHelpers.h"
38 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
39 #include "public/platform/WebUnitTestSupport.h" 40 #include "public/platform/WebUnitTestSupport.h"
41 #include "public/web/WebElement.h"
40 #include "public/web/WebSettings.h" 42 #include "public/web/WebSettings.h"
41 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
42 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
43 #include "web/WebLocalFrameImpl.h" 45 #include "web/WebLocalFrameImpl.h"
44 #include "web/tests/FrameTestHelpers.h" 46 #include "web/tests/FrameTestHelpers.h"
45 47
46 namespace blink { 48 namespace blink {
47 49
48 // These tests cover top controls scrolling on main-thread. 50 // These tests cover top controls scrolling on main-thread.
49 // The animation for completing a partial show/hide is done in compositor so 51 // The animation for completing a partial show/hide is done in compositor so
50 // it is not covered here. 52 // it is not covered here.
51 class TopControlsTest : public testing::Test { 53 class TopControlsTest : public testing::Test {
52 public: 54 public:
53 TopControlsTest() 55 TopControlsTest()
54 : m_baseURL("http://www.test.com/") 56 : m_baseURL("http://www.test.com/")
55 { 57 {
56 registerMockedHttpURLLoad("large-div.html"); 58 registerMockedHttpURLLoad("large-div.html");
57 registerMockedHttpURLLoad("overflow-scrolling.html"); 59 registerMockedHttpURLLoad("overflow-scrolling.html");
58 registerMockedHttpURLLoad("iframe-scrolling.html"); 60 registerMockedHttpURLLoad("iframe-scrolling.html");
59 registerMockedHttpURLLoad("iframe-scrolling-inner.html"); 61 registerMockedHttpURLLoad("iframe-scrolling-inner.html");
62 registerMockedHttpURLLoad("percent-height.html");
63 registerMockedHttpURLLoad("vh-height.html");
60 } 64 }
61 65
62 ~TopControlsTest() override 66 ~TopControlsTest() override
63 { 67 {
64 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 68 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
65 } 69 }
66 70
67 WebViewImpl* initialize(const std::string& pageName = "large-div.html") 71 WebViewImpl* initialize(const std::string& pageName = "large-div.html")
68 { 72 {
69 // Load a page with large body and set viewport size to 400x400 to ensur e 73 // Load a page with large body and set viewport size to 400x400 to ensur e
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 return event; 109 return event;
106 } 110 }
107 111
108 void verticalScroll(float deltaY) 112 void verticalScroll(float deltaY)
109 { 113 {
110 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llBegin)); 114 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llBegin));
111 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llUpdate, 0, deltaY)); 115 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llUpdate, 0, deltaY));
112 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llEnd)); 116 webViewImpl()->handleInputEvent(generateEvent(WebInputEvent::GestureScro llEnd));
113 } 117 }
114 118
119 PassRefPtrWillBeRawPtr<Element> getElementById(const WebString& id)
120 {
121 return static_cast<PassRefPtrWillBeRawPtr<Element>>(
122 webViewImpl()->mainFrame()->document().getElementById(id));
123 }
124
125
115 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); } 126 WebViewImpl* webViewImpl() const { return m_helper.webViewImpl(); }
116 LocalFrame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()-> frame(); } 127 LocalFrame* frame() const { return m_helper.webViewImpl()->mainFrameImpl()-> frame(); }
117 VisualViewport& visualViewport() const { return m_helper.webViewImpl()->page ()->frameHost().visualViewport(); } 128 VisualViewport& visualViewport() const { return m_helper.webViewImpl()->page ()->frameHost().visualViewport(); }
118 129
119 private: 130 private:
120 std::string m_baseURL; 131 std::string m_baseURL;
121 FrameTestHelpers::WebViewHelper m_helper; 132 FrameTestHelpers::WebViewHelper m_helper;
122 }; 133 };
123 134
124 #define EXPECT_POINT_EQ(expected, actual) \ 135 #define EXPECT_POINT_EQ(expected, actual) \
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // Both states are permitted so controls can either show or hide 548 // Both states are permitted so controls can either show or hide
538 verticalScroll(50.f); 549 verticalScroll(50.f);
539 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); 550 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset());
540 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 551 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
541 552
542 verticalScroll(-50.f); 553 verticalScroll(-50.f);
543 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); 554 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset());
544 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 555 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
545 } 556 }
546 557
558 // Ensure that top controls do not affect the layout by showing and hiding
559 // except for position: fixed elements.
560 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
561 {
562 // Initialize with the top controls showing.
563 WebViewImpl* webView = initialize("percent-height.html");
564 webView->setTopControlsHeight(100.f, true);
565 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, fal se);
566 webView->topControls().setShownRatio(1);
567 webView->resize(WebSize(400, 300));
568 webView->updateAllLifecyclePhases();
569 EXPECT_FLOAT_EQ(100.f, webView->topControls().contentOffset());
570
571 // When the top controls are showing, there's 300px for the layout height so 50%
572 // should result in both the position:fixed and position: absolute divs havi ng
573 // 150px of height.
574 RefPtrWillBeRawPtr<Element> absPos = getElementById(WebString::fromUTF8("abs "));
575 RefPtrWillBeRawPtr<Element> fixedPos = getElementById(WebString::fromUTF8("f ixed"));
576 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
577 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height());
578
579 // The layout size on the FrameView should not include the top controls.
580 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
581
582 // Hide the top controls.
583 verticalScroll(-100.f);
584 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
585 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
586 webView->setTopControlsHeight(100.f, false);
587 webView->resize(WebSize(400, 400));
588 webView->updateAllLifecyclePhases();
589
590 // Hiding the top controls shouldn't change the height of the initial
591 // containing block for non-position: fixed. Position: fixed however should
592 // use the entire height of the viewport however.
593 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
594 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
595
596 // The layout size should not change as a result of top controls hiding.
597 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
598 }
599
600 // Ensure that top controls do not affect vh units.
601 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
602 {
603 // Initialize with the top controls showing.
604 WebViewImpl* webView = initialize("vh-height.html");
605 webView->setTopControlsHeight(100.f, true);
606 webView->updateTopControlsState(WebTopControlsBoth, WebTopControlsShown, fal se);
607 webView->topControls().setShownRatio(1);
608 webView->resize(WebSize(400, 300));
609 webView->updateAllLifecyclePhases();
610 EXPECT_FLOAT_EQ(100.f, webView->topControls().contentOffset());
611
612 // 'vh' units should be based on the viewport when the top controls are
613 // hidden.
614 RefPtrWillBeRawPtr<Element> absPos = getElementById(WebString::fromUTF8("abs "));
615 RefPtrWillBeRawPtr<Element> fixedPos = getElementById(WebString::fromUTF8("f ixed"));
616 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
617 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
618
619 // The size used for viewport units should not be reduced by the top control s.
620 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
621
622 // Hide the top controls.
623 verticalScroll(-100.f);
624 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
625 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
626 webView->setTopControlsHeight(100.f, false);
627 webView->resize(WebSize(400, 400));
628 webView->updateAllLifecyclePhases();
629
630 // vh units should be static with respect to the top controls so neighter
631 // <div> should change size are a result of the top controls hiding.
632 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
633 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
634
635 // The viewport size used for vh units should not change as a result of top controls hiding.
636 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
637 }
638
547 } // namespace blink 639 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698