Skip to content

Commit

Permalink
Merge views_mus_unittests and views_unittests
Browse files Browse the repository at this point in the history
- Allow testing DesktopNativeWidgetAura on Chrome OS by doing necessary
  Mus setup.
- To accommodate Chrome OS, tests must specify that they will be testing
  desktop widgets before SetUp (for tests that inherit from
  ViewsTestBase). On Chrome OS, these are the tests that provide Mus
  coverage.
- Command line flags are ignored, so views_unittests will perform the
  same tests with and without --enable-features=SingleProcessMash
- Enable some test suites on Chrome OS, such as
  desktop_native_widget_aura_unittest.cc, and some individual tests.

Bug: 911784
Change-Id: Ic3acd21770f07fb8298a172dc556b3fa036d6791
Reviewed-on: https://chromium-review.googlesource.com/c/1378666
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618646}
  • Loading branch information
Evan Stade authored and Commit Bot committed Dec 21, 2018
1 parent f01e9f4 commit bddf4c6
Show file tree
Hide file tree
Showing 91 changed files with 1,142 additions and 1,604 deletions.
2 changes: 0 additions & 2 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,6 @@ group("gn_all") {
"//mash:all",
"//media/mojo/services:media_service_unittests",
"//mojo",
"//ui/views/mus:views_mus_interactive_ui_tests",
"//ui/views/mus:views_mus_unittests",
]

