Skip to content

Commit

Permalink
views/mus: Run some more tests from views_unittests in mus.
Browse files Browse the repository at this point in the history
BUG=577274

Review-Url: https://codereview.chromium.org/2010083002
Cr-Commit-Position: refs/heads/master@{#398705}
  • Loading branch information
sadrulhc authored and Commit bot committed Jun 8, 2016
1 parent 96a6dfa commit 3a5132a
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gn
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,5 @@ exec_script_whitelist = [
"//tools/gn/setup.cc",
"//ui/accessibility/BUILD.gn",
"//ui/views/BUILD.gn",
"//ui/views/mus/BUILD.gn",
]
2 changes: 2 additions & 0 deletions ui/views/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ source_set("test_support_internal") {
]
deps = [
"//base",
"//base/test:test_support",
"//ipc:test_support",
"//skia",
"//testing/gtest",
Expand All @@ -176,6 +177,7 @@ source_set("test_support_internal") {
"//ui/events/platform",
"//ui/gfx",
"//ui/gfx/geometry",
"//ui/gl:test_support",
]

sources += [
Expand Down
20 changes: 12 additions & 8 deletions ui/views/accessible_pane_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) {
widget_main->Init(params_main);
View* root_main = widget_main->GetRootView();
root_main->AddChildView(test_view_main);
widget_main->Show();
widget_main->Activate();
test_view_main->GetFocusManager()->SetFocusedView(test_view_main);
EXPECT_TRUE(widget_main->IsActive());
Expand All @@ -136,16 +137,19 @@ TEST_F(AccessiblePaneViewTest, SetPaneFocusAndRestore) {
EXPECT_EQ(test_view_bar->child_button(),
test_view_bar->GetWidget()->GetFocusManager()->GetFocusedView());

// Deactivate() is only reliable on Ash. On Windows it uses ::GetNextWindow()
// to simply activate another window, and which one is not predictable. On
// Mac, Deactivate() is not implemented. Note that TestBarView calls
// set_allow_deactivate_on_esc(true), which is only otherwise used in Ash.
if (!IsMus()) {
// Deactivate() is only reliable on Ash. On Windows it uses
// ::GetNextWindow() to simply activate another window, and which one is not
// predictable. On Mac, Deactivate() is not implemented. Note that
// TestBarView calls set_allow_deactivate_on_esc(true), which is only
// otherwise used in Ash.
#if !defined(OS_MACOSX) || defined(USE_ASH)
// Esc should deactivate the widget.
test_view_bar->AcceleratorPressed(test_view_bar->escape_key());
EXPECT_TRUE(widget_main->IsActive());
EXPECT_FALSE(widget_bar->IsActive());
// Esc should deactivate the widget.
test_view_bar->AcceleratorPressed(test_view_bar->escape_key());
EXPECT_TRUE(widget_main->IsActive());
EXPECT_FALSE(widget_bar->IsActive());
#endif
}

widget_bar->CloseNow();
widget_bar.reset();
Expand Down
31 changes: 17 additions & 14 deletions ui/views/controls/button/custom_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CustomButtonTest : public ViewsTestBase {

// Tests that hover state changes correctly when visiblity/enableness changes.
TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) {
ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
ui::test::EventGenerator generator(widget()->GetNativeWindow());

generator.PressLeftButton();
EXPECT_EQ(CustomButton::STATE_PRESSED, button()->state());
Expand Down Expand Up @@ -192,21 +192,24 @@ TEST_F(CustomButtonTest, HoverStateOnVisibilityChange) {
aura::test::TestCursorClient cursor_client(
widget()->GetNativeView()->GetRootWindow());

// In Aura views, no new hover effects are invoked if mouse events
// are disabled.
cursor_client.DisableMouseEvents();
// Mus doesn't support disabling mouse events. https://crbug.com/618321
if (!IsMus()) {
// In Aura views, no new hover effects are invoked if mouse events
// are disabled.
cursor_client.DisableMouseEvents();

button()->SetEnabled(false);
EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state());
button()->SetEnabled(false);
EXPECT_EQ(CustomButton::STATE_DISABLED, button()->state());

button()->SetEnabled(true);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());
button()->SetEnabled(true);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());

button()->SetVisible(false);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());
button()->SetVisible(false);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());

button()->SetVisible(true);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());
button()->SetVisible(true);
EXPECT_EQ(CustomButton::STATE_NORMAL, button()->state());
}
#endif // !defined(OS_MACOSX) || defined(USE_AURA)
}

