| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/toolbar/toolbar_actions_bar.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 12 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 13 #include "chrome/browser/extensions/browser_action_test_util.h" | 13 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 14 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_action_test_util.h" | 16 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/test_extension_system.h" | 18 #include "chrome/browser/extensions/test_extension_system.h" |
| 19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
| 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 21 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h" | 21 #include "chrome/browser/ui/toolbar/test_toolbar_actions_bar_helper.h" |
| 22 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h" |
| 24 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/browser_with_test_window_test.h" | 25 #include "chrome/test/base/browser_with_test_window_test.h" |
| 25 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 26 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/feature_switch.h" | 28 #include "extensions/common/feature_switch.h" |
| 28 | 29 |
| 29 namespace { | 30 namespace { |
| 30 | 31 |
| 31 // Verifies that the toolbar order matches for the given |actions_bar|. If the | 32 // Verifies that the toolbar order matches for the given |actions_bar|. If the |
| 32 // order matches, the return value is empty; otherwise, it contains the error. | 33 // order matches, the return value is empty; otherwise, it contains the error. |
| 33 std::string VerifyToolbarOrderForBar( | 34 std::string VerifyToolbarOrderForBar( |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); | 383 EXPECT_EQ(2u, toolbar_actions_bar()->GetIconCount()); |
| 383 | 384 |
| 384 // If we shrink the bar so that a full icon can't fit, it should resize to | 385 // If we shrink the bar so that a full icon can't fit, it should resize to |
| 385 // hide that icon. | 386 // hide that icon. |
| 386 toolbar_actions_bar()->OnResizeComplete(width - 1); | 387 toolbar_actions_bar()->OnResizeComplete(width - 1); |
| 387 width -= ToolbarActionsBar::IconWidth(true); | 388 width -= ToolbarActionsBar::IconWidth(true); |
| 388 EXPECT_EQ(width, toolbar_actions_bar()->GetPreferredSize().width()); | 389 EXPECT_EQ(width, toolbar_actions_bar()->GetPreferredSize().width()); |
| 389 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); | 390 EXPECT_EQ(1u, toolbar_actions_bar()->GetIconCount()); |
| 390 } | 391 } |
| 391 | 392 |
| 393 class ToolbarActionsBarRedesignUnitTest : public ToolbarActionsBarUnitTest { |
| 394 public: |
| 395 ToolbarActionsBarRedesignUnitTest() : ToolbarActionsBarUnitTest(true) {} |
| 396 ~ToolbarActionsBarRedesignUnitTest() override {} |
| 397 |
| 398 private: |
| 399 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarRedesignUnitTest); |
| 400 }; |
| 401 |
| 402 TEST_F(ToolbarActionsBarRedesignUnitTest, IconSurfacingBubbleAppearance) { |
| 403 // Without showing anything new, we shouldn't show the bubble, and should |
| 404 // auto-acknowledge it. |
| 405 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble()); |
| 406 PrefService* prefs = profile()->GetPrefs(); |
| 407 EXPECT_TRUE( |
| 408 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged)); |
| 409 |
| 410 // Clear the pref for testing, and add an extension that wouldn't normally |
| 411 // have an icon. We should now show the bubble. |
| 412 prefs->ClearPref(prefs::kToolbarIconSurfacingBubbleAcknowledged); |
| 413 CreateAndAddExtension("extension", |
| 414 extensions::extension_action_test_util::NO_ACTION); |
| 415 EXPECT_TRUE(toolbar_actions_bar()->ShouldShowInfoBubble()); |
| 416 |
| 417 // If the bubble was recently shown, we shouldn't show it again... |
| 418 ToolbarActionsBarBubbleDelegate* bubble_delegate = |
| 419 static_cast<ToolbarActionsBarBubbleDelegate*>(toolbar_actions_bar()); |
| 420 bubble_delegate->OnToolbarActionsBarBubbleShown(); |
| 421 bubble_delegate->OnToolbarActionsBarBubbleClosed( |
| 422 ToolbarActionsBarBubbleDelegate::DISMISSED); |
| 423 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble()); |
| 424 |
| 425 // ...But if it was only dismissed, we should show it before too long. |
| 426 base::Time two_days_ago = base::Time::Now() - base::TimeDelta::FromDays(2); |
| 427 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| 428 two_days_ago.ToInternalValue()); |
| 429 EXPECT_TRUE(toolbar_actions_bar()->ShouldShowInfoBubble()); |
| 430 |
| 431 // If it's acknowledged, then it should never show again, and should be |
| 432 // recorded as acknowledged. |
| 433 bubble_delegate->OnToolbarActionsBarBubbleShown(); |
| 434 bubble_delegate->OnToolbarActionsBarBubbleClosed( |
| 435 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED); |
| 436 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble()); |
| 437 base::Time one_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7); |
| 438 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime, |
| 439 one_week_ago.ToInternalValue()); |
| 440 EXPECT_TRUE( |
| 441 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged)); |
| 442 } |
| 443 |
| 392 class ToolbarActionsBarPopOutUnitTest | 444 class ToolbarActionsBarPopOutUnitTest |
| 393 : public ToolbarActionsBarUnitTest { | 445 : public ToolbarActionsBarRedesignUnitTest { |
| 394 public: | 446 public: |
| 395 ToolbarActionsBarPopOutUnitTest() : ToolbarActionsBarUnitTest(true) {} | 447 ToolbarActionsBarPopOutUnitTest() {} |
| 396 | 448 |
| 397 protected: | 449 protected: |
| 398 void SetUp() override { | 450 void SetUp() override { |
| 399 ToolbarActionsBar::set_pop_out_actions_to_run_for_testing(true); | 451 ToolbarActionsBar::set_pop_out_actions_to_run_for_testing(true); |
| 400 ToolbarActionsBarUnitTest::SetUp(); | 452 ToolbarActionsBarUnitTest::SetUp(); |
| 401 } | 453 } |
| 402 | 454 |
| 403 private: | 455 private: |
| 404 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarPopOutUnitTest); | 456 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarPopOutUnitTest); |
| 405 }; | 457 }; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 EXPECT_TRUE(VerifyToolbarOrder(expected_names, 3u, 3u)); | 733 EXPECT_TRUE(VerifyToolbarOrder(expected_names, 3u, 3u)); |
| 682 // Move "page action" to the overflow menu. | 734 // Move "page action" to the overflow menu. |
| 683 toolbar_actions_bar()->OnDragDrop( | 735 toolbar_actions_bar()->OnDragDrop( |
| 684 0, 2, ToolbarActionsBar::DRAG_TO_OVERFLOW); | 736 0, 2, ToolbarActionsBar::DRAG_TO_OVERFLOW); |
| 685 const char* expected_names2[] = { kBrowserAction, kSynthetic, kPageAction }; | 737 const char* expected_names2[] = { kBrowserAction, kSynthetic, kPageAction }; |
| 686 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); | 738 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); |
| 687 SetActionWantsToRunOnTab(action, web_contents, false); | 739 SetActionWantsToRunOnTab(action, web_contents, false); |
| 688 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); | 740 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); |
| 689 } | 741 } |
| 690 } | 742 } |
| OLD | NEW |