# crbug.com/676055: media_service_unittests fails to link under Windows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/browser/ui/views/bookmarks/bookmark_bar_view_test_helper.h"
#include "chrome/browser/ui/views/native_widget_factory.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h"
Expand Down Expand Up @@ -377,13 +378,13 @@ TEST_F(BookmarkBarViewTest, UpdateTooltipText) {
views::Widget widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
#if !defined(OS_CHROMEOS)
#if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
// On Chrome OS, this always creates a NativeWidgetAura, but it should create
// a DesktopNativeWidgetAura for Mash. We can get by without manually creating
// it because AshTestViewsDelegate and MusClient will do the right thing
// automatically.
params.native_widget = views::test::CreatePlatformDesktopNativeWidgetImpl(
params, &widget, nullptr);
params.native_widget = CreateNativeWidget(
NativeWidgetType::DESKTOP_NATIVE_WIDGET_AURA, &params, &widget);
#endif
widget.Init(params);
widget.Show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "ui/events/base_event_utils.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/table/table_view.h"
#include "ui/views/test/native_widget_factory.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h"

Expand All @@ -35,8 +34,6 @@ class ChooserDialogViewTest : public ChromeViewsTestBase {
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(10, 11, 200, 200);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.native_widget = views::test::CreatePlatformDesktopNativeWidgetImpl(
params, &parent_widget_, nullptr);
parent_widget_.Init(params);

widget_ = views::DialogDelegate::CreateDialogWidget(
Expand Down
31 changes: 19 additions & 12 deletions chrome/browser/ui/views/infobars/infobar_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/views/chrome_views_test_base.h"
#include "content/public/test/test_web_contents_factory.h"
#include "chrome/test/base/browser_with_test_window_test.h"

class TestInfoBarDelegate : public infobars::InfoBarDelegate {
public:
Expand All @@ -22,17 +20,27 @@ class TestInfoBarDelegate : public infobars::InfoBarDelegate {
InfoBarIdentifier GetIdentifier() const override { return TEST_INFOBAR; }
};

class InfoBarViewTest : public ChromeViewsTestBase {
class InfoBarViewTest : public BrowserWithTestWindowTest {
public:
InfoBarViewTest()
: web_contents_(web_contents_factory_.CreateWebContents(&profile_)),
infobar_container_view_(nullptr) {
InfoBarService::CreateForWebContents(web_contents_);
InfoBarViewTest() : infobar_container_view_(nullptr) {}
~InfoBarViewTest() override = default;

// ChromeViewsTestBase:
void SetUp() override {
BrowserWithTestWindowTest::SetUp();

AddTab(browser(), GURL("about:blank"));
infobar_container_view_.ChangeInfoBarManager(infobar_service());
}

void TearDown() override {
DetachContainer();
BrowserWithTestWindowTest::TearDown();
}

InfoBarService* infobar_service() {
return InfoBarService::FromWebContents(web_contents_);
return InfoBarService::FromWebContents(
browser()->tab_strip_model()->GetWebContentsAt(0));
}

// Detaches |infobar_container_view_| from infobar_service(), so that newly-
Expand All @@ -43,10 +51,9 @@ class InfoBarViewTest : public ChromeViewsTestBase {
}

private:
TestingProfile profile_;
content::TestWebContentsFactory web_contents_factory_;
content::WebContents* web_contents_;
InfoBarContainerView infobar_container_view_;

DISALLOW_COPY_AND_ASSIGN(InfoBarViewTest);
};

TEST_F(InfoBarViewTest, ShouldDrawSeparator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ class CastToolbarButtonTest : public ChromeViewsTestBase {

void SetUp() override {
ChromeViewsTestBase::SetUp();

profile_ = std::make_unique<TestingProfile>();

MediaRouterFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating(&MockMediaRouter::Create));
profile_.get(), base::BindRepeating(&MockMediaRouter::Create));
MediaRouterUIServiceFactory::GetInstance()->SetTestingFactory(
&profile_, base::BindRepeating(&BuildUIService));
profile_.get(), base::BindRepeating(&BuildUIService));

window_ = std::make_unique<TestBrowserWindow>();
Browser::CreateParams browser_params(&profile_, true);
Browser::CreateParams browser_params(profile_.get(), true);
browser_params.window = window_.get();
browser_ = std::make_unique<Browser>(browser_params);
MediaRouter* media_router =
MediaRouterFactory::GetApiForBrowserContext(&profile_);
MediaRouterFactory::GetApiForBrowserContext(profile_.get());
auto context_menu = std::make_unique<MediaRouterContextualMenu>(
browser_.get(), true, false, &context_menu_observer_);
button_ = std::make_unique<CastToolbarButton>(browser_.get(), media_router,
Expand All @@ -89,6 +92,7 @@ class CastToolbarButtonTest : public ChromeViewsTestBase {
button_.reset();
browser_.reset();
window_.reset();
profile_.reset();
ChromeViewsTestBase::TearDown();
}

Expand All @@ -101,7 +105,7 @@ class CastToolbarButtonTest : public ChromeViewsTestBase {
std::unique_ptr<Browser> browser_;
std::unique_ptr<CastToolbarButton> button_;
MockContextMenuObserver context_menu_observer_;
TestingProfile profile_;
std::unique_ptr<TestingProfile> profile_;

const gfx::Image idle_icon_ =
gfx::Image(gfx::CreateVectorIcon(vector_icons::kMediaRouterIdleIcon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class CloudServicesDialogViewTest : public ChromeViewsTestBase {
void SetUp() override {
ChromeViewsTestBase::SetUp();

profile_ = std::make_unique<TestingProfile>();
window_ = std::make_unique<TestBrowserWindow>();
Browser::CreateParams browser_params(&profile_, true);
Browser::CreateParams browser_params(profile_.get(), true);
browser_params.window = window_.get();
browser_ = std::make_unique<Browser>(browser_params);

Expand All @@ -41,6 +42,7 @@ class CloudServicesDialogViewTest : public ChromeViewsTestBase {
anchor_widget_.reset();
browser_.reset();
window_.reset();
profile_.reset();

ChromeViewsTestBase::TearDown();
}
Expand All @@ -67,7 +69,7 @@ class CloudServicesDialogViewTest : public ChromeViewsTestBase {
std::unique_ptr<BrowserWindow> window_;
std::unique_ptr<Browser> browser_;
std::unique_ptr<views::Widget> anchor_widget_;
TestingProfile profile_;
std::unique_ptr<TestingProfile> profile_;
};

TEST_F(CloudServicesDialogViewTest, Enable) {
Expand Down
14 changes: 6 additions & 8 deletions chrome/browser/ui/views/menu_interactive_uitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/native_widget_factory.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/test_browser_window.h"
Expand All @@ -17,10 +19,6 @@
#include "ui/views/test/platform_test_helper.h"
#include "ui/views/widget/widget.h"

#if !defined(OS_CHROMEOS)
#include "ui/views/test/native_widget_factory.h"
#endif

namespace views {
namespace test {

Expand Down Expand Up @@ -78,11 +76,11 @@ IN_PROC_BROWSER_TEST_F(MenuControllerUITest, TestMouseOverShownMenu) {
// Create a parent widget.
Widget* widget = new views::Widget;
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
#if !defined(OS_CHROMEOS)
params.native_widget = ::views::test::CreatePlatformDesktopNativeWidgetImpl(
params, widget, nullptr);
#endif
params.bounds = {0, 0, 200, 200};
#if !defined(OS_CHROMEOS) && !defined(OS_MACOSX)
params.native_widget = CreateNativeWidget(
NativeWidgetType::DESKTOP_NATIVE_WIDGET_AURA, &params, widget);
#endif
widget->Init(params);
widget->Show();
widget->Activate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ namespace {

class PopupsOnlyUiDelegateTest : public views::test::WidgetTest {
public:
PopupsOnlyUiDelegateTest() {}
~PopupsOnlyUiDelegateTest() override {}
PopupsOnlyUiDelegateTest() = default;
~PopupsOnlyUiDelegateTest() override = default;

void SetUp() override {
set_native_widget_type(NativeWidgetType::kDesktop);
views::test::WidgetTest::SetUp();
test_views_delegate()->set_use_desktop_native_widgets(true);
MessageCenter::Initialize();
}

Expand Down
19 changes: 12 additions & 7 deletions chrome/browser/ui/views/omnibox/omnibox_view_views_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
}

private:
TestingProfile profile_;
TemplateURLServiceFactoryTestUtil util_;
std::unique_ptr<TestingProfile> profile_;
std::unique_ptr<TemplateURLServiceFactoryTestUtil> util_;
CommandUpdaterImpl command_updater_;
TestLocationBarModel location_bar_model_;
TestingOmniboxEditController omnibox_edit_controller_;
Expand All @@ -260,7 +260,6 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
OmniboxViewViewsTest::OmniboxViewViewsTest(
const std::vector<base::Feature>& enabled_features)
: OmniboxViewViewsTestBase(enabled_features),
util_(&profile_),
command_updater_(nullptr),
omnibox_edit_controller_(&command_updater_, &location_bar_model_) {}

Expand All @@ -280,6 +279,9 @@ void OmniboxViewViewsTest::SetAndEmphasizeText(const std::string& new_text,
void OmniboxViewViewsTest::SetUp() {
ChromeViewsTestBase::SetUp();

profile_ = std::make_unique<TestingProfile>();
util_ = std::make_unique<TemplateURLServiceFactoryTestUtil>(profile_.get());

// We need a widget so OmniboxView can be correctly focused and unfocused.
widget_ = std::make_unique<views::Widget>();
views::Widget::InitParams params =
Expand All @@ -294,11 +296,12 @@ void OmniboxViewViewsTest::SetUp() {
new chromeos::input_method::MockInputMethodManagerImpl);
#endif
AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse(
&profile_,
profile_.get(),
base::BindRepeating(&AutocompleteClassifierFactory::BuildInstanceFor));
omnibox_view_ = new TestingOmniboxView(
&omnibox_edit_controller_, std::make_unique<ChromeOmniboxClient>(
&omnibox_edit_controller_, &profile_));
omnibox_view_ =
new TestingOmniboxView(&omnibox_edit_controller_,
std::make_unique<ChromeOmniboxClient>(
&omnibox_edit_controller_, profile_.get()));
test_api_ = std::make_unique<views::TextfieldTestApi>(omnibox_view_);
omnibox_view_->Init();

Expand All @@ -311,6 +314,8 @@ void OmniboxViewViewsTest::TearDown() {
omnibox_view_->GetInputMethod()->DetachTextInputClient(omnibox_view_);

widget_.reset();
util_.reset();
profile_.reset();

#if defined(OS_CHROMEOS)
chromeos::input_method::Shutdown();
Expand Down
9 changes: 4 additions & 5 deletions chrome/test/views/chrome_views_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
#include "chrome/test/views/chrome_test_views_delegate.h"
#include "content/public/test/test_browser_thread_bundle.h"

ChromeViewsTestBase::ChromeViewsTestBase()
: views::ViewsTestBase(
std::make_unique<content::TestBrowserThreadBundle>()) {}

ChromeViewsTestBase::~ChromeViewsTestBase() {}
ChromeViewsTestBase::ChromeViewsTestBase() = default;
ChromeViewsTestBase::~ChromeViewsTestBase() = default;

void ChromeViewsTestBase::SetUp() {
set_scoped_task_environment(
std::make_unique<content::TestBrowserThreadBundle>());
set_views_delegate(std::make_unique<ChromeTestViewsDelegate>());
views::ViewsTestBase::SetUp();
}
1 change: 1 addition & 0 deletions components/constrained_window/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ source_set("unit_tests") {
deps = [
":constrained_window",
"//components/web_modal:test_support",
"//ui/views",
"//ui/views:test_support",
]
}
3 changes: 2 additions & 1 deletion content/public/test/test_launcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ void WrapperTestLauncherDelegate::GTestCallback(
// parsing failed.
if (have_test_results && !parsed_results.empty()) {
// We expect only one test result here.
DCHECK_EQ(1U, parsed_results.size());
DCHECK_EQ(1U, parsed_results.size())
<< "Unexpectedly ran test more than once: " << test_name;
DCHECK_EQ(test_name, parsed_results.front().full_name);

result = parsed_results.front();
Expand Down
24 changes: 0 additions & 24 deletions testing/buildbot/chromium.chromiumos.json
Original file line number Diff line number Diff line change
Expand Up @@ -1056,18 +1056,6 @@
},
"test": "url_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "views_mus_interactive_ui_tests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "views_mus_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
Expand Down Expand Up @@ -1761,18 +1749,6 @@
},
"test": "url_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "views_mus_interactive_ui_tests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
},
"test": "views_mus_unittests"
},
{
"swarming": {
"can_use_on_swarming_builders": true
Expand Down
Loading

0 comments on commit bddf4c6

Please sign in to comment.