Commit 7e71a94d authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

polychrome: fix BrowserViewTests

This change:
1) Factors out the scoped feature list pattern used in TestWithBrowserView to a
   separate helper class;
2) Changes TestWithBrowserView to use the new helper classe;
3) Makes BrowserViewTests use the helper class as well.

Bug: 817408
Change-Id: I99c4ac591676d61936a75b38b0de22dbf27137da
Reviewed-on: https://chromium-review.googlesource.com/955778Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542094}
parent b351b2be
......@@ -16,6 +16,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/invalidate_type.h"
......@@ -57,6 +58,8 @@ class BrowserViewTest : public InProcessBrowserTest {
DevToolsWindow* devtools_;
private:
test::ScopedMacViewsBrowserMode views_mode_{true};
DISALLOW_COPY_AND_ASSIGN(BrowserViewTest);
};
......
......@@ -31,11 +31,6 @@
#include "chrome/browser/chromeos/input_method/mock_input_method_manager_impl.h"
#endif
#if defined(OS_MACOSX)
#include "chrome/common/chrome_features.h"
#include "ui/base/ui_base_features.h"
#endif
namespace {
std::unique_ptr<KeyedService> CreateTemplateURLService(
......@@ -77,9 +72,6 @@ void TestWithBrowserView::SetUp() {
#if defined(OS_CHROMEOS)
chromeos::input_method::InitializeForTesting(
new chromeos::input_method::MockInputMethodManagerImpl);
#endif
#if defined(OS_MACOSX)
feature_list_.InitAndEnableFeature(features::kViewsBrowserWindows);
#endif
BrowserWithTestWindowTest::SetUp();
browser_view_ = static_cast<BrowserView*>(browser()->window());
......
......@@ -8,9 +8,8 @@
#include <memory>
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
class BrowserView;
......@@ -33,7 +32,7 @@ class TestWithBrowserView : public BrowserWithTestWindowTest {
private:
BrowserView* browser_view_; // Not owned.
base::test::ScopedFeatureList feature_list_;
test::ScopedMacViewsBrowserMode views_mode_{true};
DISALLOW_COPY_AND_ASSIGN(TestWithBrowserView);
};
......
......@@ -251,6 +251,8 @@ static_library("test_support") {
sources += [
"views/chrome_views_test_base.cc",
"views/chrome_views_test_base.h",
"views/scoped_macviews_browser_mode.cc",
"views/scoped_macviews_browser_mode.h",
]
}
......
// Copyright 2018 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.
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "build/build_config.h"
#include "build/buildflag.h"
#include "ui/base/ui_base_features.h"
namespace test {
ScopedMacViewsBrowserMode::ScopedMacViewsBrowserMode(bool is_views) {
#if defined(OS_MACOSX) && BUILDFLAG(MAC_VIEWS_BROWSER)
if (is_views)
feature_list_.InitAndEnableFeature(features::kViewsBrowserWindows);
else
feature_list_.InitAndDisableFeature(features::kViewsBrowserWindows);
#endif
}
ScopedMacViewsBrowserMode::~ScopedMacViewsBrowserMode() {}
} // namespace test
// Copyright 2018 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 CHROME_TEST_VIEWS_SCOPED_MACVIEWS_BROWSER_MODE_H_
#define CHROME_TEST_VIEWS_SCOPED_MACVIEWS_BROWSER_MODE_H_
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
namespace test {
// TODO(ellyjones): Delete this class once Mac Chrome always uses a Views
// browser window.
//
// This is a transitional class, designed for forcing a test case to run with a
// specific type of browser window on the Mac. This class is available on all
// platforms so that every use of it doesn't have to be wrapped in preprocessor
// conditionals, but is a no-op on non-Mac platforms.
//
// Tests that care about using a specific type of browser window, or that only
// work with one type of browser window, can include a member variable of type
// ScopedMacViewsBrowserMode to enforce that.
class ScopedMacViewsBrowserMode {
public:
explicit ScopedMacViewsBrowserMode(bool is_views);
virtual ~ScopedMacViewsBrowserMode();
private:
base::test::ScopedFeatureList feature_list_;
DISALLOW_COPY_AND_ASSIGN(ScopedMacViewsBrowserMode);
};
} // namespace test
#endif // CHROME_TEST_VIEWS_SCOPED_MACVIEWS_BROWSER_MODE_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