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

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

Issue 671763002: Extract ProcessManager from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browsertest_util.h" 5 #include "chrome/browser/extensions/browsertest_util.h"
6 6
7 #include "chrome/browser/profiles/profile.h" 7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/test/browser_test_utils.h" 8 #include "content/public/test/browser_test_utils.h"
9 #include "extensions/browser/extension_host.h" 9 #include "extensions/browser/extension_host.h"
10 #include "extensions/browser/extension_system.h"
11 #include "extensions/browser/process_manager.h" 10 #include "extensions/browser/process_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 namespace extensions { 13 namespace extensions {
15 namespace browsertest_util { 14 namespace browsertest_util {
16 15
17 std::string ExecuteScriptInBackgroundPage(Profile* profile, 16 std::string ExecuteScriptInBackgroundPage(Profile* profile,
18 const std::string& extension_id, 17 const std::string& extension_id,
19 const std::string& script) { 18 const std::string& script) {
20 extensions::ProcessManager* manager = 19 extensions::ProcessManager* manager =
21 extensions::ExtensionSystem::Get(profile)->process_manager(); 20 extensions::ProcessManager::Get(profile);
22 extensions::ExtensionHost* host = 21 extensions::ExtensionHost* host =
23 manager->GetBackgroundHostForExtension(extension_id); 22 manager->GetBackgroundHostForExtension(extension_id);
24 if (host == NULL) { 23 if (host == NULL) {
25 ADD_FAILURE() << "Extension " << extension_id << " has no background page."; 24 ADD_FAILURE() << "Extension " << extension_id << " has no background page.";
26 return ""; 25 return "";
27 } 26 }
28 std::string result; 27 std::string result;
29 if (!content::ExecuteScriptAndExtractString( 28 if (!content::ExecuteScriptAndExtractString(
30 host->host_contents(), script, &result)) { 29 host->host_contents(), script, &result)) {
31 ADD_FAILURE() << "Executing script failed: " << script; 30 ADD_FAILURE() << "Executing script failed: " << script;
32 result.clear(); 31 result.clear();
33 } 32 }
34 return result; 33 return result;
35 } 34 }
36 35
37 bool ExecuteScriptInBackgroundPageNoWait(Profile* profile, 36 bool ExecuteScriptInBackgroundPageNoWait(Profile* profile,
38 const std::string& extension_id, 37 const std::string& extension_id,
39 const std::string& script) { 38 const std::string& script) {
40 extensions::ProcessManager* manager = 39 extensions::ProcessManager* manager =
41 extensions::ExtensionSystem::Get(profile)->process_manager(); 40 extensions::ProcessManager::Get(profile);
42 extensions::ExtensionHost* host = 41 extensions::ExtensionHost* host =
43 manager->GetBackgroundHostForExtension(extension_id); 42 manager->GetBackgroundHostForExtension(extension_id);
44 if (host == NULL) { 43 if (host == NULL) {
45 ADD_FAILURE() << "Extension " << extension_id << " has no background page."; 44 ADD_FAILURE() << "Extension " << extension_id << " has no background page.";
46 return false; 45 return false;
47 } 46 }
48 return content::ExecuteScript(host->host_contents(), script); 47 return content::ExecuteScript(host->host_contents(), script);
49 } 48 }
50 49
51 } // namespace browsertest_util 50 } // namespace browsertest_util
52 } // namespace extensions 51 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698