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

Side by Side Diff: chrome/browser/extensions/extension_message_bubble_controller_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "build/build_config.h" 17 #include "build/build_config.h"
17 #include "chrome/browser/extensions/dev_mode_bubble_delegate.h" 18 #include "chrome/browser/extensions/dev_mode_bubble_delegate.h"
18 #include "chrome/browser/extensions/extension_function_test_utils.h" 19 #include "chrome/browser/extensions/extension_function_test_utils.h"
19 #include "chrome/browser/extensions/extension_service.h" 20 #include "chrome/browser/extensions/extension_service.h"
20 #include "chrome/browser/extensions/extension_web_ui_override_registrar.h" 21 #include "chrome/browser/extensions/extension_web_ui_override_registrar.h"
21 #include "chrome/browser/extensions/ntp_overridden_bubble_delegate.h" 22 #include "chrome/browser/extensions/ntp_overridden_bubble_delegate.h"
(...skipping 17 matching lines...) Expand all
39 #include "extensions/common/feature_switch.h" 40 #include "extensions/common/feature_switch.h"
40 #include "extensions/common/value_builder.h" 41 #include "extensions/common/value_builder.h"
41 #include "testing/gtest/include/gtest/gtest.h" 42 #include "testing/gtest/include/gtest/gtest.h"
42 43
43 namespace { 44 namespace {
44 45
45 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; 46 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk";
46 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; 47 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl";
47 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; 48 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek";
48 49
49 scoped_ptr<KeyedService> BuildOverrideRegistrar( 50 std::unique_ptr<KeyedService> BuildOverrideRegistrar(
50 content::BrowserContext* context) { 51 content::BrowserContext* context) {
51 return make_scoped_ptr( 52 return base::WrapUnique(
52 new extensions::ExtensionWebUIOverrideRegistrar(context)); 53 new extensions::ExtensionWebUIOverrideRegistrar(context));
53 } 54 }
54 55
55 } // namespace 56 } // namespace
56 57
57 namespace extensions { 58 namespace extensions {
58 59
59 class TestExtensionMessageBubbleController : 60 class TestExtensionMessageBubbleController :
60 public ExtensionMessageBubbleController { 61 public ExtensionMessageBubbleController {
61 public: 62 public:
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing( 324 ExtensionMessageBubbleController::set_should_ignore_learn_more_for_testing(
324 false); 325 false);
325 BrowserWithTestWindowTest::TearDown(); 326 BrowserWithTestWindowTest::TearDown();
326 } 327 }
327 328
328 protected: 329 protected:
329 scoped_refptr<Extension> CreateExtension( 330 scoped_refptr<Extension> CreateExtension(
330 Manifest::Location location, 331 Manifest::Location location,
331 const std::string& data, 332 const std::string& data,
332 const std::string& id) { 333 const std::string& id) {
333 scoped_ptr<base::DictionaryValue> parsed_manifest( 334 std::unique_ptr<base::DictionaryValue> parsed_manifest(
334 api_test_utils::ParseDictionary(data)); 335 api_test_utils::ParseDictionary(data));
335 return api_test_utils::CreateExtension(location, parsed_manifest.get(), id); 336 return api_test_utils::CreateExtension(location, parsed_manifest.get(), id);
336 } 337 }
337 338
338 ExtensionService* service_; 339 ExtensionService* service_;
339 340
340 private: 341 private:
341 scoped_ptr<base::CommandLine> command_line_; 342 std::unique_ptr<base::CommandLine> command_line_;
342 343
343 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleTest); 344 DISALLOW_COPY_AND_ASSIGN(ExtensionMessageBubbleTest);
344 }; 345 };
345 346
346 TEST_F(ExtensionMessageBubbleTest, BubbleReshowsOnDeactivationDismissal) { 347 TEST_F(ExtensionMessageBubbleTest, BubbleReshowsOnDeactivationDismissal) {
347 Init(); 348 Init();
348 349
349 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::INTERNAL)); 350 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::INTERNAL));
350 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::INTERNAL)); 351 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::INTERNAL));
351 scoped_ptr<TestExtensionMessageBubbleController> controller( 352 std::unique_ptr<TestExtensionMessageBubbleController> controller(
352 new TestExtensionMessageBubbleController( 353 new TestExtensionMessageBubbleController(
353 new NtpOverriddenBubbleDelegate(browser()->profile()), browser())); 354 new NtpOverriddenBubbleDelegate(browser()->profile()), browser()));
354 355
355 // The list will contain one enabled unpacked extension (ext 2). 356 // The list will contain one enabled unpacked extension (ext 2).
356 EXPECT_TRUE(controller->ShouldShow()); 357 EXPECT_TRUE(controller->ShouldShow());
357 std::vector<base::string16> override_extensions = 358 std::vector<base::string16> override_extensions =
358 controller->GetExtensionList(); 359 controller->GetExtensionList();
359 ASSERT_EQ(1U, override_extensions.size()); 360 ASSERT_EQ(1U, override_extensions.size());
360 EXPECT_EQ(base::ASCIIToUTF16("Extension 2"), override_extensions[0]); 361 EXPECT_EQ(base::ASCIIToUTF16("Extension 2"), override_extensions[0]);
361 EXPECT_EQ(0U, controller->link_click_count()); 362 EXPECT_EQ(0U, controller->link_click_count());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // The feature this is meant to test is only enacted on Windows, but it should 411 // The feature this is meant to test is only enacted on Windows, but it should
411 // pass on all platforms. 412 // pass on all platforms.
412 TEST_F(ExtensionMessageBubbleTest, WipeoutControllerTest) { 413 TEST_F(ExtensionMessageBubbleTest, WipeoutControllerTest) {
413 Init(); 414 Init();
414 // Add three extensions, and control two of them in this test (extension 1 415 // Add three extensions, and control two of them in this test (extension 1
415 // and 2). 416 // and 2).
416 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); 417 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE));
417 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); 418 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED));
418 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); 419 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY));
419 420
420 scoped_ptr<TestExtensionMessageBubbleController> controller( 421 std::unique_ptr<TestExtensionMessageBubbleController> controller(
421 new TestExtensionMessageBubbleController( 422 new TestExtensionMessageBubbleController(
422 new SuspiciousExtensionBubbleDelegate(browser()->profile()), 423 new SuspiciousExtensionBubbleDelegate(browser()->profile()),
423 browser())); 424 browser()));
424 FakeExtensionMessageBubble bubble; 425 FakeExtensionMessageBubble bubble;
425 bubble.set_action_on_show( 426 bubble.set_action_on_show(
426 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); 427 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
427 428
428 // Validate that we don't have a suppress value for the extensions. 429 // Validate that we don't have a suppress value for the extensions.
429 EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId1)); 430 EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId1));
430 EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId1)); 431 EXPECT_FALSE(controller->delegate()->HasBubbleInfoBeenAcknowledged(kId1));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 FeatureSwitch::ScopedOverride force_dev_mode_highlighting( 490 FeatureSwitch::ScopedOverride force_dev_mode_highlighting(
490 FeatureSwitch::force_dev_mode_highlighting(), true); 491 FeatureSwitch::force_dev_mode_highlighting(), true);
491 Init(); 492 Init();
492 // Add three extensions, and control two of them in this test (extension 1 493 // Add three extensions, and control two of them in this test (extension 1
493 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it 494 // and 2). Extension 1 is a regular extension, Extension 2 is UNPACKED so it
494 // counts as a DevMode extension. 495 // counts as a DevMode extension.
495 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE)); 496 ASSERT_TRUE(LoadExtensionWithAction("1", kId1, Manifest::COMMAND_LINE));
496 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED)); 497 ASSERT_TRUE(LoadGenericExtension("2", kId2, Manifest::UNPACKED));
497 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY)); 498 ASSERT_TRUE(LoadGenericExtension("3", kId3, Manifest::EXTERNAL_POLICY));
498 499
499 scoped_ptr<TestExtensionMessageBubbleController> controller( 500 std::unique_ptr<TestExtensionMessageBubbleController> controller(
500 new TestExtensionMessageBubbleController( 501 new TestExtensionMessageBubbleController(
501 new DevModeBubbleDelegate(browser()->profile()), 502 new DevModeBubbleDelegate(browser()->profile()), browser()));
502 browser()));
503 503
504 // The list will contain one enabled unpacked extension. 504 // The list will contain one enabled unpacked extension.
505 EXPECT_TRUE(controller->ShouldShow()); 505 EXPECT_TRUE(controller->ShouldShow());
506 std::vector<base::string16> dev_mode_extensions = 506 std::vector<base::string16> dev_mode_extensions =
507 controller->GetExtensionList(); 507 controller->GetExtensionList();
508 ASSERT_EQ(2U, dev_mode_extensions.size()); 508 ASSERT_EQ(2U, dev_mode_extensions.size());
509 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]); 509 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == dev_mode_extensions[0]);
510 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]); 510 EXPECT_TRUE(base::ASCIIToUTF16("Extension 1") == dev_mode_extensions[1]);
511 EXPECT_EQ(0U, controller->link_click_count()); 511 EXPECT_EQ(0U, controller->link_click_count());
512 EXPECT_EQ(0U, controller->dismiss_click_count()); 512 EXPECT_EQ(0U, controller->dismiss_click_count());
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 ASSERT_TRUE( 623 ASSERT_TRUE(
624 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED)); 624 LoadExtensionOverridingStart("2", kId2, Manifest::UNPACKED));
625 ASSERT_TRUE(LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED)); 625 ASSERT_TRUE(LoadExtensionOverridingHome("3", kId3, Manifest::UNPACKED));
626 break; 626 break;
627 default: 627 default:
628 NOTREACHED(); 628 NOTREACHED();
629 break; 629 break;
630 } 630 }
631 631
632 SettingsApiOverrideType type = static_cast<SettingsApiOverrideType>(i); 632 SettingsApiOverrideType type = static_cast<SettingsApiOverrideType>(i);
633 scoped_ptr<TestExtensionMessageBubbleController> controller( 633 std::unique_ptr<TestExtensionMessageBubbleController> controller(
634 new TestExtensionMessageBubbleController( 634 new TestExtensionMessageBubbleController(
635 new SettingsApiBubbleDelegate(browser()->profile(), type), 635 new SettingsApiBubbleDelegate(browser()->profile(), type),
636 browser())); 636 browser()));
637 637
638 // The list will contain one enabled unpacked extension (ext 2). 638 // The list will contain one enabled unpacked extension (ext 2).
639 EXPECT_TRUE(controller->ShouldShow()); 639 EXPECT_TRUE(controller->ShouldShow());
640 std::vector<base::string16> override_extensions = 640 std::vector<base::string16> override_extensions =
641 controller->GetExtensionList(); 641 controller->GetExtensionList();
642 ASSERT_EQ(1U, override_extensions.size()); 642 ASSERT_EQ(1U, override_extensions.size());
643 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == 643 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") ==
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 // pass on all platforms. 734 // pass on all platforms.
735 TEST_F(ExtensionMessageBubbleTest, NtpOverriddenControllerTest) { 735 TEST_F(ExtensionMessageBubbleTest, NtpOverriddenControllerTest) {
736 Init(); 736 Init();
737 // Load two extensions overriding new tab page and one overriding something 737 // Load two extensions overriding new tab page and one overriding something
738 // unrelated (to check for interference). Extension 2 should still win 738 // unrelated (to check for interference). Extension 2 should still win
739 // on the new tab page setting. 739 // on the new tab page setting.
740 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED)); 740 ASSERT_TRUE(LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED));
741 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED)); 741 ASSERT_TRUE(LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED));
742 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); 742 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED));
743 743
744 scoped_ptr<TestExtensionMessageBubbleController> controller( 744 std::unique_ptr<TestExtensionMessageBubbleController> controller(
745 new TestExtensionMessageBubbleController( 745 new TestExtensionMessageBubbleController(
746 new NtpOverriddenBubbleDelegate(browser()->profile()), 746 new NtpOverriddenBubbleDelegate(browser()->profile()), browser()));
747 browser()));
748 747
749 // The list will contain one enabled unpacked extension (ext 2). 748 // The list will contain one enabled unpacked extension (ext 2).
750 EXPECT_TRUE(controller->ShouldShow()); 749 EXPECT_TRUE(controller->ShouldShow());
751 std::vector<base::string16> override_extensions = 750 std::vector<base::string16> override_extensions =
752 controller->GetExtensionList(); 751 controller->GetExtensionList();
753 ASSERT_EQ(1U, override_extensions.size()); 752 ASSERT_EQ(1U, override_extensions.size());
754 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == 753 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") ==
755 override_extensions[0].c_str()); 754 override_extensions[0].c_str());
756 EXPECT_EQ(0U, controller->link_click_count()); 755 EXPECT_EQ(0U, controller->link_click_count());
757 EXPECT_EQ(0U, controller->dismiss_click_count()); 756 EXPECT_EQ(0U, controller->dismiss_click_count());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED)); 869 ASSERT_TRUE(LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED));
871 870
872 // The bubble will not show if the extension was installed in the last 7 days 871 // The bubble will not show if the extension was installed in the last 7 days
873 // so we artificially set the install time to simulate an old install during 872 // so we artificially set the install time to simulate an old install during
874 // testing. 873 // testing.
875 base::Time old_enough = base::Time::Now() - base::TimeDelta::FromDays(8); 874 base::Time old_enough = base::Time::Now() - base::TimeDelta::FromDays(8);
876 SetInstallTime(kId1, old_enough, prefs); 875 SetInstallTime(kId1, old_enough, prefs);
877 SetInstallTime(kId2, base::Time::Now(), prefs); 876 SetInstallTime(kId2, base::Time::Now(), prefs);
878 SetInstallTime(kId3, old_enough, prefs); 877 SetInstallTime(kId3, old_enough, prefs);
879 878
880 scoped_ptr<TestExtensionMessageBubbleController> controller( 879 std::unique_ptr<TestExtensionMessageBubbleController> controller(
881 new TestExtensionMessageBubbleController( 880 new TestExtensionMessageBubbleController(
882 new ProxyOverriddenBubbleDelegate(browser()->profile()), 881 new ProxyOverriddenBubbleDelegate(browser()->profile()), browser()));
883 browser()));
884 882
885 // The second extension is too new to warn about. 883 // The second extension is too new to warn about.
886 EXPECT_FALSE(controller->ShouldShow()); 884 EXPECT_FALSE(controller->ShouldShow());
887 EXPECT_FALSE(controller->ShouldShow()); 885 EXPECT_FALSE(controller->ShouldShow());
888 // Lets make it old enough. 886 // Lets make it old enough.
889 SetInstallTime(kId2, old_enough, prefs); 887 SetInstallTime(kId2, old_enough, prefs);
890 888
891 // The list will contain one enabled unpacked extension (ext 2). 889 // The list will contain one enabled unpacked extension (ext 2).
892 EXPECT_TRUE(controller->ShouldShow()); 890 EXPECT_TRUE(controller->ShouldShow());
893 EXPECT_FALSE(controller->ShouldShow()); 891 EXPECT_FALSE(controller->ShouldShow());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 extensions::UNINSTALL_REASON_FOR_TESTING, 976 extensions::UNINSTALL_REASON_FOR_TESTING,
979 base::Bind(&base::DoNothing), 977 base::Bind(&base::DoNothing),
980 NULL); 978 NULL);
981 service_->UninstallExtension(kId3, 979 service_->UninstallExtension(kId3,
982 extensions::UNINSTALL_REASON_FOR_TESTING, 980 extensions::UNINSTALL_REASON_FOR_TESTING,
983 base::Bind(&base::DoNothing), 981 base::Bind(&base::DoNothing),
984 NULL); 982 NULL);
985 } 983 }
986 984
987 } // namespace extensions 985 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698