| 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 } |
| 97 |
| 98 void ExtensionSettingsUIBrowserTest::DisableErrorConsole() { |
| 99 error_console_override_.reset(new extensions::FeatureSwitch::ScopedOverride( |
| 100 extensions::FeatureSwitch::error_console(), false)); |
| 101 } |
| 102 |
| 93 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { | 103 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { |
| 94 public: | 104 public: |
| 95 explicit MockAutoConfirmExtensionInstallPrompt( | 105 explicit MockAutoConfirmExtensionInstallPrompt( |
| 96 content::WebContents* web_contents) | 106 content::WebContents* web_contents) |
| 97 : ExtensionInstallPrompt(web_contents) {} | 107 : ExtensionInstallPrompt(web_contents) {} |
| 98 | 108 |
| 99 // Proceed without confirmation prompt. | 109 // Proceed without confirmation prompt. |
| 100 void ConfirmInstall(Delegate* delegate, | 110 void ConfirmInstall(Delegate* delegate, |
| 101 const Extension* extension, | 111 const Extension* extension, |
| 102 const ShowDialogCallback& show_dialog_callback) override { | 112 const ShowDialogCallback& show_dialog_callback) override { |
| 103 delegate->InstallUIProceed(); | 113 delegate->InstallUIProceed(); |
| 104 } | 114 } |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( | 117 const Extension* ExtensionSettingsUIBrowserTest::InstallUnpackedExtension( |
| 108 const base::FilePath& path) { | 118 const base::FilePath& path) { |
| 109 if (path.empty()) | 119 if (path.empty()) |
| 110 return NULL; | 120 return nullptr; |
| 111 | 121 |
| 112 Profile* profile = GetProfile(); | 122 Profile* profile = GetProfile(); |
| 113 ExtensionService* service = | 123 ExtensionService* service = |
| 114 extensions::ExtensionSystem::Get(profile)->extension_service(); | 124 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 115 service->set_show_extensions_prompts(false); | 125 service->set_show_extensions_prompts(false); |
| 116 extensions::ExtensionRegistry* registry = | 126 extensions::ExtensionRegistry* registry = |
| 117 extensions::ExtensionRegistry::Get(profile); | 127 extensions::ExtensionRegistry::Get(profile); |
| 118 extensions::TestExtensionRegistryObserver observer(registry); | 128 extensions::TestExtensionRegistryObserver observer(registry); |
| 119 extensions::UnpackedInstaller::Create(service)->Load(path); | 129 extensions::UnpackedInstaller::Create(service)->Load(path); |
| 120 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); | 130 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 136 service->set_show_extensions_prompts(false); | 146 service->set_show_extensions_prompts(false); |
| 137 size_t num_before = registry->enabled_extensions().size(); | 147 size_t num_before = registry->enabled_extensions().size(); |
| 138 { | 148 { |
| 139 scoped_ptr<ExtensionInstallPrompt> install_ui; | 149 scoped_ptr<ExtensionInstallPrompt> install_ui; |
| 140 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( | 150 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( |
| 141 browser()->tab_strip_model()->GetActiveWebContents())); | 151 browser()->tab_strip_model()->GetActiveWebContents())); |
| 142 | 152 |
| 143 base::FilePath crx_path = path; | 153 base::FilePath crx_path = path; |
| 144 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); | 154 DCHECK(crx_path.Extension() == FILE_PATH_LITERAL(".crx")); |
| 145 if (crx_path.empty()) | 155 if (crx_path.empty()) |
| 146 return NULL; | 156 return nullptr; |
| 147 | 157 |
| 148 scoped_refptr<extensions::CrxInstaller> installer( | 158 scoped_refptr<extensions::CrxInstaller> installer( |
| 149 extensions::CrxInstaller::Create(service, install_ui.Pass())); | 159 extensions::CrxInstaller::Create(service, install_ui.Pass())); |
| 150 installer->set_expected_id(std::string()); | 160 installer->set_expected_id(std::string()); |
| 151 installer->set_is_gallery_install(false); | 161 installer->set_is_gallery_install(false); |
| 152 installer->set_install_source(extensions::Manifest::INTERNAL); | 162 installer->set_install_source(extensions::Manifest::INTERNAL); |
| 153 installer->set_install_immediately(true); | 163 installer->set_install_immediately(true); |
| 154 installer->set_off_store_install_allow_reason( | 164 installer->set_off_store_install_allow_reason( |
| 155 extensions::CrxInstaller::OffStoreInstallAllowedInTest); | 165 extensions::CrxInstaller::OffStoreInstallAllowedInTest); |
| 156 | 166 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 173 registry->enabled_extensions()) | 183 registry->enabled_extensions()) |
| 174 VLOG(1) << " " << extension->id(); | 184 VLOG(1) << " " << extension->id(); |
| 175 | 185 |
| 176 VLOG(1) << "Errors follow:"; | 186 VLOG(1) << "Errors follow:"; |
| 177 const std::vector<base::string16>* errors = | 187 const std::vector<base::string16>* errors = |
| 178 ExtensionErrorReporter::GetInstance()->GetErrors(); | 188 ExtensionErrorReporter::GetInstance()->GetErrors(); |
| 179 for (std::vector<base::string16>::const_iterator iter = errors->begin(); | 189 for (std::vector<base::string16>::const_iterator iter = errors->begin(); |
| 180 iter != errors->end(); ++iter) | 190 iter != errors->end(); ++iter) |
| 181 VLOG(1) << *iter; | 191 VLOG(1) << *iter; |
| 182 | 192 |
| 183 return NULL; | 193 return nullptr; |
| 184 } | 194 } |
| 185 | 195 |
| 186 if (!observer_->WaitForExtensionViewsToLoad()) | 196 if (!observer_->WaitForExtensionViewsToLoad()) |
| 187 return NULL; | 197 return nullptr; |
| 188 return service->GetExtensionById(last_loaded_extension_id(), false); | 198 return service->GetExtensionById(last_loaded_extension_id(), false); |
| 189 } | 199 } |
| OLD | NEW |