Commit 056bd4f2 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Use the MD test API instead of command line switches.

This is part of an effort to move away from direct reliance on the switches, so
they can be renamed or removed.

Bug: none
Change-Id: I64c5a521f7d6e6e148d0d4329a1710d8efa3b69b
Reviewed-on: https://chromium-review.googlesource.com/c/1297582Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602460}
parent b8c2f027
......@@ -23,10 +23,8 @@
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" // mash-ok
#include "base/command_line.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/strings/string_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
......@@ -83,8 +81,8 @@
#include "ui/aura/test/env_test_helper.h"
#include "ui/base/class_property.h"
#include "ui/base/hit_test.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/ui_base_switches.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/base_event_utils.h"
#include "ui/events/event.h"
......@@ -141,29 +139,19 @@ BrowserNonClientFrameViewAsh* GetFrameViewAsh(BrowserView* browser_view) {
return frame_view;
}
// Generates the test names suffixes based on the value of the test param.
std::string TopChromeMdParamToString(
const ::testing::TestParamInfo<const char*>& info) {
std::string result;
base::ReplaceChars(info.param, "-", "_", &result);
return result;
}
// Template to be used as a base class for touch-optimized UI parameterized test
// fixtures.
template <class BaseTest>
class TopChromeMdParamTest : public BaseTest,
public ::testing::WithParamInterface<const char*> {
class TopChromeMdParamTest
: public BaseTest,
public ::testing::WithParamInterface<ui::MaterialDesignController::Mode> {
public:
TopChromeMdParamTest() = default;
TopChromeMdParamTest() : test_api_(GetParam()) {}
~TopChromeMdParamTest() override = default;
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(switches::kTopChromeMD, GetParam());
BaseTest::SetUpCommandLine(command_line);
}
private:
ui::test::MaterialDesignControllerTestAPI test_api_;
DISALLOW_COPY_AND_ASSIGN(TopChromeMdParamTest);
};
......@@ -1455,12 +1443,11 @@ IN_PROC_BROWSER_TEST_P(NonHomeLauncherBrowserNonClientFrameViewAshTest,
EXPECT_EQ(expected_height, frame_view->frame_header_->GetHeaderHeight());
}
#define INSTANTIATE_TEST_CASE(name) \
INSTANTIATE_TEST_CASE_P( \
, name, \
::testing::Values(switches::kTopChromeMDMaterialRefresh, \
switches::kTopChromeMDMaterialRefreshTouchOptimized), \
&TopChromeMdParamToString)
#define INSTANTIATE_TEST_CASE(name) \
INSTANTIATE_TEST_CASE_P( \
, name, \
::testing::Values(ui::MaterialDesignController::MATERIAL_REFRESH, \
ui::MaterialDesignController::MATERIAL_TOUCH_REFRESH))
INSTANTIATE_TEST_CASE(BrowserNonClientFrameViewAshTest);
INSTANTIATE_TEST_CASE(ImmersiveModeBrowserViewTest);
......
......@@ -6,7 +6,6 @@
#include <string>
#include "base/command_line.h"
#include "base/macros.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h"
......@@ -21,8 +20,7 @@
#include "chrome/test/views/chrome_test_views_delegate.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/test/material_design_controller_test_api.h"
#include "ui/events/base_event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/rect_conversions.h"
......@@ -45,12 +43,6 @@ views::View* FindTabView(views::View* view) {
return current;
}
// Generates the test names suffixes based on the value of the test param.
std::string TouchOptimizedUiStatusToString(
const ::testing::TestParamInfo<bool>& info) {
return info.param ? "TouchOptimizedUiEnabled" : "TouchOptimizedUiDisabled";
}
class TabStripTestViewsDelegate : public ChromeTestViewsDelegate {
public:
TabStripTestViewsDelegate() = default;
......@@ -144,20 +136,15 @@ class TestTabStripObserver : public TabStripObserver {
DISALLOW_COPY_AND_ASSIGN(TestTabStripObserver);
};
class TabStripTest : public ChromeViewsTestBase,
public testing::WithParamInterface<bool> {
class TabStripTest
: public ChromeViewsTestBase,
public testing::WithParamInterface<ui::MaterialDesignController::Mode> {
public:
TabStripTest() {}
TabStripTest() : test_api_(GetParam()) {}
~TabStripTest() override {}
void SetUp() override {
if (GetParam()) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kTopChromeMD,
switches::kTopChromeMDMaterialRefreshTouchOptimized);
}
ChromeViewsTestBase::SetUp();
controller_ = new FakeBaseTabStripController;
......@@ -239,6 +226,8 @@ class TabStripTest : public ChromeViewsTestBase,
std::unique_ptr<views::Widget> widget_;
private:
ui::test::MaterialDesignControllerTestAPI test_api_;
DISALLOW_COPY_AND_ASSIGN(TabStripTest);
};
......@@ -415,7 +404,8 @@ TEST_P(TabStripTest, TabForEventWhenStacked) {
// the tabstrip is in stacked tab mode.
TEST_P(TabStripTest, TabCloseButtonVisibilityWhenStacked) {
// Touch-optimized UI requires a larger width for tabs to show close buttons.
tab_strip_->SetBounds(0, 0, GetParam() ? 442 : 346, 20);
const bool touch = ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
tab_strip_->SetBounds(0, 0, touch ? 442 : 346, 20);
controller_->AddTab(0, false);
controller_->AddTab(1, true);
controller_->AddTab(2, false);
......@@ -486,7 +476,8 @@ TEST_P(TabStripTest, TabCloseButtonVisibilityWhenNotStacked) {
// Set the tab strip width to be wide enough for three tabs to show all
// three icons, but not enough for five tabs to show all three icons.
// Touch-optimized UI requires a larger width for tabs to show close buttons.
tab_strip_->SetBounds(0, 0, GetParam() ? 442 : 346, 20);
const bool touch = ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
tab_strip_->SetBounds(0, 0, touch ? 442 : 346, 20);
controller_->AddTab(0, false);
controller_->AddTab(1, true);
controller_->AddTab(2, false);
......@@ -833,11 +824,7 @@ TEST_P(TabStripTest, TabNeedsAttentionGeneric) {
EXPECT_TRUE(IsShowingAttentionIndicator(tab1));
}
// Defines an alias to be used for tests that are only relevant to the touch-
// optimized UI mode.
using TabStripTouchOptimizedUiOnlyTest = TabStripTest;
TEST_P(TabStripTouchOptimizedUiOnlyTest, NewTabButtonInkDrop) {
TEST_P(TabStripTest, NewTabButtonInkDrop) {
constexpr int kTabStripWidth = 500;
tab_strip_->SetBounds(0, 0, kTabStripWidth, GetLayoutConstant(TAB_HEIGHT));
......@@ -855,12 +842,8 @@ TEST_P(TabStripTouchOptimizedUiOnlyTest, NewTabButtonInkDrop) {
}
}
INSTANTIATE_TEST_CASE_P(,
TabStripTest,
::testing::Values(true, false),
&TouchOptimizedUiStatusToString);
INSTANTIATE_TEST_CASE_P(,
TabStripTouchOptimizedUiOnlyTest,
::testing::Values(true),
&TouchOptimizedUiStatusToString);
INSTANTIATE_TEST_CASE_P(
,
TabStripTest,
::testing::Values(ui::MaterialDesignController::MATERIAL_REFRESH,
ui::MaterialDesignController::MATERIAL_TOUCH_REFRESH));
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