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 21 matching lines...) Expand all Loading... | |
160 install_warnings.begin(); it != install_warnings.end(); ++it) { | 179 install_warnings.begin(); it != install_warnings.end(); ++it) { |
161 install_warnings_message += " " + it->message + "\n"; | 180 install_warnings_message += " " + it->message + "\n"; |
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 std::string extension_id = extension->id(); |
Finnur
2014/03/13 16:37:51
Out of curiosity... What necessitates the const re
vasilii
2014/03/14 10:54:58
I wanted to remove the reference here..
| |
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 // Reenable the extension if needed |
Finnur
2014/03/13 16:37:51
nit:
s/Reenable/Re-enable/
... and end the comment
vasilii
2014/03/14 10:54:58
Done.
| |
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 service->ReloadExtension(extension_id); | |
Finnur
2014/03/13 16:37:51
Maybe document why this is needed?
vasilii
2014/03/14 10:54:58
Done.
| |
200 load_signal.Wait(); | |
201 extension = service->GetExtensionById(extension_id, false); | |
202 CHECK(extension) << extension_id << " not found after reloading."; | |
203 } | |
204 } | |
179 | 205 |
180 // Toggling incognito or file access will reload the extension, so wait for | 206 // 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 | 207 // 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 | 208 // incognito disabled and file access enabled, so we don't wait in those |
183 // cases. | 209 // cases. |
184 { | 210 { |
185 content::WindowedNotificationObserver load_signal( | 211 content::WindowedNotificationObserver load_signal( |
186 chrome::NOTIFICATION_EXTENSION_LOADED, | 212 chrome::NOTIFICATION_EXTENSION_LOADED, |
187 content::Source<Profile>(profile())); | 213 content::Source<Profile>(profile())); |
188 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); | 214 CHECK(!extensions::util::IsIncognitoEnabled(extension_id, profile())); |
(...skipping 18 matching lines...) Expand all Loading... | |
207 CHECK(extension) << extension_id << " not found after reloading."; | 233 CHECK(extension) << extension_id << " not found after reloading."; |
208 } | 234 } |
209 } | 235 } |
210 | 236 |
211 if (!observer_->WaitForExtensionViewsToLoad()) | 237 if (!observer_->WaitForExtensionViewsToLoad()) |
212 return NULL; | 238 return NULL; |
213 | 239 |
214 return extension; | 240 return extension; |
215 } | 241 } |
216 | 242 |
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( | 243 const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest( |
229 const base::FilePath& path, | 244 const base::FilePath& path, |
230 const base::FilePath::CharType* manifest_relative_path) { | 245 const base::FilePath::CharType* manifest_relative_path) { |
231 ExtensionService* service = extensions::ExtensionSystem::Get( | 246 ExtensionService* service = extensions::ExtensionSystem::Get( |
232 profile())->extension_service(); | 247 profile())->extension_service(); |
233 | 248 |
234 std::string manifest; | 249 std::string manifest; |
235 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) { | 250 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) { |
236 return NULL; | 251 return NULL; |
237 } | 252 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 EXPECT_EQ(expected_hosts, num_hosts); | 604 EXPECT_EQ(expected_hosts, num_hosts); |
590 return host; | 605 return host; |
591 } | 606 } |
592 | 607 |
593 std::string ExtensionBrowserTest::ExecuteScriptInBackgroundPage( | 608 std::string ExtensionBrowserTest::ExecuteScriptInBackgroundPage( |
594 const std::string& extension_id, | 609 const std::string& extension_id, |
595 const std::string& script) { | 610 const std::string& script) { |
596 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 611 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
597 profile(), extension_id, script); | 612 profile(), extension_id, script); |
598 } | 613 } |
OLD | NEW |