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

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

Issue 8725013: Improve ExtensionBrowserTest. Part of moving ExtensionService to use ExtensionSet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 public: 222 public:
223 explicit MockAutoConfirmExtensionInstallUI(Profile* profile) : 223 explicit MockAutoConfirmExtensionInstallUI(Profile* profile) :
224 ExtensionInstallUI(profile) {} 224 ExtensionInstallUI(profile) {}
225 225
226 // Proceed without confirmation prompt. 226 // Proceed without confirmation prompt.
227 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) { 227 virtual void ConfirmInstall(Delegate* delegate, const Extension* extension) {
228 delegate->InstallUIProceed(); 228 delegate->InstallUIProceed();
229 } 229 }
230 }; 230 };
231 231
232 bool ExtensionBrowserTest::InstallExtensionFromWebstore(const FilePath& path, 232 const Extension* ExtensionBrowserTest::InstallExtensionFromWebstore(
233 int expected_change) { 233 const FilePath& path,
234 int expected_change) {
234 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE, 235 return InstallOrUpdateExtension("", path, INSTALL_UI_TYPE_NONE,
235 expected_change, browser()->profile(), 236 expected_change, browser()->profile(),
236 true); 237 true);
237 } 238 }
238 239
239 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, 240 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
240 const FilePath& path, 241 const std::string& id,
241 InstallUIType ui_type, 242 const FilePath& path,
242 int expected_change) { 243 InstallUIType ui_type,
244 int expected_change) {
243 return InstallOrUpdateExtension(id, path, ui_type, expected_change, 245 return InstallOrUpdateExtension(id, path, ui_type, expected_change,
244 browser()->profile(), false); 246 browser()->profile(), false);
245 } 247 }
246 248
247 bool ExtensionBrowserTest::InstallOrUpdateExtension(const std::string& id, 249 const Extension* ExtensionBrowserTest::InstallOrUpdateExtension(
248 const FilePath& path, 250 const std::string& id,
249 InstallUIType ui_type, 251 const FilePath& path,
250 int expected_change, 252 InstallUIType ui_type,
251 Profile* profile, 253 int expected_change,
252 bool from_webstore) { 254 Profile* profile,
255 bool from_webstore) {
253 ExtensionService* service = profile->GetExtensionService(); 256 ExtensionService* service = profile->GetExtensionService();
254 service->set_show_extensions_prompts(false); 257 service->set_show_extensions_prompts(false);
255 size_t num_before = service->extensions()->size(); 258 size_t num_before = service->extensions()->size();
256 259
257 { 260 {
258 content::NotificationRegistrar registrar;
259 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
260 content::NotificationService::AllSources());
261 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
262 content::NotificationService::AllSources());
263 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
264 content::NotificationService::AllSources());
265 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
266 content::NotificationService::AllSources());
267
268 ExtensionInstallUI* install_ui = NULL; 261 ExtensionInstallUI* install_ui = NULL;
269 if (ui_type == INSTALL_UI_TYPE_CANCEL) 262 if (ui_type == INSTALL_UI_TYPE_CANCEL)
270 install_ui = new MockAbortExtensionInstallUI(); 263 install_ui = new MockAbortExtensionInstallUI();
271 else if (ui_type == INSTALL_UI_TYPE_NORMAL) 264 else if (ui_type == INSTALL_UI_TYPE_NORMAL)
272 install_ui = new ExtensionInstallUI(profile); 265 install_ui = new ExtensionInstallUI(profile);
273 else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) 266 else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM)
274 install_ui = new MockAutoConfirmExtensionInstallUI(profile); 267 install_ui = new MockAutoConfirmExtensionInstallUI(profile);
275 268
276 // TODO(tessamac): Update callers to always pass an unpacked extension 269 // TODO(tessamac): Update callers to always pass an unpacked extension
277 // and then always pack the extension here. 270 // and then always pack the extension here.
278 FilePath crx_path = path; 271 FilePath crx_path = path;
279 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) { 272 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) {
280 crx_path = PackExtension(path); 273 crx_path = PackExtension(path);
281 } 274 }
282 if (crx_path.empty()) 275 if (crx_path.empty())
283 return false; 276 return NULL;
284 277
285 scoped_refptr<CrxInstaller> installer( 278 scoped_refptr<CrxInstaller> installer(
286 CrxInstaller::Create(service, install_ui)); 279 CrxInstaller::Create(service, install_ui));
287 installer->set_expected_id(id); 280 installer->set_expected_id(id);
288 installer->set_is_gallery_install(from_webstore); 281 installer->set_is_gallery_install(from_webstore);
282
283 content::NotificationRegistrar registrar;
284 registrar.Add(this, chrome::NOTIFICATION_CRX_INSTALLER_DONE,
285 content::Source<CrxInstaller>(installer.get()));
286
289 installer->InstallCrx(crx_path); 287 installer->InstallCrx(crx_path);
290 288
291 ui_test_utils::RunMessageLoop(); 289 ui_test_utils::RunMessageLoop();
292 } 290 }
293 291
294 size_t num_after = service->extensions()->size(); 292 size_t num_after = service->extensions()->size();
295 if (num_after != (num_before + expected_change)) { 293 EXPECT_EQ(num_before + expected_change, num_after);
294 if (num_before + expected_change != num_after) {
296 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) 295 VLOG(1) << "Num extensions before: " << base::IntToString(num_before)
297 << " num after: " << base::IntToString(num_after) 296 << " num after: " << base::IntToString(num_after)
298 << " Installed extensions follow:"; 297 << " Installed extensions follow:";
299 298
300 for (size_t i = 0; i < service->extensions()->size(); ++i) 299 for (size_t i = 0; i < service->extensions()->size(); ++i)
301 VLOG(1) << " " << (*service->extensions())[i]->id(); 300 VLOG(1) << " " << (*service->extensions())[i]->id();
302 301
303 VLOG(1) << "Errors follow:"; 302 VLOG(1) << "Errors follow:";
304 const std::vector<std::string>* errors = 303 const std::vector<std::string>* errors =
305 ExtensionErrorReporter::GetInstance()->GetErrors(); 304 ExtensionErrorReporter::GetInstance()->GetErrors();
306 for (std::vector<std::string>::const_iterator iter = errors->begin(); 305 for (std::vector<std::string>::const_iterator iter = errors->begin();
307 iter != errors->end(); ++iter) 306 iter != errors->end(); ++iter)
308 VLOG(1) << *iter; 307 VLOG(1) << *iter;
309 308
310 return false; 309 return NULL;
311 } 310 }
312 311
313 return WaitForExtensionHostsToLoad(); 312 if (!WaitForExtensionHostsToLoad())
313 return NULL;
314 return service->GetExtensionById(last_loaded_extension_id_, false);
314 } 315 }
315 316
316 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { 317 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) {
317 ExtensionService* service = browser()->profile()->GetExtensionService(); 318 ExtensionService* service = browser()->profile()->GetExtensionService();
318 service->ReloadExtension(extension_id); 319 service->ReloadExtension(extension_id);
319 ui_test_utils::RegisterAndWait(this, 320 ui_test_utils::RegisterAndWait(this,
320 chrome::NOTIFICATION_EXTENSION_LOADED, 321 chrome::NOTIFICATION_EXTENSION_LOADED,
321 content::NotificationService::AllSources()); 322 content::NotificationService::AllSources());
322 } 323 }
323 324
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 const content::NotificationSource& source, 431 const content::NotificationSource& source,
431 const content::NotificationDetails& details) { 432 const content::NotificationDetails& details) {
432 switch (type) { 433 switch (type) {
433 case chrome::NOTIFICATION_EXTENSION_LOADED: 434 case chrome::NOTIFICATION_EXTENSION_LOADED:
434 last_loaded_extension_id_ = 435 last_loaded_extension_id_ =
435 content::Details<const Extension>(details).ptr()->id(); 436 content::Details<const Extension>(details).ptr()->id();
436 VLOG(1) << "Got EXTENSION_LOADED notification."; 437 VLOG(1) << "Got EXTENSION_LOADED notification.";
437 MessageLoopForUI::current()->Quit(); 438 MessageLoopForUI::current()->Quit();
438 break; 439 break;
439 440
440 case chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED: 441 case chrome::NOTIFICATION_CRX_INSTALLER_DONE:
441 VLOG(1) << "Got EXTENSION_UPDATE_DISABLED notification."; 442 VLOG(1) << "Got CRX_INSTALLER_DONE notification.";
443 {
444 const Extension* extension =
445 content::Details<const Extension>(details).ptr();
446 if (extension)
447 last_loaded_extension_id_ = extension->id();
448 else
449 last_loaded_extension_id_ = "";
450 }
442 MessageLoopForUI::current()->Quit(); 451 MessageLoopForUI::current()->Quit();
443 break; 452 break;
444 453
445 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: 454 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
446 VLOG(1) << "Got EXTENSION_HOST_DID_STOP_LOADING notification."; 455 VLOG(1) << "Got EXTENSION_HOST_DID_STOP_LOADING notification.";
447 MessageLoopForUI::current()->Quit(); 456 MessageLoopForUI::current()->Quit();
448 break; 457 break;
449 458
450 case chrome::NOTIFICATION_EXTENSION_INSTALLED: 459 case chrome::NOTIFICATION_EXTENSION_INSTALLED:
451 VLOG(1) << "Got EXTENSION_INSTALLED notification."; 460 VLOG(1) << "Got EXTENSION_INSTALLED notification.";
452 ++extension_installs_observed_; 461 ++extension_installs_observed_;
453 MessageLoopForUI::current()->Quit(); 462 MessageLoopForUI::current()->Quit();
454 break; 463 break;
455 464
456 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR:
457 VLOG(1) << "Got EXTENSION_LOAD_ERROR notification.";
458 MessageLoopForUI::current()->Quit();
459 break;
460
461 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: 465 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR:
462 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; 466 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification.";
463 MessageLoopForUI::current()->Quit(); 467 MessageLoopForUI::current()->Quit();
464 break; 468 break;
465 469
466 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: 470 case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED:
467 VLOG(1) << "Got EXTENSION_PROCESS_TERMINATED notification."; 471 VLOG(1) << "Got EXTENSION_PROCESS_TERMINATED notification.";
468 MessageLoopForUI::current()->Quit(); 472 MessageLoopForUI::current()->Quit();
469 break; 473 break;
470 474
(...skipping 22 matching lines...) Expand all
493 MessageLoopForUI::current()->Quit(); 497 MessageLoopForUI::current()->Quit();
494 } 498 }
495 break; 499 break;
496 } 500 }
497 501
498 default: 502 default:
499 NOTREACHED(); 503 NOTREACHED();
500 break; 504 break;
501 } 505 }
502 } 506 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_management_api_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698