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

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

Issue 11190016: Do not add TabContents from packaged apps to the task manager. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 8 years, 2 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::LoadExtensionWithFlags( 77 const Extension* ExtensionBrowserTest::LoadExtensionWithFlags(
78 Browser* browser, NotificationObserver* observer,
78 const FilePath& path, int flags) { 79 const FilePath& path, int flags) {
79 ExtensionService* service = browser()->profile()->GetExtensionService(); 80 ExtensionService* service = browser->profile()->GetExtensionService();
80 { 81 {
81 content::NotificationRegistrar registrar; 82 content::NotificationRegistrar registrar;
82 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 83 registrar.Add(observer, chrome::NOTIFICATION_EXTENSION_LOADED,
83 content::NotificationService::AllSources()); 84 content::NotificationService::AllSources());
84 scoped_refptr<extensions::UnpackedInstaller> installer( 85 scoped_refptr<extensions::UnpackedInstaller> installer(
85 extensions::UnpackedInstaller::Create(service)); 86 extensions::UnpackedInstaller::Create(service));
86 installer->set_prompt_for_plugins(false); 87 installer->set_prompt_for_plugins(false);
87 installer->set_require_modern_manifest_version( 88 installer->set_require_modern_manifest_version(
88 (flags & kFlagAllowOldManifestVersions) == 0); 89 (flags & kFlagAllowOldManifestVersions) == 0);
89 installer->Load(path); 90 installer->Load(path);
90 content::RunMessageLoop(); 91 content::RunMessageLoop();
91 } 92 }
92 93
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 extension, Extension::ENABLED, 133 extension, Extension::ENABLED,
133 syncer::StringOrdinal::CreateInitialOrdinal()); 134 syncer::StringOrdinal::CreateInitialOrdinal());
134 135
135 // Toggling incognito or file access will reload the extension, so wait for 136 // Toggling incognito or file access will reload the extension, so wait for
136 // the reload and grab the new extension instance. The default state is 137 // the reload and grab the new extension instance. The default state is
137 // incognito disabled and file access enabled, so we don't wait in those 138 // incognito disabled and file access enabled, so we don't wait in those
138 // cases. 139 // cases.
139 { 140 {
140 content::WindowedNotificationObserver load_signal( 141 content::WindowedNotificationObserver load_signal(
141 chrome::NOTIFICATION_EXTENSION_LOADED, 142 chrome::NOTIFICATION_EXTENSION_LOADED,
142 content::Source<Profile>(browser()->profile())); 143 content::Source<Profile>(browser->profile()));
143 CHECK(!service->IsIncognitoEnabled(extension_id)); 144 CHECK(!service->IsIncognitoEnabled(extension_id));
144 145
145 if (flags & kFlagEnableIncognito) { 146 if (flags & kFlagEnableIncognito) {
146 service->SetIsIncognitoEnabled(extension_id, true); 147 service->SetIsIncognitoEnabled(extension_id, true);
147 load_signal.Wait(); 148 load_signal.Wait();
148 extension = service->GetExtensionById(extension_id, false); 149 extension = service->GetExtensionById(extension_id, false);
149 CHECK(extension) << extension_id << " not found after reloading."; 150 CHECK(extension) << extension_id << " not found after reloading.";
150 } 151 }
151 } 152 }
152 153
153 { 154 {
154 content::WindowedNotificationObserver load_signal( 155 content::WindowedNotificationObserver load_signal(
155 chrome::NOTIFICATION_EXTENSION_LOADED, 156 chrome::NOTIFICATION_EXTENSION_LOADED,
156 content::Source<Profile>(browser()->profile())); 157 content::Source<Profile>(browser->profile()));
157 CHECK(service->AllowFileAccess(extension)); 158 CHECK(service->AllowFileAccess(extension));
158 if (!(flags & kFlagEnableFileAccess)) { 159 if (!(flags & kFlagEnableFileAccess)) {
159 service->SetAllowFileAccess(extension, false); 160 service->SetAllowFileAccess(extension, false);
160 load_signal.Wait(); 161 load_signal.Wait();
161 extension = service->GetExtensionById(extension_id, false); 162 extension = service->GetExtensionById(extension_id, false);
162 CHECK(extension) << extension_id << " not found after reloading."; 163 CHECK(extension) << extension_id << " not found after reloading.";
163 } 164 }
164 } 165 }
165 166
166 if (!WaitForExtensionViewsToLoad()) 167 if (!WaitForExtensionViewsToLoad(browser, observer))
167 return NULL; 168 return NULL;
168 169
169 return extension; 170 return extension;
170 } 171 }
171 172
172 const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) { 173 const Extension* ExtensionBrowserTest::LoadExtension(
173 return LoadExtensionWithFlags(path, kFlagEnableFileAccess); 174 Browser* browser, NotificationObserver* observer, const FilePath& path) {
175 return LoadExtensionWithFlags(browser, observer, path, kFlagEnableFileAccess);
174 } 176 }
175 177
176 const Extension* ExtensionBrowserTest::LoadExtensionIncognito( 178 const Extension* ExtensionBrowserTest::LoadExtensionIncognito(
177 const FilePath& path) { 179 const FilePath& path) {
178 return LoadExtensionWithFlags(path, 180 return LoadExtensionWithFlags(path,
179 kFlagEnableFileAccess | kFlagEnableIncognito); 181 kFlagEnableFileAccess | kFlagEnableIncognito);
180 } 182 }
181 183
182 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( 184 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent(
183 const FilePath& path) { 185 const FilePath& path) {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 browser()->window()->GetLocationBar()->GetLocationBarForTesting(); 448 browser()->window()->GetLocationBar()->GetLocationBarForTesting();
447 if (location_bar->PageActionVisibleCount() != count) { 449 if (location_bar->PageActionVisibleCount() != count) {
448 target_visible_page_action_count_ = count; 450 target_visible_page_action_count_ = count;
449 ui_test_utils::RegisterAndWait(this, 451 ui_test_utils::RegisterAndWait(this,
450 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 452 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
451 content::NotificationService::AllSources()); 453 content::NotificationService::AllSources());
452 } 454 }
453 return location_bar->PageActionVisibleCount() == count; 455 return location_bar->PageActionVisibleCount() == count;
454 } 456 }
455 457
456 bool ExtensionBrowserTest::WaitForExtensionViewsToLoad() { 458 bool ExtensionBrowserTest::WaitForExtensionViewsToLoad(
459 Browser* browser, NotificationObserver* observer) {
457 // Wait for all the extension render view hosts that exist to finish loading. 460 // Wait for all the extension render view hosts that exist to finish loading.
458 content::NotificationRegistrar registrar; 461 content::NotificationRegistrar registrar;
459 registrar.Add(this, content::NOTIFICATION_LOAD_STOP, 462 registrar.Add(observer, content::NOTIFICATION_LOAD_STOP,
460 content::NotificationService::AllSources()); 463 content::NotificationService::AllSources());
461 464
462 ExtensionProcessManager* manager = 465 ExtensionProcessManager* manager =
463 browser()->profile()->GetExtensionProcessManager(); 466 browser->profile()->GetExtensionProcessManager();
464 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); 467 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews();
465 for (ExtensionProcessManager::ViewSet::const_iterator iter = 468 for (ExtensionProcessManager::ViewSet::const_iterator iter =
466 all_views.begin(); 469 all_views.begin();
467 iter != all_views.end();) { 470 iter != all_views.end();) {
468 if (!(*iter)->IsLoading()) { 471 if (!(*iter)->IsLoading()) {
469 ++iter; 472 ++iter;
470 } else { 473 } else {
471 content::RunMessageLoop(); 474 content::RunMessageLoop();
472 475
473 // Test activity may have modified the set of extension processes during 476 // Test activity may have modified the set of extension processes during
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 case content::NOTIFICATION_LOAD_STOP: 680 case content::NOTIFICATION_LOAD_STOP:
678 VLOG(1) << "Got LOAD_STOP notification."; 681 VLOG(1) << "Got LOAD_STOP notification.";
679 MessageLoopForUI::current()->Quit(); 682 MessageLoopForUI::current()->Quit();
680 break; 683 break;
681 684
682 default: 685 default:
683 NOTREACHED(); 686 NOTREACHED();
684 break; 687 break;
685 } 688 }
686 } 689 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/platform_app_browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698