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

Side by Side Diff: chrome/browser/extensions/extension_apitest.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_apitest.h" 5 #include "chrome/browser/extensions/extension_apitest.h"
6 6
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/unpacked_installer.h" 11 #include "chrome/browser/extensions/unpacked_installer.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/extensions/application_launch.h" 14 #include "chrome/browser/ui/extensions/application_launch.h"
15 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "extensions/browser/api/test/test_api.h" 16 #include "extensions/browser/api/test/test_api.h"
17 #include "extensions/browser/extension_registry.h"
17 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
18 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
19 #include "extensions/common/extension_set.h" 20 #include "extensions/common/extension_set.h"
20 #include "extensions/test/result_catcher.h" 21 #include "extensions/test/result_catcher.h"
21 #include "net/base/escape.h" 22 #include "net/base/escape.h"
22 #include "net/base/filename_util.h" 23 #include "net/base/filename_util.h"
23 #include "net/test/embedded_test_server/embedded_test_server.h" 24 #include "net/test/embedded_test_server/embedded_test_server.h"
24 #include "net/test/embedded_test_server/http_request.h" 25 #include "net/test/embedded_test_server/http_request.h"
25 #include "net/test/embedded_test_server/http_response.h" 26 #include "net/test/embedded_test_server/http_response.h"
26 #include "net/test/spawned_test_server/spawned_test_server.h" 27 #include "net/test/spawned_test_server/spawned_test_server.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 if (!catcher.GetNextResult()) { 319 if (!catcher.GetNextResult()) {
319 message_ = catcher.message(); 320 message_ = catcher.message();
320 return false; 321 return false;
321 } 322 }
322 323
323 return true; 324 return true;
324 } 325 }
325 326
326 // Test that exactly one extension is loaded, and return it. 327 // Test that exactly one extension is loaded, and return it.
327 const extensions::Extension* ExtensionApiTest::GetSingleLoadedExtension() { 328 const extensions::Extension* ExtensionApiTest::GetSingleLoadedExtension() {
328 ExtensionService* service = extensions::ExtensionSystem::Get( 329 extensions::ExtensionRegistry* registry =
329 browser()->profile())->extension_service(); 330 extensions::ExtensionRegistry::Get(browser()->profile());
330 331
331 const extensions::Extension* extension = NULL; 332 const extensions::Extension* result = NULL;
332 for (extensions::ExtensionSet::const_iterator it = 333 for (const scoped_refptr<const extensions::Extension>& extension :
333 service->extensions()->begin(); 334 registry->enabled_extensions()) {
334 it != service->extensions()->end(); ++it) {
335 // Ignore any component extensions. They are automatically loaded into all 335 // Ignore any component extensions. They are automatically loaded into all
336 // profiles and aren't the extension we're looking for here. 336 // profiles and aren't the extension we're looking for here.
337 if ((*it)->location() == extensions::Manifest::COMPONENT) 337 if (extension->location() == extensions::Manifest::COMPONENT)
338 continue; 338 continue;
339 339
340 if (extension != NULL) { 340 if (result != NULL) {
341 // TODO(yoz): this is misleading; it counts component extensions. 341 // TODO(yoz): this is misleading; it counts component extensions.
342 message_ = base::StringPrintf( 342 message_ = base::StringPrintf(
343 "Expected only one extension to be present. Found %u.", 343 "Expected only one extension to be present. Found %u.",
344 static_cast<unsigned>(service->extensions()->size())); 344 static_cast<unsigned>(registry->enabled_extensions().size()));
345 return NULL; 345 return NULL;
346 } 346 }
347 347
348 extension = it->get(); 348 result = extension.get();
349 } 349 }
350 350
351 if (!extension) { 351 if (!result) {
352 message_ = "extension pointer is NULL."; 352 message_ = "extension pointer is NULL.";
353 return NULL; 353 return NULL;
354 } 354 }
355 return extension; 355 return result;
356 } 356 }
357 357
358 bool ExtensionApiTest::StartEmbeddedTestServer() { 358 bool ExtensionApiTest::StartEmbeddedTestServer() {
359 if (!embedded_test_server()->InitializeAndWaitUntilReady()) 359 if (!embedded_test_server()->InitializeAndWaitUntilReady())
360 return false; 360 return false;
361 361
362 // Build a dictionary of values that tests can use to build URLs that 362 // Build a dictionary of values that tests can use to build URLs that
363 // access the test server and local file system. Tests can see these values 363 // access the test server and local file system. Tests can see these values
364 // using the extension API function chrome.test.getConfig(). 364 // using the extension API function chrome.test.getConfig().
365 test_config_->SetInteger(kTestServerPort, 365 test_config_->SetInteger(kTestServerPort,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 test_config_->SetInteger(kSpawnedTestServerPort, 409 test_config_->SetInteger(kSpawnedTestServerPort,
410 test_server()->host_port_pair().port()); 410 test_server()->host_port_pair().port());
411 411
412 return true; 412 return true;
413 } 413 }
414 414
415 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { 415 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
416 ExtensionBrowserTest::SetUpCommandLine(command_line); 416 ExtensionBrowserTest::SetUpCommandLine(command_line);
417 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); 417 test_data_dir_ = test_data_dir_.AppendASCII("api_test");
418 } 418 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/extension_browsertest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698