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/process_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace extensions
{
14 namespace browsertest_util
{
16 std::string
ExecuteScriptInBackgroundPage(Profile
* profile
,
17 const std::string
& extension_id
,
18 const std::string
& script
) {
19 extensions::ProcessManager
* manager
=
20 extensions::ProcessManager::Get(profile
);
21 extensions::ExtensionHost
* host
=
22 manager
->GetBackgroundHostForExtension(extension_id
);
24 ADD_FAILURE() << "Extension " << extension_id
<< " has no background page.";
28 if (!content::ExecuteScriptAndExtractString(
29 host
->host_contents(), script
, &result
)) {
30 ADD_FAILURE() << "Executing script failed: " << script
;
36 bool ExecuteScriptInBackgroundPageNoWait(Profile
* profile
,
37 const std::string
& extension_id
,
38 const std::string
& script
) {
39 extensions::ProcessManager
* manager
=
40 extensions::ProcessManager::Get(profile
);
41 extensions::ExtensionHost
* host
=
42 manager
->GetBackgroundHostForExtension(extension_id
);
44 ADD_FAILURE() << "Extension " << extension_id
<< " has no background page.";
47 return content::ExecuteScript(host
->host_contents(), script
);
50 } // namespace browsertest_util
51 } // namespace extensions