Commit 23804a86 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Make RenderingTest to use ScopedOverlayScrollbarsForTest

RenderingTest::SetUp has been using RuntimeEnabledFeatures::SetOverlayScrollbarsEnabled
for testing. This CL remove the use, instead make it to use ScopedOverlayScrollbarsForTest.

Bug: 769541
Change-Id: I7fa923adc379ad219065bdc57c54878dea637acd
Reviewed-on: https://chromium-review.googlesource.com/762968
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515961}
parent 6ff391dc
......@@ -40,6 +40,7 @@
#include "platform/WebTaskRunner.h"
#include "platform/runtime_enabled_features.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/testing/UseMockScrollbarSettings.h"
#include "platform/testing/WebLayerTreeViewImplForTesting.h"
#include "public/platform/Platform.h"
#include "public/platform/WebMouseEvent.h"
......@@ -158,42 +159,6 @@ WebRemoteFrameImpl* CreateRemoteChild(WebRemoteFrame& parent,
scoped_refptr<SecurityOrigin> = nullptr,
TestWebRemoteFrameClient* = nullptr);
// Forces to use mocked overlay scrollbars instead of the default native theme
// scrollbars to avoid crash in Chromium code when it tries to load UI
// resources that are not available when running blink unit tests, and to
// ensure consistent layout regardless of differences between scrollbar themes.
// WebViewHelper includes this, so this is only needed if a test doesn't use
// WebViewHelper or the test needs a bigger scope of mock scrollbar settings
// than the scope of WebViewHelper.
class UseMockScrollbarSettings {
public:
UseMockScrollbarSettings()
: original_mock_scrollbar_enabled_(Settings::MockScrollbarsEnabled()),
original_overlay_scrollbars_enabled_(
RuntimeEnabledFeatures::OverlayScrollbarsEnabled()) {
Settings::SetMockScrollbarsEnabled(true);
RuntimeEnabledFeatures::SetOverlayScrollbarsEnabled(true);
}
UseMockScrollbarSettings(bool use_mock, bool use_overlay)
: original_mock_scrollbar_enabled_(Settings::MockScrollbarsEnabled()),
original_overlay_scrollbars_enabled_(
RuntimeEnabledFeatures::OverlayScrollbarsEnabled()) {
Settings::SetMockScrollbarsEnabled(use_mock);
RuntimeEnabledFeatures::SetOverlayScrollbarsEnabled(use_overlay);
}
~UseMockScrollbarSettings() {
Settings::SetMockScrollbarsEnabled(original_mock_scrollbar_enabled_);
RuntimeEnabledFeatures::SetOverlayScrollbarsEnabled(
original_overlay_scrollbars_enabled_);
}
private:
bool original_mock_scrollbar_enabled_;
bool original_overlay_scrollbars_enabled_;
};
class TestWebWidgetClient : public WebWidgetClient {
public:
~TestWebWidgetClient() override {}
......
......@@ -39,7 +39,7 @@ ChromeClient& RenderingTest::GetChromeClient() const {
}
RenderingTest::RenderingTest(LocalFrameClient* local_frame_client)
: local_frame_client_(local_frame_client) {}
: UseMockScrollbarSettings(), local_frame_client_(local_frame_client) {}
void RenderingTest::SetUp() {
Page::PageClients page_clients;
......@@ -47,7 +47,6 @@ void RenderingTest::SetUp() {
page_clients.chrome_client = &GetChromeClient();
SetupPageWithClients(&page_clients, local_frame_client_, SettingOverrider());
Settings::SetMockScrollbarsEnabled(true);
RuntimeEnabledFeatures::SetOverlayScrollbarsEnabled(true);
EXPECT_TRUE(
GetDocument().GetPage()->GetScrollbarTheme().UsesOverlayScrollbars());
......
......@@ -17,6 +17,7 @@
#include "core/layout/api/LayoutViewItem.h"
#include "core/loader/EmptyClients.h"
#include "core/testing/PageTestBase.h"
#include "platform/testing/UseMockScrollbarSettings.h"
#include "platform/wtf/Allocator.h"
namespace blink {
......@@ -66,7 +67,7 @@ class LocalFrameClientWithParent final : public EmptyLocalFrameClient {
Member<LocalFrame> parent_;
};
class RenderingTest : public PageTestBase {
class RenderingTest : public PageTestBase, public UseMockScrollbarSettings {
USING_FAST_MALLOC(RenderingTest);
public:
......@@ -75,7 +76,7 @@ class RenderingTest : public PageTestBase {
}
virtual ChromeClient& GetChromeClient() const;
RenderingTest(LocalFrameClient* = nullptr);
explicit RenderingTest(LocalFrameClient* = nullptr);
protected:
void SetUp() override;
......
......@@ -1322,7 +1322,7 @@ class ScrollbarAppearanceTest
ScrollbarAppearanceTest() : mock_scrollbars_(false, GetParam()) {}
private:
FrameTestHelpers::UseMockScrollbarSettings mock_scrollbars_;
UseMockScrollbarSettings mock_scrollbars_;
};
class StubWebThemeEngine : public WebThemeEngine {
......
......@@ -1670,6 +1670,7 @@ jumbo_static_library("test_support") {
"testing/URLTestHelpers.h",
"testing/UnitTestHelpers.cpp",
"testing/UnitTestHelpers.h",
"testing/UseMockScrollbarSettings.h",
"testing/WebLayerTreeViewImplForTesting.cpp",
"testing/WebLayerTreeViewImplForTesting.h",
"testing/weburl_loader_mock.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UseMockScrollbarSettings_h
#define UseMockScrollbarSettings_h
#include "platform/scroll/ScrollbarTheme.h"
#include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
namespace blink {
// Forces to use mocked overlay scrollbars instead of the default native theme
// scrollbars to avoid crash in Chromium code when it tries to load UI
// resources that are not available when running blink unit tests, and to
// ensure consistent layout regardless of differences between scrollbar themes.
// WebViewHelper includes this, so this is only needed if a test doesn't use
// WebViewHelper or the test needs a bigger scope of mock scrollbar settings
// than the scope of WebViewHelper.
class UseMockScrollbarSettings : private ScopedOverlayScrollbarsForTest {
public:
UseMockScrollbarSettings()
: ScopedOverlayScrollbarsForTest(true),
original_mock_scrollbar_enabled_(
ScrollbarTheme::MockScrollbarsEnabled()),
original_overlay_scrollbars_enabled_(
RuntimeEnabledFeatures::OverlayScrollbarsEnabled()) {
ScrollbarTheme::SetMockScrollbarsEnabled(true);
}
UseMockScrollbarSettings(bool use_mock, bool use_overlay)
: ScopedOverlayScrollbarsForTest(use_overlay),
original_mock_scrollbar_enabled_(
ScrollbarTheme::MockScrollbarsEnabled()),
original_overlay_scrollbars_enabled_(
RuntimeEnabledFeatures::OverlayScrollbarsEnabled()) {
ScrollbarTheme::SetMockScrollbarsEnabled(use_mock);
}
~UseMockScrollbarSettings() {
ScrollbarTheme::SetMockScrollbarsEnabled(original_mock_scrollbar_enabled_);
}
private:
bool original_mock_scrollbar_enabled_;
bool original_overlay_scrollbars_enabled_;
};
} // namespace blink
#endif // UseMockScrollbarSettings_h
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment