OLD | NEW |
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 27 matching lines...) Expand all Loading... |
54 | 55 |
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 |
| 65 const extensions::ExtensionSet& extension_set = |
| 66 extensions::ExtensionRegistry::Get(profile())->enabled_extensions(); |
| 67 const std::vector<ToolbarActionsModel::ToolbarItem>& toolbar_items = |
| 68 toolbar_model()->toolbar_items(); |
| 69 |
64 // This order should be reflected in the underlying model. | 70 // This order should be reflected in the underlying model. |
65 EXPECT_EQ(extension_b(), toolbar_model()->toolbar_items()[0].get()); | 71 EXPECT_EQ(extension_b(), extension_set.GetByID(toolbar_items[0].id)); |
66 EXPECT_EQ(extension_a(), toolbar_model()->toolbar_items()[1].get()); | 72 EXPECT_EQ(extension_a(), extension_set.GetByID(toolbar_items[1].id)); |
67 EXPECT_EQ(extension_c(), toolbar_model()->toolbar_items()[2].get()); | 73 EXPECT_EQ(extension_c(), extension_set.GetByID(toolbar_items[2].id)); |
68 | 74 |
69 // Simulate a drag and drop to the left. | 75 // Simulate a drag and drop to the left. |
70 ui::OSExchangeData drop_data2; | 76 ui::OSExchangeData drop_data2; |
71 // Drag extension A from index 1... | 77 // Drag extension A from index 1... |
72 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); | 78 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); |
73 browser_action_drag_data2.Write(profile(), &drop_data2); | 79 browser_action_drag_data2.Write(profile(), &drop_data2); |
74 // ...to the left of extension B (which is now at index 0). | 80 // ...to the left of extension B (which is now at index 0). |
75 location = gfx::Point(view->x(), view->y()); | 81 location = gfx::Point(view->x(), view->y()); |
76 ui::DropTargetEvent target_event2( | 82 ui::DropTargetEvent target_event2( |
77 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); | 83 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Next, simulate a resize by shrinking the container. | 180 // Next, simulate a resize by shrinking the container. |
175 first->OnResize(1, true); | 181 first->OnResize(1, true); |
176 // The first and second container should each have resized. | 182 // The first and second container should each have resized. |
177 EXPECT_EQ(2u, first->VisibleBrowserActions()); | 183 EXPECT_EQ(2u, first->VisibleBrowserActions()); |
178 EXPECT_EQ(2u, second->VisibleBrowserActions()); | 184 EXPECT_EQ(2u, second->VisibleBrowserActions()); |
179 } | 185 } |
180 | 186 |
181 // Test that the BrowserActionsContainer responds correctly when the underlying | 187 // Test that the BrowserActionsContainer responds correctly when the underlying |
182 // model enters highlight mode, and that browser actions are undraggable in | 188 // model enters highlight mode, and that browser actions are undraggable in |
183 // highlight mode. (Highlight mode itself it tested more thoroughly in the | 189 // highlight mode. (Highlight mode itself it tested more thoroughly in the |
184 // ExtensionToolbarModel browsertests). | 190 // ToolbarActionsModel browsertests). |
185 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, HighlightMode) { | 191 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, HighlightMode) { |
186 LoadExtensions(); | 192 LoadExtensions(); |
187 | 193 |
188 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); | 194 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); |
189 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); | 195 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); |
190 | 196 |
191 BrowserActionsContainer* container = | 197 BrowserActionsContainer* container = |
192 BrowserView::GetBrowserViewForBrowser(browser()) | 198 BrowserView::GetBrowserViewForBrowser(browser()) |
193 ->toolbar()->browser_actions(); | 199 ->toolbar()->browser_actions(); |
194 | 200 |
195 // Currently, dragging should be enabled. | 201 // Currently, dragging should be enabled. |
196 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0); | 202 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0); |
197 ASSERT_TRUE(action_view); | 203 ASSERT_TRUE(action_view); |
198 gfx::Point point(action_view->x(), action_view->y()); | 204 gfx::Point point(action_view->x(), action_view->y()); |
199 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); | 205 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); |
200 | 206 |
201 extensions::ExtensionIdList extension_ids; | 207 std::vector<std::string> action_ids; |
202 extension_ids.push_back(extension_a()->id()); | 208 action_ids.push_back(extension_a()->id()); |
203 extension_ids.push_back(extension_b()->id()); | 209 action_ids.push_back(extension_b()->id()); |
204 toolbar_model()->HighlightExtensions( | 210 toolbar_model()->HighlightActions(action_ids, |
205 extension_ids, extensions::ExtensionToolbarModel::HIGHLIGHT_WARNING); | 211 ToolbarActionsModel::HIGHLIGHT_WARNING); |
206 | 212 |
207 // Only two browser actions should be visible. | 213 // Only two browser actions should be visible. |
208 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); | 214 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); |
209 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); | 215 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); |
210 | 216 |
211 // We shouldn't be able to drag in highlight mode. | 217 // We shouldn't be able to drag in highlight mode. |
212 action_view = container->GetToolbarActionViewAt(0); | 218 action_view = container->GetToolbarActionViewAt(0); |
213 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); | 219 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); |
214 | 220 |
215 // We should go back to normal after leaving highlight mode. | 221 // We should go back to normal after leaving highlight mode. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // only A and B should be visible on the main bar. | 341 // only A and B should be visible on the main bar. |
336 toolbar_model()->SetVisibleIconCount(2u); | 342 toolbar_model()->SetVisibleIconCount(2u); |
337 overflow_bar()->Layout(); // Kick. | 343 overflow_bar()->Layout(); // Kick. |
338 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 344 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
339 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); | 345 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
340 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); | 346 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
341 EXPECT_TRUE(VerifyVisibleCount(2u)); | 347 EXPECT_TRUE(VerifyVisibleCount(2u)); |
342 | 348 |
343 // Move extension C to the first position. Order should now be C A B, with | 349 // Move extension C to the first position. Order should now be C A B, with |
344 // C and A visible in the main bar. | 350 // C and A visible in the main bar. |
345 toolbar_model()->MoveExtensionIcon(extension_c()->id(), 0); | 351 toolbar_model()->MoveActionIcon(extension_c()->id(), 0); |
346 overflow_bar()->Layout(); // Kick. | 352 overflow_bar()->Layout(); // Kick. |
347 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u)); | 353 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u)); |
348 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); | 354 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); |
349 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); | 355 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
350 EXPECT_TRUE(VerifyVisibleCount(2u)); | 356 EXPECT_TRUE(VerifyVisibleCount(2u)); |
351 | 357 |
352 // Hide action A. This results in it being sent to overflow, and reducing the | 358 // 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 | 359 // visible size to 1, so the order should be C A B, with only C visible in the |
354 // main bar. | 360 // main bar. |
355 extensions::ExtensionActionAPI::Get(profile())->SetBrowserActionVisibility( | 361 extensions::ExtensionActionAPI::Get(profile())->SetBrowserActionVisibility( |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 432 |
427 main_bar()->OnDragUpdated(target_event3); | 433 main_bar()->OnDragUpdated(target_event3); |
428 main_bar()->OnPerformDrop(target_event3); | 434 main_bar()->OnPerformDrop(target_event3); |
429 | 435 |
430 // Order should be A C B, and there should be no extensions in overflow. | 436 // Order should be A C B, and there should be no extensions in overflow. |
431 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 437 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
432 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); | 438 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); |
433 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); | 439 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
434 EXPECT_TRUE(VerifyVisibleCount(3u)); | 440 EXPECT_TRUE(VerifyVisibleCount(3u)); |
435 } | 441 } |
OLD | NEW |