Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ntp_overridden_bubble_controller.h" |
| 13 #include "chrome/browser/extensions/proxy_overridden_bubble_controller.h" | |
| 13 #include "chrome/browser/extensions/settings_api_bubble_controller.h" | 14 #include "chrome/browser/extensions/settings_api_bubble_controller.h" |
| 14 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" | 15 #include "chrome/browser/extensions/suspicious_extension_bubble_controller.h" |
| 15 #include "chrome/browser/extensions/test_extension_system.h" | 16 #include "chrome/browser/extensions/test_extension_system.h" |
| 16 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 19 #include "extensions/common/extension.h" | 20 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_builder.h" | 21 #include "extensions/common/extension_builder.h" |
|
Devlin
2014/05/20 17:26:31
nit: also include value_builder.h
Finnur
2014/05/21 16:30:32
Done.
| |
| 21 #include "extensions/common/feature_switch.h" | 22 #include "extensions/common/feature_switch.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; | 26 const char kId1[] = "iccfkkhkfiphcjdakkmcjmkfboccmndk"; |
| 26 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; | 27 const char kId2[] = "ajjhifimiemdpmophmkkkcijegphclbl"; |
| 27 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; | 28 const char kId3[] = "ioibbbfddncmmabjmpokikkeiofalaek"; |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 ++dismiss_button_callback_count_; | 152 ++dismiss_button_callback_count_; |
| 152 NtpOverriddenBubbleController::OnBubbleDismiss(); | 153 NtpOverriddenBubbleController::OnBubbleDismiss(); |
| 153 } | 154 } |
| 154 | 155 |
| 155 virtual void OnLinkClicked() OVERRIDE { | 156 virtual void OnLinkClicked() OVERRIDE { |
| 156 ++link_click_callback_count_; | 157 ++link_click_callback_count_; |
| 157 NtpOverriddenBubbleController::OnLinkClicked(); | 158 NtpOverriddenBubbleController::OnLinkClicked(); |
| 158 } | 159 } |
| 159 }; | 160 }; |
| 160 | 161 |
| 162 // A test class for the ProxyOverriddenBubbleController. | |
| 163 class TestProxyOverriddenBubbleController | |
| 164 : public ProxyOverriddenBubbleController, | |
| 165 public TestDelegate { | |
| 166 public: | |
| 167 explicit TestProxyOverriddenBubbleController(Profile* profile) | |
| 168 : ProxyOverriddenBubbleController(profile) { | |
| 169 } | |
| 170 | |
| 171 virtual void OnBubbleAction() OVERRIDE { | |
| 172 ++action_button_callback_count_; | |
| 173 ProxyOverriddenBubbleController::OnBubbleAction(); | |
|
Devlin
2014/05/20 17:26:31
So much of this code is duplicated, but I can't th
Finnur
2014/05/21 16:30:32
The only way I could think of was to move these co
| |
| 174 } | |
| 175 | |
| 176 virtual void OnBubbleDismiss() OVERRIDE { | |
| 177 ++dismiss_button_callback_count_; | |
| 178 ProxyOverriddenBubbleController::OnBubbleDismiss(); | |
| 179 } | |
| 180 | |
| 181 virtual void OnLinkClicked() OVERRIDE { | |
| 182 ++link_click_callback_count_; | |
| 183 ProxyOverriddenBubbleController::OnLinkClicked(); | |
| 184 } | |
| 185 }; | |
| 186 | |
| 161 // A fake bubble used for testing the controller. Takes an action that specifies | 187 // A fake bubble used for testing the controller. Takes an action that specifies |
| 162 // what should happen when the bubble is "shown" (the bubble is actually not | 188 // what should happen when the bubble is "shown" (the bubble is actually not |
| 163 // shown, the corresponding action is taken immediately). | 189 // shown, the corresponding action is taken immediately). |
| 164 class FakeExtensionMessageBubble : public ExtensionMessageBubble { | 190 class FakeExtensionMessageBubble : public ExtensionMessageBubble { |
| 165 public: | 191 public: |
| 166 enum ExtensionBubbleAction { | 192 enum ExtensionBubbleAction { |
| 167 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, | 193 BUBBLE_ACTION_CLICK_ACTION_BUTTON = 0, |
| 168 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, | 194 BUBBLE_ACTION_CLICK_DISMISS_BUTTON, |
| 169 BUBBLE_ACTION_CLICK_LINK, | 195 BUBBLE_ACTION_CLICK_LINK, |
| 170 }; | 196 }; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 .Set("manifest_version", 2) | 307 .Set("manifest_version", 2) |
| 282 .Set("chrome_url_overrides", | 308 .Set("chrome_url_overrides", |
| 283 extensions::DictionaryBuilder().Set( | 309 extensions::DictionaryBuilder().Set( |
| 284 "newtab", "Default.html"))); | 310 "newtab", "Default.html"))); |
| 285 | 311 |
| 286 builder.SetLocation(location); | 312 builder.SetLocation(location); |
| 287 builder.SetID(id); | 313 builder.SetID(id); |
| 288 service_->AddExtension(builder.Build().get()); | 314 service_->AddExtension(builder.Build().get()); |
| 289 } | 315 } |
| 290 | 316 |
| 317 void LoadExtensionOverridingProxy(const std::string& index, | |
| 318 const std::string& id, | |
| 319 Manifest::Location location) { | |
| 320 extensions::ExtensionBuilder builder; | |
|
Devlin
2014/05/20 17:26:31
no extensions:: prefix.
Finnur
2014/05/21 16:30:32
Indeed.
| |
| 321 builder.SetManifest(extensions::DictionaryBuilder() | |
| 322 .Set("name", std::string("Extension " + index)) | |
| 323 .Set("version", "1.0") | |
| 324 .Set("manifest_version", 2) | |
| 325 .Set("permissions", | |
| 326 extensions::ListBuilder().Append("proxy"))); | |
| 327 | |
| 328 builder.SetLocation(location); | |
| 329 builder.SetID(id); | |
| 330 service_->AddExtension(builder.Build().get()); | |
|
Devlin
2014/05/20 17:26:31
We'll get a ton of fun errors if these extensions
Finnur
2014/05/21 16:30:32
Done.
| |
| 331 } | |
| 332 | |
| 291 void Init() { | 333 void Init() { |
| 292 // The two lines of magical incantation required to get the extension | 334 // The two lines of magical incantation required to get the extension |
| 293 // service to work inside a unit test and access the extension prefs. | 335 // service to work inside a unit test and access the extension prefs. |
| 294 thread_bundle_.reset(new content::TestBrowserThreadBundle); | 336 thread_bundle_.reset(new content::TestBrowserThreadBundle); |
| 295 profile_.reset(new TestingProfile); | 337 profile_.reset(new TestingProfile); |
| 296 static_cast<TestExtensionSystem*>( | 338 static_cast<TestExtensionSystem*>( |
| 297 ExtensionSystem::Get(profile()))->CreateExtensionService( | 339 ExtensionSystem::Get(profile()))->CreateExtensionService( |
| 298 CommandLine::ForCurrentProcess(), | 340 CommandLine::ForCurrentProcess(), |
| 299 base::FilePath(), | 341 base::FilePath(), |
| 300 false); | 342 false); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); | 758 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId1)); |
| 717 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); | 759 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId2)); |
| 718 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); | 760 EXPECT_FALSE(prefs->HasNtpOverriddenBubbleBeenAcknowledged(kId3)); |
| 719 | 761 |
| 720 // Clean up after ourselves. | 762 // Clean up after ourselves. |
| 721 service_->UninstallExtension(kId1, false, NULL); | 763 service_->UninstallExtension(kId1, false, NULL); |
| 722 service_->UninstallExtension(kId2, false, NULL); | 764 service_->UninstallExtension(kId2, false, NULL); |
| 723 service_->UninstallExtension(kId3, false, NULL); | 765 service_->UninstallExtension(kId3, false, NULL); |
| 724 } | 766 } |
| 725 | 767 |
| 768 // The feature this is meant to test is only implemented on Windows. | |
| 769 #if defined(OS_WIN) | |
| 770 #define MAYBE_ProxyOverriddenControllerTest ProxyOverriddenControllerTest | |
| 771 #else | |
| 772 #define MAYBE_ProxyOverriddenControllerTest DISABLED_ProxyOverriddenControllerTe st | |
| 773 #endif | |
| 774 | |
| 775 TEST_F(ExtensionMessageBubbleTest, MAYBE_ProxyOverriddenControllerTest) { | |
| 776 Init(); | |
| 777 extensions::ExtensionPrefs* prefs = | |
|
Devlin
2014/05/20 17:26:31
No extensions:: prefix.
Finnur
2014/05/21 16:30:32
Done.
| |
| 778 extensions::ExtensionPrefs::Get(profile()); | |
| 779 // Load two extensions overriding proxy and one overriding something | |
|
Devlin
2014/05/20 17:26:31
It looks like all three are overriding proxy - am
Finnur
2014/05/21 16:30:32
Yes, the last one is overriding the StartPage.
Devlin
2014/05/21 17:00:39
D'oh. Long function names + monospace font + same
| |
| 780 // unrelated (to check for interference). Extension 2 should still win | |
| 781 // on the proxy setting. | |
| 782 LoadExtensionOverridingProxy("1", kId1, Manifest::UNPACKED); | |
|
Devlin
2014/05/20 17:26:31
nit: Why pass in location if it's always unpacked?
Finnur
2014/05/21 16:30:32
Readability (location not buried inside the functi
Devlin
2014/05/21 17:00:39
Fair enough. :)
| |
| 783 LoadExtensionOverridingProxy("2", kId2, Manifest::UNPACKED); | |
| 784 LoadExtensionOverridingStart("3", kId3, Manifest::UNPACKED); | |
| 785 | |
| 786 scoped_ptr<TestProxyOverriddenBubbleController> controller( | |
| 787 new TestProxyOverriddenBubbleController(profile())); | |
| 788 | |
| 789 // The list will contain one enabled unpacked extension (ext 2). | |
| 790 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
|
Devlin
2014/05/20 17:26:31
To be safe, maybe an EXPECT_FALSE(controller->Shou
Finnur
2014/05/21 16:30:32
Done.
| |
| 791 std::vector<base::string16> override_extensions = | |
| 792 controller->GetExtensionList(); | |
| 793 ASSERT_EQ(1U, override_extensions.size()); | |
| 794 EXPECT_TRUE(base::ASCIIToUTF16("Extension 2") == | |
|
Devlin
2014/05/20 17:26:31
Why not
EXPECT_EQ(base::ASCIIToUTF16("Extension 2"
Finnur
2014/05/21 16:30:32
I got failures on other platforms when I tried tha
Devlin
2014/05/21 17:00:39
If there are compiler errors, feel free to change
| |
| 795 override_extensions[0].c_str()); | |
| 796 EXPECT_EQ(0U, controller->link_click_count()); | |
| 797 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
| 798 EXPECT_EQ(0U, controller->action_click_count()); | |
| 799 | |
| 800 // Simulate showing the bubble and dismissing it. | |
| 801 FakeExtensionMessageBubble bubble; | |
| 802 bubble.set_action_on_show( | |
| 803 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_DISMISS_BUTTON); | |
| 804 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
|
Devlin
2014/05/20 17:26:31
This was already checked on line 790, right?
Finnur
2014/05/21 16:30:32
Done.
| |
| 805 controller->Show(&bubble); | |
| 806 EXPECT_EQ(0U, controller->link_click_count()); | |
| 807 EXPECT_EQ(0U, controller->action_click_count()); | |
| 808 EXPECT_EQ(1U, controller->dismiss_click_count()); | |
| 809 // No extension should have become disabled. | |
| 810 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | |
|
Devlin
2014/05/20 17:26:31
Please use ExtensionRegistry::enabled_extensions()
Finnur
2014/05/21 16:30:32
Done.
| |
| 811 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | |
| 812 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | |
| 813 // Only extension 2 should have been acknowledged. | |
| 814 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
| 815 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
| 816 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
| 817 // Clean up after ourselves. | |
| 818 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); | |
| 819 | |
| 820 // Simulate clicking the learn more link to dismiss it. | |
| 821 bubble.set_action_on_show( | |
| 822 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_LINK); | |
| 823 controller.reset(new TestProxyOverriddenBubbleController(profile())); | |
| 824 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
| 825 controller->Show(&bubble); | |
| 826 EXPECT_EQ(1U, controller->link_click_count()); | |
| 827 EXPECT_EQ(0U, controller->action_click_count()); | |
| 828 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
| 829 // No extension should have become disabled. | |
| 830 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | |
| 831 EXPECT_TRUE(service_->GetExtensionById(kId2, false) != NULL); | |
| 832 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | |
| 833 // Only extension 2 should have been acknowledged. | |
| 834 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
| 835 EXPECT_TRUE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
| 836 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
| 837 // Clean up after ourselves. | |
| 838 prefs->SetProxyOverriddenBubbleBeenAcknowledged(kId2, false); | |
| 839 | |
| 840 // Do it again, but now opt to disable the extension. | |
| 841 bubble.set_action_on_show( | |
| 842 FakeExtensionMessageBubble::BUBBLE_ACTION_CLICK_ACTION_BUTTON); | |
| 843 controller.reset(new TestProxyOverriddenBubbleController(profile())); | |
| 844 EXPECT_TRUE(controller->ShouldShow(kId2)); | |
| 845 override_extensions = controller->GetExtensionList(); | |
| 846 EXPECT_EQ(1U, override_extensions.size()); | |
| 847 controller->Show(&bubble); // Simulate showing the bubble. | |
| 848 EXPECT_EQ(0U, controller->link_click_count()); | |
| 849 EXPECT_EQ(1U, controller->action_click_count()); | |
| 850 EXPECT_EQ(0U, controller->dismiss_click_count()); | |
| 851 // Only extension 2 should have become disabled. | |
| 852 EXPECT_TRUE(service_->GetExtensionById(kId1, false) != NULL); | |
| 853 EXPECT_TRUE(service_->GetExtensionById(kId2, false) == NULL); | |
|
Devlin
2014/05/20 17:26:31
ExtensionRegistry will help here, too, because it'
Finnur
2014/05/21 16:30:32
Done.
| |
| 854 EXPECT_TRUE(service_->GetExtensionById(kId3, false) != NULL); | |
| 855 // No extension should have been acknowledged (it got disabled). | |
| 856 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId1)); | |
| 857 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId2)); | |
| 858 EXPECT_FALSE(prefs->HasProxyOverriddenBubbleBeenAcknowledged(kId3)); | |
| 859 | |
| 860 // Clean up after ourselves. | |
| 861 service_->UninstallExtension(kId1, false, NULL); | |
| 862 service_->UninstallExtension(kId2, false, NULL); | |
| 863 service_->UninstallExtension(kId3, false, NULL); | |
| 864 } | |
| 865 | |
| 726 } // namespace extensions | 866 } // namespace extensions |
| OLD | NEW |