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

Unified Diff: chrome/browser/extensions/browsertest_util.cc

Issue 23874006: Add a function to send scripts from a browsertest to an extension's background page. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add browsertest_util.cc to other binaries to fix link errors Created 7 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/browsertest_util.cc
diff --git a/chrome/browser/extensions/browsertest_util.cc b/chrome/browser/extensions/browsertest_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7808e85a283a34befbbb7aeab0a85ae19b90e43c
--- /dev/null
+++ b/chrome/browser/extensions/browsertest_util.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/browsertest_util.h"
+
+#include "chrome/browser/extensions/extension_host.h"
+#include "chrome/browser/extensions/extension_process_manager.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "content/public/test/browser_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+namespace browsertest_util {
+
+std::string ExecuteScriptInBackgroundPage(Profile* profile,
+ const std::string& extension_id,
+ const std::string& script) {
+ ExtensionProcessManager* manager =
+ extensions::ExtensionSystem::Get(profile)->process_manager();
+ extensions::ExtensionHost* host =
+ manager->GetBackgroundHostForExtension(extension_id);
+ if (host == NULL) {
+ ADD_FAILURE() << "Extension " << extension_id << " has no background page.";
+ return "";
+ }
+ std::string result;
+ if (!content::ExecuteScriptAndExtractString(
+ host->host_contents(), script, &result)) {
+ ADD_FAILURE() << "Executing script failed: " << script;
+ result.clear();
+ }
+ return result;
+}
+
+} // namespace browsertest_util
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698