| OLD | NEW |
| 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/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | |
| 9 #include "chrome/browser/extensions/extension_system.h" | 8 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "content/public/test/browser_test_utils.h" | 9 #include "content/public/test/browser_test_utils.h" |
| 10 #include "extensions/browser/process_manager.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 namespace browsertest_util { | 14 namespace browsertest_util { |
| 15 | 15 |
| 16 std::string ExecuteScriptInBackgroundPage(Profile* profile, | 16 std::string ExecuteScriptInBackgroundPage(Profile* profile, |
| 17 const std::string& extension_id, | 17 const std::string& extension_id, |
| 18 const std::string& script) { | 18 const std::string& script) { |
| 19 ExtensionProcessManager* manager = | 19 extensions::ProcessManager* manager = |
| 20 extensions::ExtensionSystem::Get(profile)->process_manager(); | 20 extensions::ExtensionSystem::Get(profile)->process_manager(); |
| 21 extensions::ExtensionHost* host = | 21 extensions::ExtensionHost* host = |
| 22 manager->GetBackgroundHostForExtension(extension_id); | 22 manager->GetBackgroundHostForExtension(extension_id); |
| 23 if (host == NULL) { | 23 if (host == NULL) { |
| 24 ADD_FAILURE() << "Extension " << extension_id << " has no background page."; | 24 ADD_FAILURE() << "Extension " << extension_id << " has no background page."; |
| 25 return ""; | 25 return ""; |
| 26 } | 26 } |
| 27 std::string result; | 27 std::string result; |
| 28 if (!content::ExecuteScriptAndExtractString( | 28 if (!content::ExecuteScriptAndExtractString( |
| 29 host->host_contents(), script, &result)) { | 29 host->host_contents(), script, &result)) { |
| 30 ADD_FAILURE() << "Executing script failed: " << script; | 30 ADD_FAILURE() << "Executing script failed: " << script; |
| 31 result.clear(); | 31 result.clear(); |
| 32 } | 32 } |
| 33 return result; | 33 return result; |
| 34 } | 34 } |
| 35 | 35 |
| 36 } // namespace browsertest_util | 36 } // namespace browsertest_util |
| 37 } // namespace extensions | 37 } // namespace extensions |
| OLD | NEW |