Commit 08dbcae9 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup in advance of drag-and-drop fixes:

* Use =default more
* Use in-declaration initialization more
* Use inequality forms of expects/asserts over e.g. ASSERT_TRUE(a == b)
* Use temps to avoid subepxr repetition
* Use ui_test_utils::GetCenterInScreenCoordinates() more
* Prefer EXPECT to ASSERT where failing the expectation wouldn't crash
* TestTargetView::Init() is called after being added to the view hierarchy
  and thus can use parent()
* Make overrides match the access control level of the parent declaration
* git cl format
* Update comments slightly
* Don't bother caching things in ToolbarViewInteractiveUITest that can be
  computed on the fly
* SetUpCommandLine() should be used to actually tweak the command line,
  other setup can be done from SetUpOnMainThread()
* No need to reset browser flags and such during interactive UI test
  teardown, since interactive UI tests always tear down the whole process

Bug: none
Change-Id: I5a7ca34b4c59ff12a17f163466c5af76815cb329
Reviewed-on: https://chromium-review.googlesource.com/c/1478372
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633885}
parent b721381c
......@@ -270,9 +270,8 @@ class TestingPageNavigator : public PageNavigator {
// TearDown.
class BookmarkBarViewEventTestBase : public ViewEventTestBase {
public:
BookmarkBarViewEventTestBase()
: ViewEventTestBase(),
model_(NULL) {}
BookmarkBarViewEventTestBase() = default;
~BookmarkBarViewEventTestBase() override = default;
void SetUp() override {
content_client_.reset(new ChromeContentClient);
......@@ -377,7 +376,7 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase {
// See comment above class description for what this does.
virtual bool CreateBigMenu() { return false; }
BookmarkModel* model_;
BookmarkModel* model_ = nullptr;
std::unique_ptr<BookmarkBarView> bb_view_;
TestingPageNavigator navigator_;
......@@ -717,12 +716,11 @@ class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase {
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
ASSERT_NE(nullptr, menu);
views::SubmenuView* submenu = menu->GetSubmenu();
ASSERT_TRUE(submenu->IsShowing());
views::MenuItemView* child_menu = submenu->GetMenuItemAt(0);
ASSERT_NE(nullptr, child_menu);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
......@@ -827,12 +825,11 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
ASSERT_NE(nullptr, menu);
views::SubmenuView* submenu = menu->GetSubmenu();
ASSERT_TRUE(submenu->IsShowing());
views::MenuItemView* child_menu = submenu->GetMenuItemAt(0);
ASSERT_NE(nullptr, child_menu);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
......@@ -842,9 +839,8 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
void Step3() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
gfx::Point loc = ui_test_utils::GetCenterInScreenCoordinates(
bb_view_->other_bookmarks_button());
#if defined(USE_AURA)
// TODO: fix this. Aura requires an additional mouse event to trigger drag
......@@ -865,9 +861,8 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
void Step3A() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
gfx::Point loc = ui_test_utils::GetCenterInScreenCoordinates(
bb_view_->other_bookmarks_button());
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(),
......@@ -876,14 +871,15 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
void Step4() {
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
ASSERT_NE(nullptr, drop_menu);
views::SubmenuView* drop_submenu = drop_menu->GetSubmenu();
ASSERT_TRUE(drop_submenu->IsShowing());
// The button should be highlighted now.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
ASSERT_EQ(views::Button::STATE_PRESSED, other_button->state());
EXPECT_EQ(views::Button::STATE_PRESSED, other_button->state());
views::MenuItemView* target_menu =
drop_menu->GetSubmenu()->GetMenuItemAt(0);
views::MenuItemView* target_menu = drop_submenu->GetMenuItemAt(0);
gfx::Point loc(1, 1);
views::View::ConvertPointToScreen(target_menu, &loc);
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
......@@ -897,10 +893,10 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase {
}
void Step6() {
ASSERT_TRUE(model_->other_node()->GetChild(0)->url() == url_dragging_);
EXPECT_EQ(url_dragging_, model_->other_node()->GetChild(0)->url());
// The button should be in normal state now.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
ASSERT_EQ(views::Button::STATE_NORMAL, other_button->state());
EXPECT_EQ(views::Button::STATE_NORMAL, other_button->state());
Done();
}
......@@ -934,12 +930,11 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu != NULL);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
ASSERT_NE(nullptr, menu);
views::SubmenuView* submenu = menu->GetSubmenu();
ASSERT_TRUE(submenu->IsShowing());
views::MenuItemView* child_menu = submenu->GetMenuItemAt(0);
ASSERT_NE(nullptr, child_menu);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT,
......@@ -949,9 +944,8 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
void Step3() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
gfx::Point loc = ui_test_utils::GetCenterInScreenCoordinates(
bb_view_->other_bookmarks_button());
// Start a drag.
#if defined(USE_AURA)
......@@ -971,9 +965,8 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
void Step3A() {
// Drag over other button.
views::LabelButton* other_button = bb_view_->other_bookmarks_button();
gfx::Point loc(other_button->width() / 2, other_button->height() / 2);
views::View::ConvertPointToScreen(other_button, &loc);
gfx::Point loc = ui_test_utils::GetCenterInScreenCoordinates(
bb_view_->other_bookmarks_button());
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10, loc.y(),
......@@ -982,13 +975,12 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
void Step4() {
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_NE(nullptr, drop_menu);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
// Now drag back over first menu.
views::LabelButton* button = GetBookmarkButton(0);
gfx::Point loc(button->width() / 2, button->height() / 2);
views::View::ConvertPointToScreen(button, &loc);
gfx::Point loc =
ui_test_utils::GetCenterInScreenCoordinates(GetBookmarkButton(0));
ASSERT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
loc.x(), loc.y(),
base::BindOnce(&BookmarkBarViewTest8::Step5, base::Unretained(this))));
......@@ -997,11 +989,11 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
void Step5() {
// Drop on folder F11.
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_TRUE(drop_menu != NULL);
ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing());
ASSERT_NE(nullptr, drop_menu);
views::SubmenuView* drop_submenu = drop_menu->GetSubmenu();
ASSERT_TRUE(drop_submenu->IsShowing());
views::MenuItemView* target_menu =
drop_menu->GetSubmenu()->GetMenuItemAt(1);
views::MenuItemView* target_menu = drop_submenu->GetMenuItemAt(1);
ui_test_utils::MoveMouseToCenterAndPress(
target_menu, ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &BookmarkBarViewTest8::Step6));
......@@ -1011,7 +1003,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase {
// Make sure drop was processed.
GURL final_url = model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->
GetChild(1)->url();
ASSERT_TRUE(final_url == url_dragging_);
EXPECT_EQ(url_dragging_, final_url);
Done();
}
......@@ -2025,13 +2017,13 @@ class BookmarkBarViewTest22 : public BookmarkBarViewEventTestBase {
private:
void Step2() {
// Menu should be showing.
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu);
ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
views::MenuItemView* drop_menu = bb_view_->GetDropMenu();
ASSERT_NE(nullptr, drop_menu);
views::SubmenuView* drop_submenu = drop_menu->GetSubmenu();
ASSERT_TRUE(drop_submenu->IsShowing());
views::MenuItemView* child_menu =
menu->GetSubmenu()->GetMenuItemAt(0);
ASSERT_TRUE(child_menu != NULL);
views::MenuItemView* child_menu = drop_submenu->GetMenuItemAt(0);
ASSERT_NE(nullptr, child_menu);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(
......
......@@ -53,12 +53,13 @@ void TestDragView::WriteDragData(const gfx::Point& point,
// A simple view to serve as a drop target.
class TestTargetView : public views::View {
public:
TestTargetView();
~TestTargetView() override;
TestTargetView() = default;
~TestTargetView() override = default;
// Initializes this view to have the same bounds as its parent, and to have
// two draggable child views.
void Init();
// Initializes this view to have the same bounds as |parent| and two draggable
// child views.
void Init(views::View* parent);
bool dragging() const { return dragging_; }
bool dropped() const { return dropped_; }
......@@ -74,20 +75,17 @@ class TestTargetView : public views::View {
void OnDragExited() override;
// Whether or not we are currently dragging.
bool dragging_;
bool dragging_ = false;
// Whether or not a drop has been performed on the view.
bool dropped_;
bool dropped_ = false;
DISALLOW_COPY_AND_ASSIGN(TestTargetView);
};
TestTargetView::TestTargetView() : dragging_(false), dropped_(false) {
}
void TestTargetView::Init(views::View* parent) {
// First, match the parent's size.
SetSize(parent->size());
void TestTargetView::Init() {
// First, fill the parent completely.
SetBoundsRect(parent()->GetLocalBounds());
// Then add two draggable views, each 10x2.
views::View* first = new TestDragView();
......@@ -99,9 +97,6 @@ void TestTargetView::Init(views::View* parent) {
second->SetBounds(15, 2, 10, 2);
}
TestTargetView::~TestTargetView() {
}
bool TestTargetView::GetDropFormats(
int* formats,
std::set<ui::ClipboardFormatType>* format_types) {
......@@ -141,18 +136,18 @@ void TestTargetView::OnDragExited() {
class MenuViewDragAndDropTest : public MenuTestBase {
public:
MenuViewDragAndDropTest();
~MenuViewDragAndDropTest() override;
MenuViewDragAndDropTest() = default;
~MenuViewDragAndDropTest() override = default;
protected:
// MenuTestBase:
void BuildMenu(views::MenuItemView* menu) override;
TestTargetView* target_view() { return target_view_; }
bool asked_to_close() const { return asked_to_close_; }
bool performed_in_menu_drop() const { return performed_in_menu_drop_; }
private:
// MenuTestBase:
void BuildMenu(views::MenuItemView* menu) override;
// views::MenuDelegate:
bool GetDropFormats(views::MenuItemView* menu,
int* formats,
......@@ -173,34 +168,23 @@ class MenuViewDragAndDropTest : public MenuTestBase {
bool ShouldCloseOnDragComplete() override;
// The special view in the menu, which supports its own drag and drop.
TestTargetView* target_view_;
TestTargetView* target_view_ = nullptr;
// Whether or not we have been asked to close on drag complete.
bool asked_to_close_;
bool asked_to_close_ = false;
// Whether or not a drop was performed in-menu (i.e., not including drops
// in separate child views).
bool performed_in_menu_drop_;
bool performed_in_menu_drop_ = false;
DISALLOW_COPY_AND_ASSIGN(MenuViewDragAndDropTest);
};
MenuViewDragAndDropTest::MenuViewDragAndDropTest()
: target_view_(NULL),
asked_to_close_(false),
performed_in_menu_drop_(false) {
}
MenuViewDragAndDropTest::~MenuViewDragAndDropTest() {
}
void MenuViewDragAndDropTest::BuildMenu(views::MenuItemView* menu) {
// Build a menu item that has a nested view that supports its own drag and
// drop...
views::MenuItemView* menu_item_view =
menu->AppendMenuItem(1,
base::ASCIIToUTF16("item 1"),
views::MenuItemView::NORMAL);
views::MenuItemView* menu_item_view = menu->AppendMenuItem(
1, base::ASCIIToUTF16("item 1"), views::MenuItemView::NORMAL);
target_view_ = new TestTargetView();
menu_item_view->AddChildView(target_view_);
// ... as well as two other, normal items.
......@@ -261,13 +245,14 @@ bool MenuViewDragAndDropTest::ShouldCloseOnDragComplete() {
class MenuViewDragAndDropTestTestInMenuDrag : public MenuViewDragAndDropTest {
public:
MenuViewDragAndDropTestTestInMenuDrag() {}
~MenuViewDragAndDropTestTestInMenuDrag() override {}
MenuViewDragAndDropTestTestInMenuDrag() = default;
~MenuViewDragAndDropTestTestInMenuDrag() override = default;
private:
protected:
// MenuViewDragAndDropTest:
void DoTestWithMenuOpen() override;
private:
void Step2();
void Step3();
void Step4();
......@@ -282,17 +267,15 @@ void MenuViewDragAndDropTestTestInMenuDrag::DoTestWithMenuOpen() {
// We do this here (instead of in BuildMenu()) so that the menu is already
// built and the bounds are correct.
target_view()->Init(submenu->GetMenuItemAt(0));
target_view()->Init();
// We're going to drag the second menu element.
views::MenuItemView* drag_view = submenu->GetMenuItemAt(1);
ASSERT_TRUE(drag_view != NULL);
ASSERT_NE(nullptr, drag_view);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(
drag_view,
ui_controls::LEFT,
ui_controls::DOWN,
drag_view, ui_controls::LEFT, ui_controls::DOWN,
CreateEventTask(this, &MenuViewDragAndDropTestTestInMenuDrag::Step2));
}
......@@ -303,8 +286,7 @@ void MenuViewDragAndDropTestTestInMenuDrag::Step2() {
// Start a drag.
ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 10,
loc.y(),
loc.x() + 10, loc.y(),
CreateEventTask(this, &MenuViewDragAndDropTestTestInMenuDrag::Step3));
ScheduleMouseMoveInBackground(loc.x(), loc.y());
......@@ -318,13 +300,11 @@ void MenuViewDragAndDropTestTestInMenuDrag::Step3() {
ui_controls::SendMouseMove(loc.x(), loc.y());
ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT,
ui_controls::UP,
ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &MenuViewDragAndDropTestTestInMenuDrag::Step4));
}
void MenuViewDragAndDropTestTestInMenuDrag::Step4() {
// Verify our state.
// We should have performed an in-menu drop, and the nested view should not
// have had a drag and drop. Since the drag happened in menu code, the
// delegate should not have been asked whether or not to close, and the menu
......@@ -347,13 +327,14 @@ VIEW_TEST(MenuViewDragAndDropTestTestInMenuDrag, DISABLED_TestInMenuDrag)
class MenuViewDragAndDropTestNestedDrag : public MenuViewDragAndDropTest {
public:
MenuViewDragAndDropTestNestedDrag() {}
~MenuViewDragAndDropTestNestedDrag() override {}
MenuViewDragAndDropTestNestedDrag() = default;
~MenuViewDragAndDropTestNestedDrag() override = default;
private:
protected:
// MenuViewDragAndDropTest:
void DoTestWithMenuOpen() override;
private:
void Step2();
void Step3();
void Step4();
......@@ -370,23 +351,21 @@ void MenuViewDragAndDropTestNestedDrag::DoTestWithMenuOpen() {
views::View* first_view = submenu->GetMenuItemAt(0);
ASSERT_EQ(1, first_view->child_count());
views::View* child_view = first_view->child_at(0);
ASSERT_EQ(child_view, target_view());
EXPECT_EQ(child_view, target_view());
// We do this here (instead of in BuildMenu()) so that the menu is already
// built and the bounds are correct.
target_view()->Init(submenu->GetMenuItemAt(0));
target_view()->Init();
// The target view should now have two children.
ASSERT_EQ(2, target_view()->child_count());
views::View* drag_view = target_view()->child_at(0);
ASSERT_TRUE(drag_view != NULL);
ASSERT_NE(nullptr, drag_view);
// Move mouse to center of menu and press button.
ui_test_utils::MoveMouseToCenterAndPress(
drag_view,
ui_controls::LEFT,
ui_controls::DOWN,
drag_view, ui_controls::LEFT, ui_controls::DOWN,
CreateEventTask(this, &MenuViewDragAndDropTestNestedDrag::Step2));
}
......@@ -397,8 +376,7 @@ void MenuViewDragAndDropTestNestedDrag::Step2() {
// Start a drag.
ui_controls::SendMouseMoveNotifyWhenDone(
loc.x() + 3,
loc.y(),
loc.x() + 3, loc.y(),
CreateEventTask(this, &MenuViewDragAndDropTestNestedDrag::Step3));
ScheduleMouseMoveInBackground(loc.x(), loc.y());
......@@ -415,13 +393,11 @@ void MenuViewDragAndDropTestNestedDrag::Step3() {
ui_controls::SendMouseMove(loc.x(), loc.y());
ui_controls::SendMouseEventsNotifyWhenDone(
ui_controls::LEFT,
ui_controls::UP,
ui_controls::LEFT, ui_controls::UP,
CreateEventTask(this, &MenuViewDragAndDropTestNestedDrag::Step4));
}
void MenuViewDragAndDropTestNestedDrag::Step4() {
// Check our state.
// The target view should have finished its drag, and should have dropped the
// view. The main menu should not have done any drag, and the delegate should
// have been asked if it wanted to close. Since the delegate did not want to
......@@ -430,10 +406,11 @@ void MenuViewDragAndDropTestNestedDrag::Step4() {
EXPECT_TRUE(target_view()->dropped());
EXPECT_FALSE(performed_in_menu_drop());
EXPECT_TRUE(asked_to_close());
EXPECT_TRUE(menu()->GetSubmenu()->IsShowing());
views::SubmenuView* submenu = menu()->GetSubmenu();
EXPECT_TRUE(submenu->IsShowing());
// Clean up.
menu()->GetSubmenu()->Close();
submenu->Close();
Done();
}
......
......@@ -51,8 +51,16 @@ class ToolbarViewInteractiveUITest : public AppMenuButtonObserver,
void AppMenuShown() override;
protected:
AppMenuButton* app_menu_button() { return app_menu_button_; }
BrowserActionsContainer* browser_actions() { return browser_actions_; }
AppMenuButton* GetAppMenuButton() {
return BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetAppMenuButton();
}
BrowserActionsContainer* GetBrowserActions() {
return BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetBrowserActionsContainer();
}
// Performs a drag-and-drop operation by moving the mouse to |start|, clicking
// the left button, moving the mouse to |end|, and releasing the left button.
......@@ -60,12 +68,8 @@ class ToolbarViewInteractiveUITest : public AppMenuButtonObserver,
private:
// InProcessBrowserTest:
void SetUpCommandLine(base::CommandLine* command_line) override;
void SetUpOnMainThread() override;
void TearDownOnMainThread() override;
AppMenuButton* app_menu_button_ = nullptr;
BrowserActionsContainer* browser_actions_ = nullptr;
bool menu_shown_ = false;
base::OnceClosure quit_closure_;
};
......@@ -85,17 +89,17 @@ void ToolbarViewInteractiveUITest::DoDragAndDrop(const gfx::Point& start,
// Begin listening for the app menu to open.
ScopedObserver<AppMenuButton, AppMenuButtonObserver> observer(this);
observer.Add(app_menu_button());
observer.Add(GetAppMenuButton());
// Send the mouse to |start|, and click. The event queue must be flushed
// after processing the click, or the next mouse move sent may get processed
// before the click is fully handled, causing the test to fail.
ASSERT_TRUE(ui_controls::SendMouseMove(start.x(), start.y()));
ASSERT_TRUE(
EXPECT_TRUE(ui_controls::SendMouseMove(start.x(), start.y()));
EXPECT_TRUE(
ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::DOWN));
// Enqueue an event to move the mouse, which will start a drag.
ASSERT_TRUE(ui_controls::SendMouseMove(end.x() + 10, end.y()));
EXPECT_TRUE(ui_controls::SendMouseMove(end.x() + 10, end.y()));
// Enqueue an event to move the mouse to |end|. This must be done on a
// background thread, since starting a drag triggers a nested message loop
......@@ -113,32 +117,19 @@ void ToolbarViewInteractiveUITest::DoDragAndDrop(const gfx::Point& start,
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitWhenIdleClosure();
run_loop.Run();
EXPECT_TRUE(menu_shown_);
// Verify postconditions.
EXPECT_TRUE(menu_shown_);
// The app menu should have closed once the drag-and-drop completed.
EXPECT_FALSE(app_menu_button()->IsMenuShowing());
}
void ToolbarViewInteractiveUITest::SetUpCommandLine(
base::CommandLine* command_line) {
extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
ToolbarActionsBar::disable_animations_for_testing_ = true;
BrowserAppMenuButton::g_open_app_immediately_for_testing = true;
EXPECT_FALSE(GetAppMenuButton()->IsMenuShowing());
}
void ToolbarViewInteractiveUITest::SetUpOnMainThread() {
extensions::ExtensionBrowserTest::SetUpOnMainThread();
ExtensionToolbarMenuView::set_close_menu_delay_for_testing(base::TimeDelta());
auto* browser_view = BrowserView::GetBrowserViewForBrowser(browser());
auto* toolbar_button_provider = browser_view->toolbar_button_provider();
app_menu_button_ = toolbar_button_provider->GetAppMenuButton();
browser_actions_ = toolbar_button_provider->GetBrowserActionsContainer();
}
void ToolbarViewInteractiveUITest::TearDownOnMainThread() {
ToolbarActionsBar::disable_animations_for_testing_ = false;
BrowserAppMenuButton::g_open_app_immediately_for_testing = false;
BrowserAppMenuButton::g_open_app_immediately_for_testing = true;
ExtensionToolbarMenuView::set_close_menu_delay_for_testing(base::TimeDelta());
ToolbarActionsBar::disable_animations_for_testing_ = true;
}
#if defined(OS_LINUX) && defined(USE_AURA)
......@@ -161,17 +152,20 @@ IN_PROC_BROWSER_TEST_F(ToolbarViewInteractiveUITest,
ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
.AppendASCII("browser_action")
.AppendASCII("basics")));
base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded.
ASSERT_EQ(1u, browser_actions()->VisibleBrowserActions());
// Ensure the extension is fully loaded, and that the next steps will happen
// with a clean slate.
base::RunLoop().RunUntilIdle();
ToolbarActionView* view = browser_actions()->GetToolbarActionViewAt(0);
ASSERT_TRUE(view);
BrowserActionsContainer* const browser_actions = GetBrowserActions();
ASSERT_EQ(1u, browser_actions->VisibleBrowserActions());
ToolbarActionView* toolbar_action =
browser_actions->GetToolbarActionViewAt(0);
ASSERT_TRUE(toolbar_action);
gfx::Point browser_action_view_loc =
ui_test_utils::GetCenterInScreenCoordinates(view);
ui_test_utils::GetCenterInScreenCoordinates(toolbar_action);
gfx::Point app_button_loc =
ui_test_utils::GetCenterInScreenCoordinates(app_menu_button());
ui_test_utils::GetCenterInScreenCoordinates(GetAppMenuButton());
// Perform a drag and drop from the browser action view to the app button,
// which should open the app menu.
......
......@@ -31,12 +31,17 @@ void MoveMouseToCenterAndPress(views::View* view,
animator->StopAnimating();
}
gfx::Point view_center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, &view_center);
gfx::Point view_center = GetCenterInScreenCoordinates(view);
ui_controls::SendMouseMoveNotifyWhenDone(
view_center.x(), view_center.y(),
base::BindOnce(&internal::ClickTask, button, button_state, closure,
accelerator_state));
}
gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
gfx::Point center = view->GetLocalBounds().CenterPoint();
views::View::ConvertPointToScreen(view, &center);
return center;
}
} // namespace ui_test_utils
......@@ -44,10 +44,4 @@ void FocusView(const Browser* browser, ViewID vid) {
view->RequestFocus();
}
gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
gfx::Point center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, &center);
return center;
}
} // namespace ui_test_utils
......@@ -65,7 +65,7 @@ class VIEWS_EXPORT DragDropClientMac : public views_bridge_mac::DragDropClient {
DropHelper drop_helper_;
// The drag and drop operation.
int operation_;
int operation_ = 0;
// The bridge between the content view and the drag drop client.
BridgedNativeWidgetImpl* bridge_; // Weak. Owns |this|.
......@@ -74,7 +74,7 @@ class VIEWS_EXPORT DragDropClientMac : public views_bridge_mac::DragDropClient {
base::Closure quit_closure_;
// Whether |this| is the source of current dragging session.
bool is_drag_source_;
bool is_drag_source_ = false;
DISALLOW_COPY_AND_ASSIGN(DragDropClientMac);
};
......
......@@ -18,11 +18,7 @@ namespace views {
DragDropClientMac::DragDropClientMac(BridgedNativeWidgetImpl* bridge,
View* root_view)
: drop_helper_(root_view),
operation_(0),
bridge_(bridge),
quit_closure_(base::Closure()),
is_drag_source_(false) {
: drop_helper_(root_view), bridge_(bridge) {
DCHECK(bridge);
}
......
......@@ -176,12 +176,12 @@ class VIEWS_EXPORT MenuController
void OnDragEnteredScrollButton(SubmenuView* source, bool is_up);
void OnDragExitedScrollButton(SubmenuView* source);
// Called by the Widget when a drag is about to start on a child view. This
// could be initiated by one of our MenuItemViews, or could be through another
// child View.
// Called by the MenuHost when a drag is about to start on a child view.
// This could be initiated by one of our MenuItemViews, or could be through
// another child View.
void OnDragWillStart();
// Called by the Widget when the drag has completed. |should_close|
// Called by the MenuHost when the drag has completed. |should_close|
// corresponds to whether or not the menu should close.
void OnDragComplete(bool should_close);
......
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