Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: trunk/src/chrome/browser/ui/views/toolbar/toolbar_view_interactive_uitest.cc

Issue 416903002: Revert 285142 "Open the WrenchMenu on mouseover when dragging a ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/run_loop.h"
6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/ui/views/frame/browser_view.h"
8 #include "chrome/browser/ui/views/frame/test_with_browser_view.h"
9 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
10 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
11 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
12 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
13 #include "chrome/test/base/interactive_test_utils.h"
14 #include "extensions/common/feature_switch.h"
15
16 // Borrowed from chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc,
17 // since these are also disabled on Linux for drag and drop.
18 // TODO(erg): Fix DND tests on linux_aura. crbug.com/163931
19 #if defined(OS_LINUX) && defined(USE_AURA)
20 #define MAYBE(x) DISABLED_##x
21 #else
22 #define MAYBE(x) x
23 #endif
24
25 class ToolbarViewInteractiveUITest : public ExtensionBrowserTest {
26 public:
27 ToolbarViewInteractiveUITest();
28 virtual ~ToolbarViewInteractiveUITest();
29
30 protected:
31 ToolbarView* toolbar_view() { return toolbar_view_; }
32 BrowserActionsContainer* browser_actions() { return browser_actions_; }
33
34 // Performs a drag-and-drop operation by moving the mouse to |start|, clicking
35 // the left button, moving the mouse to |end|, and releasing the left button.
36 // TestWhileInDragOperation() is called after the mouse has moved to |end|,
37 // but before the click is released.
38 void DoDragAndDrop(const gfx::Point& start, const gfx::Point& end);
39
40 // A function to perform testing actions while in the drag operation from
41 // DoDragAndDrop.
42 void TestWhileInDragOperation();
43
44 private:
45 // Finishes the drag-and-drop operation started in DoDragAndDrop().
46 void FinishDragAndDrop(const base::Closure& quit_closure);
47
48 // InProcessBrowserTest:
49 virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
50 virtual void SetUpOnMainThread() OVERRIDE;
51
52 ToolbarView* toolbar_view_;
53
54 BrowserActionsContainer* browser_actions_;
55
56 // The drag-and-drop background thread.
57 scoped_ptr<base::Thread> dnd_thread_;
58
59 // Override the extensions-action-redesign switch.
60 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> feature_override_;
61 };
62
63 ToolbarViewInteractiveUITest::ToolbarViewInteractiveUITest()
64 : toolbar_view_(NULL),
65 browser_actions_(NULL) {
66 }
67
68 ToolbarViewInteractiveUITest::~ToolbarViewInteractiveUITest() {
69 }
70
71 void ToolbarViewInteractiveUITest::DoDragAndDrop(const gfx::Point& start,
72 const gfx::Point& end) {
73 // Much of this function is modeled after methods in ViewEventTestBase (in
74 // particular, the |dnd_thread_|, but it's easier to move that here than try
75 // to make ViewEventTestBase play nice with a BrowserView (for the toolbar).
76 // TODO(devlin): In a perfect world, this would be factored better.
77
78 // Send the mouse to |start|, and click.
79 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(start));
80 ASSERT_TRUE(ui_test_utils::SendMouseEventsSync(
81 ui_controls::LEFT, ui_controls::DOWN));
82
83 scoped_refptr<content::MessageLoopRunner> runner =
84 new content::MessageLoopRunner();
85
86 ui_controls::SendMouseMoveNotifyWhenDone(
87 end.x() + 10,
88 end.y(),
89 base::Bind(&ToolbarViewInteractiveUITest::FinishDragAndDrop,
90 base::Unretained(this),
91 runner->QuitClosure()));
92
93 // Also post a move task to the drag and drop thread.
94 if (!dnd_thread_.get()) {
95 dnd_thread_.reset(new base::Thread("mouse_move_thread"));
96 dnd_thread_->Start();
97 }
98
99 dnd_thread_->message_loop()->PostDelayedTask(
100 FROM_HERE,
101 base::Bind(base::IgnoreResult(&ui_controls::SendMouseMove),
102 end.x(),
103 end.y()),
104 base::TimeDelta::FromMilliseconds(200));
105 runner->Run();
106 }
107
108 void ToolbarViewInteractiveUITest::TestWhileInDragOperation() {
109 EXPECT_TRUE(toolbar_view()->IsWrenchMenuShowing());
110 }
111
112 void ToolbarViewInteractiveUITest::FinishDragAndDrop(
113 const base::Closure& quit_closure) {
114 dnd_thread_.reset();
115 TestWhileInDragOperation();
116 ui_controls::SendMouseEvents(ui_controls::LEFT, ui_controls::UP);
117 ui_controls::RunClosureAfterAllPendingUIEvents(
118 quit_closure);
119 }
120
121 void ToolbarViewInteractiveUITest::SetUpCommandLine(
122 base::CommandLine* command_line) {
123 ExtensionBrowserTest::SetUpCommandLine(command_line);
124 // We do this before the rest of the setup because it can affect how the views
125 // are constructed.
126 feature_override_.reset(new extensions::FeatureSwitch::ScopedOverride(
127 extensions::FeatureSwitch::extension_action_redesign(), true));
128 }
129
130 void ToolbarViewInteractiveUITest::SetUpOnMainThread() {
131 ExtensionBrowserTest::SetUpOnMainThread();
132
133 toolbar_view_ = BrowserView::GetBrowserViewForBrowser(browser())->toolbar();
134 browser_actions_ = toolbar_view_->browser_actions();
135 }
136
137 IN_PROC_BROWSER_TEST_F(ToolbarViewInteractiveUITest,
138 MAYBE(TestWrenchMenuOpensOnDrag)) {
139 WrenchToolbarButton::g_open_wrench_immediately_for_testing = true;
140
141 // Load an extension that has a browser action.
142 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
143 .AppendASCII("browser_action")
144 .AppendASCII("basics")));
145 ASSERT_EQ(1u, browser_actions()->VisibleBrowserActions());
146
147 BrowserActionView* view = browser_actions()->GetBrowserActionViewAt(0);
148 ASSERT_TRUE(view);
149
150 gfx::Point browser_action_view_loc = test::GetCenterInScreenCoordinates(view);
151 gfx::Point wrench_button_loc =
152 test::GetCenterInScreenCoordinates(toolbar_view()->app_menu());
153
154 // Perform a drag and drop from the browser action view to the wrench button,
155 // which should open the wrench menu.
156 DoDragAndDrop(browser_action_view_loc, wrench_button_loc);
157 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/views/toolbar/toolbar_view.cc ('k') | trunk/src/chrome/browser/ui/views/toolbar/wrench_menu.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698