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

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

Issue 19045002: Use Blink support to watch CSS selectors directly instead of using a MutationObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unCamelCase in Chrome code. Created 7 years, 2 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/chrome_renderer.gypi » ('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"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // than waiting for the extension to run. 89 // than waiting for the extension to run.
90 EXPECT_TRUE(page_action->GetIsVisible(tab_id)); 90 EXPECT_TRUE(page_action->GetIsVisible(tab_id));
91 91
92 // Make sure leaving a matching page unshows the page action. 92 // Make sure leaving a matching page unshows the page action.
93 NavigateInRenderer(tab, GURL("http://not_checked/")); 93 NavigateInRenderer(tab, GURL("http://not_checked/"));
94 EXPECT_FALSE(page_action->GetIsVisible(tab_id)); 94 EXPECT_FALSE(page_action->GetIsVisible(tab_id));
95 95
96 // Insert a password field to make sure that's noticed. 96 // Insert a password field to make sure that's noticed.
97 ASSERT_TRUE(content::ExecuteScript( 97 ASSERT_TRUE(content::ExecuteScript(
98 tab, "document.body.innerHTML = '<input type=\"password\">';")); 98 tab, "document.body.innerHTML = '<input type=\"password\">';"));
99 // Give the mutation observer a chance to run and send back the 99 // Give the style match a chance to run and send back the matching-selector
100 // matching-selector update. 100 // update. This takes one time through the Blink message loop to apply the
101 // style to the new element, and a second to dedupe updates.
102 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
101 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 103 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
102 EXPECT_TRUE(page_action->GetIsVisible(tab_id)) 104 EXPECT_TRUE(page_action->GetIsVisible(tab_id))
103 << "Adding a matching element should show the page action."; 105 << "Adding a matching element should show the page action.";
104 106
105 // Remove it again to make sure that reverts the action. 107 // Remove it again to make sure that reverts the action.
106 ASSERT_TRUE(content::ExecuteScript( 108 ASSERT_TRUE(content::ExecuteScript(
107 tab, "document.body.innerHTML = 'Hello world';")); 109 tab, "document.body.innerHTML = 'Hello world';"));
108 // Give the mutation observer a chance to run and send back the 110 // Give the style match a chance to run and send back the
109 // matching-selector update. 111 // matching-selector update. This also takes 2 iterations.
112 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
110 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 113 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
111 EXPECT_FALSE(page_action->GetIsVisible(tab_id)) 114 EXPECT_FALSE(page_action->GetIsVisible(tab_id))
112 << "Removing the matching element should hide the page action again."; 115 << "Removing the matching element should hide the page action again.";
113 } 116 }
114 117
115 // This tests against a renderer crash that was present during development. 118 // This tests against a renderer crash that was present during development.
116 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest, 119 IN_PROC_BROWSER_TEST_F(DeclarativeContentApiTest,
117 AddExtensionMatchingExistingTabWithDeadFrames) { 120 AddExtensionMatchingExistingTabWithDeadFrames) {
118 ext_dir_.WriteManifest(kDeclarativeContentManifest); 121 ext_dir_.WriteManifest(kDeclarativeContentManifest);
119 ext_dir_.WriteFile( 122 ext_dir_.WriteFile(
(...skipping 28 matching lines...) Expand all
148 151
149 EXPECT_EQ("rule0", 152 EXPECT_EQ("rule0",
150 ExecuteScriptInBackgroundPage( 153 ExecuteScriptInBackgroundPage(
151 extension->id(), 154 extension->id(),
152 "setRules([{\n" 155 "setRules([{\n"
153 " conditions: [new PageStateMatcher({\n" 156 " conditions: [new PageStateMatcher({\n"
154 " css: [\"span[class=foo]\"]})],\n" 157 " css: [\"span[class=foo]\"]})],\n"
155 " actions: [new ShowPageAction()]\n" 158 " actions: [new ShowPageAction()]\n"
156 "}], 'rule0');\n")); 159 "}], 'rule0');\n"));
157 // Give the renderer a chance to apply the rules change and notify the 160 // Give the renderer a chance to apply the rules change and notify the
158 // browser. 161 // browser. This takes one time through the Blink message loop to receive
162 // the rule change and apply the new stylesheet, and a second to dedupe the
163 // update.
164 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
159 ASSERT_TRUE(content::ExecuteScript(tab, std::string())); 165 ASSERT_TRUE(content::ExecuteScript(tab, std::string()));
160 166
161 EXPECT_FALSE(tab->IsCrashed()); 167 EXPECT_FALSE(tab->IsCrashed());
162 EXPECT_TRUE(page_action->GetIsVisible(tab_id)) 168 EXPECT_TRUE(page_action->GetIsVisible(tab_id))
163 << "Loading an extension when an open page matches its rules " 169 << "Loading an extension when an open page matches its rules "
164 << "should show the page action."; 170 << "should show the page action.";
165 171
166 EXPECT_EQ("removed", 172 EXPECT_EQ("removed",
167 ExecuteScriptInBackgroundPage( 173 ExecuteScriptInBackgroundPage(
168 extension->id(), 174 extension->id(),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 " new PageStateMatcher({css: ['div input']});\n" 232 " new PageStateMatcher({css: ['div input']});\n"
227 " Return('Failed to throw');\n" 233 " Return('Failed to throw');\n"
228 "} catch (e) {\n" 234 "} catch (e) {\n"
229 " Return(e.message);\n" 235 " Return(e.message);\n"
230 "}\n"), 236 "}\n"),
231 testing::ContainsRegex("compound selector.*: div input$")); 237 testing::ContainsRegex("compound selector.*: div input$"));
232 } 238 }
233 239
234 } // namespace 240 } // namespace
235 } // namespace extensions 241 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698