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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc

Issue 550313002: Pop extensions out of the action overflow menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: name change + latest master for CQ Created 6 years, 3 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
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h" 9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_toolbar_model.h" 11 #include "chrome/browser/extensions/extension_toolbar_model.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/browser_window_testing_views.h" 13 #include "chrome/browser/ui/browser_window_testing_views.h"
14 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 15 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" 16 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
17 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
18 #include "extensions/browser/extension_prefs.h" 19 #include "extensions/browser/extension_prefs.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
21 #include "ui/base/dragdrop/drop_target_event.h"
22 #include "ui/base/dragdrop/os_exchange_data.h"
20 #include "ui/gfx/geometry/point.h" 23 #include "ui/gfx/geometry/point.h"
21 #include "ui/views/view.h" 24 #include "ui/views/view.h"
22 25
23 using extensions::Extension; 26 using extensions::Extension;
24 27
25 class BrowserActionsContainerTest : public ExtensionBrowserTest { 28 class BrowserActionsContainerTest : public ExtensionBrowserTest {
26 public: 29 public:
27 BrowserActionsContainerTest() { 30 BrowserActionsContainerTest() {
28 } 31 }
29 virtual ~BrowserActionsContainerTest() {} 32 virtual ~BrowserActionsContainerTest() {}
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // Unload the extension. 78 // Unload the extension.
76 std::string id = browser_actions_bar()->GetExtensionId(0); 79 std::string id = browser_actions_bar()->GetExtensionId(0);
77 UnloadExtension(id); 80 UnloadExtension(id);
78 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions()); 81 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
79 } 82 }
80 83
81 // Test moving various browser actions. This is not to check the logic of the 84 // Test moving various browser actions. This is not to check the logic of the
82 // move (that's in the toolbar model tests), but just to check our ui. 85 // move (that's in the toolbar model tests), but just to check our ui.
83 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, 86 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest,
84 MoveBrowserActions) { 87 MoveBrowserActions) {
88 base::FilePath data_dir =
89 test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action");
85 // Load three extensions with browser actions. 90 // Load three extensions with browser actions.
86 const extensions::Extension* extension_a = 91 const extensions::Extension* extension_a =
87 LoadExtension(test_data_dir_.AppendASCII("api_test") 92 LoadExtension(data_dir.AppendASCII("basics"));
88 .AppendASCII("browser_action")
89 .AppendASCII("basics"));
90 ASSERT_TRUE(extension_a); 93 ASSERT_TRUE(extension_a);
91 const extensions::Extension* extension_b = 94 const extensions::Extension* extension_b =
92 LoadExtension(test_data_dir_.AppendASCII("api_test") 95 LoadExtension(data_dir.AppendASCII("add_popup"));
93 .AppendASCII("browser_action")
94 .AppendASCII("add_popup"));
95 ASSERT_TRUE(extension_b); 96 ASSERT_TRUE(extension_b);
96 const extensions::Extension* extension_c = 97 const extensions::Extension* extension_c =
97 LoadExtension(test_data_dir_.AppendASCII("api_test") 98 LoadExtension(data_dir.AppendASCII("remove_popup"));
98 .AppendASCII("browser_action")
99 .AppendASCII("remove_popup"));
100 ASSERT_TRUE(extension_c); 99 ASSERT_TRUE(extension_c);
101 100
102 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); 101 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
103 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); 102 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
104 103
105 extensions::ExtensionToolbarModel* model = 104 extensions::ExtensionToolbarModel* model =
106 extensions::ExtensionToolbarModel::Get(profile()); 105 extensions::ExtensionToolbarModel::Get(profile());
107 ASSERT_TRUE(model); 106 ASSERT_TRUE(model);
108 107
109 // Order is now A B C. 108 // Order is now A B C.
(...skipping 13 matching lines...) Expand all
123 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1)); 122 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1));
124 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2)); 123 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2));
125 124
126 // Move B to middle position. Order is C B A. 125 // Move B to middle position. Order is C B A.
127 model->MoveExtensionIcon(extension_b, 1); 126 model->MoveExtensionIcon(extension_b, 1);
128 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(0)); 127 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(0));
129 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1)); 128 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1));
130 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(2)); 129 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(2));
131 } 130 }
132 131
132 // Test that dragging browser actions works, and that dragging a browser action
133 // from the overflow menu results in it "popping" out (growing the container
134 // size by 1), rather than just reordering the extensions.
135 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) {
136 base::FilePath data_dir =
137 test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action");
138 // Load three extensions with browser actions.
139 const extensions::Extension* extension_a =
140 LoadExtension(data_dir.AppendASCII("basics"));
141 ASSERT_TRUE(extension_a);
142 const extensions::Extension* extension_b =
143 LoadExtension(data_dir.AppendASCII("add_popup"));
144 ASSERT_TRUE(extension_b);
145 const extensions::Extension* extension_c =
146 LoadExtension(data_dir.AppendASCII("remove_popup"));
147 ASSERT_TRUE(extension_c);
148
149 // Sanity check: All extensions showing; order is A B C.
150 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
151 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
152 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0));
153 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1));
154 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2));
155
156 BrowserActionsContainer* container =
157 BrowserView::GetBrowserViewForBrowser(browser())
158 ->toolbar()->browser_actions();
159
160 // Simulate a drag and drop to the right.
161 ui::OSExchangeData drop_data;
162 // Drag extension A from index 0...
163 BrowserActionDragData browser_action_drag_data(extension_a->id(), 0u);
164 browser_action_drag_data.Write(profile(), &drop_data);
165 BrowserActionView* view = container->GetViewForExtension(extension_b);
166 // ...to the right of extension B.
167 gfx::Point location(view->x() + view->width(), view->y());
168 ui::DropTargetEvent target_event(
169 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
170
171 // Drag and drop.
172 container->OnDragUpdated(target_event);
173 container->OnPerformDrop(target_event);
174
175 // The order should now be B A C, since A was dragged to the right of B.
176 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(0));
177 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1));
178 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2));
179
180 // This order should be reflected in the underlying model.
181 extensions::ExtensionToolbarModel* model =
182 extensions::ExtensionToolbarModel::Get(profile());
183 EXPECT_EQ(extension_b, model->toolbar_items()[0]);
184 EXPECT_EQ(extension_a, model->toolbar_items()[1]);
185 EXPECT_EQ(extension_c, model->toolbar_items()[2]);
186
187 // Simulate a drag and drop to the left.
188 ui::OSExchangeData drop_data2;
189 // Drag extension A from index 1...
190 BrowserActionDragData browser_action_drag_data2(extension_a->id(), 1u);
191 browser_action_drag_data2.Write(profile(), &drop_data2);
192 // ...to the left of extension B (which is now at index 0).
193 location = gfx::Point(view->x(), view->y());
194 ui::DropTargetEvent target_event2(
195 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE);
196
197 // Drag and drop.
198 container->OnDragUpdated(target_event2);
199 container->OnPerformDrop(target_event2);
200
201 // Order should be restored to A B C.
202 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0));
203 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1));
204 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2));
205
206 // Shrink the size of the container so we have an overflow menu.
207 model->SetVisibleIconCountForTest(2u);
208 EXPECT_EQ(2u, container->VisibleBrowserActions());
209 ASSERT_TRUE(container->chevron());
210 EXPECT_TRUE(container->chevron()->visible());
211
212 // Simulate a drag and drop from the overflow menu.
213 ui::OSExchangeData drop_data3;
214 // Drag extension C from index 2 (in the overflow menu)...
215 BrowserActionDragData browser_action_drag_data3(extension_c->id(), 2u);
216 browser_action_drag_data3.Write(profile(), &drop_data3);
217 // ...to the left of extension B (which is back in index 1 on the main bar).
218 location = gfx::Point(view->x(), view->y());
219 ui::DropTargetEvent target_event3(
220 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE);
221
222 // Drag and drop.
223 container->OnDragUpdated(target_event3);
224 container->OnPerformDrop(target_event3);
225
226 // The order should have changed *and* the container should have grown to
227 // accommodate extension C. The new order should be A C B, and all three
228 // extensions should be visible, with no overflow menu.
229 EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0));
230 EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(1));
231 EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2));
232 EXPECT_EQ(3u, container->VisibleBrowserActions());
233 EXPECT_FALSE(container->chevron()->visible());
234 EXPECT_EQ(-1, model->GetVisibleIconCount());
235
236 // TODO(devlin): Ideally, we'd also have tests for dragging from the legacy
237 // overflow menu (i.e., chevron) to the main bar, but this requires either
238 // having a fairly complicated interactive UI test or finding a good way to
239 // mock up the BrowserActionOverflowMenuController.
240 }
241
133 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) { 242 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) {
134 // Load extension A (contains browser action). 243 // Load extension A (contains browser action).
135 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") 244 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test")
136 .AppendASCII("browser_action") 245 .AppendASCII("browser_action")
137 .AppendASCII("basics"))); 246 .AppendASCII("basics")));
138 EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions()); 247 EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
139 EXPECT_TRUE(browser_actions_bar()->HasIcon(0)); 248 EXPECT_TRUE(browser_actions_bar()->HasIcon(0));
140 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); 249 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
141 std::string idA = browser_actions_bar()->GetExtensionId(0); 250 std::string idA = browser_actions_bar()->GetExtensionId(0);
142 251
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 extensions::ExtensionActionAPI::SetBrowserActionVisibility( 598 extensions::ExtensionActionAPI::SetBrowserActionVisibility(
490 extensions::ExtensionPrefs::Get(profile()), 599 extensions::ExtensionPrefs::Get(profile()),
491 extension_a->id(), 600 extension_a->id(),
492 false); 601 false);
493 overflow_bar()->Layout(); // Kick. 602 overflow_bar()->Layout(); // Kick.
494 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(0)->extension()); 603 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(0)->extension());
495 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension()); 604 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension());
496 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension()); 605 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension());
497 EXPECT_TRUE(VerifyVisibleCount(1u)); 606 EXPECT_TRUE(VerifyVisibleCount(1u));
498 } 607 }
608
609 // Test drag and drop between the overflow container and the main container.
610 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest,
611 TestOverflowDragging) {
612 base::FilePath test_data_path =
613 test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action");
614 const extensions::Extension* extension_a =
615 LoadExtension(test_data_path.AppendASCII("basics"));
616 const extensions::Extension* extension_b =
617 LoadExtension(test_data_path.AppendASCII("add_popup"));
618 const extensions::Extension* extension_c =
619 LoadExtension(test_data_path.AppendASCII("remove_popup"));
620
621 // Start with one extension in overflow.
622 model()->SetVisibleIconCountForTest(2u);
623 overflow_bar()->Layout();
624
625 // Verify starting state is A B [C].
626 ASSERT_EQ(3u, main_bar()->num_browser_actions());
627 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension());
628 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension());
629 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension());
630 EXPECT_TRUE(VerifyVisibleCount(2u));
631
632 // Drag extension A (on the main bar) to the left of extension C (in
633 // overflow).
634 ui::OSExchangeData drop_data;
635 BrowserActionDragData browser_action_drag_data(extension_a->id(), 0u);
636 browser_action_drag_data.Write(profile(), &drop_data);
637 BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c);
638 gfx::Point location(view->x(), view->y());
639 ui::DropTargetEvent target_event(
640 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
641
642 overflow_bar()->OnDragUpdated(target_event);
643 overflow_bar()->OnPerformDrop(target_event);
644 overflow_bar()->Layout();
645
646 // Order should now be B [A C].
647 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(0)->extension());
648 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension());
649 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension());
650 VerifyVisibleCount(1u);
651
652 // Drag extension A back from overflow to the main bar.
653 ui::OSExchangeData drop_data2;
654 BrowserActionDragData browser_action_drag_data2(extension_a->id(), 1u);
655 browser_action_drag_data2.Write(profile(), &drop_data2);
656 view = main_bar()->GetViewForExtension(extension_b);
657 location = gfx::Point(view->x(), view->y());
658 ui::DropTargetEvent target_event2(
659 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE);
660
661 main_bar()->OnDragUpdated(target_event2);
662 main_bar()->OnPerformDrop(target_event2);
663
664 // Order should be A B [C] again.
665 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension());
666 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension());
667 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension());
668 VerifyVisibleCount(2u);
669
670 // Drag extension C from overflow to the main bar (before extension B).
671 ui::OSExchangeData drop_data3;
672 BrowserActionDragData browser_action_drag_data3(extension_c->id(), 2u);
673 browser_action_drag_data3.Write(profile(), &drop_data3);
674 location = gfx::Point(view->x(), view->y());
675 ui::DropTargetEvent target_event3(
676 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE);
677
678 main_bar()->OnDragUpdated(target_event3);
679 main_bar()->OnPerformDrop(target_event3);
680
681 // Order should be A C B, and there should be no extensions in overflow.
682 EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension());
683 EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(1)->extension());
684 EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension());
685 VerifyVisibleCount(3u);
686 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698