/* * Copyright (C) 2015 Google Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "third_party/blink/renderer/core/frame/browser_controls.h" #include "build/build_config.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/common/input/web_coalesced_input_event.h" #include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_settings.h" #include "third_party/blink/renderer/core/css/css_variable_data.h" #include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/qualified_name.h" #include "third_party/blink/renderer/core/frame/frame_test_helpers.h" #include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/visual_viewport.h" #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" #include "third_party/blink/renderer/core/fullscreen/fullscreen.h" #include "third_party/blink/renderer/core/geometry/dom_rect.h" #include "third_party/blink/renderer/core/layout/layout_view.h" #include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/paint/paint_and_raster_invalidation_test.h" #include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h" #include "third_party/blink/renderer/core/testing/scoped_mock_overlay_scrollbars.h" #include "third_party/blink/renderer/core/testing/sim/sim_request.h" #include "third_party/blink/renderer/core/testing/sim/sim_test.h" #include "third_party/blink/renderer/platform/testing/task_environment.h" #include "third_party/blink/renderer/platform/testing/testing_platform_support.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/url_loader_mock_factory.h" #include "third_party/blink/renderer/platform/testing/url_test_helpers.h" #include "ui/gfx/geometry/insets.h" namespace blink { namespace { // From browser_controls_offset_manager.cc. const int64_t kShowHideMaxDurationMs = …; } // namespace // These tests cover interactions between scrolling and browser controls, with a // focus on Blink-observable side effects. Scrolling happens in the compositor, // but browser controls state is propagated into blink::BrowserControls through // LayerTreeHost::ApplyCompositorChanges. Additional tests relating to cc state // can be found under LayerTreeHostImplBrowserControlsTest. class BrowserControlsTest : public testing::Test, public ScopedMockOverlayScrollbars { … }; class BrowserControlsSimTest : public SimTest { … }; struct ViewportUnitTestCase { … }; class BrowserControlsViewportUnitTest : public BrowserControlsTest, public ::testing::WithParamInterface<ViewportUnitTestCase> { … }; // Disable these tests on Mac OSX until further investigation. // Local build on Mac is OK but the bot fails. This is not an issue as // Browser Controls are currently only used on Android. #if BUILDFLAG(IS_MAC) #define MAYBE … #else #define MAYBE … #endif // Scrolling down should hide browser controls. TEST_F(BrowserControlsTest, MAYBE(HideOnScrollDown)) { … } // Scrolling down should hide bottom browser controls. TEST_F(BrowserControlsTest, MAYBE(HideBottomControlsOnScrollDown)) { … } TEST_F(BrowserControlsTest, MAYBE(DynamicSafeAreaInsetBottomUntilScrollDownFinished)) { … } TEST_F(BrowserControlsTest, MAYBE(DynamicSafeAreaInsetBottomScrollDown)) { … } // Scrolling up should show browser controls. TEST_F(BrowserControlsTest, MAYBE(ShowOnScrollUp)) { … } // Scrolling up should show the bottom browser controls. TEST_F(BrowserControlsTest, MAYBE(ShowBottomControlsOnScrollUp)) { … } TEST_F(BrowserControlsTest, MAYBE(DynamicSafeAreaInsetBottomUntilScrollUpFinished)) { … } TEST_F(BrowserControlsTest, MAYBE(DynamicSafeAreaInsetBottomScrollUp)) { … } // Scrolling up after previous scroll downs should cause browser controls to be // shown only after all previously scrolled down amount is compensated. TEST_F(BrowserControlsTest, MAYBE(ScrollDownThenUp)) { … } // Scrolling down should always cause visible browser controls to start hiding // even if we have been scrolling up previously. TEST_F(BrowserControlsTest, MAYBE(ScrollUpThenDown)) { … } // Browser controls should not consume horizontal scroll. TEST_F(BrowserControlsTest, MAYBE(HorizontalScroll)) { … } // Page scale should not impact browser controls scrolling TEST_F(BrowserControlsTest, MAYBE(PageScaleHasNoImpact)) { … } // Scrollable subregions should scroll before browser controls TEST_F(BrowserControlsTest, MAYBE(ScrollableSubregionScrollFirst)) { … } // Scrollable iframes should scroll before browser controls TEST_F(BrowserControlsTest, MAYBE(ScrollableIframeScrollFirst)) { … } TEST_F(BrowserControlsTest, MAYBE(SetMaxSafeAreaInsetWithDynamicSafeAreaInsets)) { … } TEST_F(BrowserControlsTest, MAYBE(SetMaxSafeAreaInsetWithSubFrames)) { … } TEST_F(BrowserControlsTest, MAYBE(SetMaxSafeAreaInsetWithSubFramesWithDynamicSafeAreaInsets)) { … } // Browser controls visibility should remain consistent when height is changed. TEST_F(BrowserControlsTest, MAYBE(HeightChangeMaintainsVisibility)) { … } // Zero delta should not have any effect on browser controls. TEST_F(BrowserControlsTest, MAYBE(ZeroHeightMeansNoEffect)) { … } // Browser controls should not hide when scrolling up past limit TEST_F(BrowserControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide)) { … } // Browser controls should honor its constraints TEST_F(BrowserControlsSimTest, MAYBE(StateConstraints)) { … } // Ensure that browser controls do not affect the layout by showing and hiding // except for position: fixed elements. TEST_F(BrowserControlsTest, MAYBE(DontAffectLayoutHeight)) { … } // Ensure that browser controls do not affect the layout by showing and hiding // except for position: fixed elements. TEST_F(BrowserControlsSimTest, MAYBE(AffectLayoutHeightWhenConstrained)) { … } // Ensure that browser controls affect layout of viewport constrained // position: sticky elements. TEST_F(BrowserControlsSimTest, MAYBE(AffectViewportConstrainedSticky)) { … } // Ensure that browser controls do not affect "static" viewport units // (vh, svh, lvh). TEST_P(BrowserControlsViewportUnitTest, MAYBE(DontAffectStaticUnits)) { … } static ViewportUnitTestCase viewport_unit_test_cases[] = …; INSTANTIATE_TEST_SUITE_P(…); // Ensure that browser controls *do* affect dvh units. TEST_F(BrowserControlsTest, MAYBE(DoAffectDVHUnits)) { … } // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill // the viewport, with browser controls hidden, when the viewport encompasses the // layout width. TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnitsWithScale)) { … } // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport // at minimum-scale is larger than the layout size, 100vh units fill the // viewport, with browser controls hidden, when the viewport is scaled such that // its width equals the layout width. TEST_F(BrowserControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize)) { … } // Ensure that vh units are correctly calculated when a top controls min-height // is set. TEST_F(BrowserControlsTest, MAYBE(VHUnitsWithTopMinHeight)) { … } // Ensure that vh units are correctly calculated when a bottom controls // min-height is set. TEST_F(BrowserControlsTest, MAYBE(VHUnitsWithBottomMinHeight)) { … } // Ensure that vh units are correctly calculated with changing min-heights. TEST_F(BrowserControlsTest, MAYBE(VHUnitsWithMinHeightsChanging)) { … } // This tests that the viewport remains anchored when browser controls are // brought in while the document is fully scrolled. This normally causes // clamping of the visual viewport to keep it bounded by the layout viewport // so we're testing that the viewport anchoring logic is working to keep the // view unchanged. TEST_F(BrowserControlsTest, MAYBE(AnchorViewportDuringBrowserControlsAdjustment)) { … } // Ensure that vh units are correct when browser controls are in a locked // state. That is, normally we need to add the browser controls height to vh // units since 100vh includes the browser controls even if they're hidden while // the ICB height does not. When the controls are locked hidden, the ICB size // is the full viewport height so there's no need to add the browser controls // height. crbug.com/688738. TEST_F(BrowserControlsSimTest, MAYBE(ViewportUnitsWhenControlsLocked)) { … } // Test the size adjustment sent to the viewport when top controls exist. TEST_F(BrowserControlsTest, MAYBE(TopControlsSizeAdjustment)) { … } // Test the size adjustment sent to the viewport when bottom controls exist. // There should never be an adjustment since the bottom controls do not change // the content offset. TEST_F(BrowserControlsTest, MAYBE(BottomControlsSizeAdjustment)) { … } TEST_F(BrowserControlsTest, MAYBE(GrowingHeightKeepsTopControlsHidden)) { … } TEST_F(BrowserControlsTest, MAYBE(HidingBrowserControlsInvalidatesCompositedLayer)) { … } // Test that the browser controls have different shown ratios when scrolled with // a minimum height set for only top controls. TEST_F(BrowserControlsTest, MAYBE(ScrollWithMinHeightSetForTopControlsOnly)) { … } // Test that the browser controls don't scroll off when a minimum height is set. TEST_F(BrowserControlsTest, MAYBE(ScrollWithMinHeightSet)) { … } #undef MAYBE // Test that sending both an animated and non-animated browser control update // doesn't cause the animated one to squash the non-animated. // https://crbug.com/861618. TEST_F(BrowserControlsSimTest, MixAnimatedAndNonAnimatedUpdateState) { … } // Test that requesting an animated hide on the top controls actually // animates rather than happening instantly. TEST_F(BrowserControlsSimTest, HideAnimated) { … } // Test that requesting an animated show on the top controls actually // animates rather than happening instantly. TEST_F(BrowserControlsSimTest, ShowAnimated) { … } // Test that setting a constraint inside Blink doesn't clamp the ratio to the // constraint. This is required since the CC-side will set the ratio correctly. // If we did clamp the ratio, an animation running in CC would get clobbered // when we commit. TEST_F(BrowserControlsSimTest, ConstraintDoesntClampRatioInBlink) { … } } // namespace blink