Commit 9bdd96b6 authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Delete test code that forces Harmony to be on or off.

Bug: 867557
Change-Id: I0c982fc17740e1de9f458b92e7782aa00dc463eb
Reviewed-on: https://chromium-review.googlesource.com/1150501
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578480}
parent 408f60ca
......@@ -6,7 +6,6 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_danger_prompt.h"
#include "chrome/browser/profiles/profile.h"
......@@ -25,7 +24,6 @@
#include "content/public/browser/download_item_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ui_base_features.h"
#include "url/gurl.h"
using ::testing::_;
......@@ -42,32 +40,9 @@ namespace {
const char kTestDownloadUrl[] = "http://evildownload.com";
const char kDownloadResponseToken[] = "default_token";
// An enum to parameterize the tests so that the tests can be run with and
// without the secondary-ui-md flag.
enum class SecondaryUiMd {
ENABLED,
DISABLED,
};
// Generates the test name suffix depending on the value of the SecondaryUiMd
// param.
std::string SecondaryUiMdStatusToString(
const ::testing::TestParamInfo<SecondaryUiMd>& info) {
switch (info.param) {
case SecondaryUiMd::ENABLED:
return "SecondaryUiMdEnabled";
case SecondaryUiMd::DISABLED:
return "SecondaryUiMdDisabled";
}
NOTREACHED();
return std::string();
}
} // namespace
class DownloadDangerPromptTest
: public InProcessBrowserTest,
public ::testing::WithParamInterface<SecondaryUiMd> {
class DownloadDangerPromptTest : public InProcessBrowserTest {
public:
DownloadDangerPromptTest()
: prompt_(nullptr),
......@@ -79,12 +54,6 @@ class DownloadDangerPromptTest
~DownloadDangerPromptTest() override {}
void SetUp() override {
// TODO(crbug.com/630357): Remove parameterized testing for this class when
// secondary-ui-md is enabled by default on all platforms.
if (GetParam() == SecondaryUiMd::ENABLED)
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
else
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
SafeBrowsingService::RegisterFactory(test_safe_browsing_factory_.get());
InProcessBrowserTest::SetUp();
}
......@@ -207,7 +176,6 @@ class DownloadDangerPromptTest
bool did_receive_callback_;
std::unique_ptr<TestSafeBrowsingServiceFactory> test_safe_browsing_factory_;
std::string expected_serialized_report_;
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest);
};
......@@ -218,7 +186,7 @@ class DownloadDangerPromptTest
#else
#define MAYBE_TestAll TestAll
#endif
IN_PROC_BROWSER_TEST_P(DownloadDangerPromptTest, MAYBE_TestAll) {
IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, MAYBE_TestAll) {
GURL download_url(kTestDownloadUrl);
ON_CALL(download(), GetURL()).WillByDefault(ReturnRef(download_url));
ON_CALL(download(), GetReferrerUrl())
......@@ -323,14 +291,6 @@ IN_PROC_BROWSER_TEST_P(DownloadDangerPromptTest, MAYBE_TestAll) {
VerifyExpectations(true);
}
// Prefix for test instantiations intentionally left blank since the test
// fixture class has a single parameterization.
INSTANTIATE_TEST_CASE_P(,
DownloadDangerPromptTest,
::testing::Values(SecondaryUiMd::ENABLED,
SecondaryUiMd::DISABLED),
&SecondaryUiMdStatusToString);
// Class for testing interactive dialogs.
class DownloadDangerPromptBrowserTest : public DialogBrowserTest {
protected:
......
......@@ -5,41 +5,17 @@
#include "chrome/browser/extensions/dev_mode_bubble_delegate.h"
#include "base/macros.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/feature_switch.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_features.h"
namespace extensions {
class DevModeBubbleDelegateMdUiUnitTest
: public ExtensionServiceTestBase,
public testing::WithParamInterface<bool> {
public:
DevModeBubbleDelegateMdUiUnitTest() = default;
~DevModeBubbleDelegateMdUiUnitTest() override = default;
using DevModeBubbleDelegateUiUnitTest = ExtensionServiceTestBase;
void SetUp() override {
ExtensionServiceTestBase::SetUp();
bool secondary_md_ui_enabled = GetParam();
if (secondary_md_ui_enabled)
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
else
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(DevModeBubbleDelegateMdUiUnitTest);
};
TEST_P(DevModeBubbleDelegateMdUiUnitTest, ExtensionServiceTestBase) {
TEST_F(DevModeBubbleDelegateUiUnitTest, Test) {
FeatureSwitch::ScopedOverride dev_mode_highlighting(
FeatureSwitch::force_dev_mode_highlighting(), true);
......@@ -51,19 +27,7 @@ TEST_P(DevModeBubbleDelegateMdUiUnitTest, ExtensionServiceTestBase) {
DevModeBubbleDelegate bubble_delegate(profile());
EXPECT_TRUE(bubble_delegate.ShouldIncludeExtension(extension.get()));
// The Cocoa version of the bubble doesn't have a dismiss 'x', so needs a
// dedicated 'cancel' button.
bool should_have_cancel_button =
#if defined(OS_MACOSX)
!ui::MaterialDesignController::IsSecondaryUiMaterial();
#else
false;
#endif
EXPECT_EQ(should_have_cancel_button,
!bubble_delegate.GetDismissButtonLabel().empty());
EXPECT_TRUE(bubble_delegate.GetDismissButtonLabel().empty());
}
INSTANTIATE_TEST_CASE_P(, DevModeBubbleDelegateMdUiUnitTest, testing::Bool());
} // namespace extensions
......@@ -6,7 +6,6 @@
#include "base/auto_reset.h"
#include "base/optional.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
......@@ -23,7 +22,6 @@
#include "extensions/common/extension_builder.h"
#include "extensions/common/manifest_constants.h"
#include "services/identity/public/cpp/identity_test_utils.h"
#include "ui/base/ui_base_features.h"
using extensions::Manifest;
using ActionType = extensions::ExtensionBuilder::ActionType;
......@@ -176,14 +174,6 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstalledBubbleBrowserTest,
// the BubbleUi is closed.
IN_PROC_BROWSER_TEST_F(ExtensionInstalledBubbleBrowserTest,
MAYBE_CloseBubbleUI) {
base::test::ScopedFeatureList scoped_feature_list;
#if defined(OS_MACOSX)
scoped_feature_list.InitWithFeatures(
{features::kSecondaryUiMd, features::kShowAllDialogsWithViewsToolkit},
{});
#else
scoped_feature_list.InitWithFeatures({features::kSecondaryUiMd}, {});
#endif
auto bubble = MakeBubble("No action", base::nullopt);
BubbleManager* manager = browser()->GetBubbleManager();
manager->ShowBubble(std::move(bubble));
......
......@@ -74,9 +74,8 @@ class SaveCardBubbleViews : public SaveCardBubbleView,
views::View* GetFootnoteViewForTesting();
private:
FRIEND_TEST_ALL_PREFIXES(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingCloseClosesBubbleIfSecondaryUiMdExpOn);
FRIEND_TEST_ALL_PREFIXES(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingCloseClosesBubble);
FRIEND_TEST_ALL_PREFIXES(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA);
......
......@@ -14,8 +14,6 @@
#include "components/autofill/core/browser/autofill_experiments.h"
#include "content/public/test/browser_test_utils.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/styled_label.h"
......@@ -98,49 +96,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, 1);
}
// Tests the local save bubble. Ensures that clicking the [No thanks] button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Local_ClickingNoThanksClosesBubbleIfSecondaryUiMdExpOff) {
// Pre-Harmony tests are not applicable to Refresh.
if (ui::MaterialDesignController::IsRefreshUi())
return;
// Disable the SecondaryUiMd experiment.
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
// Submitting the form and having Payments decline offering to save should
// show the local save bubble.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE,
DialogEvent::OFFERED_LOCAL_SAVE});
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_LOCAL)->visible());
// Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester;
ClickOnDialogViewWithIdAndWait(DialogViewId::CANCEL_BUTTON);
// UMA should have recorded bubble rejection.
histogram_tester.ExpectUniqueSample(
"Autofill.SaveCreditCardPrompt.Local.FirstShow",
AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1);
}
// Tests the local save bubble. Ensures that the Harmony version of the bubble
// does not have a [No thanks] button (it has an [X] Close button instead.)
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Local_ShouldNotHaveNoThanksButtonIfSecondaryUiMdExpOn) {
// Enable the SecondaryUiMd experiment.
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
Local_ShouldNotHaveNoThanksButton) {
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsDeclines();
......@@ -229,48 +188,10 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, 1);
}
// Tests the upload save bubble. Ensures that clicking the [No thanks] button
// successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingNoThanksClosesBubbleIfSecondaryUiMdExpOff) {
// Pre-Harmony tests are not applicable to Refresh.
if (ui::MaterialDesignController::IsRefreshUi())
return;
// Disable the SecondaryUiMd experiment.
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Submitting the form should show the upload save bubble and legal footer.
// (Must wait for response from Payments before accessing the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
FillAndSubmitForm();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_UPLOAD)->visible());
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::FOOTNOTE_VIEW)->visible());
// Clicking [No thanks] should cancel and close it.
base::HistogramTester histogram_tester;
ClickOnDialogViewWithIdAndWait(DialogViewId::CANCEL_BUTTON);
// UMA should have recorded bubble rejection.
histogram_tester.ExpectUniqueSample(
"Autofill.SaveCreditCardPrompt.Upload.FirstShow",
AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1);
}
// Tests the upload save bubble. Ensures that the Harmony version of the bubble
// does not have a [No thanks] button (it has an [X] Close button instead.)
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ShouldNotHaveNoThanksButtonIfSecondaryUiMdExpOn) {
// Enable the SecondaryUiMd experiment.
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
Upload_ShouldNotHaveNoThanksButton) {
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -292,10 +213,7 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
// Tests the upload save bubble. Ensures that clicking the top-right [X] close
// button successfully causes the bubble to go away.
IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormBrowserTest,
Upload_ClickingCloseClosesBubbleIfSecondaryUiMdExpOn) {
// Enable the SecondaryUiMd experiment.
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
Upload_ClickingCloseClosesBubble) {
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......@@ -810,10 +728,6 @@ IN_PROC_BROWSER_TEST_F(SaveCardBubbleViewsFullFormWithShippingBrowserTest,
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_DecliningUploadDoesNotLogUserAcceptedCardOriginUMA) {
// Enable the SecondaryUiMd experiment (required for clicking the Close
// button).
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
......
......@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/metrics/histogram_samples.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/passwords/manage_passwords_test.h"
......@@ -33,7 +32,6 @@
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_features.h"
#include "ui/views/window/dialog_client_view.h"
......@@ -72,16 +70,6 @@ class PasswordBubbleInteractiveUiTest : public ManagePasswordsTest {
PasswordBubbleInteractiveUiTest() {}
~PasswordBubbleInteractiveUiTest() override {}
// ManagePasswordsTest:
void SetUp() override {
#if defined(OS_MACOSX)
scoped_feature_list_.InitWithFeatures(
{features::kSecondaryUiMd, features::kShowAllDialogsWithViewsToolkit},
{});
#endif
ManagePasswordsTest::SetUp();
}
MOCK_METHOD0(OnIconRequestDone, void());
// Called on the server background thread.
......@@ -95,7 +83,6 @@ class PasswordBubbleInteractiveUiTest : public ManagePasswordsTest {
private:
test::ScopedMacViewsBrowserMode views_mode_{true};
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(PasswordBubbleInteractiveUiTest);
};
......
......@@ -10,7 +10,6 @@
#include "base/command_line.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/translate/chrome_translate_client.h"
......@@ -36,10 +35,6 @@ class TranslateBubbleViewBrowserTest : public InProcessBrowserTest {
~TranslateBubbleViewBrowserTest() override {}
void SetUp() override {
#if defined(OS_MACOSX)
// Enable toolkit-views bubbles on Mac (otherwise Cocoa bubbles are used).
feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
#endif
set_open_about_blank_on_browser_launch(true);
translate::TranslateManager::SetIgnoreMissingKeyForTesting(true);
InProcessBrowserTest::SetUp();
......@@ -60,7 +55,6 @@ class TranslateBubbleViewBrowserTest : public InProcessBrowserTest {
private:
std::string expected_lang_;
base::test::ScopedFeatureList feature_list_;
bool OnLanguageDetermined(const content::NotificationSource& source,
const content::NotificationDetails& details) {
......
......@@ -258,7 +258,7 @@ class VIEWS_EXPORT Label : public View,
FRIEND_TEST_ALL_PREFIXES(LabelTest, MultilineSupportedRenderText);
FRIEND_TEST_ALL_PREFIXES(LabelTest, TextChangeWithoutLayout);
FRIEND_TEST_ALL_PREFIXES(LabelTest, EmptyLabel);
FRIEND_TEST_ALL_PREFIXES(MDLabelTest, FocusBounds);
FRIEND_TEST_ALL_PREFIXES(LabelTest, FocusBounds);
FRIEND_TEST_ALL_PREFIXES(LabelTest, MultiLineSizingWithElide);
friend class LabelSelectionTest;
......
......@@ -9,13 +9,11 @@
#include "base/command_line.h"
#include "base/i18n/rtl.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/canvas_painter.h"
#include "ui/events/base_event_utils.h"
......@@ -97,13 +95,6 @@ base::string16 GetClipboardText(ui::ClipboardType clipboard_type) {
return clipboard_text;
}
enum class SecondaryUiMode { NON_MD, MD };
std::string SecondaryUiModeToString(
const ::testing::TestParamInfo<SecondaryUiMode>& info) {
return info.param == SecondaryUiMode::MD ? "MD" : "NonMD";
}
// Makes an RTL string by mapping 0..6 to [א,ב,ג,ד,ה,ו,ז].
base::string16 ToRTL(const char* ascii) {
base::string16 rtl;
......@@ -269,31 +260,6 @@ class LabelSelectionTest : public LabelTest {
DISALLOW_COPY_AND_ASSIGN(LabelSelectionTest);
};
// LabelTest harness that runs both with and without secondary UI set to MD.
class MDLabelTest : public LabelTest,
public ::testing::WithParamInterface<SecondaryUiMode> {
public:
MDLabelTest() {}
// LabelTest:
void SetUp() override {
if (GetParam() == SecondaryUiMode::MD) {
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
} else {
// Force Refresh UI to be off, since that mode implies MD secondary UI.
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, switches::kTopChromeMDMaterial);
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
}
LabelTest::SetUp();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(MDLabelTest);
};
// Crashes on Linux only. http://crbug.com/612406
#if defined(OS_LINUX)
#define MAYBE_FontPropertySymbol DISABLED_FontPropertySymbol
......@@ -933,7 +899,7 @@ TEST_F(LabelTest, NoSchedulePaintInOnPaint) {
EXPECT_EQ(count, label.schedule_paint_count()); // Unchanged.
}
TEST_P(MDLabelTest, FocusBounds) {
TEST_F(LabelTest, FocusBounds) {
label()->SetText(ASCIIToUTF16("Example"));
Link concrete_link(ASCIIToUTF16("Example"));
Label* link = &concrete_link; // Allow LabelTest to call methods as friend.
......@@ -959,16 +925,10 @@ TEST_P(MDLabelTest, FocusBounds) {
gfx::Size normal_link_size = link->GetPreferredSize();
link->SetFocusBehavior(View::FocusBehavior::ALWAYS);
gfx::Size focusable_link_size = link->GetPreferredSize();
if (GetParam() == SecondaryUiMode::MD) {
// Everything should match under MD since underlines indicates focus.
EXPECT_EQ(normal_label_size, normal_link_size);
EXPECT_EQ(normal_link_size, focusable_link_size);
} else {
// Otherwise, links get bigger in order to paint the focus rectangle.
EXPECT_NE(normal_link_size, focusable_link_size);
EXPECT_GT(focusable_link_size.width(), normal_link_size.width());
EXPECT_GT(focusable_link_size.height(), normal_link_size.height());
}
// Everything should match since underlines indicates focus.
EXPECT_EQ(normal_label_size, normal_link_size);
EXPECT_EQ(normal_link_size, focusable_link_size);
// Requesting focus doesn't change the preferred size since that would mess up
// layout.
......@@ -1405,10 +1365,4 @@ TEST_F(LabelSelectionTest, ContextMenuContents) {
EXPECT_FALSE(IsMenuCommandEnabled(IDS_APP_SELECT_ALL));
}
INSTANTIATE_TEST_CASE_P(,
MDLabelTest,
::testing::Values(SecondaryUiMode::MD,
SecondaryUiMode::NON_MD),
&SecondaryUiModeToString);
} // namespace views
......@@ -10,7 +10,6 @@
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h"
......@@ -39,9 +38,7 @@ Link::~Link() {
// static
Link::FocusStyle Link::GetDefaultFocusStyle() {
return ui::MaterialDesignController::IsSecondaryUiMaterial()
? FocusStyle::UNDERLINE
: FocusStyle::RING;
return FocusStyle::UNDERLINE;
}
Link::FocusStyle Link::GetFocusStyle() const {
......
......@@ -9,15 +9,14 @@
#include <memory>
#include <string>
#include "base/command_line.h"
#include "base/i18n/base_i18n_switches.h"
#include "base/macros.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/icu_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/font_list.h"
#include "ui/views/border.h"
......@@ -32,15 +31,6 @@
using base::ASCIIToUTF16;
namespace views {
namespace {
enum class SecondaryUiMode { NON_MD, MD };
std::string SecondaryUiModeToString(
const ::testing::TestParamInfo<SecondaryUiMode>& info) {
return info.param == SecondaryUiMode::MD ? "MD" : "NonMD";
}
} // namespace
class StyledLabelTest : public ViewsTestBase, public StyledLabelListener {
public:
......@@ -70,39 +60,6 @@ class StyledLabelTest : public ViewsTestBase, public StyledLabelListener {
DISALLOW_COPY_AND_ASSIGN(StyledLabelTest);
};
// StyledLabelTest harness that runs both with and without secondary UI set to
// MD.
class MDStyledLabelTest
: public StyledLabelTest,
public ::testing::WithParamInterface<SecondaryUiMode> {
public:
MDStyledLabelTest() {}
// StyledLabelTest:
void SetUp() override {
if (GetParam() == SecondaryUiMode::NON_MD) {
// Force Refresh UI to be off, since that mode implies MD secondary UI.
// Must be done before ViewsTestBase::SetUp().
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD, switches::kTopChromeMDMaterial);
}
// This works while StyledLabelTest has no SetUp() of its own. Otherwise the
// mode should be set after ViewsTestBase::SetUp(), but before the rest of
// StyledLabelTest::SetUp(), so that StyledLabelTest::SetUp() obeys the MD
// setting.
StyledLabelTest::SetUp();
if (GetParam() == SecondaryUiMode::MD)
scoped_feature_list_.InitAndEnableFeature(features::kSecondaryUiMd);
else
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(MDStyledLabelTest);
};
TEST_F(StyledLabelTest, NoWrapping) {
const std::string text("This is a test block of text");
InitStyledLabel(text);
......@@ -255,7 +212,7 @@ TEST_F(StyledLabelTest, WrapLongWords) {
static_cast<Label*>(styled()->child_at(1))->text());
}
TEST_P(MDStyledLabelTest, CreateLinks) {
TEST_F(StyledLabelTest, CreateLinks) {
const std::string text("This is a test block of text.");
InitStyledLabel(text);
......@@ -272,14 +229,9 @@ TEST_P(MDStyledLabelTest, CreateLinks) {
styled()->AddStyleRange(gfx::Range(12, 13),
StyledLabel::RangeStyleInfo::CreateForLink());
if (GetParam() == SecondaryUiMode::MD) {
// Insets shouldn't change under MD when links are added, since the links
// indicate focus by adding an underline instead.
EXPECT_TRUE(styled()->GetInsets().IsEmpty());
} else {
// Now there should be a focus border because there are non-empty Links.
EXPECT_FALSE(styled()->GetInsets().IsEmpty());
}
// Insets shouldn't change when links are added, since the links indicate
// focus by adding an underline instead.
EXPECT_TRUE(styled()->GetInsets().IsEmpty());
// Verify layout creates the right number of children.
styled()->SetBounds(0, 0, 1000, 1000);
......@@ -287,7 +239,7 @@ TEST_P(MDStyledLabelTest, CreateLinks) {
EXPECT_EQ(7, styled()->child_count());
}
TEST_P(MDStyledLabelTest, DontBreakLinks) {
TEST_F(StyledLabelTest, DontBreakLinks) {
const std::string text("This is a test block of text, ");
const std::string link_text("and this should be a link");
InitStyledLabel(text + link_text);
......@@ -305,16 +257,9 @@ TEST_P(MDStyledLabelTest, DontBreakLinks) {
styled()->Layout();
ASSERT_EQ(2, styled()->child_count());
if (GetParam() == SecondaryUiMode::MD) {
// No additional insets should be added under MD.
EXPECT_EQ(0, styled()->child_at(0)->x());
} else {
// The label has no focus border while, when non-MD, the link (and thus
// overall styled label) does, so the label should be inset by the width of
// the focus border.
EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x());
}
// The Link shouldn't be offset (it grows in size under non-MD instead).
// No additional insets should be added.
EXPECT_EQ(0, styled()->child_at(0)->x());
// The Link shouldn't be offset.
EXPECT_EQ(0, styled()->child_at(1)->x());
}
......@@ -488,7 +433,7 @@ TEST_F(StyledLabelTest, Color) {
widget->CloseNow();
}
TEST_P(MDStyledLabelTest, StyledRangeWithTooltip) {
TEST_F(StyledLabelTest, StyledRangeWithTooltip) {
const std::string text("This is a test block of text, ");
const std::string tooltip_text("this should have a tooltip,");
const std::string normal_text(" this should not have a tooltip, ");
......@@ -522,17 +467,9 @@ TEST_P(MDStyledLabelTest, StyledRangeWithTooltip) {
ASSERT_EQ(5, styled()->child_count());
if (GetParam() == SecondaryUiMode::MD) {
// In MD, the labels shouldn't be offset to cater for focus rings.
EXPECT_EQ(0, styled()->child_at(0)->x());
EXPECT_EQ(0, styled()->child_at(2)->x());
} else {
// The labels have no focus border while the link (and thus overall styled
// label) does, so the labels should be inset by the width of the focus
// border.
EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x());
EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(2)->x());
}
// The labels shouldn't be offset to cater for focus rings.
EXPECT_EQ(0, styled()->child_at(0)->x());
EXPECT_EQ(0, styled()->child_at(2)->x());
EXPECT_EQ(styled()->child_at(0)->bounds().right(),
styled()->child_at(1)->x());
......@@ -776,7 +713,7 @@ TEST_F(StyledLabelTest, AlignmentInRTL) {
styled()->child_at(0)->bounds().x());
}
TEST_P(MDStyledLabelTest, ViewsCenteredWithLinkAndCustomView) {
TEST_F(StyledLabelTest, ViewsCenteredWithLinkAndCustomView) {
const std::string text("This is a test block of text, ");
const std::string link_text("and this should be a link");
const std::string custom_view_text("And this is a custom view");
......@@ -810,10 +747,4 @@ TEST_P(MDStyledLabelTest, ViewsCenteredWithLinkAndCustomView) {
styled()->child_at(2)->bounds().y());
}
INSTANTIATE_TEST_CASE_P(,
MDStyledLabelTest,
::testing::Values(SecondaryUiMode::MD,
SecondaryUiMode::NON_MD),
&SecondaryUiModeToString);
} // namespace views
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