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" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 Browser* second_browser = new Browser( | 234 Browser* second_browser = new Browser( |
235 Browser::CreateParams(profile(), browser()->host_desktop_type())); | 235 Browser::CreateParams(profile(), browser()->host_desktop_type())); |
236 BrowserActionsContainer* second = | 236 BrowserActionsContainer* second = |
237 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar()-> | 237 BrowserView::GetBrowserViewForBrowser(second_browser)->toolbar()-> |
238 browser_actions(); | 238 browser_actions(); |
239 | 239 |
240 // Both containers should have the same order and visible actions, which | 240 // Both containers should have the same order and visible actions, which |
241 // is right now A B C. | 241 // is right now A B C. |
242 EXPECT_EQ(3u, first->VisibleBrowserActions()); | 242 EXPECT_EQ(3u, first->VisibleBrowserActions()); |
243 EXPECT_EQ(3u, second->VisibleBrowserActions()); | 243 EXPECT_EQ(3u, second->VisibleBrowserActions()); |
244 EXPECT_EQ(extension_a(), first->GetBrowserActionViewAt(0u)->extension()); | 244 EXPECT_EQ(extension_a()->id(), first->GetIdAt(0u)); |
245 EXPECT_EQ(extension_a(), second->GetBrowserActionViewAt(0u)->extension()); | 245 EXPECT_EQ(extension_a()->id(), second->GetIdAt(0u)); |
246 EXPECT_EQ(extension_b(), first->GetBrowserActionViewAt(1u)->extension()); | 246 EXPECT_EQ(extension_b()->id(), first->GetIdAt(1u)); |
247 EXPECT_EQ(extension_b(), second->GetBrowserActionViewAt(1u)->extension()); | 247 EXPECT_EQ(extension_b()->id(), second->GetIdAt(1u)); |
248 EXPECT_EQ(extension_c(), first->GetBrowserActionViewAt(2u)->extension()); | 248 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u)); |
249 EXPECT_EQ(extension_c(), second->GetBrowserActionViewAt(2u)->extension()); | 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 BrowserActionView* 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 |
267 // though the drag only happened in the first one. | 267 // though the drag only happened in the first one. |
268 EXPECT_EQ(extension_b(), first->GetBrowserActionViewAt(0u)->extension()); | 268 EXPECT_EQ(extension_b()->id(), first->GetIdAt(0u)); |
269 EXPECT_EQ(extension_b(), second->GetBrowserActionViewAt(0u)->extension()); | 269 EXPECT_EQ(extension_b()->id(), second->GetIdAt(0u)); |
270 EXPECT_EQ(extension_a(), first->GetBrowserActionViewAt(1u)->extension()); | 270 EXPECT_EQ(extension_a()->id(), first->GetIdAt(1u)); |
271 EXPECT_EQ(extension_a(), second->GetBrowserActionViewAt(1u)->extension()); | 271 EXPECT_EQ(extension_a()->id(), second->GetIdAt(1u)); |
272 EXPECT_EQ(extension_c(), first->GetBrowserActionViewAt(2u)->extension()); | 272 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u)); |
273 EXPECT_EQ(extension_c(), second->GetBrowserActionViewAt(2u)->extension()); | 273 EXPECT_EQ(extension_c()->id(), second->GetIdAt(2u)); |
274 | 274 |
275 // Next, simulate a resize by shrinking the container. | 275 // Next, simulate a resize by shrinking the container. |
276 first->OnResize(1, true); | 276 first->OnResize(1, true); |
277 // The first and second container should each have resized. | 277 // The first and second container should each have resized. |
278 EXPECT_EQ(2u, first->VisibleBrowserActions()); | 278 EXPECT_EQ(2u, first->VisibleBrowserActions()); |
279 EXPECT_EQ(2u, second->VisibleBrowserActions()); | 279 EXPECT_EQ(2u, second->VisibleBrowserActions()); |
280 } | 280 } |
281 | 281 |
282 // Test that the BrowserActionsContainer responds correctly when the underlying | 282 // Test that the BrowserActionsContainer responds correctly when the underlying |
283 // model enters highlight mode, and that browser actions are undraggable in | 283 // model enters highlight mode, and that browser actions are undraggable in |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_browser_actions() != |
399 overflow_bar_->num_browser_actions()) | 399 overflow_bar_->num_browser_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_browser_actions(); ++i) { |
402 if (main_bar_->GetBrowserActionViewAt(i)->extension() != | 402 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i)) |
403 overflow_bar_->GetBrowserActionViewAt(i)->extension()) | |
404 return false; | 403 return false; |
405 } | 404 } |
406 return true; | 405 return true; |
407 } | 406 } |
408 | 407 |
409 testing::AssertionResult | 408 testing::AssertionResult |
410 BrowserActionsContainerOverflowTest::VerifyVisibleCount( | 409 BrowserActionsContainerOverflowTest::VerifyVisibleCount( |
411 size_t expected_visible) { | 410 size_t expected_visible) { |
412 // 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). |
413 if (!ViewOrdersMatch()) | 412 if (!ViewOrdersMatch()) |
(...skipping 21 matching lines...) Expand all Loading... |
435 LoadExtensions(); | 434 LoadExtensions(); |
436 | 435 |
437 // 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 |
438 // 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 |
439 // bar. | 438 // bar. |
440 overflow_bar()->Layout(); | 439 overflow_bar()->Layout(); |
441 | 440 |
442 // All actions are showing, and are in the installation order. | 441 // All actions are showing, and are in the installation order. |
443 EXPECT_EQ(-1, model()->GetVisibleIconCount()); | 442 EXPECT_EQ(-1, model()->GetVisibleIconCount()); |
444 ASSERT_EQ(3u, main_bar()->num_browser_actions()); | 443 ASSERT_EQ(3u, main_bar()->num_browser_actions()); |
445 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 444 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
446 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 445 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
447 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 446 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
448 EXPECT_TRUE(VerifyVisibleCount(3u)); | 447 EXPECT_TRUE(VerifyVisibleCount(3u)); |
449 | 448 |
450 // 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 |
451 // only A and B should be visible on the main bar. | 450 // only A and B should be visible on the main bar. |
452 model()->SetVisibleIconCount(2u); | 451 model()->SetVisibleIconCount(2u); |
453 overflow_bar()->Layout(); // Kick. | 452 overflow_bar()->Layout(); // Kick. |
454 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 453 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
455 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 454 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
456 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 455 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
457 EXPECT_TRUE(VerifyVisibleCount(2u)); | 456 EXPECT_TRUE(VerifyVisibleCount(2u)); |
458 | 457 |
459 // Move extension C to the first position. Order should now be C A B, with | 458 // Move extension C to the first position. Order should now be C A B, with |
460 // C and A visible in the main bar. | 459 // C and A visible in the main bar. |
461 model()->MoveExtensionIcon(extension_c(), 0); | 460 model()->MoveExtensionIcon(extension_c()->id(), 0); |
462 overflow_bar()->Layout(); // Kick. | 461 overflow_bar()->Layout(); // Kick. |
463 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 462 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u)); |
464 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 463 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); |
465 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 464 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
466 EXPECT_TRUE(VerifyVisibleCount(2u)); | 465 EXPECT_TRUE(VerifyVisibleCount(2u)); |
467 | 466 |
468 // Hide action A. This results in it being sent to overflow, and reducing the | 467 // Hide action A. This results in it being sent to overflow, and reducing the |
469 // visible size to 1, so the order should be C A B, with only C visible in the | 468 // visible size to 1, so the order should be C A B, with only C visible in the |
470 // main bar. | 469 // main bar. |
471 extensions::ExtensionActionAPI::SetBrowserActionVisibility( | 470 extensions::ExtensionActionAPI::SetBrowserActionVisibility( |
472 extensions::ExtensionPrefs::Get(profile()), | 471 extensions::ExtensionPrefs::Get(profile()), |
473 extension_a()->id(), | 472 extension_a()->id(), |
474 false); | 473 false); |
475 overflow_bar()->Layout(); // Kick. | 474 overflow_bar()->Layout(); // Kick. |
476 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 475 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(0u)); |
477 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 476 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); |
478 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 477 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
479 EXPECT_TRUE(VerifyVisibleCount(1u)); | 478 EXPECT_TRUE(VerifyVisibleCount(1u)); |
480 } | 479 } |
481 | 480 |
482 // 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. |
483 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, | 482 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, |
484 TestOverflowDragging) { | 483 TestOverflowDragging) { |
485 LoadExtensions(); | 484 LoadExtensions(); |
486 | 485 |
487 // Start with one extension in overflow. | 486 // Start with one extension in overflow. |
488 model()->SetVisibleIconCount(2u); | 487 model()->SetVisibleIconCount(2u); |
489 overflow_bar()->Layout(); | 488 overflow_bar()->Layout(); |
490 | 489 |
491 // Verify starting state is A B [C]. | 490 // Verify starting state is A B [C]. |
492 ASSERT_EQ(3u, main_bar()->num_browser_actions()); | 491 ASSERT_EQ(3u, main_bar()->num_browser_actions()); |
493 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 492 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
494 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 493 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
495 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 494 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
496 EXPECT_TRUE(VerifyVisibleCount(2u)); | 495 EXPECT_TRUE(VerifyVisibleCount(2u)); |
497 | 496 |
498 // 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 |
499 // overflow). | 498 // overflow). |
500 ui::OSExchangeData drop_data; | 499 ui::OSExchangeData drop_data; |
501 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); | 500 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); |
502 browser_action_drag_data.Write(profile(), &drop_data); | 501 browser_action_drag_data.Write(profile(), &drop_data); |
503 BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c()); | 502 BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c()); |
504 gfx::Point location(view->x(), view->y()); | 503 gfx::Point location(view->x(), view->y()); |
505 ui::DropTargetEvent target_event( | 504 ui::DropTargetEvent target_event( |
506 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); | 505 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); |
507 | 506 |
508 overflow_bar()->OnDragUpdated(target_event); | 507 overflow_bar()->OnDragUpdated(target_event); |
509 overflow_bar()->OnPerformDrop(target_event); | 508 overflow_bar()->OnPerformDrop(target_event); |
510 overflow_bar()->Layout(); | 509 overflow_bar()->Layout(); |
511 | 510 |
512 // Order should now be B [A C]. | 511 // Order should now be B [A C]. |
513 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 512 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u)); |
514 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 513 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); |
515 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 514 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
516 VerifyVisibleCount(1u); | 515 VerifyVisibleCount(1u); |
517 | 516 |
518 // Drag extension A back from overflow to the main bar. | 517 // Drag extension A back from overflow to the main bar. |
519 ui::OSExchangeData drop_data2; | 518 ui::OSExchangeData drop_data2; |
520 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); | 519 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); |
521 browser_action_drag_data2.Write(profile(), &drop_data2); | 520 browser_action_drag_data2.Write(profile(), &drop_data2); |
522 view = main_bar()->GetViewForExtension(extension_b()); | 521 view = main_bar()->GetViewForExtension(extension_b()); |
523 location = gfx::Point(view->x(), view->y()); | 522 location = gfx::Point(view->x(), view->y()); |
524 ui::DropTargetEvent target_event2( | 523 ui::DropTargetEvent target_event2( |
525 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); | 524 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); |
526 | 525 |
527 main_bar()->OnDragUpdated(target_event2); | 526 main_bar()->OnDragUpdated(target_event2); |
528 main_bar()->OnPerformDrop(target_event2); | 527 main_bar()->OnPerformDrop(target_event2); |
529 | 528 |
530 // Order should be A B [C] again. | 529 // Order should be A B [C] again. |
531 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 530 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
532 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 531 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); |
533 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 532 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); |
534 VerifyVisibleCount(2u); | 533 VerifyVisibleCount(2u); |
535 | 534 |
536 // Drag extension C from overflow to the main bar (before extension B). | 535 // Drag extension C from overflow to the main bar (before extension B). |
537 ui::OSExchangeData drop_data3; | 536 ui::OSExchangeData drop_data3; |
538 BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u); | 537 BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u); |
539 browser_action_drag_data3.Write(profile(), &drop_data3); | 538 browser_action_drag_data3.Write(profile(), &drop_data3); |
540 location = gfx::Point(view->x(), view->y()); | 539 location = gfx::Point(view->x(), view->y()); |
541 ui::DropTargetEvent target_event3( | 540 ui::DropTargetEvent target_event3( |
542 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE); | 541 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE); |
543 | 542 |
544 main_bar()->OnDragUpdated(target_event3); | 543 main_bar()->OnDragUpdated(target_event3); |
545 main_bar()->OnPerformDrop(target_event3); | 544 main_bar()->OnPerformDrop(target_event3); |
546 | 545 |
547 // 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. |
548 EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); | 547 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); |
549 EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(1)->extension()); | 548 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); |
550 EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); | 549 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); |
551 VerifyVisibleCount(3u); | 550 VerifyVisibleCount(3u); |
552 } | 551 } |
OLD | NEW |