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

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

Issue 8417012: Refactor loading out of ExtensionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: finally Created 9 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 | 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"
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/component_loader.h"
15 #include "chrome/browser/extensions/crx_installer.h" 16 #include "chrome/browser/extensions/crx_installer.h"
16 #include "chrome/browser/extensions/extension_creator.h" 17 #include "chrome/browser/extensions/extension_creator.h"
17 #include "chrome/browser/extensions/extension_error_reporter.h" 18 #include "chrome/browser/extensions/extension_error_reporter.h"
18 #include "chrome/browser/extensions/extension_host.h" 19 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/extensions/extension_install_ui.h" 20 #include "chrome/browser/extensions/extension_install_ui.h"
20 #include "chrome/browser/extensions/extension_service.h" 21 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/unpacked_installer.h"
21 #include "chrome/browser/profiles/profile.h" 23 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_window.h" 25 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/omnibox/location_bar.h" 26 #include "chrome/browser/ui/omnibox/location_bar.h"
25 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
26 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
28 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
29 #include "content/public/browser/notification_registrar.h" 31 #include "content/public/browser/notification_registrar.h"
30 #include "content/public/browser/notification_service.h" 32 #include "content/public/browser/notification_service.h"
(...skipping 28 matching lines...) Expand all
59 #endif 61 #endif
60 } 62 }
61 63
62 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions( 64 const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
63 const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) { 65 const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) {
64 ExtensionService* service = browser()->profile()->GetExtensionService(); 66 ExtensionService* service = browser()->profile()->GetExtensionService();
65 { 67 {
66 content::NotificationRegistrar registrar; 68 content::NotificationRegistrar registrar;
67 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 69 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
68 content::NotificationService::AllSources()); 70 content::NotificationService::AllSources());
69 service->LoadExtension(path, false); 71 scoped_refptr<extensions::UnpackedInstaller> installer(
72 extensions::UnpackedInstaller::Create(service));
73 installer->set_prompt_for_plugins(false);
74 installer->Load(path);
70 ui_test_utils::RunMessageLoop(); 75 ui_test_utils::RunMessageLoop();
71 } 76 }
72 77
73 // Find the extension by iterating backwards since it is likely last. 78 // Find the extension by iterating backwards since it is likely last.
74 FilePath extension_path = path; 79 FilePath extension_path = path;
75 file_util::AbsolutePath(&extension_path); 80 file_util::AbsolutePath(&extension_path);
76 const Extension* extension = NULL; 81 const Extension* extension = NULL;
77 for (ExtensionList::const_reverse_iterator iter = 82 for (ExtensionList::const_reverse_iterator iter =
78 service->extensions()->rbegin(); 83 service->extensions()->rbegin();
79 iter != service->extensions()->rend(); ++iter) { 84 iter != service->extensions()->rend(); ++iter) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 145 }
141 146
142 bool ExtensionBrowserTest::LoadExtensionAsComponent(const FilePath& path) { 147 bool ExtensionBrowserTest::LoadExtensionAsComponent(const FilePath& path) {
143 ExtensionService* service = browser()->profile()->GetExtensionService(); 148 ExtensionService* service = browser()->profile()->GetExtensionService();
144 149
145 std::string manifest; 150 std::string manifest;
146 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename), 151 if (!file_util::ReadFileToString(path.Append(Extension::kManifestFilename),
147 &manifest)) 152 &manifest))
148 return false; 153 return false;
149 154
150 service->LoadComponentExtension( 155 service->component_loader()->Add(manifest, path);
151 ExtensionService::ComponentExtensionInfo(manifest, path));
152 156
153 return true; 157 return true;
154 } 158 }
155 159
156 FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) { 160 FilePath ExtensionBrowserTest::PackExtension(const FilePath& dir_path) {
157 FilePath crx_path = temp_dir_.path().AppendASCII("temp.crx"); 161 FilePath crx_path = temp_dir_.path().AppendASCII("temp.crx");
158 if (!file_util::Delete(crx_path, false)) { 162 if (!file_util::Delete(crx_path, false)) {
159 ADD_FAILURE() << "Failed to delete crx: " << crx_path.value(); 163 ADD_FAILURE() << "Failed to delete crx: " << crx_path.value();
160 return FilePath(); 164 return FilePath();
161 } 165 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // TODO(tessamac): Update callers to always pass an unpacked extension 266 // TODO(tessamac): Update callers to always pass an unpacked extension
263 // and then always pack the extension here. 267 // and then always pack the extension here.
264 FilePath crx_path = path; 268 FilePath crx_path = path;
265 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) { 269 if (crx_path.Extension() != FILE_PATH_LITERAL(".crx")) {
266 crx_path = PackExtension(path); 270 crx_path = PackExtension(path);
267 } 271 }
268 if (crx_path.empty()) 272 if (crx_path.empty())
269 return false; 273 return false;
270 274
271 scoped_refptr<CrxInstaller> installer( 275 scoped_refptr<CrxInstaller> installer(
272 service->MakeCrxInstaller(install_ui)); 276 CrxInstaller::Create(service, install_ui));
273 installer->set_expected_id(id); 277 installer->set_expected_id(id);
274 installer->set_is_gallery_install(from_webstore); 278 installer->set_is_gallery_install(from_webstore);
275 installer->InstallCrx(crx_path); 279 installer->InstallCrx(crx_path);
276 280
277 ui_test_utils::RunMessageLoop(); 281 ui_test_utils::RunMessageLoop();
278 } 282 }
279 283
280 size_t num_after = service->extensions()->size(); 284 size_t num_after = service->extensions()->size();
281 if (num_after != (num_before + expected_change)) { 285 if (num_after != (num_before + expected_change)) {
282 VLOG(1) << "Num extensions before: " << base::IntToString(num_before) 286 VLOG(1) << "Num extensions before: " << base::IntToString(num_before)
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 MessageLoopForUI::current()->Quit(); 488 MessageLoopForUI::current()->Quit();
485 } 489 }
486 break; 490 break;
487 } 491 }
488 492
489 default: 493 default:
490 NOTREACHED(); 494 NOTREACHED();
491 break; 495 break;
492 } 496 }
493 } 497 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer_browsertest.cc ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698