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

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

Issue 10113005: Remove EPM:all_hosts_ and use all_extension_views_ instead. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comments addressed Created 8 years, 8 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"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "chrome/browser/extensions/app_shortcut_manager.h" 15 #include "chrome/browser/extensions/app_shortcut_manager.h"
16 #include "chrome/browser/extensions/component_loader.h" 16 #include "chrome/browser/extensions/component_loader.h"
17 #include "chrome/browser/extensions/crx_installer.h" 17 #include "chrome/browser/extensions/crx_installer.h"
18 #include "chrome/browser/extensions/extension_creator.h" 18 #include "chrome/browser/extensions/extension_creator.h"
19 #include "chrome/browser/extensions/extension_error_reporter.h" 19 #include "chrome/browser/extensions/extension_error_reporter.h"
20 #include "chrome/browser/extensions/extension_host.h"
21 #include "chrome/browser/extensions/extension_install_ui.h" 20 #include "chrome/browser/extensions/extension_install_ui.h"
22 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/extensions/unpacked_installer.h" 22 #include "chrome/browser/extensions/unpacked_installer.h"
24 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/omnibox/location_bar.h" 26 #include "chrome/browser/ui/omnibox/location_bar.h"
28 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
29 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
32 #include "content/public/browser/notification_registrar.h" 31 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/render_view_host.h"
34 34
35 ExtensionBrowserTest::ExtensionBrowserTest() 35 ExtensionBrowserTest::ExtensionBrowserTest()
36 : loaded_(false), 36 : loaded_(false),
37 installed_(false), 37 installed_(false),
38 extension_installs_observed_(0), 38 extension_installs_observed_(0),
39 extension_load_errors_observed_(0), 39 extension_load_errors_observed_(0),
40 target_page_action_count_(-1), 40 target_page_action_count_(-1),
41 target_visible_page_action_count_(-1) { 41 target_visible_page_action_count_(-1) {
42 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); 42 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
43 AppShortcutManager::SetShortcutCreationDisabledForTesting(true); 43 AppShortcutManager::SetShortcutCreationDisabledForTesting(true);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 CHECK(service->AllowFileAccess(extension)); 127 CHECK(service->AllowFileAccess(extension));
128 128
129 if (!fileaccess_enabled) { 129 if (!fileaccess_enabled) {
130 service->SetAllowFileAccess(extension, fileaccess_enabled); 130 service->SetAllowFileAccess(extension, fileaccess_enabled);
131 load_signal.Wait(); 131 load_signal.Wait();
132 extension = service->GetExtensionById(extension_id, false); 132 extension = service->GetExtensionById(extension_id, false);
133 CHECK(extension) << extension_id << " not found after reloading."; 133 CHECK(extension) << extension_id << " not found after reloading.";
134 } 134 }
135 } 135 }
136 136
137 if (!WaitForExtensionHostsToLoad()) 137 if (!WaitForExtensionViewsToLoad())
138 return NULL; 138 return NULL;
139 139
140 return extension; 140 return extension;
141 } 141 }
142 142
143 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { 143 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) {
144 return LoadExtensionWithOptions(path, false, true); 144 return LoadExtensionWithOptions(path, false, true);
145 } 145 }
146 146
147 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( 147 const Extension* ExtensionBrowserTest::LoadExtensionIncognito(
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 VLOG(1) << "Errors follow:"; 323 VLOG(1) << "Errors follow:";
324 const std::vector<string16>* errors = 324 const std::vector<string16>* errors =
325 ExtensionErrorReporter::GetInstance()->GetErrors(); 325 ExtensionErrorReporter::GetInstance()->GetErrors();
326 for (std::vector<string16>::const_iterator iter = errors->begin(); 326 for (std::vector<string16>::const_iterator iter = errors->begin();
327 iter != errors->end(); ++iter) 327 iter != errors->end(); ++iter)
328 VLOG(1) << *iter; 328 VLOG(1) << *iter;
329 329
330 return NULL; 330 return NULL;
331 } 331 }
332 332
333 if (!WaitForExtensionHostsToLoad()) 333 if (!WaitForExtensionViewsToLoad())
334 return NULL; 334 return NULL;
335 return service->GetExtensionById(last_loaded_extension_id_, false); 335 return service->GetExtensionById(last_loaded_extension_id_, false);
336 } 336 }
337 337
338 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) { 338 void ExtensionBrowserTest::ReloadExtension(const std::string& extension_id) {
339 ExtensionService* service = browser()->profile()->GetExtensionService(); 339 ExtensionService* service = browser()->profile()->GetExtensionService();
340 service->ReloadExtension(extension_id); 340 service->ReloadExtension(extension_id);
341 ui_test_utils::RegisterAndWait(this, 341 ui_test_utils::RegisterAndWait(this,
342 chrome::NOTIFICATION_EXTENSION_LOADED, 342 chrome::NOTIFICATION_EXTENSION_LOADED,
343 content::NotificationService::AllSources()); 343 content::NotificationService::AllSources());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); 380 browser()->window()->GetLocationBar()->GetLocationBarForTesting();
381 if (location_bar->PageActionVisibleCount() != count) { 381 if (location_bar->PageActionVisibleCount() != count) {
382 target_visible_page_action_count_ = count; 382 target_visible_page_action_count_ = count;
383 ui_test_utils::RegisterAndWait(this, 383 ui_test_utils::RegisterAndWait(this,
384 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 384 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
385 content::NotificationService::AllSources()); 385 content::NotificationService::AllSources());
386 } 386 }
387 return location_bar->PageActionVisibleCount() == count; 387 return location_bar->PageActionVisibleCount() == count;
388 } 388 }
389 389
390 bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() { 390 bool ExtensionBrowserTest::WaitForExtensionViewsToLoad() {
391 // Wait for all the extension hosts that exist to finish loading. 391 // Wait for all the extension render view hosts that exist to finish loading.
392 content::NotificationRegistrar registrar; 392 content::NotificationRegistrar registrar;
393 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 393 registrar.Add(this, content::NOTIFICATION_LOAD_STOP,
394 content::NotificationService::AllSources()); 394 content::NotificationService::AllSources());
395 395
396 ExtensionProcessManager* manager = 396 ExtensionProcessManager* manager =
397 browser()->profile()->GetExtensionProcessManager(); 397 browser()->profile()->GetExtensionProcessManager();
398 for (ExtensionProcessManager::const_iterator iter = manager->begin(); 398 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews();
399 iter != manager->end();) { 399 for (ExtensionProcessManager::ViewSet::const_iterator iter =
400 if ((*iter)->did_stop_loading()) { 400 all_views.begin();
401 iter != all_views.end();) {
402 if (!(*iter)->IsLoading()) {
401 ++iter; 403 ++iter;
402 } else { 404 } else {
403 ui_test_utils::RunMessageLoop(); 405 ui_test_utils::RunMessageLoop();
404 406
405 // Test activity may have modified the set of extension processes during 407 // Test activity may have modified the set of extension processes during
406 // message processing, so re-start the iteration to catch added/removed 408 // message processing, so re-start the iteration to catch added/removed
407 // processes. 409 // processes.
408 iter = manager->begin(); 410 all_views = manager->GetAllViews();
411 iter = all_views.begin();
409 } 412 }
410 } 413 }
411 return true; 414 return true;
412 } 415 }
413 416
414 bool ExtensionBrowserTest::WaitForExtensionInstall() { 417 bool ExtensionBrowserTest::WaitForExtensionInstall() {
415 int before = extension_installs_observed_; 418 int before = extension_installs_observed_;
416 ui_test_utils::RegisterAndWait(this, 419 ui_test_utils::RegisterAndWait(this,
417 chrome::NOTIFICATION_EXTENSION_INSTALLED, 420 chrome::NOTIFICATION_EXTENSION_INSTALLED,
418 content::NotificationService::AllSources()); 421 content::NotificationService::AllSources());
419 return extension_installs_observed_ == (before + 1); 422 return extension_installs_observed_ == (before + 1);
420 } 423 }
421 424
422 bool ExtensionBrowserTest::WaitForExtensionInstallError() { 425 bool ExtensionBrowserTest::WaitForExtensionInstallError() {
423 int before = extension_installs_observed_; 426 int before = extension_installs_observed_;
424 ui_test_utils::RegisterAndWait(this, 427 ui_test_utils::RegisterAndWait(this,
425 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR, 428 chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR,
426 content::NotificationService::AllSources()); 429 content::NotificationService::AllSources());
427 return extension_installs_observed_ == before; 430 return extension_installs_observed_ == before;
428 } 431 }
429 432
430 void ExtensionBrowserTest::WaitForExtensionLoad() { 433 void ExtensionBrowserTest::WaitForExtensionLoad() {
431 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED, 434 ui_test_utils::RegisterAndWait(this, chrome::NOTIFICATION_EXTENSION_LOADED,
432 content::NotificationService::AllSources()); 435 content::NotificationService::AllSources());
433 WaitForExtensionHostsToLoad(); 436 WaitForExtensionViewsToLoad();
434 } 437 }
435 438
436 bool ExtensionBrowserTest::WaitForExtensionLoadError() { 439 bool ExtensionBrowserTest::WaitForExtensionLoadError() {
437 int before = extension_load_errors_observed_; 440 int before = extension_load_errors_observed_;
438 ui_test_utils::RegisterAndWait(this, 441 ui_test_utils::RegisterAndWait(this,
439 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, 442 chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
440 content::NotificationService::AllSources()); 443 content::NotificationService::AllSources());
441 return extension_load_errors_observed_ != before; 444 return extension_load_errors_observed_ != before;
442 } 445 }
443 446
(...skipping 29 matching lines...) Expand all
473 const Extension* extension = 476 const Extension* extension =
474 content::Details<const Extension>(details).ptr(); 477 content::Details<const Extension>(details).ptr();
475 if (extension) 478 if (extension)
476 last_loaded_extension_id_ = extension->id(); 479 last_loaded_extension_id_ = extension->id();
477 else 480 else
478 last_loaded_extension_id_ = ""; 481 last_loaded_extension_id_ = "";
479 } 482 }
480 MessageLoopForUI::current()->Quit(); 483 MessageLoopForUI::current()->Quit();
481 break; 484 break;
482 485
483 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
484 VLOG(1) << "Got EXTENSION_HOST_DID_STOP_LOADING notification.";
485 MessageLoopForUI::current()->Quit();
486 break;
487
488 case chrome::NOTIFICATION_EXTENSION_INSTALLED: 486 case chrome::NOTIFICATION_EXTENSION_INSTALLED:
489 VLOG(1) << "Got EXTENSION_INSTALLED notification."; 487 VLOG(1) << "Got EXTENSION_INSTALLED notification.";
490 ++extension_installs_observed_; 488 ++extension_installs_observed_;
491 MessageLoopForUI::current()->Quit(); 489 MessageLoopForUI::current()->Quit();
492 break; 490 break;
493 491
494 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: 492 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR:
495 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification."; 493 VLOG(1) << "Got EXTENSION_INSTALL_ERROR notification.";
496 MessageLoopForUI::current()->Quit(); 494 MessageLoopForUI::current()->Quit();
497 break; 495 break;
(...skipping 29 matching lines...) Expand all
527 "Number of visible page actions: " 525 "Number of visible page actions: "
528 << location_bar->PageActionVisibleCount(); 526 << location_bar->PageActionVisibleCount();
529 if (location_bar->PageActionVisibleCount() == 527 if (location_bar->PageActionVisibleCount() ==
530 target_visible_page_action_count_) { 528 target_visible_page_action_count_) {
531 target_visible_page_action_count_ = -1; 529 target_visible_page_action_count_ = -1;
532 MessageLoopForUI::current()->Quit(); 530 MessageLoopForUI::current()->Quit();
533 } 531 }
534 break; 532 break;
535 } 533 }
536 534
535 case content::NOTIFICATION_LOAD_STOP:
536 VLOG(1) << "Got LOAD_STOP notification.";
537 MessageLoopForUI::current()->Quit();
538 break;
539
537 default: 540 default:
538 NOTREACHED(); 541 NOTREACHED();
539 break; 542 break;
540 } 543 }
541 } 544 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698