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

Side by Side Diff: chrome/browser/extensions/api/declarative_content/declarative_content_apitest.cc

Issue 23478003: Check and canonicalize CSS selectors before registering PageStateMatchers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix problems kalman noticed 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_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"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 // Remove it again to make sure that reverts the action. 103 // Remove it again to make sure that reverts the action.
104 ASSERT_TRUE(content::ExecuteScript( 104 ASSERT_TRUE(content::ExecuteScript(
105 tab, "document.body.innerHTML = 'Hello world';")); 105 tab, "document.body.innerHTML = 'Hello world';"));
106 // Give the mutation observer a chance to run and send back the 106 // Give the mutation observer a chance to run and send back the
107 // matching-selector update. 107 // matching-selector update.
108 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 108 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
109 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 109 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
110 } 110 }
111 111
112 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
113 CanonicalizesPageStateMatcherCss) {
114 ext_dir_.WriteManifest(kDeclarativeContentManifest);
115 ext_dir_.WriteFile(
116 FILE_PATH_LITERAL("background.js"),
117 "var declarative = chrome.declarative;\n"
118 "\n"
119 "var PageStateMatcher = chrome.declarativeContent.PageStateMatcher;\n"
120 "function NewPageStateMatcher(obj) {\n"
121 " return new PageStateMatcher(obj);\n"
122 "}\n"
123 "\n"
124 "chrome.test.runTests([\n"
125 " function canonicalizesCss() {\n"
126 " var psm = new PageStateMatcher(\n"
127 " {css: [\"input[type='password']\"]});\n"
128 " chrome.test.assertEq(['input[type=\"password\"]'], psm.css);\n"
129 " chrome.test.succeed();\n"
130 " },\n"
131 "\n"
132 " function throwsOnNonArrayCss() {\n"
133 " chrome.test.assertThrows(NewPageStateMatcher,\n"
134 " undefined,\n"
135 " [{css: 'Not-an-array'}],\n"
136 " /css.*Expected 'array'/);\n"
137 " chrome.test.succeed();\n"
138 " },\n"
139 "\n"
140 " function throwsOnNonStringCss() {\n"
141 " chrome.test.assertThrows(NewPageStateMatcher,\n"
142 " undefined,\n"
143 " [{css: [null]}],\n"
144 " /css\\.0.*Expected 'string'/);\n"
145 " chrome.test.succeed();\n"
146 " },\n"
147 "\n"
148 " function throwsOnBadCss() {\n"
149 " chrome.test.assertThrows(NewPageStateMatcher,\n"
150 " undefined,\n"
151 " [{css: [\"input''\"]}],\n"
152 " /valid.*: input''$/);\n"
153 " chrome.test.succeed();\n"
154 " },\n"
155 "\n"
156 " function throwsOnComplexSelector() {\n"
157 " chrome.test.assertThrows(NewPageStateMatcher,\n"
158 " undefined,\n"
159 " [{css: [\"div input\"]}],\n"
160 " /compound selector.*: div input$/);\n"
161 " chrome.test.succeed();\n"
162 " },\n"
163 "]);\n"
164 "\n");
165 ResultCatcher catcher;
166 ASSERT_TRUE(LoadExtension(ext_dir_.unpacked_path()));
167 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
168 }
169
112 } // namespace 170 } // namespace
113 } // namespace extensions 171 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | chrome/renderer/extensions/css_native_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698