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

Side by Side Diff: chrome/browser/extensions/browsertest_util_browsertest.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #include "chrome/browser/extensions/browsertest_util.h"
6
7 #include "base/strings/string_number_conversions.h"
8 #include "chrome/browser/extensions/extension_browsertest.h"
9 #include "chrome/browser/extensions/test_extension_dir.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace extensions {
15 namespace {
16
17 // TODO(jyasskin): It should be possible to test extensions without
18 // inheriting from the monolithic ExtensionBrowserTest.
19 class ExtensionBrowsertestUtilTest : public ExtensionBrowserTest {
20 };
21
22 IN_PROC_BROWSER_TEST_F(ExtensionBrowsertestUtilTest,
23 ExecuteScriptInBackground) {
24 TestExtensionDir ext_dir;
25 ext_dir.WriteManifest(
26 "{\n"
27 " \"name\": \"ExecuteScript extension\",\n"
28 " \"version\": \"0.1\",\n"
29 " \"manifest_version\": 2,\n"
30 " \"background\": {\"scripts\": [\"background.js\"]}\n"
31 "}\n");
32 ext_dir.WriteFile(FILE_PATH_LITERAL("background.js"), "");
33 const Extension* extension = LoadExtension(ext_dir.unpacked_path());
34 ASSERT_TRUE(extension);
35 EXPECT_EQ(extension->id(),
36 browsertest_util::ExecuteScriptInBackgroundPage(
37 profile(),
38 extension->id(),
39 "window.domAutomationController.send(chrome.runtime.id);"));
40
41 // This test checks that executing a script doesn't block the browser process.
42 EXPECT_EQ(base::IntToString(browser()->tab_strip_model()->count()),
43 browsertest_util::ExecuteScriptInBackgroundPage(
44 profile(),
45 extension->id(),
46 "chrome.tabs.query({}, function(result) {\n"
47 " window.domAutomationController.send('' + result.length);\n"
48 "});"));
49 }
50
51 } // namespace
52 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698