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

Side by Side Diff: chrome/browser/extensions/extension_bindings_apitest.cc

Issue 2151693002: Fix extension bindings injection for iframes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use security origin, augmented tests, fix nits Created 4 years, 5 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
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 // Contains holistic tests of the bindings infrastructure 5 // Contains holistic tests of the bindings infrastructure
6 6
7 #include "chrome/browser/extensions/api/permissions/permissions_api.h" 7 #include "chrome/browser/extensions/api/permissions/permissions_api.h"
8 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "chrome/browser/net/url_request_mock_util.h" 9 #include "chrome/browser/net/url_request_mock_util.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.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/chrome_switches.h"
12 #include "chrome/test/base/ui_test_utils.h" 13 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
14 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
15 #include "extensions/browser/extension_host.h" 16 #include "extensions/browser/extension_host.h"
16 #include "extensions/browser/process_manager.h" 17 #include "extensions/browser/process_manager.h"
17 #include "extensions/test/extension_test_message_listener.h" 18 #include "extensions/test/extension_test_message_listener.h"
18 #include "extensions/test/result_catcher.h" 19 #include "extensions/test/result_catcher.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
20 21
21 namespace extensions { 22 namespace extensions {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 browser()->tab_strip_model()->GetActiveWebContents(); 202 browser()->tab_strip_model()->GetActiveWebContents();
202 EXPECT_FALSE(web_contents->IsCrashed()); 203 EXPECT_FALSE(web_contents->IsCrashed());
203 // See function_interceptions.html. 204 // See function_interceptions.html.
204 std::string result; 205 std::string result;
205 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 206 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
206 web_contents, "window.domAutomationController.send(window.testStatus);", 207 web_contents, "window.domAutomationController.send(window.testStatus);",
207 &result)); 208 &result));
208 EXPECT_EQ("success", result); 209 EXPECT_EQ("success", result);
209 } 210 }
210 211
212 // This tests that web pages with iframes or child windows pointing at
213 // chrome-extenison:// urls, both web_accessible and non-existing pages, don't
Devlin 2016/07/21 00:44:54 nit: s/non-existing/nonexistent
asargent_no_longer_on_chrome 2016/07/21 18:12:22 Done.
214 // get improper extensions bindings injected while they briefly still point at
215 // about:blank and are still scriptable by their parent.
216 //
217 // The general idea is to load up 2 extensions, one which listens for external
218 // messages ("receiver") and one which we'll try first faking messages from in
219 // the web page's iframe, as well as actually send a message from later
220 // ("sender").
221 IN_PROC_BROWSER_TEST_F(ExtensionBindingsApiTest, FramesBeforeNavigation) {
222 base::CommandLine::ForCurrentProcess()->AppendSwitch(
Devlin 2016/07/21 00:44:54 Should this be in SetUpCommandLine()?
asargent_no_longer_on_chrome 2016/07/21 18:12:22 It works fine being here, I think because we don't
Devlin 2016/07/21 22:20:34 I have two concerns: - If we ever change chrome to
223 switches::kDisablePopupBlocking);
224
225 // Load the sender and receiver extensions, and make sure they are ready.
226 ExtensionTestMessageListener sender_ready("sender_ready", true);
227 const Extension* sender = LoadExtension(
228 test_data_dir_.AppendASCII("bindings").AppendASCII("message_sender"));
229 ASSERT_NE(nullptr, sender);
230 sender_ready.set_extension_id(sender->id());
Devlin 2016/07/21 00:44:54 If the listener was satisfied before this point, t
asargent_no_longer_on_chrome 2016/07/21 18:12:21 Good point - I think in early iterations of the te
231 ASSERT_TRUE(sender_ready.WaitUntilSatisfied());
232
233 ExtensionTestMessageListener receiver_ready("receiver_ready", false);
234 const Extension* receiver =
235 LoadExtension(test_data_dir_.AppendASCII("bindings")
236 .AppendASCII("external_message_listener"));
237 ASSERT_NE(nullptr, receiver);
238 receiver_ready.set_extension_id(receiver->id());
Devlin 2016/07/21 00:44:54 ditto
asargent_no_longer_on_chrome 2016/07/21 18:12:22 Done.
239 ASSERT_TRUE(receiver_ready.WaitUntilSatisfied());
240
241 // Load the web page which tries to impersonate the sender extension via
242 // scripting iframes/child windows before they finish navigating to pages
243 // within the sender extension.
244 ASSERT_TRUE(embedded_test_server()->Start());
245 ui_test_utils::NavigateToURL(
246 browser(),
247 embedded_test_server()->GetURL(
248 "/extensions/api_test/bindings/frames_before_navigation.html"));
249
250 bool page_success = false;
251 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
252 browser()->tab_strip_model()->GetWebContentsAt(0), "getResult()",
253 &page_success));
254 EXPECT_TRUE(page_success);
255
256 ExtensionTestMessageListener receiver_count(false);
257 receiver_count.set_extension_id(receiver->id());
258
259 // This should cause |sender| to send a real message over to |receiver|, at
Devlin 2016/07/21 00:44:54 This part, to me, is just a little more difficult
asargent_no_longer_on_chrome 2016/07/21 18:12:22 I rewrote it using ExecuteScriptAndExtractInt, whi
Devlin 2016/07/21 22:20:34 Ah, I see, we need this in order to ensure there's
260 // which point |receiver| will call test.sendMessage to send over the total
261 // count of messages it got.
262 sender_ready.Reply(receiver->id());
263 ASSERT_TRUE(receiver_count.WaitUntilSatisfied());
264
265 // If the code is correct, |receiver| will not have received an impersonated
266 // messages sent by iframe_before_navigate.html, so the result should be 1.
267 EXPECT_EQ("1", receiver_count.message());
268 }
269
211 } // namespace 270 } // namespace
212 } // namespace extensions 271 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698