OLD | NEW |
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 Loading... |
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 class FramesExtensionBindingsApiTest : public ExtensionBindingsApiTest { |
| 213 public: |
| 214 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 215 ExtensionBindingsApiTest::SetUpCommandLine(command_line); |
| 216 command_line->AppendSwitch(switches::kDisablePopupBlocking); |
| 217 } |
| 218 }; |
| 219 |
| 220 // This tests that web pages with iframes or child windows pointing at |
| 221 // chrome-extenison:// urls, both web_accessible and nonexistent pages, don't |
| 222 // get improper extensions bindings injected while they briefly still point at |
| 223 // about:blank and are still scriptable by their parent. |
| 224 // |
| 225 // The general idea is to load up 2 extensions, one which listens for external |
| 226 // messages ("receiver") and one which we'll try first faking messages from in |
| 227 // the web page's iframe, as well as actually send a message from later |
| 228 // ("sender"). |
| 229 IN_PROC_BROWSER_TEST_F(FramesExtensionBindingsApiTest, FramesBeforeNavigation) { |
| 230 // Load the sender and receiver extensions, and make sure they are ready. |
| 231 ExtensionTestMessageListener sender_ready("sender_ready", true); |
| 232 const Extension* sender = LoadExtension( |
| 233 test_data_dir_.AppendASCII("bindings").AppendASCII("message_sender")); |
| 234 ASSERT_NE(nullptr, sender); |
| 235 ASSERT_TRUE(sender_ready.WaitUntilSatisfied()); |
| 236 |
| 237 ExtensionTestMessageListener receiver_ready("receiver_ready", false); |
| 238 const Extension* receiver = |
| 239 LoadExtension(test_data_dir_.AppendASCII("bindings") |
| 240 .AppendASCII("external_message_listener")); |
| 241 ASSERT_NE(nullptr, receiver); |
| 242 ASSERT_TRUE(receiver_ready.WaitUntilSatisfied()); |
| 243 |
| 244 // Load the web page which tries to impersonate the sender extension via |
| 245 // scripting iframes/child windows before they finish navigating to pages |
| 246 // within the sender extension. |
| 247 ASSERT_TRUE(embedded_test_server()->Start()); |
| 248 ui_test_utils::NavigateToURL( |
| 249 browser(), |
| 250 embedded_test_server()->GetURL( |
| 251 "/extensions/api_test/bindings/frames_before_navigation.html")); |
| 252 |
| 253 bool page_success = false; |
| 254 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 255 browser()->tab_strip_model()->GetWebContentsAt(0), "getResult()", |
| 256 &page_success)); |
| 257 EXPECT_TRUE(page_success); |
| 258 |
| 259 // Reply to |sender|, causing it to send a message over to |receiver|, and |
| 260 // then ask |receiver| for the total message count. It should be 1 since |
| 261 // |receiver| should not have received any impersonated messages. |
| 262 sender_ready.Reply(receiver->id()); |
| 263 int message_count = 0; |
| 264 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( |
| 265 ProcessManager::Get(profile()) |
| 266 ->GetBackgroundHostForExtension(receiver->id()) |
| 267 ->host_contents(), |
| 268 "getMessageCountAfterReceivingRealSenderMessage()", &message_count)); |
| 269 EXPECT_EQ(1, message_count); |
| 270 } |
| 271 |
211 } // namespace | 272 } // namespace |
212 } // namespace extensions | 273 } // namespace extensions |
OLD | NEW |