Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: chrome/browser/extensions/extension_browsertest.cc

Issue 10750010: Add an installType property to the management API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Added location param to InstallExtension, rewrote test Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_path.h" 10 #include "base/file_path.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // ExtensionService and then the real profile with one, as we do when 68 // ExtensionService and then the real profile with one, as we do when
69 // running on chromeos. 69 // running on chromeos.
70 command_line->AppendSwitchASCII(switches::kLoginUser, 70 command_line->AppendSwitchASCII(switches::kLoginUser,
71 "TestUser@gmail.com"); 71 "TestUser@gmail.com");
72 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 72 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
73 command_line->AppendSwitch(switches::kNoFirstRun); 73 command_line->AppendSwitch(switches::kNoFirstRun);
74 #endif 74 #endif
75 } 75 }
76 76
77 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions( 77 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
78 const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) { 78 const FilePath& path,
79 Extension::Location location,
80 bool incognito_enabled,
81 bool fileaccess_enabled) {
79 ExtensionService* service = browser()->profile()->GetExtensionService(); 82 ExtensionService* service = browser()->profile()->GetExtensionService();
80 { 83 {
81 content::NotificationRegistrar registrar; 84 content::NotificationRegistrar registrar;
82 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 85 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
83 content::NotificationService::AllSources()); 86 content::NotificationService::AllSources());
84 scoped_refptr<extensions::UnpackedInstaller> installer( 87 scoped_refptr<extensions::UnpackedInstaller> installer(
85 extensions::UnpackedInstaller::Create(service)); 88 extensions::UnpackedInstaller::Create(service));
86 installer->set_prompt_for_plugins(false); 89 installer->set_prompt_for_plugins(false);
87 installer->Load(path); 90 installer->Load(path);
88 content::RunMessageLoop(); 91 content::RunMessageLoop();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 extension = service->GetExtensionById(extension_id, false); 130 extension = service->GetExtensionById(extension_id, false);
128 CHECK(extension) << extension_id << " not found after reloading."; 131 CHECK(extension) << extension_id << " not found after reloading.";
129 } 132 }
130 } 133 }
131 134
132 { 135 {
133 content::WindowedNotificationObserver load_signal( 136 content::WindowedNotificationObserver load_signal(
134 chrome::NOTIFICATION_EXTENSION_LOADED, 137 chrome::NOTIFICATION_EXTENSION_LOADED,
135 content::Source<Profile>(browser()->profile())); 138 content::Source<Profile>(browser()->profile()));
136 CHECK(service->AllowFileAccess(extension)); 139 CHECK(service->AllowFileAccess(extension));
137
138 if (!fileaccess_enabled) { 140 if (!fileaccess_enabled) {
139 service->SetAllowFileAccess(extension, fileaccess_enabled); 141 service->SetAllowFileAccess(extension, fileaccess_enabled);
140 load_signal.Wait(); 142 load_signal.Wait();
141 extension = service->GetExtensionById(extension_id, false); 143 extension = service->GetExtensionById(extension_id, false);
142 CHECK(extension) << extension_id << " not found after reloading."; 144 CHECK(extension) << extension_id << " not found after reloading.";
143 } 145 }
144 } 146 }
145 147
146 if (!WaitForExtensionViewsToLoad()) 148 if (!WaitForExtensionViewsToLoad())
147 return NULL; 149 return NULL;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 // Proceed without confirmation prompt. 260 // Proceed without confirmation prompt.
259 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 261 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
260 delegate->InstallUIProceed(); 262 delegate->InstallUIProceed();
261 } 263 }
262 }; 264 };
263 265
264 const Extension* ExtensionBrowserTest::InstallExtensionFromWebstore( 266 const Extension* ExtensionBrowserTest::InstallExtensionFromWebstore(
265 const FilePath& path, 267 const FilePath& path,
266 int expected_change) { 268 int expected_change) {
267 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, 269 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE,
268 expected_change, browser(), true); 270 expected_change, Extension::INTERNAL,
271 browser(), true);
269 } 272 }
270 273
271 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension( 274 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
272 const std::string& id, 275 const std::string& id,
273 const FilePath& path, 276 const FilePath& path,
274 InstallUIType ui_type, 277 InstallUIType ui_type,
275 int expected_change) { 278 int expected_change) {
276 return InstallOrUpdateExtension(id, path, ui_type, expected_change, 279 return InstallOrUpdateExtension(id, path, ui_type, expected_change,
277 browser(), false); 280 Extension::INTERNAL, browser(), false);
278 } 281 }
279 282
280 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension( 283 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
284 const std::string& id,
285 const FilePath& path,
286 InstallUIType ui_type,
287 int expected_change,
288 Browser* browser,
289 bool from_webstore) {
290 return InstallOrUpdateExtension(id, path, ui_type, expected_change,
291 Extension::INTERNAL, browser, from_webstore);
292 }
293
294 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
295 const std::string& id,
296 const FilePath& path,
297 InstallUIType ui_type,
298 int expected_change,
299 Extension::Location install_source) {
300 return InstallOrUpdateExtension(id, path, ui_type, expected_change,
301 install_source, browser(), false);
302 }
303
304 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
281 const std::string& id, 305 const std::string& id,
282 const FilePath& path, 306 const FilePath& path,
283 InstallUIType ui_type, 307 InstallUIType ui_type,
284 int expected_change, 308 int expected_change,
309 Extension::Location install_source,
285 Browser* browser, 310 Browser* browser,
286 bool from_webstore) { 311 bool from_webstore) {
287 ExtensionService* service = browser->profile()->GetExtensionService(); 312 ExtensionService* service = browser->profile()->GetExtensionService();
288 service->set_show_extensions_prompts(false); 313 service->set_show_extensions_prompts(false);
289 size_t num_before = service->extensions()->size(); 314 size_t num_before = service->extensions()->size();
290 315
291 { 316 {
292 ExtensionInstallPrompt* install_ui = NULL; 317 ExtensionInstallPrompt* install_ui = NULL;
293 if (ui_type == INSTALL_UI_TYPE_CANCEL) { 318 if (ui_type == INSTALL_UI_TYPE_CANCEL) {
294 install_ui = new MockAbortExtensionInstallPrompt(); 319 install_ui = new MockAbortExtensionInstallPrompt();
(...skipping 14 matching lines...) Expand all
309 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) { 334 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) {
310 crx_path = PackExtension(path); 335 crx_path = PackExtension(path);
311 } 336 }
312 if (crx_path.empty()) 337 if (crx_path.empty())
313 return NULL; 338 return NULL;
314 339
315 scoped_refptr<extensions::CrxInstaller> installer( 340 scoped_refptr<extensions::CrxInstaller> installer(
316 extensions::CrxInstaller::Create(service, install_ui)); 341 extensions::CrxInstaller::Create(service, install_ui));
317 installer->set_expected_id(id); 342 installer->set_expected_id(id);
318 installer->set_is_gallery_install(from_webstore); 343 installer->set_is_gallery_install(from_webstore);
344 installer->set_install_source(install_source);
319 if (!from_webstore) { 345 if (!from_webstore) {
320 installer->set_off_store_install_allow_reason( 346 installer->set_off_store_install_allow_reason(
321 extensions::CrxInstaller::OffStoreInstallAllowedInTest); 347 extensions::CrxInstaller::OffStoreInstallAllowedInTest);
322 } 348 }
323 349
324 content::NotificationRegistrar registrar; 350 content::NotificationRegistrar registrar;
325 registrar.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE, 351 registrar.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
326 content::Source<extensions::CrxInstaller>(installer.get())); 352 content::Source<extensions::CrxInstaller>(installer.get()));
327 353
328 installer->InstallCrx(crx_path); 354 installer->InstallCrx(crx_path);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 case content::NOTIFICATION_LOAD_STOP: 658 case content::NOTIFICATION_LOAD_STOP:
633 VLOG(1) << "Got LOAD_STOP notification."; 659 VLOG(1) << "Got LOAD_STOP notification.";
634 MessageLoopForUI::current()->Quit(); 660 MessageLoopForUI::current()->Quit();
635 break; 661 break;
636 662
637 default: 663 default:
638 NOTREACHED(); 664 NOTREACHED();
639 break; 665 break;
640 } 666 }
641 } 667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698