Expand Down Expand Up @@ -349,7 +352,7 @@ TEST_F(CustomButtonTest, ButtonClickTogglesInkDrop) {
TestInkDrop* ink_drop = new TestInkDrop();
CreateButtonWithInkDrop(base::WrapUnique(ink_drop));

ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
ui::test::EventGenerator generator(widget()->GetNativeWindow());
generator.set_current_location(gfx::Point(50, 50));
generator.PressLeftButton();
EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState());
Expand All @@ -365,7 +368,7 @@ TEST_F(CustomButtonTest, CaptureLossHidesInkDrop) {
TestInkDrop* ink_drop = new TestInkDrop();
CreateButtonWithInkDrop(base::WrapUnique(ink_drop));

ui::test::EventGenerator generator(GetContext(), widget()->GetNativeWindow());
ui::test::EventGenerator generator(widget()->GetNativeWindow());
generator.set_current_location(gfx::Point(50, 50));
generator.PressLeftButton();
EXPECT_EQ(InkDropState::ACTION_PENDING, ink_drop->GetTargetInkDropState());
Expand Down
3 changes: 1 addition & 2 deletions ui/views/controls/button/label_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ class InkDropLabelButtonTest : public ViewsTestBase {
};

TEST_F(InkDropLabelButtonTest, HoverStateAfterMouseEnterAndExitEvents) {
ui::test::EventGenerator event_generator(GetContext(),
widget_->GetNativeWindow());
ui::test::EventGenerator event_generator(widget_->GetNativeWindow());
const gfx::Point out_of_bounds_point(button_->bounds().bottom_right() +
gfx::Vector2d(1, 1));
const gfx::Point in_bounds_point(button_->bounds().CenterPoint());
Expand Down
15 changes: 13 additions & 2 deletions ui/views/controls/button/menu_button_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ class MenuButtonTest : public ViewsTestBase {
private:
void CreateMenuButton(MenuButtonListener* menu_button_listener) {
CreateWidget();
generator_.reset(new ui::test::EventGenerator(GetContext(),
widget_->GetNativeWindow()));
generator_.reset(new ui::test::EventGenerator(widget_->GetNativeWindow()));
// Set initial mouse location in a consistent way so that the menu button we
// are about to create initializes its hover state in a consistent manner.
generator_->set_current_location(gfx::Point(10, 10));
Expand Down Expand Up @@ -354,6 +353,10 @@ TEST_F(MenuButtonTest, ActivateDropDownOnMouseClick) {

// Test that the MenuButton stays pressed while there are any PressedLocks.
TEST_F(MenuButtonTest, ButtonStateForMenuButtonsWithPressedLocks) {
// Hovered-state is not updated under mus when EventGenerator send a
// mouse-move event. https://crbug.com/615033
if (IsMus())
return;
CreateMenuButtonWithNoListener();

// Move the mouse over the button; the button should be in a hovered state.
Expand Down Expand Up @@ -542,6 +545,10 @@ TEST_F(MenuButtonTest,
// Tests that the MenuButton does not become pressed if it can be dragged, and a
// DragDropClient is processing the events.
TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
// The test uses drag-n-drop, which isn't yet supported on mus.
// https://crbug.com/614037.
if (IsMus())
return;
TestMenuButtonListener menu_button_listener;
CreateMenuButtonWithMenuButtonListener(&menu_button_listener);
TestDragController drag_controller;
Expand All @@ -564,6 +571,10 @@ TEST_F(MenuButtonTest, DraggableMenuButtonDoesNotActivateOnDrag) {
// Tests if the listener is notified correctly when a gesture tap happens on a
// MenuButton that has a MenuButtonListener.
TEST_F(MenuButtonTest, ActivateDropDownOnGestureTap) {
// Hovered-state is not updated under mus when EventGenerator send a
// mouse-move event. https://crbug.com/615033
if (IsMus())
return;
TestMenuButtonListener menu_button_listener;
CreateMenuButtonWithMenuButtonListener(&menu_button_listener);

Expand Down
2 changes: 1 addition & 1 deletion ui/views/controls/menu/menu_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ class MenuControllerTest : public ViewsTestBase {
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
owner_->Init(params);
event_generator_.reset(
new ui::test::EventGenerator(GetContext(), owner_->GetNativeWindow()));
new ui::test::EventGenerator(owner_->GetNativeWindow()));
owner_->Show();

SetupMenuItem();
Expand Down
4 changes: 2 additions & 2 deletions ui/views/controls/slider_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ void SliderTest::SetUp() {
widget_->SetContentsView(slider_);
widget_->Show();

event_generator_.reset(new ui::test::EventGenerator(
GetContext(), widget_->GetNativeWindow()));
event_generator_.reset(
new ui::test::EventGenerator(widget_->GetNativeWindow()));
}

void SliderTest::TearDown() {
Expand Down
2 changes: 1 addition & 1 deletion ui/views/controls/textfield/textfield_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
textfield_->RequestFocus();

event_generator_.reset(
new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow()));
new ui::test::EventGenerator(widget_->GetNativeWindow()));
}
ui::MenuModel* GetContextMenuModel() {
test_api_->UpdateContextMenu();
Expand Down
9 changes: 7 additions & 2 deletions ui/views/event_monitor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ class EventMonitorTest : public WidgetTest {
widget_ = CreateTopLevelNativeWidget();
widget_->SetSize(gfx::Size(100, 100));
widget_->Show();
generator_.reset(
new ui::test::EventGenerator(GetContext(), widget_->GetNativeWindow()));
if (IsMus()) {
generator_.reset(
new ui::test::EventGenerator(widget_->GetNativeWindow()));
} else {
generator_.reset(new ui::test::EventGenerator(
GetContext(), widget_->GetNativeWindow()));
}
generator_->set_targeting_application(true);
}
void TearDown() override {
Expand Down
37 changes: 25 additions & 12 deletions ui/views/mus/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import("//mojo/public/mojo_application_manifest.gni")
import("//testing/test.gni")
import("//tools/grit/repack.gni")

gypi = exec_script("//build/gypi_to_gn.py",
[ rebase_path("../views.gyp") ],
"scope",
[ "../views.gyp" ])
component("mus") {
output_name = "ui_views_mus_lib"

Expand Down Expand Up @@ -128,8 +132,6 @@ source_set("test_support") {

sources = [
"../test/native_widget_factory_mus.cc",
"../views_test_suite.cc",
"../views_test_suite.h",
"views_mus_test_suite.cc",
"views_mus_test_suite.h",
]
Expand Down Expand Up @@ -161,29 +163,38 @@ test("views_mus_unittests") {

configs += [ "//build/config:precompiled_headers" ]

# TODO(sky): add more files.
sources = [
"../controls/native/native_view_host_aura_unittest.cc",
"../controls/native/native_view_host_test_base.cc",
"../controls/native/native_view_host_test_base.h",
"../controls/native/native_view_host_unittest.cc",
"../focus/focus_manager_unittest.cc",
"../view_targeter_unittest.cc",
"../widget/native_widget_aura_unittest.cc",
"../widget/native_widget_unittest.cc",
"../widget/widget_unittest.cc",
"display_list_unittest.cc",
"native_widget_mus_unittest.cc",
"run_all_unittests_mus.cc",
"screen_mus_unittest.cc",
"window_manager_connection_unittest.cc",
]

sources += rebase_path(gypi.views_unittests_sources, ".", "//ui/views")
sources += rebase_path(gypi.views_unittests_aura_sources, ".", "//ui/views")

sources -= [
# Mus has its own runner.
"../run_all_unittests_main.cc",

# EventGenerator doesn't work well with IME in mus.
# crbug.com/615033 crbug.com/548407
"../controls/textfield/textfield_unittest.cc",

# Tooltips. crbug.com/599558
"../corewm/tooltip_controller_unittest.cc",

# Some of the tests need drag-drop support. crbug.com/614037
"../touchui/touch_selection_controller_impl_unittest.cc",
]

deps = [
":mus",
":test_support",
"//base",
"//base:i18n",
"//base/test:test_support",
"//cc",
"//components/mus/public/cpp",
"//components/mus/public/cpp/tests:unittest_support",
Expand All @@ -205,7 +216,9 @@ test("views_mus_unittests") {
"//ui/events/platform",
"//ui/gfx:test_support",
"//ui/gfx/geometry",
"//ui/native_theme",
"//ui/strings",
"//ui/touch_selection",
"//ui/views",
"//ui/views:test_support_internal",
"//ui/wm",
Expand Down
8 changes: 8 additions & 0 deletions ui/views/mus/native_widget_mus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "ui/aura/window_property.h"
#include "ui/base/hit_test.h"
#include "ui/base/view_prop.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/path.h"
Expand Down Expand Up @@ -839,6 +841,12 @@ void NativeWidgetMus::CenterWindow(const gfx::Size& size) {
// TODO(beng): clear user-placed property and set preferred size property.
window_->SetSharedProperty<gfx::Size>(
mus::mojom::WindowManager::kPreferredSize_Property, size);

gfx::Rect bounds = display::Screen::GetScreen()
->GetDisplayNearestWindow(content_)
.work_area();
bounds.ClampToCenteredSize(size);
window_->SetBounds(bounds);
}

void NativeWidgetMus::GetWindowPlacement(
Expand Down
2 changes: 1 addition & 1 deletion ui/views/mus/unittests_manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 1,
"name": "mojo:views_mus_unittests",
"name": "exe:views_mus_unittests",
"display_name": "Views Mus Unittests",
"capabilities": {
"required": {
Expand Down
3 changes: 3 additions & 0 deletions ui/views/view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4045,6 +4045,9 @@ class PaintTrackingView : public View {
// Makes sure child views with layers aren't painted when paint starts at an
// ancestor.
TEST_F(ViewLayerTest, DontPaintChildrenWithLayers) {
// TODO(sad): DrawWaiterForTest does not work with mus. crbug.com/618136
if (IsMus())
return;
PaintTrackingView* content_view = new PaintTrackingView;
widget()->SetContentsView(content_view);
content_view->SetPaintToLayer(true);
Expand Down
4 changes: 2 additions & 2 deletions ui/views/views.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@
'test/widget_test_mac.mm',
'test/x11_property_change_waiter.cc',
'test/x11_property_change_waiter.h',
'views_test_suite.cc',
'views_test_suite.h',
],
'views_test_support_aura_sources': [
'corewm/tooltip_controller_test_helper.cc',
Expand Down Expand Up @@ -630,8 +632,6 @@
'view_model_utils_unittest.cc',
'view_targeter_unittest.cc',
'view_unittest.cc',
'views_test_suite.cc',
'views_test_suite.h',
'widget/native_widget_mac_unittest.mm',
'widget/native_widget_unittest.cc',
'widget/root_view_unittest.cc',
Expand Down

0 comments on commit 3a5132a

Please sign in to comment.