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 #include "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 namespace { | 43 namespace { |
44 | 44 |
45 // Helper function to send a postMessage and wait for a reply message. The | 45 // Helper function to send a postMessage and wait for a reply message. The |
46 // |post_message_script| is executed on the |sender_ftn| frame, and the sender | 46 // |post_message_script| is executed on the |sender_ftn| frame, and the sender |
47 // frame is expected to post |reply_status| from the DOMAutomationController | 47 // frame is expected to post |reply_status| from the DOMAutomationController |
48 // when it receives a reply. | 48 // when it receives a reply. |
49 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, | 49 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, |
50 const std::string& post_message_script, | 50 const std::string& post_message_script, |
51 const std::string& reply_status) { | 51 const std::string& reply_status) { |
| 52 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or |
| 53 // else it might miss the message of interest. See https://crbug.com/518729. |
| 54 DOMMessageQueue msg_queue; |
| 55 |
52 bool success = false; | 56 bool success = false; |
53 EXPECT_TRUE(ExecuteScriptAndExtractBool( | 57 EXPECT_TRUE(ExecuteScriptAndExtractBool( |
54 sender_ftn->current_frame_host(), | 58 sender_ftn->current_frame_host(), |
55 "window.domAutomationController.send(" + post_message_script + ");", | 59 "window.domAutomationController.send(" + post_message_script + ");", |
56 &success)); | 60 &success)); |
57 EXPECT_TRUE(success); | 61 EXPECT_TRUE(success); |
58 | 62 |
59 content::DOMMessageQueue msg_queue; | |
60 std::string status; | 63 std::string status; |
61 while (msg_queue.WaitForMessage(&status)) { | 64 while (msg_queue.WaitForMessage(&status)) { |
62 if (status == reply_status) | 65 if (status == reply_status) |
63 break; | 66 break; |
64 } | 67 } |
65 } | 68 } |
66 | 69 |
67 // Helper function to extract and return "window.receivedMessages" from the | 70 // Helper function to extract and return "window.receivedMessages" from the |
68 // |sender_ftn| frame. This variable is used in post_message.html to count the | 71 // |sender_ftn| frame. This variable is used in post_message.html to count the |
69 // number of messages received via postMessage by the current window. | 72 // number of messages received via postMessage by the current window. |
(...skipping 2402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2472 // frame should have one message (reply from second frame). Second frame | 2475 // frame should have one message (reply from second frame). Second frame |
2473 // should have two messages (message from first frame and reply from parent). | 2476 // should have two messages (message from first frame and reply from parent). |
2474 // Parent should have one message (from second frame). | 2477 // Parent should have one message (from second frame). |
2475 EXPECT_EQ(1, GetReceivedMessages(root->child_at(0))); | 2478 EXPECT_EQ(1, GetReceivedMessages(root->child_at(0))); |
2476 EXPECT_EQ(2, GetReceivedMessages(root->child_at(1))); | 2479 EXPECT_EQ(2, GetReceivedMessages(root->child_at(1))); |
2477 EXPECT_EQ(1, GetReceivedMessages(root)); | 2480 EXPECT_EQ(1, GetReceivedMessages(root)); |
2478 } | 2481 } |
2479 | 2482 |
2480 // Check that postMessage can be sent from a subframe on a cross-process opener | 2483 // Check that postMessage can be sent from a subframe on a cross-process opener |
2481 // tab, and that its event.source points to a valid proxy. | 2484 // tab, and that its event.source points to a valid proxy. |
2482 // Very flaky on windows (crbug.com/518729). | |
2483 #if defined(OS_WIN) | |
2484 #define MAYBE_PostMessageWithSubframeOnOpenerChain \ | |
2485 DISABLED_PostMessageWithSubframeOnOpenerChain | |
2486 #else | |
2487 #define MAYBE_PostMessageWithSubframeOnOpenerChain \ | |
2488 PostMessageWithSubframeOnOpenerChain | |
2489 #endif // defined(OS_WIN) | |
2490 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | 2485 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
2491 MAYBE_PostMessageWithSubframeOnOpenerChain) { | 2486 PostMessageWithSubframeOnOpenerChain) { |
2492 GURL main_url(embedded_test_server()->GetURL( | 2487 GURL main_url(embedded_test_server()->GetURL( |
2493 "a.com", "/frame_tree/page_with_post_message_frames.html")); | 2488 "a.com", "/frame_tree/page_with_post_message_frames.html")); |
2494 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2489 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
2495 | 2490 |
2496 // It is safe to obtain the root frame tree node here, as it doesn't change. | 2491 // It is safe to obtain the root frame tree node here, as it doesn't change. |
2497 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2492 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
2498 ->GetFrameTree() | 2493 ->GetFrameTree() |
2499 ->root(); | 2494 ->root(); |
2500 | 2495 |
2501 ASSERT_EQ(2U, root->child_count()); | 2496 ASSERT_EQ(2U, root->child_count()); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2910 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); | 2905 foo_root->render_manager()->GetRenderFrameProxyHost(site_instance_a)); |
2911 | 2906 |
2912 // Verify that the a.com popup can now find the "foo" popup by name. | 2907 // Verify that the a.com popup can now find the "foo" popup by name. |
2913 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); | 2908 GURL named_frame_url(embedded_test_server()->GetURL("c.com", "/title2.html")); |
2914 NavigateNamedFrame(a_com_shell->web_contents(), named_frame_url, "foo"); | 2909 NavigateNamedFrame(a_com_shell->web_contents(), named_frame_url, "foo"); |
2915 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); | 2910 EXPECT_TRUE(WaitForLoadStop(foo_shell->web_contents())); |
2916 EXPECT_EQ(named_frame_url, foo_root->current_url()); | 2911 EXPECT_EQ(named_frame_url, foo_root->current_url()); |
2917 } | 2912 } |
2918 | 2913 |
2919 } // namespace content | 2914 } // namespace content |
OLD | NEW |