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" | 9 #include "chrome/browser/extensions/extension_toolbar_model.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
11 #include "chrome/browser/ui/browser_window_testing_views.h" | 11 #include "chrome/browser/ui/browser_window_testing_views.h" |
12 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" | 12 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" |
13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 15 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" |
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
17 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
18 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
19 #include "ui/base/dragdrop/drop_target_event.h" | 19 #include "ui/base/dragdrop/drop_target_event.h" |
20 #include "ui/base/dragdrop/os_exchange_data.h" | 20 #include "ui/base/dragdrop/os_exchange_data.h" |
21 #include "ui/gfx/geometry/point.h" | 21 #include "ui/gfx/geometry/point.h" |
22 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
23 | 23 |
24 // TODO(devlin): Continue moving any tests that should be platform independent | 24 // TODO(devlin): Continue moving any tests that should be platform independent |
25 // from this file to the crossplatform tests in | 25 // from this file to the crossplatform tests in |
(...skipping 14 matching lines...) Expand all Loading... |
40 | 40 |
41 BrowserActionsContainer* container = | 41 BrowserActionsContainer* container = |
42 BrowserView::GetBrowserViewForBrowser(browser()) | 42 BrowserView::GetBrowserViewForBrowser(browser()) |
43 ->toolbar()->browser_actions(); | 43 ->toolbar()->browser_actions(); |
44 | 44 |
45 // Simulate a drag and drop to the right. | 45 // Simulate a drag and drop to the right. |
46 ui::OSExchangeData drop_data; | 46 ui::OSExchangeData drop_data; |
47 // Drag extension A from index 0... | 47 // Drag extension A from index 0... |
48 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); | 48 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); |
49 browser_action_drag_data.Write(profile(), &drop_data); | 49 browser_action_drag_data.Write(profile(), &drop_data); |
50 BrowserActionView* view = container->GetViewForExtension(extension_b()); | 50 ToolbarActionView* view = container->GetViewForExtension(extension_b()); |
51 // ...to the right of extension B. | 51 // ...to the right of extension B. |
52 gfx::Point location(view->x() + view->width(), view->y()); | 52 gfx::Point location(view->x() + view->width(), view->y()); |
53 ui::DropTargetEvent target_event( | 53 ui::DropTargetEvent target_event( |
54 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); | 54 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); |
55 | 55 |
56 // Drag and drop. | 56 // Drag and drop. |
57 container->OnDragUpdated(target_event); | 57 container->OnDragUpdated(target_event); |
58 container->OnPerformDrop(target_event); | 58 container->OnPerformDrop(target_event); |
59 | 59 |
60 // 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. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 EXPECT_EQ(extension_b()->id(), first->GetIdAt(1u)); | 246 EXPECT_EQ(extension_b()->id(), first->GetIdAt(1u)); |
247 EXPECT_EQ(extension_b()->id(), second->GetIdAt(1u)); | 247 EXPECT_EQ(extension_b()->id(), second->GetIdAt(1u)); |
248 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u)); | 248 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u)); |
249 EXPECT_EQ(extension_c()->id(), second->GetIdAt(2u)); | 249 EXPECT_EQ(extension_c()->id(), second->GetIdAt(2u)); |
250 | 250 |
251 // Simulate a drag and drop to the right. | 251 // Simulate a drag and drop to the right. |
252 ui::OSExchangeData drop_data; | 252 ui::OSExchangeData drop_data; |
253 // Drag extension A from index 0... | 253 // Drag extension A from index 0... |
254 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); | 254 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); |
255 browser_action_drag_data.Write(profile(), &drop_data); | 255 browser_action_drag_data.Write(profile(), &drop_data); |
256 BrowserActionView* view = first->GetViewForExtension(extension_b()); | 256 ToolbarActionView* view = first->GetViewForExtension(extension_b()); |
257 // ...to the right of extension B. | 257 // ...to the right of extension B. |
258 gfx::Point location(view->x() + view->width(), view->y()); | 258 gfx::Point location(view->x() + view->width(), view->y()); |
259 ui::DropTargetEvent target_event( | 259 ui::DropTargetEvent target_event( |
260 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); | 260 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); |
261 | 261 |
262 // Drag and drop. | 262 // Drag and drop. |
263 first->OnDragUpdated(target_event); | 263 first->OnDragUpdated(target_event); |
264 first->OnPerformDrop(target_event); | 264 first->OnPerformDrop(target_event); |
265 | 265 |
266 // The new order, B A C, should be reflected in *both* containers, even | 266 // The new order, B A C, should be reflected in *both* containers, even |
(...skipping 22 matching lines...) Expand all Loading... |
289 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); | 289 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); |
290 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); | 290 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); |
291 | 291 |
292 BrowserActionsContainer* container = browser() | 292 BrowserActionsContainer* container = browser() |
293 ->window() | 293 ->window() |
294 ->GetBrowserWindowTesting() | 294 ->GetBrowserWindowTesting() |
295 ->GetToolbarView() | 295 ->GetToolbarView() |
296 ->browser_actions(); | 296 ->browser_actions(); |
297 | 297 |
298 // Currently, dragging should be enabled. | 298 // Currently, dragging should be enabled. |
299 BrowserActionView* action_view = container->GetBrowserActionViewAt(0); | 299 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0); |
300 ASSERT_TRUE(action_view); | 300 ASSERT_TRUE(action_view); |
301 gfx::Point point(action_view->x(), action_view->y()); | 301 gfx::Point point(action_view->x(), action_view->y()); |
302 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); | 302 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); |
303 | 303 |
304 extensions::ExtensionToolbarModel* model = | 304 extensions::ExtensionToolbarModel* model = |
305 extensions::ExtensionToolbarModel::Get(profile()); | 305 extensions::ExtensionToolbarModel::Get(profile()); |
306 | 306 |
307 extensions::ExtensionIdList extension_ids; | 307 extensions::ExtensionIdList extension_ids; |
308 extension_ids.push_back(extension_a()->id()); | 308 extension_ids.push_back(extension_a()->id()); |
309 extension_ids.push_back(extension_b()->id()); | 309 extension_ids.push_back(extension_b()->id()); |
310 model->HighlightExtensions(extension_ids); | 310 model->HighlightExtensions(extension_ids); |
311 | 311 |
312 // Only two browser actions should be visible. | 312 // Only two browser actions should be visible. |
313 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); | 313 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); |
314 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); | 314 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); |
315 | 315 |
316 // We shouldn't be able to drag in highlight mode. | 316 // We shouldn't be able to drag in highlight mode. |
317 action_view = container->GetBrowserActionViewAt(0); | 317 action_view = container->GetToolbarActionViewAt(0); |
318 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); | 318 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); |
319 | 319 |
320 // We should go back to normal after leaving highlight mode. | 320 // We should go back to normal after leaving highlight mode. |
321 model->StopHighlighting(); | 321 model->StopHighlighting(); |
322 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); | 322 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); |
323 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); | 323 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); |
324 action_view = container->GetBrowserActionViewAt(0); | 324 action_view = container->GetToolbarActionViewAt(0); |
325 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); | 325 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); |
326 } | 326 } |
327 | 327 |
328 // Test the behavior of the overflow container for Extension Actions. | 328 // Test the behavior of the overflow container for Extension Actions. |
329 class BrowserActionsContainerOverflowTest | 329 class BrowserActionsContainerOverflowTest |
330 : public BrowserActionsBarBrowserTest { | 330 : public BrowserActionsBarBrowserTest { |
331 public: | 331 public: |
332 BrowserActionsContainerOverflowTest() : main_bar_(NULL), model_(NULL) { | 332 BrowserActionsContainerOverflowTest() : main_bar_(NULL), model_(NULL) { |
333 } | 333 } |
334 virtual ~BrowserActionsContainerOverflowTest() { | 334 virtual ~BrowserActionsContainerOverflowTest() { |
335 } | 335 } |
336 | 336 |
337 protected: | 337 protected: |
338 // Returns true if the order of the BrowserActionViews in |main_bar_| | 338 // Returns true if the order of the ToolbarActionViews in |main_bar_| |
339 // and |overflow_bar_| match. | 339 // and |overflow_bar_| match. |
340 bool ViewOrdersMatch(); | 340 bool ViewOrdersMatch(); |
341 | 341 |
342 // Returns Success if the visible count matches |expected_visible|. This means | 342 // Returns Success if the visible count matches |expected_visible|. This means |
343 // that the number of visible browser actions in |main_bar_| is | 343 // that the number of visible browser actions in |main_bar_| is |
344 // |expected_visible| and shows the first icons, and that the overflow bar | 344 // |expected_visible| and shows the first icons, and that the overflow bar |
345 // shows all (and only) the remainder. | 345 // shows all (and only) the remainder. |
346 testing::AssertionResult VerifyVisibleCount(size_t expected_visible); | 346 testing::AssertionResult VerifyVisibleCount(size_t expected_visible); |
347 | 347 |
348 // Accessors. | 348 // Accessors. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 model_ = extensions::ExtensionToolbarModel::Get(profile()); | 388 model_ = extensions::ExtensionToolbarModel::Get(profile()); |
389 } | 389 } |
390 | 390 |
391 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() { | 391 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() { |
392 overflow_bar_.reset(); | 392 overflow_bar_.reset(); |
393 enable_redesign_.reset(); | 393 enable_redesign_.reset(); |
394 BrowserActionsBarBrowserTest::TearDownOnMainThread(); | 394 BrowserActionsBarBrowserTest::TearDownOnMainThread(); |
395 } | 395 } |
396 | 396 |
397 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() { | 397 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() { |
398 if (main_bar_->num_browser_actions() != | 398 if (main_bar_->num_toolbar_actions() != |
399 overflow_bar_->num_browser_actions()) | 399 overflow_bar_->num_toolbar_actions()) |
400 return false; | 400 return false; |
401 for (size_t i = 0; i < main_bar_->num_browser_actions(); ++i) { | 401 for (size_t i = 0; i < main_bar_->num_toolbar_actions(); ++i) { |
402 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i)) | 402 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i)) |
403 return false; | 403 return false; |
404 } | 404 } |
405 return true; | 405 return true; |
406 } | 406 } |
407 | 407 |
408 testing::AssertionResult | 408 testing::AssertionResult |
409 BrowserActionsContainerOverflowTest::VerifyVisibleCount( | 409 BrowserActionsContainerOverflowTest::VerifyVisibleCount( |
410 size_t expected_visible) { | 410 size_t expected_visible) { |
411 // Views order should always match (as it is based directly off the model). | 411 // Views order should always match (as it is based directly off the model). |
412 if (!ViewOrdersMatch()) | 412 if (!ViewOrdersMatch()) |
413 return testing::AssertionFailure() << "View orders don't match"; | 413 return testing::AssertionFailure() << "View orders don't match"; |
414 | 414 |
415 // Loop through and check each browser action for proper visibility (which | 415 // Loop through and check each browser action for proper visibility (which |
416 // implicitly also guarantees that the proper number are visible). | 416 // implicitly also guarantees that the proper number are visible). |
417 for (size_t i = 0; i < overflow_bar_->num_browser_actions(); ++i) { | 417 for (size_t i = 0; i < overflow_bar_->num_toolbar_actions(); ++i) { |
418 bool visible = i < expected_visible; | 418 bool visible = i < expected_visible; |
419 if (main_bar_->GetBrowserActionViewAt(i)->visible() != visible) { | 419 if (main_bar_->GetToolbarActionViewAt(i)->visible() != visible) { |
420 return testing::AssertionFailure() << "Index " << i << | 420 return testing::AssertionFailure() << "Index " << i << |
421 " has improper visibility in main: " << !visible; | 421 " has improper visibility in main: " << !visible; |
422 } | 422 } |
423 if (overflow_bar_->GetBrowserActionViewAt(i)->visible() == visible) { | 423 if (overflow_bar_->GetToolbarActionViewAt(i)->visible() == visible) { |
424 return testing::AssertionFailure() << "Index " << i << | 424 return testing::AssertionFailure() << "Index " << i << |
425 " has improper visibility in overflow: " << visible; | 425 " has improper visibility in overflow: " << visible; |
426 } | 426 } |
427 } | 427 } |
428 return testing::AssertionSuccess(); | 428 return testing::AssertionSuccess(); |
429 } | 429 } |
430 | 430 |
431 // Test the basic functionality of the BrowserActionsContainer in overflow mode. | 431 // Test the basic functionality of the BrowserActionsContainer in overflow mode. |
432 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, | 432 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, |
433 TestBasicActionOverflow) { | 433 TestBasicActionOverflow) { |
434 LoadExtensions(); | 434 LoadExtensions(); |
435 | 435 |
436 // Since the overflow bar isn't attached to a view, we have to kick it in | 436 // Since the overflow bar isn't attached to a view, we have to kick it in |
437 // order to retrigger layout each time we change the number of icons in the | 437 // order to retrigger layout each time we change the number of icons in the |
438 // bar. | 438 // bar. |
439 overflow_bar()->Layout(); | 439 overflow_bar()->Layout(); |
440 | 440 |
441 // All actions are showing, and are in the installation order. | 441 // All actions are showing, and are in the installation order. |
442 EXPECT_EQ(-1, model()->GetVisibleIconCount()); | 442 EXPECT_EQ(-1, model()->GetVisibleIconCount()); |
443 ASSERT_EQ(3u, main_bar()->num_browser_actions()); | 443 ASSERT_EQ(3u, main_bar()->num_toolbar_actions()); |
444 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 444 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
445 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); | 445 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
446 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); | 446 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
447 EXPECT_TRUE(VerifyVisibleCount(3u)); | 447 EXPECT_TRUE(VerifyVisibleCount(3u)); |
448 | 448 |
449 // Reduce the visible count to 2. Order should be unchanged (A B C), but | 449 // Reduce the visible count to 2. Order should be unchanged (A B C), but |
450 // only A and B should be visible on the main bar. | 450 // only A and B should be visible on the main bar. |
451 model()->SetVisibleIconCount(2u); | 451 model()->SetVisibleIconCount(2u); |
452 overflow_bar()->Layout(); // Kick. | 452 overflow_bar()->Layout(); // Kick. |
453 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 453 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
(...skipping 27 matching lines...) Expand all Loading... |
481 // Test drag and drop between the overflow container and the main container. | 481 // Test drag and drop between the overflow container and the main container. |
482 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, | 482 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, |
483 TestOverflowDragging) { | 483 TestOverflowDragging) { |
484 LoadExtensions(); | 484 LoadExtensions(); |
485 | 485 |
486 // Start with one extension in overflow. | 486 // Start with one extension in overflow. |
487 model()->SetVisibleIconCount(2u); | 487 model()->SetVisibleIconCount(2u); |
488 overflow_bar()->Layout(); | 488 overflow_bar()->Layout(); |
489 | 489 |
490 // Verify starting state is A B [C]. | 490 // Verify starting state is A B [C]. |
491 ASSERT_EQ(3u, main_bar()->num_browser_actions()); | 491 ASSERT_EQ(3u, main_bar()->num_toolbar_actions()); |
492 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 492 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
493 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); | 493 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
494 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); | 494 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
495 EXPECT_TRUE(VerifyVisibleCount(2u)); | 495 EXPECT_TRUE(VerifyVisibleCount(2u)); |
496 | 496 |
497 // Drag extension A (on the main bar) to the left of extension C (in | 497 // Drag extension A (on the main bar) to the left of extension C (in |
498 // overflow). | 498 // overflow). |
499 ui::OSExchangeData drop_data; | 499 ui::OSExchangeData drop_data; |
500 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); | 500 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); |
501 browser_action_drag_data.Write(profile(), &drop_data); | 501 browser_action_drag_data.Write(profile(), &drop_data); |
502 BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c()); | 502 ToolbarActionView* view = overflow_bar()->GetViewForExtension(extension_c()); |
503 gfx::Point location(view->x(), view->y()); | 503 gfx::Point location(view->x(), view->y()); |
504 ui::DropTargetEvent target_event( | 504 ui::DropTargetEvent target_event( |
505 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); | 505 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); |
506 | 506 |
507 overflow_bar()->OnDragUpdated(target_event); | 507 overflow_bar()->OnDragUpdated(target_event); |
508 overflow_bar()->OnPerformDrop(target_event); | 508 overflow_bar()->OnPerformDrop(target_event); |
509 overflow_bar()->Layout(); | 509 overflow_bar()->Layout(); |
510 | 510 |
511 // Order should now be B [A C]. | 511 // Order should now be B [A C]. |
512 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u)); | 512 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u)); |
(...skipping 29 matching lines...) Expand all Loading... |
542 | 542 |
543 main_bar()->OnDragUpdated(target_event3); | 543 main_bar()->OnDragUpdated(target_event3); |
544 main_bar()->OnPerformDrop(target_event3); | 544 main_bar()->OnPerformDrop(target_event3); |
545 | 545 |
546 // Order should be A C B, and there should be no extensions in overflow. | 546 // Order should be A C B, and there should be no extensions in overflow. |
547 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); | 547 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
548 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); | 548 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); |
549 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); | 549 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
550 VerifyVisibleCount(3u); | 550 VerifyVisibleCount(3u); |
551 } | 551 } |
OLD | NEW |