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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc

Issue 1004063003: [Extensions] Add logic for when to show the toolbar redesign bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +Test Created 5 years, 9 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 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
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 PrefService* prefs = profile()->GetPrefs();
406 // ToolbarActionsBar::RegisterPrefs(prefs);
battre 2015/03/19 09:28:45 indenting / should this be commented out?
Devlin 2015/03/19 16:28:08 Done.
407 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble());
408 EXPECT_TRUE(
409 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged));
410
411 // Clear the pref for testing, and add an extension that wouldn't normally
412 // have an icon. We should now show the bubble.
413 prefs->ClearPref(prefs::kToolbarIconSurfacingBubbleAcknowledged);
414 CreateAndAddExtension("extension",
415 extensions::extension_action_test_util::NO_ACTION);
416 EXPECT_TRUE(toolbar_actions_bar()->ShouldShowInfoBubble());
417
418 // If the bubble was recently shown, we shouldn't show it again...
419 ToolbarActionsBarBubbleDelegate* bubble_delegate =
420 static_cast<ToolbarActionsBarBubbleDelegate*>(toolbar_actions_bar());
421 bubble_delegate->OnToolbarActionsBarBubbleShown();
422 bubble_delegate->OnToolbarActionsBarBubbleClosed(
423 ToolbarActionsBarBubbleDelegate::DISMISSED);
424 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble());
425
426 // ...But if it was only dismissed, we should show it before too long.
427 base::Time two_days_ago = base::Time::Now() - base::TimeDelta::FromDays(2);
428 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime,
429 two_days_ago.ToInternalValue());
430 EXPECT_TRUE(toolbar_actions_bar()->ShouldShowInfoBubble());
431
432 // If it's acknowledged, then it should never show again, and should be
433 // recorded as acknowledged.
434 bubble_delegate->OnToolbarActionsBarBubbleShown();
435 bubble_delegate->OnToolbarActionsBarBubbleClosed(
436 ToolbarActionsBarBubbleDelegate::ACKNOWLEDGED);
437 EXPECT_FALSE(toolbar_actions_bar()->ShouldShowInfoBubble());
438 base::Time one_week_ago = base::Time::Now() - base::TimeDelta::FromDays(7);
439 prefs->SetInt64(prefs::kToolbarIconSurfacingBubbleLastShowTime,
440 one_week_ago.ToInternalValue());
441 EXPECT_TRUE(
442 prefs->GetBoolean(prefs::kToolbarIconSurfacingBubbleAcknowledged));
443 }
444
392 class ToolbarActionsBarPopOutUnitTest 445 class ToolbarActionsBarPopOutUnitTest
393 : public ToolbarActionsBarUnitTest { 446 : public ToolbarActionsBarRedesignUnitTest {
394 public: 447 public:
395 ToolbarActionsBarPopOutUnitTest() : ToolbarActionsBarUnitTest(true) {} 448 ToolbarActionsBarPopOutUnitTest() {}
396 449
397 protected: 450 protected:
398 void SetUp() override { 451 void SetUp() override {
399 ToolbarActionsBar::set_pop_out_actions_to_run_for_testing(true); 452 ToolbarActionsBar::set_pop_out_actions_to_run_for_testing(true);
400 ToolbarActionsBarUnitTest::SetUp(); 453 ToolbarActionsBarUnitTest::SetUp();
401 } 454 }
402 455
403 private: 456 private:
404 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarPopOutUnitTest); 457 DISALLOW_COPY_AND_ASSIGN(ToolbarActionsBarPopOutUnitTest);
405 }; 458 };
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 EXPECT_TRUE(VerifyToolbarOrder(expected_names, 3u, 3u)); 734 EXPECT_TRUE(VerifyToolbarOrder(expected_names, 3u, 3u));
682 // Move "page action" to the overflow menu. 735 // Move "page action" to the overflow menu.
683 toolbar_actions_bar()->OnDragDrop( 736 toolbar_actions_bar()->OnDragDrop(
684 0, 2, ToolbarActionsBar::DRAG_TO_OVERFLOW); 737 0, 2, ToolbarActionsBar::DRAG_TO_OVERFLOW);
685 const char* expected_names2[] = { kBrowserAction, kSynthetic, kPageAction }; 738 const char* expected_names2[] = { kBrowserAction, kSynthetic, kPageAction };
686 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); 739 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u));
687 SetActionWantsToRunOnTab(action, web_contents, false); 740 SetActionWantsToRunOnTab(action, web_contents, false);
688 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u)); 741 EXPECT_TRUE(VerifyToolbarOrder(expected_names2, 3u, 2u));
689 } 742 }
690 } 743 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698