Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_browsertest.h" | 5 #include "chrome/browser/extensions/extension_browsertest.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | 117 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
| 118 } | 118 } |
| 119 #endif | 119 #endif |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ExtensionBrowserTest::SetUpOnMainThread() { | 122 void ExtensionBrowserTest::SetUpOnMainThread() { |
| 123 InProcessBrowserTest::SetUpOnMainThread(); | 123 InProcessBrowserTest::SetUpOnMainThread(); |
| 124 observer_.reset(new ExtensionTestNotificationObserver(browser())); | 124 observer_.reset(new ExtensionTestNotificationObserver(browser())); |
| 125 } | 125 } |
| 126 | 126 |
| 127 const Extension* ExtensionBrowserTest::LoadExtension( | |
| 128 const base::FilePath& path) { | |
| 129 return LoadExtensionWithFlags(path, kFlagEnableFileAccess); | |
| 130 } | |
| 131 | |
| 132 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | |
| 133 const base::FilePath& path) { | |
| 134 return LoadExtensionWithFlags(path, | |
| 135 kFlagEnableFileAccess | kFlagEnableIncognito); | |
| 136 } | |
| 137 | |
| 127 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( | 138 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags( |
| 128 const base::FilePath& path, int flags) { | 139 const base::FilePath& path, int flags) { |
| 140 return LoadExtensionWithInstallParam(path, flags, std::string()); | |
| 141 } | |
| 142 | |
| 143 const extensions::Extension* | |
| 144 ExtensionBrowserTest::LoadExtensionWithInstallParam( | |
| 145 const base::FilePath& path, | |
| 146 int flags, | |
| 147 const std::string& install_param) { | |
| 129 ExtensionService* service = extensions::ExtensionSystem::Get( | 148 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 130 profile())->extension_service(); | 149 profile())->extension_service(); |
| 131 { | 150 { |
| 132 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED, | 151 observer_->Watch(chrome::NOTIFICATION_EXTENSION_LOADED, |
| 133 content::NotificationService::AllSources()); | 152 content::NotificationService::AllSources()); |
| 134 | 153 |
| 135 scoped_refptr<extensions::UnpackedInstaller> installer( | 154 scoped_refptr<extensions::UnpackedInstaller> installer( |
| 136 extensions::UnpackedInstaller::Create(service)); | 155 extensions::UnpackedInstaller::Create(service)); |
| 137 installer->set_prompt_for_plugins(false); | 156 installer->set_prompt_for_plugins(false); |
| 138 installer->set_require_modern_manifest_version( | 157 installer->set_require_modern_manifest_version( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 162 } | 181 } |
| 163 | 182 |
| 164 EXPECT_TRUE(extension->install_warnings().empty()) << | 183 EXPECT_TRUE(extension->install_warnings().empty()) << |
| 165 install_warnings_message; | 184 install_warnings_message; |
| 166 return NULL; | 185 return NULL; |
| 167 } | 186 } |
| 168 } | 187 } |
| 169 | 188 |
| 170 const std::string extension_id = extension->id(); | 189 const std::string extension_id = extension->id(); |
| 171 | 190 |
| 172 // The call to OnExtensionInstalled ensures the other extension prefs | 191 if (!install_param.empty()) { |
| 173 // are set up with the defaults. | 192 extensions::ExtensionPrefs::Get(profile()) |
| 174 extensions::ExtensionPrefs::Get(profile()) | 193 ->SetInstallParam(extension_id, install_param); |
| 175 ->OnExtensionInstalled(extension, | 194 // Re-enable the extension if needed. |
| 176 Extension::ENABLED, | 195 if (service->extensions()->Contains(extension_id)) { |
| 177 false, | 196 content::WindowedNotificationObserver load_signal( |
| 178 syncer::StringOrdinal::CreateInitialOrdinal()); | 197 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 198 content::Source<Profile>(profile())); | |
| 199 // Reload the extension so that the NOTIFICATION_EXTENSION_LOADED | |
| 200 // observers may access |install_param|. | |
|
Yoyo Zhou
2014/03/18 00:07:51
I'm struggling to understand the reason for this.
vasilii
2014/03/18 10:01:22
We don't know its id yet. It'd be ideal if we coul
| |
| 201 service->ReloadExtension(extension_id); | |
| 202 load_signal.Wait(); | |
| 203 extension = service->GetExtensionById(extension_id, false); | |
| 204 CHECK(extension) << extension_id << " not found after reloading."; | |
| 205 } | |
| 206 } | |
| 179 | 207 |
| 180 // Toggling incognito or file access will reload the extension, so wait for | 208 // Toggling incognito or file access will reload the extension, so wait for |
| 181 // the reload and grab the new extension instance. The default state is | 209 // the reload and grab the new extension instance. The default state is |
| 182 // incognito disabled and file access enabled, so we don't wait in those | 210 // incognito disabled and file access enabled, so we don't wait in those |
| 183 // cases. | 211 // cases. |
| 184 { | 212 { |
| 185 content::WindowedNotificationObserver load_signal( | 213 content::WindowedNotificationObserver load_signal( |
| 186 chrome::NOTIFICATION_EXTENSION_LOADED, | 214 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 187 content::Source<Profile>(profile())); | 215 content::Source<Profile>(profile())); |
| 188 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); | 216 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 207 CHECK(extension) << extension_id << " not found after reloading."; | 235 CHECK(extension) << extension_id << " not found after reloading."; |
| 208 } | 236 } |
| 209 } | 237 } |
| 210 | 238 |
| 211 if (!observer_->WaitForExtensionViewsToLoad()) | 239 if (!observer_->WaitForExtensionViewsToLoad()) |
| 212 return NULL; | 240 return NULL; |
| 213 | 241 |
| 214 return extension; | 242 return extension; |
| 215 } | 243 } |
| 216 | 244 |
| 217 const Extension* ExtensionBrowserTest::LoadExtension( | |
| 218 const base::FilePath& path) { | |
| 219 return LoadExtensionWithFlags(path, kFlagEnableFileAccess); | |
| 220 } | |
| 221 | |
| 222 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( | |
| 223 const base::FilePath& path) { | |
| 224 return LoadExtensionWithFlags(path, | |
| 225 kFlagEnableFileAccess | kFlagEnableIncognito); | |
| 226 } | |
| 227 | |
| 228 const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest( | 245 const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest( |
| 229 const base::FilePath& path, | 246 const base::FilePath& path, |
| 230 const base::FilePath::CharType* manifest_relative_path) { | 247 const base::FilePath::CharType* manifest_relative_path) { |
| 231 ExtensionService* service = extensions::ExtensionSystem::Get( | 248 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 232 profile())->extension_service(); | 249 profile())->extension_service(); |
| 233 | 250 |
| 234 std::string manifest; | 251 std::string manifest; |
| 235 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) { | 252 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) { |
| 236 return NULL; | 253 return NULL; |
| 237 } | 254 } |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 EXPECT_EQ(expected_hosts, num_hosts); | 606 EXPECT_EQ(expected_hosts, num_hosts); |
| 590 return host; | 607 return host; |
| 591 } | 608 } |
| 592 | 609 |
| 593 std::string ExtensionBrowserTest::ExecuteScriptInBackgroundPage( | 610 std::string ExtensionBrowserTest::ExecuteScriptInBackgroundPage( |
| 594 const std::string& extension_id, | 611 const std::string& extension_id, |
| 595 const std::string& script) { | 612 const std::string& script) { |
| 596 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 613 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 597 profile(), extension_id, script); | 614 profile(), extension_id, script); |
| 598 } | 615 } |
| OLD | NEW |