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

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

Issue 246653003: Settings Overides -- warn user when extensions override their NTP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 6 years, 7 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h" 8 #include "chrome/browser/extensions/dev_mode_bubble_controller.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "chrome/browser/extensions/extension_message_bubble.h" 10 #include "chrome/browser/extensions/extension_message_bubble.h"
11 #include "chrome/browser/extensions/extension_service.h" 11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/extensions/ntp_overridden_bubble_controller.h"
12 #include "chrome/browser/extensions/settings_api_bubble_controller.h" 13 #include "chrome/browser/extensions/settings_api_bubble_controller.h"
13 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" 14 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h"
14 #include "chrome/browser/extensions/test_extension_system.h" 15 #include "chrome/browser/extensions/test_extension_system.h"
15 #include "chrome/common/chrome_version_info.h" 16 #include "chrome/common/chrome_version_info.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_builder.h" 20 #include "extensions/common/extension_builder.h"
20 #include "extensions/common/feature_switch.h" 21 #include "extensions/common/feature_switch.h"
21 22
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 ++dismiss_button_callback_count_; 126 ++dismiss_button_callback_count_;
126 SettingsApiBubbleController::OnBubbleDismiss(); 127 SettingsApiBubbleController::OnBubbleDismiss();
127 } 128 }
128 129
129 virtual void OnLinkClicked() OVERRIDE { 130 virtual void OnLinkClicked() OVERRIDE {
130 ++link_click_callback_count_; 131 ++link_click_callback_count_;
131 SettingsApiBubbleController::OnLinkClicked(); 132 SettingsApiBubbleController::OnLinkClicked();
132 } 133 }
133 }; 134 };
134 135
136 // A test class for the NtpOverriddenBubbleController.
137 class TestNtpOverriddenBubbleController
138 : public NtpOverriddenBubbleController,
139 public TestDelegate {
140 public:
141 explicit TestNtpOverriddenBubbleController(Profile* profile)
142 : NtpOverriddenBubbleController(profile) {
143 }
144
145 virtual void OnBubbleAction() OVERRIDE {
146 ++action_button_callback_count_;
147 NtpOverriddenBubbleController::OnBubbleAction();
148 }
149
150 virtual void OnBubbleDismiss() OVERRIDE {
151 ++dismiss_button_callback_count_;
152 NtpOverriddenBubbleController::OnBubbleDismiss();
153 }
154
155 virtual void OnLinkClicked() OVERRIDE {
156 ++link_click_callback_count_;
157 NtpOverriddenBubbleController::OnLinkClicked();
158 }
159 };
160
135 // A fake bubble used for testing the controller. Takes an action that specifies 161 // A fake bubble used for testing the controller. Takes an action that specifies
136 // what should happen when the bubble is "shown" (the bubble is actually not 162 // what should happen when the bubble is "shown" (the bubble is actually not
137 // shown, the corresponding action is taken immediately). 163 // shown, the corresponding action is taken immediately).
138 class FakeExtensionMessageBubble : public ExtensionMessageBubble { 164 class FakeExtensionMessageBubble : public ExtensionMessageBubble {
139 public: 165 public:
140 enum ExtensionBubbleAction { 166 enum ExtensionBubbleAction {
141 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, 167 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0,
142 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, 168 BUBBLE_ACTION_CLICK_DISMISS_BUTTON,
143 BUBBLE_ACTION_CLICK_LINK, 169 BUBBLE_ACTION_CLICK_LINK,
144 }; 170 };
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 .Set("chrome_settings_overrides", 264 .Set("chrome_settings_overrides",
239 extensions::DictionaryBuilder().Set( 265 extensions::DictionaryBuilder().Set(
240 "startup_pages", 266 "startup_pages",
241 extensions::ListBuilder().Append( 267 extensions::ListBuilder().Append(
242 "http://www.google.com")))); 268 "http://www.google.com"))));
243 builder.SetLocation(location); 269 builder.SetLocation(location);
244 builder.SetID(id); 270 builder.SetID(id);
245 service_->AddExtension(builder.Build().get()); 271 service_->AddExtension(builder.Build().get());
246 } 272 }
247 273
274 void LoadExtensionOverridingNtp(const std::string& index,
275 const std::string& id,
276 Manifest::Location location) {
277 extensions::ExtensionBuilder builder;
278 builder.SetManifest(extensions::DictionaryBuilder()
279 .Set("name", std::string("Extension " + index))
280 .Set("version", "1.0")
281 .Set("manifest_version", 2)
282 .Set("chrome_url_overrides",
283 extensions::DictionaryBuilder().Set(
284 "newtab", "Default.html")));
285
286 builder.SetLocation(location);
287 builder.SetID(id);
288 service_->AddExtension(builder.Build().get());
289 }
290
248 void Init() { 291 void Init() {
249 // The two lines of magical incantation required to get the extension 292 // The two lines of magical incantation required to get the extension
250 // service to work inside a unit test and access the extension prefs. 293 // service to work inside a unit test and access the extension prefs.
251 thread_bundle_.reset(new content::TestBrowserThreadBundle); 294 thread_bundle_.reset(new content::TestBrowserThreadBundle);
252 profile_.reset(new TestingProfile); 295 profile_.reset(new TestingProfile);
253 static_cast<TestExtensionSystem*>( 296 static_cast<TestExtensionSystem*>(
254 ExtensionSystem::Get(profile()))->CreateExtensionService( 297 ExtensionSystem::Get(profile()))->CreateExtensionService(
255 CommandLine::ForCurrentProcess(), 298 CommandLine::ForCurrentProcess(),
256 base::FilePath(), 299 base::FilePath(),
257 false); 300 false);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2)); 618 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId2));
576 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3)); 619 EXPECT_FALSE(prefs->HasSettingsApiBubbleBeenAcknowledged(kId3));
577 620
578 // Clean up after ourselves. 621 // Clean up after ourselves.
579 service_->UninstallExtension(kId1, false, NULL); 622 service_->UninstallExtension(kId1, false, NULL);
580 service_->UninstallExtension(kId2, false, NULL); 623 service_->UninstallExtension(kId2, false, NULL);
581 service_->UninstallExtension(kId3, false, NULL); 624 service_->UninstallExtension(kId3, false, NULL);
582 } 625 }
583 } 626 }
584 627
628 // The feature this is meant to test is only implemented on Windows.
629 #if defined(OS_WIN)
630 #define MAYBE_NtpOverriddenControllerTest NtpOverriddenControllerTest
631 #else
632 #define MAYBE_NtpOverriddenControllerTest DISABLED_NtpOverriddenControllerTest
633 #endif
634
635 TEST_F(ExtensionMessageBubbleTest, MAYBE_NtpOverriddenControllerTest) {
636 Init();
637 extensions::ExtensionPrefs* prefs =
638 extensions::ExtensionPrefs::Get(profile());
639 // Load two extensions overriding new tab page and one overriding something
640 // unrelated (to check for interference). Extension 2 should still win
641 // on the new tab page setting.
642 LoadExtensionOverridingNtp("1", kId1, Manifest::UNPACKED);
643 LoadExtensionOverridingNtp("2", kId2, Manifest::UNPACKED);
644 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED);
645
646 scoped_ptr<TestNtpOverriddenBubbleController> controller(
647 new TestNtpOverriddenBubbleController(profile()));
648
649 // The list will contain one enabled unpacked extension (ext 2).
650 EXPECT_TRUE(controller->ShouldShow(kId2));
651 std::vector<base::string16> override_extensions =
652 controller->GetExtensionList();
653 ASSERT_EQ(1U, override_extensions.size());
654 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") ==
655 override_extensions[0].c_str());
656 EXPECT_EQ(0U, controller->link_click_count());
657 EXPECT_EQ(0U, controller->dismiss_click_count());
658 EXPECT_EQ(0U, controller->action_click_count());
659
660 // Simulate showing the bubble and dismissing it.
661 FakeExtensionMessageBubble bubble;
662 bubble.set_action_on_show(
663 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON);
664 EXPECT_TRUE(controller->ShouldShow(kId2));
665 controller->Show(&bubble);
666 EXPECT_EQ(0U, controller->link_click_count());
667 EXPECT_EQ(0U, controller->action_click_count());
668 EXPECT_EQ(1U, controller->dismiss_click_count());
669 // No extension should have become disabled.
670 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
671 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
672 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
673 // Only extension 2 should have been acknowledged.
674 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
675 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
676 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
677 // Clean up after ourselves.
678 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false);
679
680 // Simulate clicking the learn more link to dismiss it.
681 bubble.set_action_on_show(
682 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK);
683 controller.reset(new TestNtpOverriddenBubbleController(profile()));
684 EXPECT_TRUE(controller->ShouldShow(kId2));
685 controller->Show(&bubble);
686 EXPECT_EQ(1U, controller->link_click_count());
687 EXPECT_EQ(0U, controller->action_click_count());
688 EXPECT_EQ(0U, controller->dismiss_click_count());
689 // No extension should have become disabled.
690 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
691 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL);
692 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
693 // Only extension 2 should have been acknowledged.
694 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
695 EXPECT_TRUE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
696 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
697 // Clean up after ourselves.
698 prefs->SetNtpOverriddenBubbleBeenAcknowledged(kId2, false);
699
700 // Do it again, but now opt to disable the extension.
701 bubble.set_action_on_show(
702 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON);
703 controller.reset(new TestNtpOverriddenBubbleController(profile()));
704 EXPECT_TRUE(controller->ShouldShow(kId2));
705 override_extensions = controller->GetExtensionList();
706 EXPECT_EQ(1U, override_extensions.size());
707 controller->Show(&bubble); // Simulate showing the bubble.
708 EXPECT_EQ(0U, controller->link_click_count());
709 EXPECT_EQ(1U, controller->action_click_count());
710 EXPECT_EQ(0U, controller->dismiss_click_count());
711 // Only extension 2 should have become disabled.
712 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL);
713 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL);
714 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL);
715 // No extension should have been acknowledged (it got disabled).
716 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1));
717 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2));
718 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3));
719
720 // Clean up after ourselves.
721 service_->UninstallExtension(kId1, false, NULL);
722 service_->UninstallExtension(kId2, false, NULL);
723 service_->UninstallExtension(kId3, false, NULL);
724 }
725
585 } // namespace extensions 726 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698