This source file includes following definitions.
- IN_PROC_BROWSER_TEST_F
#include "chrome/browser/extensions/browsertest_util.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/test_extension_dir.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
class ExtensionBrowsertestUtilTest : public ExtensionBrowserTest {
};
IN_PROC_BROWSER_TEST_F(ExtensionBrowsertestUtilTest,
ExecuteScriptInBackground) {
TestExtensionDir ext_dir;
ext_dir.WriteManifest(
"{\n"
" \"name\": \"ExecuteScript extension\",\n"
" \"version\": \"0.1\",\n"
" \"manifest_version\": 2,\n"
" \"background\": {\"scripts\": [\"background.js\"]}\n"
"}\n");
ext_dir.WriteFile(FILE_PATH_LITERAL("background.js"), "");
const Extension* extension = LoadExtension(ext_dir.unpacked_path());
ASSERT_TRUE(extension);
EXPECT_EQ(extension->id(),
browsertest_util::ExecuteScriptInBackgroundPage(
profile(),
extension->id(),
"window.domAutomationController.send(chrome.runtime.id);"));
EXPECT_EQ(base::IntToString(browser()->tab_strip_model()->count()),
browsertest_util::ExecuteScriptInBackgroundPage(
profile(),
extension->id(),
"chrome.tabs.query({}, function(result) {\n"
" window.domAutomationController.send('' + result.length);\n"
"});"));
EXPECT_NONFATAL_FAILURE(browsertest_util::ExecuteScriptInBackgroundPage(
profile(),
extension->id(),
"window.domAutomationController.send(3);"),
"send(3)");
}
}
}