Commit da9c32f9 authored by Emily Stark's avatar Emily Stark Committed by Commit Bot

OmniboxViewViews tests: pull out ScopedFeatureList into text fixture class

ScopedFeatureLists are supposed to be initialized in text fixture
constructors to avoid data races.

Bug: 1095832
Change-Id: Ifd4a290cd4cf49421df99c5c0338e0fa8633d2f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2250084
Commit-Queue: Emily Stark <estark@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779980}
parent 8506d3da
...@@ -173,17 +173,21 @@ class OmniboxViewViews : public OmniboxView, ...@@ -173,17 +173,21 @@ class OmniboxViewViews : public OmniboxView,
bool IsDropCursorForInsertion() const override; bool IsDropCursorForInsertion() const override;
private: private:
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, RevealOnHover); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, HoverAndExit);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FRIEND_TEST_ALL_PREFIXES(
HideOnInteractionAndRevealOnHover); OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, UserInteractionAndHover);
FRIEND_TEST_ALL_PREFIXES(
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
HideOnInteractionAfterFocusAndBlur); HideOnInteractionAfterFocusAndBlur);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, RevealOnHoverAfterBlur); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsRevealOnHoverTest, AfterBlur);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, PathChangeDuringAnimation); FRIEND_TEST_ALL_PREFIXES(
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
HideOnInteractionSameDocNavigations); PathChangeDuringAnimation);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
HideOnInteractionSubframeNavigations); SameDocNavigations);
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsHideOnInteractionTest,
SubframeNavigations);
// TODO(tommycli): Remove the rest of these friends after porting these // TODO(tommycli): Remove the rest of these friends after porting these
// browser tests to unit tests. // browser tests to unit tests.
FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag); FRIEND_TEST_ALL_PREFIXES(OmniboxViewViewsTest, CloseOmniboxPopupOnTextDrag);
......
...@@ -214,9 +214,10 @@ class TestingOmniboxEditController : public ChromeOmniboxEditController { ...@@ -214,9 +214,10 @@ class TestingOmniboxEditController : public ChromeOmniboxEditController {
// Base class that ensures ScopedFeatureList is initialized first. // Base class that ensures ScopedFeatureList is initialized first.
class OmniboxViewViewsTestBase : public ChromeViewsTestBase { class OmniboxViewViewsTestBase : public ChromeViewsTestBase {
public: public:
explicit OmniboxViewViewsTestBase( OmniboxViewViewsTestBase(
const std::vector<base::Feature>& enabled_features) { const std::vector<base::Feature>& enabled_features,
scoped_feature_list_.InitWithFeatures(enabled_features, {}); const std::vector<base::Feature>& disabled_features) {
scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
} }
protected: protected:
...@@ -225,10 +226,12 @@ class OmniboxViewViewsTestBase : public ChromeViewsTestBase { ...@@ -225,10 +226,12 @@ class OmniboxViewViewsTestBase : public ChromeViewsTestBase {
class OmniboxViewViewsTest : public OmniboxViewViewsTestBase { class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
public: public:
explicit OmniboxViewViewsTest( OmniboxViewViewsTest(const std::vector<base::Feature>& enabled_features,
const std::vector<base::Feature>& enabled_features); const std::vector<base::Feature>& disabled_features);
OmniboxViewViewsTest() : OmniboxViewViewsTest(std::vector<base::Feature>()) {} OmniboxViewViewsTest()
: OmniboxViewViewsTest(std::vector<base::Feature>(),
std::vector<base::Feature>()) {}
TestLocationBarModel* location_bar_model() { return &location_bar_model_; } TestLocationBarModel* location_bar_model() { return &location_bar_model_; }
CommandUpdaterImpl* command_updater() { return &command_updater_; } CommandUpdaterImpl* command_updater() { return &command_updater_; }
...@@ -289,8 +292,9 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase { ...@@ -289,8 +292,9 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
}; };
OmniboxViewViewsTest::OmniboxViewViewsTest( OmniboxViewViewsTest::OmniboxViewViewsTest(
const std::vector<base::Feature>& enabled_features) const std::vector<base::Feature>& enabled_features,
: OmniboxViewViewsTestBase(enabled_features), const std::vector<base::Feature>& disabled_features)
: OmniboxViewViewsTestBase(enabled_features, disabled_features),
command_updater_(nullptr), command_updater_(nullptr),
omnibox_edit_controller_(&command_updater_, &location_bar_model_) {} omnibox_edit_controller_(&command_updater_, &location_bar_model_) {}
...@@ -838,16 +842,14 @@ INSTANTIATE_TEST_SUITE_P(OmniboxViewViewsClipboardTest, ...@@ -838,16 +842,14 @@ INSTANTIATE_TEST_SUITE_P(OmniboxViewViewsClipboardTest,
class OmniboxViewViewsSteadyStateElisionsTest : public OmniboxViewViewsTest { class OmniboxViewViewsSteadyStateElisionsTest : public OmniboxViewViewsTest {
public: public:
OmniboxViewViewsSteadyStateElisionsTest() OmniboxViewViewsSteadyStateElisionsTest()
: OmniboxViewViewsTest({ : OmniboxViewViewsTest(
{
omnibox::kHideSteadyStateUrlScheme, omnibox::kHideSteadyStateUrlScheme,
omnibox::kHideSteadyStateUrlTrivialSubdomains, omnibox::kHideSteadyStateUrlTrivialSubdomains,
}) {} },
{}) {}
protected: protected:
explicit OmniboxViewViewsSteadyStateElisionsTest(
const std::vector<base::Feature>& enabled_features)
: OmniboxViewViewsTest(enabled_features) {}
const int kCharacterWidth = 10; const int kCharacterWidth = 10;
const GURL kFullUrl = GURL("https://www.example.com/"); const GURL kFullUrl = GURL("https://www.example.com/");
...@@ -1271,12 +1273,23 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideFromModel) { ...@@ -1271,12 +1273,23 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, UnelideFromModel) {
ExpectFullUrlDisplayed(); ExpectFullUrlDisplayed();
} }
class OmniboxViewViewsNoPathHidingTest : public OmniboxViewViewsTest {
public:
OmniboxViewViewsNoPathHidingTest()
: OmniboxViewViewsTest({},
{
omnibox::kHideSteadyStateUrlPathQueryAndRef,
}) {}
OmniboxViewViewsNoPathHidingTest(const OmniboxViewViewsNoPathHidingTest&) =
delete;
OmniboxViewViewsNoPathHidingTest& operator=(
const OmniboxViewViewsNoPathHidingTest&) = delete;
};
// Tests that when no path-hiding field trials are enabled, the path is not // Tests that when no path-hiding field trials are enabled, the path is not
// hidden. Regression test for https://crbug.com/1093748. // hidden. Regression test for https://crbug.com/1093748.
TEST_F(OmniboxViewViewsTest, PathNotHiddenByDefault) { TEST_F(OmniboxViewViewsNoPathHidingTest, PathNotHiddenByDefault) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{}, {omnibox::kHideSteadyStateUrlPathQueryAndRef});
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1287,14 +1300,23 @@ TEST_F(OmniboxViewViewsTest, PathNotHiddenByDefault) { ...@@ -1287,14 +1300,23 @@ TEST_F(OmniboxViewViewsTest, PathNotHiddenByDefault) {
EXPECT_NE(SK_ColorTRANSPARENT, omnibox_view()->path_color()); EXPECT_NE(SK_ColorTRANSPARENT, omnibox_view()->path_color());
} }
// Tests the field trial variation that hides the path by default and reveals on class OmniboxViewViewsRevealOnHoverTest : public OmniboxViewViewsTest {
// hover. public:
TEST_F(OmniboxViewViewsTest, RevealOnHover) { OmniboxViewViewsRevealOnHoverTest()
base::test::ScopedFeatureList scoped_feature_list; : OmniboxViewViewsTest(
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef, {omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover}, omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover},
{}); {}) {}
OmniboxViewViewsRevealOnHoverTest(const OmniboxViewViewsRevealOnHoverTest&) =
delete;
OmniboxViewViewsRevealOnHoverTest& operator=(
const OmniboxViewViewsRevealOnHoverTest&) = delete;
};
// Tests the field trial variation that hides the path by default and reveals on
// hover.
TEST_F(OmniboxViewViewsRevealOnHoverTest, HoverAndExit) {
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1356,15 +1378,26 @@ TEST_F(OmniboxViewViewsTest, RevealOnHover) { ...@@ -1356,15 +1378,26 @@ TEST_F(OmniboxViewViewsTest, RevealOnHover) {
path_fade_out_after_hover_animation->GetCurrentColor()); path_fade_out_after_hover_animation->GetCurrentColor());
} }
// Tests the field trial variation that hides the path when the user interacts class OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest
// with the page and brings it back when the user hovers over the omnibox. : public OmniboxViewViewsTest {
TEST_F(OmniboxViewViewsTest, HideOnInteractionAndRevealOnHover) { public:
base::test::ScopedFeatureList scoped_feature_list; OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest()
scoped_feature_list.InitWithFeatures( : OmniboxViewViewsTest(
{omnibox::kHideSteadyStateUrlPathQueryAndRef, {omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction, omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction,
omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover}, omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover},
{}); {}) {}
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest(
const OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest&) = delete;
OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest& operator=(
const OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest&) = delete;
};
// Tests the field trial variation that hides the path when the user interacts
// with the page and brings it back when the user hovers over the omnibox.
TEST_F(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
UserInteractionAndHover) {
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1428,13 +1461,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionAndRevealOnHover) { ...@@ -1428,13 +1461,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionAndRevealOnHover) {
// Tests that in the hide-on-interaction field trial, when the path changes // Tests that in the hide-on-interaction field trial, when the path changes
// while being faded out, the animation is stopped. // while being faded out, the animation is stopped.
TEST_F(OmniboxViewViewsTest, PathChangeDuringAnimation) { TEST_F(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
base::test::ScopedFeatureList scoped_feature_list; PathChangeDuringAnimation) {
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction,
omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover},
{});
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1465,14 +1493,23 @@ TEST_F(OmniboxViewViewsTest, PathChangeDuringAnimation) { ...@@ -1465,14 +1493,23 @@ TEST_F(OmniboxViewViewsTest, PathChangeDuringAnimation) {
EXPECT_FALSE(fade_out->IsAnimating()); EXPECT_FALSE(fade_out->IsAnimating());
} }
// Tests that in the hide-on-interaction field trial, the path is shown on class OmniboxViewViewsHideOnInteractionTest : public OmniboxViewViewsTest {
// cross-document main-frame navigations, but not on same-document navigations. public:
TEST_F(OmniboxViewViewsTest, HideOnInteractionSameDocNavigations) { OmniboxViewViewsHideOnInteractionTest()
base::test::ScopedFeatureList scoped_feature_list; : OmniboxViewViewsTest(
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef, {omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction}, omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction},
{}); {}) {}
OmniboxViewViewsHideOnInteractionTest(
const OmniboxViewViewsHideOnInteractionTest&) = delete;
OmniboxViewViewsHideOnInteractionTest& operator=(
const OmniboxViewViewsHideOnInteractionTest&) = delete;
};
// Tests that in the hide-on-interaction field trial, the path is shown on
// cross-document main-frame navigations, but not on same-document navigations.
TEST_F(OmniboxViewViewsHideOnInteractionTest, SameDocNavigations) {
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1547,13 +1584,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionSameDocNavigations) { ...@@ -1547,13 +1584,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionSameDocNavigations) {
// Tests that in the hide-on-interaction field trial, the path is not re-shown // Tests that in the hide-on-interaction field trial, the path is not re-shown
// on subframe navigations. // on subframe navigations.
TEST_F(OmniboxViewViewsTest, HideOnInteractionSubframeNavigations) { TEST_F(OmniboxViewViewsHideOnInteractionTest, SubframeNavigations) {
content::RenderViewHostTestEnabler rvh_enabler; content::RenderViewHostTestEnabler rvh_enabler;
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction},
{});
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1605,13 +1637,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionSubframeNavigations) { ...@@ -1605,13 +1637,8 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionSubframeNavigations) {
// Tests that in the hide-on-interaction field trial variation, the path is // Tests that in the hide-on-interaction field trial variation, the path is
// faded out after omnibox focus and blur. // faded out after omnibox focus and blur.
TEST_F(OmniboxViewViewsTest, HideOnInteractionAfterFocusAndBlur) { TEST_F(OmniboxViewViewsHideOnInteractionAndRevealOnHoverTest,
base::test::ScopedFeatureList scoped_feature_list; HideOnInteractionAfterFocusAndBlur) {
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction,
omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover},
{});
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
...@@ -1654,12 +1681,7 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionAfterFocusAndBlur) { ...@@ -1654,12 +1681,7 @@ TEST_F(OmniboxViewViewsTest, HideOnInteractionAfterFocusAndBlur) {
// Tests that in the reveal-on-hover field trial variation (without // Tests that in the reveal-on-hover field trial variation (without
// hide-on-interaction), the path is faded back in after focus, then blur, then // hide-on-interaction), the path is faded back in after focus, then blur, then
// hover. // hover.
TEST_F(OmniboxViewViewsTest, RevealOnHoverAfterBlur) { TEST_F(OmniboxViewViewsRevealOnHoverTest, AfterBlur) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{omnibox::kHideSteadyStateUrlPathQueryAndRef,
omnibox::kRevealSteadyStateUrlPathQueryAndRefOnHover},
{omnibox::kHideSteadyStateUrlPathQueryAndRefOnInteraction});
location_bar_model()->set_url(GURL("https://example.test/foo")); location_bar_model()->set_url(GURL("https://example.test/foo"));
location_bar_model()->set_url_for_display( location_bar_model()->set_url_for_display(
base::ASCIIToUTF16("example.test/foo")); base::ASCIIToUTF16("example.test/foo"));
......
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