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

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

Issue 709813004: Remove the deprecated function ExtensionService::extensions(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed thestig@'s comments. Created 6 years, 1 month 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/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/common/chrome_version_info.h" 36 #include "chrome/common/chrome_version_info.h"
37 #include "content/public/browser/navigation_controller.h" 37 #include "content/public/browser/navigation_controller.h"
38 #include "content/public/browser/navigation_entry.h" 38 #include "content/public/browser/navigation_entry.h"
39 #include "content/public/browser/notification_registrar.h" 39 #include "content/public/browser/notification_registrar.h"
40 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
41 #include "content/public/browser/render_view_host.h" 41 #include "content/public/browser/render_view_host.h"
42 #include "content/public/test/browser_test_utils.h" 42 #include "content/public/test/browser_test_utils.h"
43 #include "content/public/test/test_utils.h" 43 #include "content/public/test/test_utils.h"
44 #include "extensions/browser/extension_host.h" 44 #include "extensions/browser/extension_host.h"
45 #include "extensions/browser/extension_prefs.h" 45 #include "extensions/browser/extension_prefs.h"
46 #include "extensions/browser/extension_registry.h"
46 #include "extensions/browser/extension_system.h" 47 #include "extensions/browser/extension_system.h"
47 #include "extensions/browser/notification_types.h" 48 #include "extensions/browser/notification_types.h"
48 #include "extensions/browser/uninstall_reason.h" 49 #include "extensions/browser/uninstall_reason.h"
49 #include "extensions/common/constants.h" 50 #include "extensions/common/constants.h"
50 #include "extensions/common/extension_set.h" 51 #include "extensions/common/extension_set.h"
51 #include "sync/api/string_ordinal.h" 52 #include "sync/api/string_ordinal.h"
52 53
53 #if defined(OS_CHROMEOS) 54 #if defined(OS_CHROMEOS)
54 #include "chromeos/chromeos_switches.h" 55 #include "chromeos/chromeos_switches.h"
55 #endif 56 #endif
56 57
57 using extensions::Extension; 58 using extensions::Extension;
58 using extensions::ExtensionCreator; 59 using extensions::ExtensionCreator;
60 using extensions::ExtensionRegistry;
59 using extensions::FeatureSwitch; 61 using extensions::FeatureSwitch;
60 using extensions::Manifest; 62 using extensions::Manifest;
61 63
62 ExtensionBrowserTest::ExtensionBrowserTest() 64 ExtensionBrowserTest::ExtensionBrowserTest()
63 : loaded_(false), 65 : loaded_(false),
64 installed_(false), 66 installed_(false),
65 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
66 set_chromeos_user_(true), 68 set_chromeos_user_(true),
67 #endif 69 #endif
68 // Default channel is STABLE but override with UNKNOWN so that unlaunched 70 // Default channel is STABLE but override with UNKNOWN so that unlaunched
(...skipping 21 matching lines...) Expand all
90 if (browser()) 92 if (browser())
91 profile_ = browser()->profile(); 93 profile_ = browser()->profile();
92 else 94 else
93 profile_ = ProfileManager::GetActiveUserProfile(); 95 profile_ = ProfileManager::GetActiveUserProfile();
94 } 96 }
95 return profile_; 97 return profile_;
96 } 98 }
97 99
98 // static 100 // static
99 const Extension* ExtensionBrowserTest::GetExtensionByPath( 101 const Extension* ExtensionBrowserTest::GetExtensionByPath(
100 const extensions::ExtensionSet* extensions, const base::FilePath& path) { 102 const extensions::ExtensionSet& extensions,
103 const base::FilePath& path) {
101 base::FilePath extension_path = base::MakeAbsoluteFilePath(path); 104 base::FilePath extension_path = base::MakeAbsoluteFilePath(path);
102 EXPECT_TRUE(!extension_path.empty()); 105 EXPECT_TRUE(!extension_path.empty());
103 for (extensions::ExtensionSet::const_iterator iter = extensions->begin(); 106 for (const scoped_refptr<const Extension>& extension : extensions) {
104 iter != extensions->end(); ++iter) { 107 if (extension->path() == extension_path) {
105 if ((*iter)->path() == extension_path) { 108 return extension.get();
106 return iter->get();
107 } 109 }
108 } 110 }
109 return NULL; 111 return NULL;
110 } 112 }
111 113
112 void ExtensionBrowserTest::SetUp() { 114 void ExtensionBrowserTest::SetUp() {
113 test_extension_cache_.reset(new extensions::ExtensionCacheFake()); 115 test_extension_cache_.reset(new extensions::ExtensionCacheFake());
114 InProcessBrowserTest::SetUp(); 116 InProcessBrowserTest::SetUp();
115 } 117 }
116 118
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 return LoadExtensionWithInstallParam(path, flags, std::string()); 158 return LoadExtensionWithInstallParam(path, flags, std::string());
157 } 159 }
158 160
159 const extensions::Extension* 161 const extensions::Extension*
160 ExtensionBrowserTest::LoadExtensionWithInstallParam( 162 ExtensionBrowserTest::LoadExtensionWithInstallParam(
161 const base::FilePath& path, 163 const base::FilePath& path,
162 int flags, 164 int flags,
163 const std::string& install_param) { 165 const std::string& install_param) {
164 ExtensionService* service = extensions::ExtensionSystem::Get( 166 ExtensionService* service = extensions::ExtensionSystem::Get(
165 profile())->extension_service(); 167 profile())->extension_service();
168 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
166 { 169 {
167 observer_->Watch(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 170 observer_->Watch(extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
168 content::NotificationService::AllSources()); 171 content::NotificationService::AllSources());
169 172
170 scoped_refptr<extensions::UnpackedInstaller> installer( 173 scoped_refptr<extensions::UnpackedInstaller> installer(
171 extensions::UnpackedInstaller::Create(service)); 174 extensions::UnpackedInstaller::Create(service));
172 installer->set_prompt_for_plugins(false); 175 installer->set_prompt_for_plugins(false);
173 installer->set_require_modern_manifest_version( 176 installer->set_require_modern_manifest_version(
174 (flags & kFlagAllowOldManifestVersions) == 0); 177 (flags & kFlagAllowOldManifestVersions) == 0);
175 installer->Load(path); 178 installer->Load(path);
176 179
177 observer_->Wait(); 180 observer_->Wait();
178 } 181 }
179 182
180 // Find the loaded extension by its path. See crbug.com/59531 for why 183 // Find the loaded extension by its path. See crbug.com/59531 for why
181 // we cannot just use last_loaded_extension_id(). 184 // we cannot just use last_loaded_extension_id().
182 const Extension* extension = GetExtensionByPath(service->extensions(), path); 185 const Extension* extension =
186 GetExtensionByPath(registry->enabled_extensions(), path);
183 if (!extension) 187 if (!extension)
184 return NULL; 188 return NULL;
185 189
186 if (!(flags & kFlagIgnoreManifestWarnings)) { 190 if (!(flags & kFlagIgnoreManifestWarnings)) {
187 const std::vector<extensions::InstallWarning>& install_warnings = 191 const std::vector<extensions::InstallWarning>& install_warnings =
188 extension->install_warnings(); 192 extension->install_warnings();
189 if (!install_warnings.empty()) { 193 if (!install_warnings.empty()) {
190 std::string install_warnings_message = base::StringPrintf( 194 std::string install_warnings_message = base::StringPrintf(
191 "Unexpected warnings when loading test extension %s:\n", 195 "Unexpected warnings when loading test extension %s:\n",
192 path.AsUTF8Unsafe().c_str()); 196 path.AsUTF8Unsafe().c_str());
193 197
194 for (std::vector<extensions::InstallWarning>::const_iterator it = 198 for (std::vector<extensions::InstallWarning>::const_iterator it =
195 install_warnings.begin(); it != install_warnings.end(); ++it) { 199 install_warnings.begin(); it != install_warnings.end(); ++it) {
196 install_warnings_message += " " + it->message + "\n"; 200 install_warnings_message += " " + it->message + "\n";
197 } 201 }
198 202
199 EXPECT_EQ(0u, extension->install_warnings().size()) 203 EXPECT_EQ(0u, extension->install_warnings().size())
200 << install_warnings_message; 204 << install_warnings_message;
201 return NULL; 205 return NULL;
202 } 206 }
203 } 207 }
204 208
205 const std::string extension_id = extension->id(); 209 const std::string extension_id = extension->id();
206 210
207 if (!install_param.empty()) { 211 if (!install_param.empty()) {
208 extensions::ExtensionPrefs::Get(profile()) 212 extensions::ExtensionPrefs::Get(profile())
209 ->SetInstallParam(extension_id, install_param); 213 ->SetInstallParam(extension_id, install_param);
210 // Re-enable the extension if needed. 214 // Re-enable the extension if needed.
211 if (service->extensions()->Contains(extension_id)) { 215 if (registry->enabled_extensions().Contains(extension_id)) {
212 content::WindowedNotificationObserver load_signal( 216 content::WindowedNotificationObserver load_signal(
213 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 217 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
214 content::Source<Profile>(profile())); 218 content::Source<Profile>(profile()));
215 // Reload the extension so that the 219 // Reload the extension so that the
216 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED 220 // NOTIFICATION_EXTENSION_LOADED_DEPRECATED
217 // observers may access |install_param|. 221 // observers may access |install_param|.
218 service->ReloadExtension(extension_id); 222 service->ReloadExtension(extension_id);
219 load_signal.Wait(); 223 load_signal.Wait();
220 extension = service->GetExtensionById(extension_id, false); 224 extension = service->GetExtensionById(extension_id, false);
221 CHECK(extension) << extension_id << " not found after reloading."; 225 CHECK(extension) << extension_id << " not found after reloading.";
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 return NULL; 261 return NULL;
258 262
259 return extension; 263 return extension;
260 } 264 }
261 265
262 const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest( 266 const Extension* ExtensionBrowserTest::LoadExtensionAsComponentWithManifest(
263 const base::FilePath& path, 267 const base::FilePath& path,
264 const base::FilePath::CharType* manifest_relative_path) { 268 const base::FilePath::CharType* manifest_relative_path) {
265 ExtensionService* service = extensions::ExtensionSystem::Get( 269 ExtensionService* service = extensions::ExtensionSystem::Get(
266 profile())->extension_service(); 270 profile())->extension_service();
271 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
267 272
268 std::string manifest; 273 std::string manifest;
269 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) { 274 if (!base::ReadFileToString(path.Append(manifest_relative_path), &manifest)) {
270 return NULL; 275 return NULL;
271 } 276 }
272 277
273 std::string extension_id = service->component_loader()->Add(manifest, path); 278 std::string extension_id = service->component_loader()->Add(manifest, path);
274 const Extension* extension = service->extensions()->GetByID(extension_id); 279 const Extension* extension =
280 registry->enabled_extensions().GetByID(extension_id);
275 if (!extension) 281 if (!extension)
276 return NULL; 282 return NULL;
277 observer_->set_last_loaded_extension_id(extension->id()); 283 observer_->set_last_loaded_extension_id(extension->id());
278 return extension; 284 return extension;
279 } 285 }
280 286
281 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent( 287 const Extension* ExtensionBrowserTest::LoadExtensionAsComponent(
282 const base::FilePath& path) { 288 const base::FilePath& path) {
283 return LoadExtensionAsComponentWithManifest(path, 289 return LoadExtensionAsComponentWithManifest(path,
284 extensions::kManifestFilename); 290 extensions::kManifestFilename);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 const base::FilePath& path, 466 const base::FilePath& path,
461 InstallUIType ui_type, 467 InstallUIType ui_type,
462 int expected_change, 468 int expected_change,
463 Manifest::Location install_source, 469 Manifest::Location install_source,
464 Browser* browser, 470 Browser* browser,
465 Extension::InitFromValueFlags creation_flags, 471 Extension::InitFromValueFlags creation_flags,
466 bool install_immediately, 472 bool install_immediately,
467 bool is_ephemeral) { 473 bool is_ephemeral) {
468 ExtensionService* service = 474 ExtensionService* service =
469 extensions::ExtensionSystem::Get(profile())->extension_service(); 475 extensions::ExtensionSystem::Get(profile())->extension_service();
476 ExtensionRegistry* registry = ExtensionRegistry::Get(profile());
470 service->set_show_extensions_prompts(false); 477 service->set_show_extensions_prompts(false);
471 size_t num_before = service->extensions()->size(); 478 size_t num_before = registry->enabled_extensions().size();
472 479
473 { 480 {
474 scoped_ptr<ExtensionInstallPrompt> install_ui; 481 scoped_ptr<ExtensionInstallPrompt> install_ui;
475 if (ui_type == INSTALL_UI_TYPE_CANCEL) { 482 if (ui_type == INSTALL_UI_TYPE_CANCEL) {
476 install_ui.reset(new MockAbortExtensionInstallPrompt()); 483 install_ui.reset(new MockAbortExtensionInstallPrompt());
477 } else if (ui_type == INSTALL_UI_TYPE_NORMAL) { 484 } else if (ui_type == INSTALL_UI_TYPE_NORMAL) {
478 install_ui.reset(new ExtensionInstallPrompt( 485 install_ui.reset(new ExtensionInstallPrompt(
479 browser->tab_strip_model()->GetActiveWebContents())); 486 browser->tab_strip_model()->GetActiveWebContents()));
480 } else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) { 487 } else if (ui_type == INSTALL_UI_TYPE_AUTO_CONFIRM) {
481 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt( 488 install_ui.reset(new MockAutoConfirmExtensionInstallPrompt(
(...skipping 23 matching lines...) Expand all
505 512
506 observer_->Watch( 513 observer_->Watch(
507 extensions::NOTIFICATION_CRX_INSTALLER_DONE, 514 extensions::NOTIFICATION_CRX_INSTALLER_DONE,
508 content::Source<extensions::CrxInstaller>(installer.get())); 515 content::Source<extensions::CrxInstaller>(installer.get()));
509 516
510 installer->InstallCrx(crx_path); 517 installer->InstallCrx(crx_path);
511 518
512 observer_->Wait(); 519 observer_->Wait();
513 } 520 }
514 521
515 size_t num_after = service->extensions()->size(); 522 size_t num_after = registry->enabled_extensions().size();
516 EXPECT_EQ(num_before + expected_change, num_after); 523 EXPECT_EQ(num_before + expected_change, num_after);
517 if (num_before + expected_change != num_after) { 524 if (num_before + expected_change != num_after) {
518 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) 525 VLOG(1) << "Num extensions before: " << base::IntToString(num_before)
519 << " num after: " << base::IntToString(num_after) 526 << " num after: " << base::IntToString(num_after)
520 << " Installed extensions follow:"; 527 << " Installed extensions follow:";
521 528
522 for (extensions::ExtensionSet::const_iterator it = 529 for (const scoped_refptr<const Extension>& extension :
523 service->extensions()->begin(); 530 registry->enabled_extensions())
524 it != service->extensions()->end(); ++it) 531 VLOG(1) << " " << extension->id();
525 VLOG(1) << " " << (*it)->id();
526 532
527 VLOG(1) << "Errors follow:"; 533 VLOG(1) << "Errors follow:";
528 const std::vector<base::string16>* errors = 534 const std::vector<base::string16>* errors =
529 ExtensionErrorReporter::GetInstance()->GetErrors(); 535 ExtensionErrorReporter::GetInstance()->GetErrors();
530 for (std::vector<base::string16>::const_iterator iter = errors->begin(); 536 for (std::vector<base::string16>::const_iterator iter = errors->begin();
531 iter != errors->end(); ++iter) 537 iter != errors->end(); ++iter)
532 VLOG(1) << *iter; 538 VLOG(1) << *iter;
533 539
534 return NULL; 540 return NULL;
535 } 541 }
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( 660 return extensions::browsertest_util::ExecuteScriptInBackgroundPage(
655 profile(), extension_id, script); 661 profile(), extension_id, script);
656 } 662 }
657 663
658 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( 664 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait(
659 const std::string& extension_id, 665 const std::string& extension_id,
660 const std::string& script) { 666 const std::string& script) {
661 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( 667 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait(
662 profile(), extension_id, script); 668 profile(), extension_id, script);
663 } 669 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.h ('k') | chrome/browser/extensions/extension_functional_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698