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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/declarative_content_apitest.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: Test that sending a non-string fails the test 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
« no previous file with comments | « no previous file | chrome/browser/extensions/browsertest_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_action.h" 5 #include "chrome/browser/extensions/extension_action.h"
6 #include "chrome/browser/extensions/extension_action_manager.h" 6 #include "chrome/browser/extensions/extension_action_manager.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_tab_util.h" 8 #include "chrome/browser/extensions/extension_tab_util.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h" 9 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/extensions/test_extension_dir.h" 10 #include "chrome/browser/extensions/test_extension_dir.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/extensions/features/feature_channel.h" 12 #include "chrome/common/extensions/features/feature_channel.h"
13 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 namespace { 17 namespace {
17 18
18 const char kDeclarativeContentManifest[] = 19 const char kDeclarativeContentManifest[] =
19 "{\n" 20 "{\n"
20 " \"name\": \"Declarative Content apitest\",\n" 21 " \"name\": \"Declarative Content apitest\",\n"
21 " \"version\": \"0.1\",\n" 22 " \"version\": \"0.1\",\n"
22 " \"manifest_version\": 2,\n" 23 " \"manifest_version\": 2,\n"
23 " \"description\": \n" 24 " \"description\": \n"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // matching-selector update. 108 // matching-selector update.
108 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 109 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
109 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 110 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
110 } 111 }
111 112
112 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 113 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
113 CanonicalizesPageStateMatcherCss) { 114 CanonicalizesPageStateMatcherCss) {
114 ext_dir_.WriteManifest(kDeclarativeContentManifest); 115 ext_dir_.WriteManifest(kDeclarativeContentManifest);
115 ext_dir_.WriteFile( 116 ext_dir_.WriteFile(
116 FILE_PATH_LITERAL("background.js"), 117 FILE_PATH_LITERAL("background.js"),
117 "var declarative = chrome.declarative;\n"
118 "\n"
119 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" 118 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n"
120 "function NewPageStateMatcher(obj) {\n" 119 "function Return(obj) {\n"
121 " return new PageStateMatcher(obj);\n" 120 " window.domAutomationController.send('' + obj);\n"
122 "}\n" 121 "}\n");
123 "\n" 122 const Extension* extension = LoadExtension(ext_dir_.unpacked_path());
124 "chrome.test.runTests([\n" 123 ASSERT_TRUE(extension);
125 " function canonicalizesCss() {\n" 124
126 " var psm = new PageStateMatcher(\n" 125 EXPECT_EQ("input[type=\"password\"]",
127 " {css: [\"input[type='password']\"]});\n" 126 ExecuteScriptInBackgroundPage(
128 " chrome.test.assertEq(['input[type=\"password\"]'], psm.css);\n" 127 extension->id(),
129 " chrome.test.succeed();\n" 128 "var psm = new PageStateMatcher(\n"
130 " },\n" 129 " {css: [\"input[type='password']\"]});\n"
131 "\n" 130 "Return(psm.css);"));
132 " function throwsOnNonArrayCss() {\n" 131
133 " chrome.test.assertThrows(NewPageStateMatcher,\n" 132 EXPECT_THAT(ExecuteScriptInBackgroundPage(
134 " undefined,\n" 133 extension->id(),
135 " [{css: 'Not-an-array'}],\n" 134 "try {\n"
136 " /css.*Expected 'array'/);\n" 135 " new PageStateMatcher({css: 'Not-an-array'});\n"
137 " chrome.test.succeed();\n" 136 " Return('Failed to throw');\n"
138 " },\n" 137 "} catch (e) {\n"
139 "\n" 138 " Return(e.message);\n"
140 " function throwsOnNonStringCss() {\n" 139 "}\n"),
141 " chrome.test.assertThrows(NewPageStateMatcher,\n" 140 testing::ContainsRegex("css.*Expected 'array'"));
142 " undefined,\n" 141 EXPECT_THAT(ExecuteScriptInBackgroundPage(
143 " [{css: [null]}],\n" 142 extension->id(),
144 " /css\\.0.*Expected 'string'/);\n" 143 "try {\n"
145 " chrome.test.succeed();\n" 144 " new PageStateMatcher({css: [null]});\n" // Not a string.
146 " },\n" 145 " Return('Failed to throw');\n"
147 "\n" 146 "} catch (e) {\n"
148 " function throwsOnBadCss() {\n" 147 " Return(e.message);\n"
149 " chrome.test.assertThrows(NewPageStateMatcher,\n" 148 "}\n"),
150 " undefined,\n" 149 testing::ContainsRegex("css\\.0.*Expected 'string'"));
151 " [{css: [\"input''\"]}],\n" 150 EXPECT_THAT(ExecuteScriptInBackgroundPage(
152 " /valid.*: input''$/);\n" 151 extension->id(),
153 " chrome.test.succeed();\n" 152 "try {\n"
154 " },\n" 153 // Invalid CSS:
155 "\n" 154 " new PageStateMatcher({css: [\"input''\"]});\n"
156 " function throwsOnComplexSelector() {\n" 155 " Return('Failed to throw');\n"
157 " chrome.test.assertThrows(NewPageStateMatcher,\n" 156 "} catch (e) {\n"
158 " undefined,\n" 157 " Return(e.message);\n"
159 " [{css: [\"div input\"]}],\n" 158 "}\n"),
160 " /compound selector.*: div input$/);\n" 159 testing::ContainsRegex("valid.*: input''$"));
161 " chrome.test.succeed();\n" 160 EXPECT_THAT(ExecuteScriptInBackgroundPage(
162 " },\n" 161 extension->id(),
163 "]);\n" 162 "try {\n"
164 "\n"); 163 // "Complex" selector:
165 ResultCatcher catcher; 164 " new PageStateMatcher({css: ['div input']});\n"
166 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path())); 165 " Return('Failed to throw');\n"
167 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 166 "} catch (e) {\n"
167 " Return(e.message);\n"
168 "}\n"),
169 testing::ContainsRegex("compound selector.*: div input$"));
168 } 170 }
169 171
170 } // namespace 172 } // namespace
171 } // namespace extensions 173 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698