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

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

Issue 1241063003: Support Component Actions in the toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per mfoltz@'s comments. Created 5 years, 4 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
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/extensions/api/extension_action/extension_action_api.h" 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
8 #include "chrome/browser/extensions/browser_action_test_util.h" 8 #include "chrome/browser/extensions/browser_action_test_util.h"
9 #include "chrome/browser/extensions/extension_toolbar_model.h"
10 #include "chrome/browser/ui/browser_window.h" 9 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" 10 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h"
11 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
12 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 12 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" 14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
16 #include "extensions/browser/extension_prefs.h" 16 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/browser/extension_registry.h"
17 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
18 #include "ui/base/dragdrop/drop_target_event.h" 19 #include "ui/base/dragdrop/drop_target_event.h"
19 #include "ui/base/dragdrop/os_exchange_data.h" 20 #include "ui/base/dragdrop/os_exchange_data.h"
20 #include "ui/gfx/geometry/point.h" 21 #include "ui/gfx/geometry/point.h"
21 #include "ui/views/view.h" 22 #include "ui/views/view.h"
22 23
23 // TODO(devlin): Continue moving any tests that should be platform independent 24 // TODO(devlin): Continue moving any tests that should be platform independent
24 // from this file to the crossplatform tests in 25 // from this file to the crossplatform tests in
25 // chrome/browser/ui/toolbar/browser_actions_bar_browsertest.cc. 26 // chrome/browser/ui/toolbar/browser_actions_bar_browsertest.cc.
26 27
(...skipping 28 matching lines...) Expand all
55 // Drag and drop. 56 // Drag and drop.
56 container->OnDragUpdated(target_event); 57 container->OnDragUpdated(target_event);
57 container->OnPerformDrop(target_event); 58 container->OnPerformDrop(target_event);
58 59
59 // The order should now be B A C, since A was dragged to the right of B. 60 // The order should now be B A C, since A was dragged to the right of B.
60 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0)); 61 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0));
61 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1)); 62 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1));
62 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2)); 63 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2));
63 64
64 // This order should be reflected in the underlying model. 65 // This order should be reflected in the underlying model.
65 EXPECT_EQ(extension_b(), toolbar_model()->toolbar_items()[0].get()); 66 EXPECT_EQ(extension_b(), extensions::ExtensionRegistry::Get(
66 EXPECT_EQ(extension_a(), toolbar_model()->toolbar_items()[1].get()); 67 profile())->enabled_extensions().GetByID(
67 EXPECT_EQ(extension_c(), toolbar_model()->toolbar_items()[2].get()); 68 toolbar_model()->toolbar_items()[0]));
69 EXPECT_EQ(extension_a(), extensions::ExtensionRegistry::Get(
70 profile())->enabled_extensions().GetByID(
71 toolbar_model()->toolbar_items()[1]));
72 EXPECT_EQ(extension_c(), extensions::ExtensionRegistry::Get(
73 profile())->enabled_extensions().GetByID(
74 toolbar_model()->toolbar_items()[2]));
68 75
69 // Simulate a drag and drop to the left. 76 // Simulate a drag and drop to the left.
70 ui::OSExchangeData drop_data2; 77 ui::OSExchangeData drop_data2;
71 // Drag extension A from index 1... 78 // Drag extension A from index 1...
72 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); 79 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u);
73 browser_action_drag_data2.Write(profile(), &drop_data2); 80 browser_action_drag_data2.Write(profile(), &drop_data2);
74 // ...to the left of extension B (which is now at index 0). 81 // ...to the left of extension B (which is now at index 0).
75 location = gfx::Point(view->x(), view->y()); 82 location = gfx::Point(view->x(), view->y());
76 ui::DropTargetEvent target_event2( 83 ui::DropTargetEvent target_event2(
77 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); 84 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Next, simulate a resize by shrinking the container. 181 // Next, simulate a resize by shrinking the container.
175 first->OnResize(1, true); 182 first->OnResize(1, true);
176 // The first and second container should each have resized. 183 // The first and second container should each have resized.
177 EXPECT_EQ(2u, first->VisibleBrowserActions()); 184 EXPECT_EQ(2u, first->VisibleBrowserActions());
178 EXPECT_EQ(2u, second->VisibleBrowserActions()); 185 EXPECT_EQ(2u, second->VisibleBrowserActions());
179 } 186 }
180 187
181 // Test that the BrowserActionsContainer responds correctly when the underlying 188 // Test that the BrowserActionsContainer responds correctly when the underlying
182 // model enters highlight mode, and that browser actions are undraggable in 189 // model enters highlight mode, and that browser actions are undraggable in
183 // highlight mode. (Highlight mode itself it tested more thoroughly in the 190 // highlight mode. (Highlight mode itself it tested more thoroughly in the
184 // ExtensionToolbarModel browsertests). 191 // ToolbarActionsModel browsertests).
185 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, HighlightMode) { 192 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, HighlightMode) {
186 LoadExtensions(); 193 LoadExtensions();
187 194
188 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); 195 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
189 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); 196 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
190 197
191 BrowserActionsContainer* container = 198 BrowserActionsContainer* container =
192 BrowserView::GetBrowserViewForBrowser(browser()) 199 BrowserView::GetBrowserViewForBrowser(browser())
193 ->toolbar()->browser_actions(); 200 ->toolbar()->browser_actions();
194 201
195 // Currently, dragging should be enabled. 202 // Currently, dragging should be enabled.
196 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0); 203 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0);
197 ASSERT_TRUE(action_view); 204 ASSERT_TRUE(action_view);
198 gfx::Point point(action_view->x(), action_view->y()); 205 gfx::Point point(action_view->x(), action_view->y());
199 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); 206 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
200 207
201 extensions::ExtensionIdList extension_ids; 208 ActionIdList action_ids;
202 extension_ids.push_back(extension_a()->id()); 209 action_ids.push_back(extension_a()->id());
203 extension_ids.push_back(extension_b()->id()); 210 action_ids.push_back(extension_b()->id());
204 toolbar_model()->HighlightExtensions( 211 toolbar_model()->HighlightActions(
205 extension_ids, extensions::ExtensionToolbarModel::HIGHLIGHT_WARNING); 212 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
206 213
207 // Only two browser actions should be visible. 214 // Only two browser actions should be visible.
208 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); 215 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
209 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); 216 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
210 217
211 // We shouldn't be able to drag in highlight mode. 218 // We shouldn't be able to drag in highlight mode.
212 action_view = container->GetToolbarActionViewAt(0); 219 action_view = container->GetToolbarActionViewAt(0);
213 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); 220 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point));
214 221
215 // We should go back to normal after leaving highlight mode. 222 // We should go back to normal after leaving highlight mode.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // only A and B should be visible on the main bar. 342 // only A and B should be visible on the main bar.
336 toolbar_model()->SetVisibleIconCount(2u); 343 toolbar_model()->SetVisibleIconCount(2u);
337 overflow_bar()->Layout(); // Kick. 344 overflow_bar()->Layout(); // Kick.
338 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 345 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
339 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); 346 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u));
340 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); 347 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u));
341 EXPECT_TRUE(VerifyVisibleCount(2u)); 348 EXPECT_TRUE(VerifyVisibleCount(2u));
342 349
343 // Move extension C to the first position. Order should now be C A B, with 350 // Move extension C to the first position. Order should now be C A B, with
344 // C and A visible in the main bar. 351 // C and A visible in the main bar.
345 toolbar_model()->MoveExtensionIcon(extension_c()->id(), 0); 352 toolbar_model()->MoveActionIcon(extension_c()->id(), 0);
346 overflow_bar()->Layout(); // Kick. 353 overflow_bar()->Layout(); // Kick.
347 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u)); 354 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u));
348 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); 355 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u));
349 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); 356 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u));
350 EXPECT_TRUE(VerifyVisibleCount(2u)); 357 EXPECT_TRUE(VerifyVisibleCount(2u));
351 358
352 // Hide action A. This results in it being sent to overflow, and reducing the 359 // Hide action A. This results in it being sent to overflow, and reducing the
353 // visible size to 1, so the order should be C A B, with only C visible in the 360 // visible size to 1, so the order should be C A B, with only C visible in the
354 // main bar. 361 // main bar.
355 extensions::ExtensionActionAPI::Get(profile())->SetBrowserActionVisibility( 362 extensions::ExtensionActionAPI::Get(profile())->SetBrowserActionVisibility(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 433
427 main_bar()->OnDragUpdated(target_event3); 434 main_bar()->OnDragUpdated(target_event3);
428 main_bar()->OnPerformDrop(target_event3); 435 main_bar()->OnPerformDrop(target_event3);
429 436
430 // Order should be A C B, and there should be no extensions in overflow. 437 // Order should be A C B, and there should be no extensions in overflow.
431 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 438 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
432 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); 439 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u));
433 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); 440 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u));
434 EXPECT_TRUE(VerifyVisibleCount(3u)); 441 EXPECT_TRUE(VerifyVisibleCount(3u));
435 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698