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

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: 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
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_browsertest_util.h"
8 #include "chrome/browser/extensions/extension_tab_util.h" 9 #include "chrome/browser/extensions/extension_tab_util.h"
9 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
10 #include "chrome/browser/extensions/test_extension_dir.h" 11 #include "chrome/browser/extensions/test_extension_dir.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/extensions/features/feature_channel.h" 13 #include "chrome/common/extensions/features/feature_channel.h"
13 #include "content/public/test/browser_test_utils.h" 14 #include "content/public/test/browser_test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h"
14 16
15 namespace extensions { 17 namespace extensions {
16 namespace { 18 namespace {
17 19
18 const char kDeclarativeContentManifest[] = 20 const char kDeclarativeContentManifest[] =
19 "{\n" 21 "{\n"
20 " \"name\": \"Declarative Content apitest\",\n" 22 " \"name\": \"Declarative Content apitest\",\n"
21 " \"version\": \"0.1\",\n" 23 " \"version\": \"0.1\",\n"
22 " \"manifest_version\": 2,\n" 24 " \"manifest_version\": 2,\n"
23 " \"description\": \n" 25 " \"description\": \n"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // matching-selector update. 109 // matching-selector update.
108 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 110 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
109 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 111 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
110 } 112 }
111 113
112 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 114 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
113 CanonicalizesPageStateMatcherCss) { 115 CanonicalizesPageStateMatcherCss) {
114 ext_dir_.WriteManifest(kDeclarativeContentManifest); 116 ext_dir_.WriteManifest(kDeclarativeContentManifest);
115 ext_dir_.WriteFile( 117 ext_dir_.WriteFile(
116 FILE_PATH_LITERAL("background.js"), 118 FILE_PATH_LITERAL("background.js"),
117 "var declarative = chrome.declarative;\n"
118 "\n"
119 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n" 119 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n"
120 "function NewPageStateMatcher(obj) {\n" 120 "function Return(obj) {\n"
121 " return new PageStateMatcher(obj);\n" 121 " window.domAutomationController.send('' + obj);\n"
122 "}\n" 122 "}\n");
123 "\n" 123 const Extension* extension = LoadExtension(ext_dir_.unpacked_path());
124 "chrome.test.runTests([\n" 124 ASSERT_TRUE(extension);
125 " function canonicalizesCss() {\n" 125
126 " var psm = new PageStateMatcher(\n" 126 EXPECT_EQ("input[type=\"password\"]",
127 " {css: [\"input[type='password']\"]});\n" 127 ExecuteScriptInBackgroundPage(
128 " chrome.test.assertEq(['input[type=\"password\"]'], psm.css);\n" 128 profile(),
129 " chrome.test.succeed();\n" 129 extension->id(),
130 " },\n" 130 "var psm = new PageStateMatcher(\n"
131 "\n" 131 " {css: [\"input[type='password']\"]});\n"
132 " function throwsOnNonArrayCss() {\n" 132 "Return(psm.css);"));
133 " chrome.test.assertThrows(NewPageStateMatcher,\n" 133
134 " undefined,\n" 134 EXPECT_THAT(ExecuteScriptInBackgroundPage(
135 " [{css: 'Not-an-array'}],\n" 135 profile(),
136 " /css.*Expected 'array'/);\n" 136 extension->id(),
137 " chrome.test.succeed();\n" 137 "try {\n"
138 " },\n" 138 " new PageStateMatcher({css: 'Not-an-array'});\n"
139 "\n" 139 " Return('Failed to throw');\n"
140 " function throwsOnNonStringCss() {\n" 140 "} catch (e) {\n"
141 " chrome.test.assertThrows(NewPageStateMatcher,\n" 141 " Return(e.message);\n"
142 " undefined,\n" 142 "}\n"),
143 " [{css: [null]}],\n" 143 testing::ContainsRegex("css.*Expected 'array'"));
144 " /css\\.0.*Expected 'string'/);\n" 144 EXPECT_THAT(ExecuteScriptInBackgroundPage(
145 " chrome.test.succeed();\n" 145 profile(),
146 " },\n" 146 extension->id(),
147 "\n" 147 "try {\n"
148 " function throwsOnBadCss() {\n" 148 " new PageStateMatcher({css: [null]});\n" // Not a string.
149 " chrome.test.assertThrows(NewPageStateMatcher,\n" 149 " Return('Failed to throw');\n"
150 " undefined,\n" 150 "} catch (e) {\n"
151 " [{css: [\"input''\"]}],\n" 151 " Return(e.message);\n"
152 " /valid.*: input''$/);\n" 152 "}\n"),
153 " chrome.test.succeed();\n" 153 testing::ContainsRegex("css\\.0.*Expected 'string'"));
154 " },\n" 154 EXPECT_THAT(ExecuteScriptInBackgroundPage(
155 "\n" 155 profile(),
156 " function throwsOnComplexSelector() {\n" 156 extension->id(),
157 " chrome.test.assertThrows(NewPageStateMatcher,\n" 157 "try {\n"
158 " undefined,\n" 158 // Invalid CSS:
159 " [{css: [\"div input\"]}],\n" 159 " new PageStateMatcher({css: [\"input''\"]});\n"
160 " /compound selector.*: div input$/);\n" 160 " Return('Failed to throw');\n"
161 " chrome.test.succeed();\n" 161 "} catch (e) {\n"
162 " },\n" 162 " Return(e.message);\n"
163 "]);\n" 163 "}\n"),
164 "\n"); 164 testing::ContainsRegex("valid.*: input''$"));
165 ResultCatcher catcher; 165 EXPECT_THAT(ExecuteScriptInBackgroundPage(
166 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path())); 166 profile(),
167 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); 167 extension->id(),
168 "try {\n"
169 // "Complex" selector:
170 " new PageStateMatcher({css: ['div input']});\n"
171 " Return('Failed to throw');\n"
172 "} catch (e) {\n"
173 " Return(e.message);\n"
174 "}\n"),
175 testing::ContainsRegex("compound selector.*: div input$"));
168 } 176 }
169 177
170 } // namespace 178 } // namespace
171 } // namespace extensions 179 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698