OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/webui/extensions/extension_settings_browsertest.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_settings_browsertest.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 #include "extensions/browser/api/management/management_api.h" | 27 #include "extensions/browser/api/management/management_api.h" |
28 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
29 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
30 #include "extensions/browser/test_extension_registry_observer.h" | 30 #include "extensions/browser/test_extension_registry_observer.h" |
31 #include "extensions/common/extension_set.h" | 31 #include "extensions/common/extension_set.h" |
32 | 32 |
33 using extensions::Extension; | 33 using extensions::Extension; |
34 using extensions::TestManagementPolicyProvider; | 34 using extensions::TestManagementPolicyProvider; |
35 | 35 |
36 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() | 36 ExtensionSettingsUIBrowserTest::ExtensionSettingsUIBrowserTest() |
37 : profile_(NULL), | 37 : profile_(nullptr), |
38 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | | 38 policy_provider_(TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS | |
39 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | | 39 TestManagementPolicyProvider::MUST_REMAIN_ENABLED | |
40 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) { | 40 TestManagementPolicyProvider::MUST_REMAIN_INSTALLED) { |
41 CHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); | 41 CHECK(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_)); |
42 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); | 42 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); |
43 } | 43 } |
44 | 44 |
45 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} | 45 ExtensionSettingsUIBrowserTest::~ExtensionSettingsUIBrowserTest() {} |
46 | 46 |
47 Profile* ExtensionSettingsUIBrowserTest::GetProfile() { | 47 Profile* ExtensionSettingsUIBrowserTest::GetProfile() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 83 |
84 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { | 84 void ExtensionSettingsUIBrowserTest::AddManagedPolicyProvider() { |
85 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); | 85 auto* extension_service = extensions::ExtensionSystem::Get(GetProfile()); |
86 extension_service->management_policy()->RegisterProvider(&policy_provider_); | 86 extension_service->management_policy()->RegisterProvider(&policy_provider_); |
87 } | 87 } |
88 | 88 |
89 void ExtensionSettingsUIBrowserTest::SetAutoConfirmUninstall() { | 89 void ExtensionSettingsUIBrowserTest::SetAutoConfirmUninstall() { |
90 extensions::ManagementUninstallFunctionBase::SetAutoConfirmForTest(true); | 90 extensions::ManagementUninstallFunctionBase::SetAutoConfirmForTest(true); |
91 } | 91 } |
92 | 92 |
93 void ExtensionSettingsUIBrowserTest::EnableErrorConsole() { | |
94 error_console_override_.reset(new extensions::FeatureSwitch::ScopedOverride( | |
95 extensions::FeatureSwitch::error_console(), true)); | |
96 channel_override_.reset(new extensions::ScopedCurrentChannel( | |
97 chrome::VersionInfo::CHANNEL_DEV)); | |
Dan Beam
2015/05/07 21:47:34
i don't like doing these things because it changes
Devlin
2015/05/07 21:53:36
I'm not super keen on the channels either, but I d
hcarmona
2015/05/07 22:49:53
Updated the ErrorConsole check and removed the cha
| |
98 } | |
99 | |
100 void ExtensionSettingsUIBrowserTest::DisableErrorConsole() { | |
101 error_console_override_.reset(new extensions::FeatureSwitch::ScopedOverride( | |
102 extensions::FeatureSwitch::error_console(), false)); | |
103 channel_override_.reset(new extensions::ScopedCurrentChannel( | |
104 chrome::VersionInfo::CHANNEL_STABLE)); | |
105 } | |
106 | |
93 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { | 107 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { |
94 public: | 108 public: |
95 explicit MockAutoConfirmExtensionInstallPrompt( | 109 explicit MockAutoConfirmExtensionInstallPrompt( |
96 content::WebContents* web_contents) | 110 content::WebContents* web_contents) |
97 : ExtensionInstallPrompt(web_contents) {} | 111 : ExtensionInstallPrompt(web_contents) {} |
98 | 112 |
99 // Proceed without confirmation prompt. | 113 // Proceed without confirmation prompt. |
100 void ConfirmInstall(Delegate* delegate, | 114 void ConfirmInstall(Delegate* delegate, |
101 const Extension* extension, | 115 const Extension* extension, |
102 const ShowDialogCallback& show_dialog_callback) override { | 116 const ShowDialogCallback& show_dialog_callback) override { |
103 delegate->InstallUIProceed(); | 117 delegate->InstallUIProceed(); |
104 } | 118 } |
105 }; | 119 }; |
106 | 120 |
107 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( | 121 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( |
108 const base::FilePath& path) { | 122 const base::FilePath& path) { |
109 if (path.empty()) | 123 if (path.empty()) |
110 return NULL; | 124 return nullptr; |
111 | 125 |
112 Profile* profile = GetProfile(); | 126 Profile* profile = GetProfile(); |
113 ExtensionService* service = | 127 ExtensionService* service = |
114 extensions::ExtensionSystem::Get(profile)->extension_service(); | 128 extensions::ExtensionSystem::Get(profile)->extension_service(); |
115 service->set_show_extensions_prompts(false); | 129 service->set_show_extensions_prompts(false); |
116 extensions::ExtensionRegistry* registry = | 130 extensions::ExtensionRegistry* registry = |
117 extensions::ExtensionRegistry::Get(profile); | 131 extensions::ExtensionRegistry::Get(profile); |
118 extensions::TestExtensionRegistryObserver observer(registry); | 132 extensions::TestExtensionRegistryObserver observer(registry); |
119 extensions::UnpackedInstaller::Create(service)->Load(path); | 133 extensions::UnpackedInstaller::Create(service)->Load(path); |
120 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | 134 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
(...skipping 15 matching lines...) Expand all Loading... | |
136 service->set_show_extensions_prompts(false); | 150 service->set_show_extensions_prompts(false); |
137 size_t num_before = registry->enabled_extensions().size(); | 151 size_t num_before = registry->enabled_extensions().size(); |
138 { | 152 { |
139 scoped_ptr<ExtensionInstallPrompt> install_ui; | 153 scoped_ptr<ExtensionInstallPrompt> install_ui; |
140 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( | 154 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( |
141 browser()->tab_strip_model()->GetActiveWebContents())); | 155 browser()->tab_strip_model()->GetActiveWebContents())); |
142 | 156 |
143 base::FilePath crx_path = path; | 157 base::FilePath crx_path = path; |
144 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); | 158 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); |
145 if (crx_path.empty()) | 159 if (crx_path.empty()) |
146 return NULL; | 160 return nullptr; |
147 | 161 |
148 scoped_refptr<extensions::CrxInstaller> installer( | 162 scoped_refptr<extensions::CrxInstaller> installer( |
149 extensions::CrxInstaller::Create(service, install_ui.Pass())); | 163 extensions::CrxInstaller::Create(service, install_ui.Pass())); |
150 installer->set_expected_id(std::string()); | 164 installer->set_expected_id(std::string()); |
151 installer->set_is_gallery_install(false); | 165 installer->set_is_gallery_install(false); |
152 installer->set_install_source(extensions::Manifest::INTERNAL); | 166 installer->set_install_source(extensions::Manifest::INTERNAL); |
153 installer->set_install_immediately(true); | 167 installer->set_install_immediately(true); |
154 installer->set_off_store_install_allow_reason( | 168 installer->set_off_store_install_allow_reason( |
155 extensions::CrxInstaller::OffStoreInstallAllowedInTest); | 169 extensions::CrxInstaller::OffStoreInstallAllowedInTest); |
156 | 170 |
(...skipping 16 matching lines...) Expand all Loading... | |
173 registry->enabled_extensions()) | 187 registry->enabled_extensions()) |
174 VLOG(1) << " " << extension->id(); | 188 VLOG(1) << " " << extension->id(); |
175 | 189 |
176 VLOG(1) << "Errors follow:"; | 190 VLOG(1) << "Errors follow:"; |
177 const std::vector<base::string16>* errors = | 191 const std::vector<base::string16>* errors = |
178 ExtensionErrorReporter::GetInstance()->GetErrors(); | 192 ExtensionErrorReporter::GetInstance()->GetErrors(); |
179 for (std::vector<base::string16>::const_iterator iter = errors->begin(); | 193 for (std::vector<base::string16>::const_iterator iter = errors->begin(); |
180 iter != errors->end(); ++iter) | 194 iter != errors->end(); ++iter) |
181 VLOG(1) << *iter; | 195 VLOG(1) << *iter; |
182 | 196 |
183 return NULL; | 197 return nullptr; |
184 } | 198 } |
185 | 199 |
186 if (!observer_->WaitForExtensionViewsToLoad()) | 200 if (!observer_->WaitForExtensionViewsToLoad()) |
187 return NULL; | 201 return nullptr; |
188 return service->GetExtensionById(last_loaded_extension_id(), false); | 202 return service->GetExtensionById(last_loaded_extension_id(), false); |
189 } | 203 } |
OLD | NEW |