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
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/browsertest_util.h"
7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "extensions/browser/extension_host.h"
10 #include "extensions/browser/extension_system.h"
11 #include "extensions/browser/process_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace extensions
{
15 namespace browsertest_util
{
17 std::string
ExecuteScriptInBackgroundPage(Profile
* profile
,
18 const std::string
& extension_id
,
19 const std::string
& script
) {
20 extensions::ProcessManager
* manager
=
21 extensions::ExtensionSystem::Get(profile
)->process_manager();
22 extensions::ExtensionHost
* host
=
23 manager
->GetBackgroundHostForExtension(extension_id
);
25 ADD_FAILURE() << "Extension " << extension_id
<< " has no background page.";
29 if (!content::ExecuteScriptAndExtractString(
30 host
->host_contents(), script
, &result
)) {
31 ADD_FAILURE() << "Executing script failed: " << script
;
37 bool ExecuteScriptInBackgroundPageNoWait(Profile
* profile
,
38 const std::string
& extension_id
,
39 const std::string
& script
) {
40 extensions::ProcessManager
* manager
=
41 extensions::ExtensionSystem::Get(profile
)->process_manager();
42 extensions::ExtensionHost
* host
=
43 manager
->GetBackgroundHostForExtension(extension_id
);
45 ADD_FAILURE() << "Extension " << extension_id
<< " has no background page.";
48 return content::ExecuteScript(host
->host_contents(), script
);
51 } // namespace browsertest_util
52 } // namespace extensions