| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 2177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2188 " |--Site D ------- proxies for A\n" | 2188 " |--Site D ------- proxies for A\n" |
| 2189 " +--Site A ------- proxies for D\n" | 2189 " +--Site A ------- proxies for D\n" |
| 2190 " +--Site A -- proxies for D\n" | 2190 " +--Site A -- proxies for D\n" |
| 2191 "Where A = http://a.com/\n" | 2191 "Where A = http://a.com/\n" |
| 2192 " D = http://f00.com/", | 2192 " D = http://f00.com/", |
| 2193 DepictFrameTree(root)); | 2193 DepictFrameTree(root)); |
| 2194 | 2194 |
| 2195 // Navigate the iframe itself to about:blank using a script executing in its | 2195 // Navigate the iframe itself to about:blank using a script executing in its |
| 2196 // own context. It should stay in the same SiteInstance as before, not the | 2196 // own context. It should stay in the same SiteInstance as before, not the |
| 2197 // parent one. | 2197 // parent one. |
| 2198 std::string script( | |
| 2199 "window.domAutomationController.send(" | |
| 2200 "window.location.href = 'about:blank');"); | |
| 2201 TestFrameNavigationObserver frame_observer(child); | 2198 TestFrameNavigationObserver frame_observer(child); |
| 2202 EXPECT_TRUE(ExecuteScript(child, script)); | 2199 ExecuteScriptAsync(child, "window.location.href = 'about:blank';"); |
| 2203 frame_observer.Wait(); | 2200 frame_observer.Wait(); |
| 2204 EXPECT_EQ(about_blank_url, child->current_url()); | 2201 EXPECT_EQ(about_blank_url, child->current_url()); |
| 2205 | 2202 |
| 2206 // Ensure that we have navigated using the top level process. | 2203 // Ensure that we have navigated using the top level process. |
| 2207 EXPECT_EQ( | 2204 EXPECT_EQ( |
| 2208 " Site A ------------ proxies for D\n" | 2205 " Site A ------------ proxies for D\n" |
| 2209 " |--Site D ------- proxies for A\n" | 2206 " |--Site D ------- proxies for A\n" |
| 2210 " +--Site A ------- proxies for D\n" | 2207 " +--Site A ------- proxies for D\n" |
| 2211 " +--Site A -- proxies for D\n" | 2208 " +--Site A -- proxies for D\n" |
| 2212 "Where A = http://a.com/\n" | 2209 "Where A = http://a.com/\n" |
| (...skipping 3236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5449 const char kSetupFocusEvents[] = | 5446 const char kSetupFocusEvents[] = |
| 5450 "window.addEventListener('focus', function() {" | 5447 "window.addEventListener('focus', function() {" |
| 5451 " domAutomationController.setAutomationId(0);" | 5448 " domAutomationController.setAutomationId(0);" |
| 5452 " domAutomationController.send('%s-got-focus');" | 5449 " domAutomationController.send('%s-got-focus');" |
| 5453 "});" | 5450 "});" |
| 5454 "window.addEventListener('blur', function() {" | 5451 "window.addEventListener('blur', function() {" |
| 5455 " domAutomationController.setAutomationId(0);" | 5452 " domAutomationController.setAutomationId(0);" |
| 5456 " domAutomationController.send('%s-lost-focus');" | 5453 " domAutomationController.send('%s-lost-focus');" |
| 5457 "});"; | 5454 "});"; |
| 5458 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); | 5455 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); |
| 5459 EXPECT_TRUE(ExecuteScript(shell(), script)); | 5456 ExecuteScriptAsync(shell(), script); |
| 5460 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); | 5457 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); |
| 5461 EXPECT_TRUE(ExecuteScript(child1, script)); | 5458 ExecuteScriptAsync(child1, script); |
| 5462 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); | 5459 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); |
| 5463 EXPECT_TRUE(ExecuteScript(child2, script)); | 5460 ExecuteScriptAsync(child2, script); |
| 5464 | 5461 |
| 5465 // Execute window.focus on the B subframe from the A main frame. | 5462 // Execute window.focus on the B subframe from the A main frame. |
| 5466 EXPECT_TRUE(ExecuteScript(root, "frames[0].focus()")); | 5463 ExecuteScriptAsync(root, "frames[0].focus()"); |
| 5467 | 5464 |
| 5468 // Helper to wait for two specified messages to arrive on the specified | 5465 // Helper to wait for two specified messages to arrive on the specified |
| 5469 // DOMMessageQueue, assuming that the two messages can arrive in any order. | 5466 // DOMMessageQueue, assuming that the two messages can arrive in any order. |
| 5470 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, | 5467 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, |
| 5471 const std::string& msg1, | 5468 const std::string& msg1, |
| 5472 const std::string& msg2) { | 5469 const std::string& msg2) { |
| 5473 bool msg1_received = false; | 5470 bool msg1_received = false; |
| 5474 bool msg2_received = false; | 5471 bool msg2_received = false; |
| 5475 std::string status; | 5472 std::string status; |
| 5476 while (msg_queue->WaitForMessage(&status)) { | 5473 while (msg_queue->WaitForMessage(&status)) { |
| 5477 if (status == msg1) | 5474 if (status == msg1) |
| 5478 msg1_received = true; | 5475 msg1_received = true; |
| 5479 if (status == msg2) | 5476 if (status == msg2) |
| 5480 msg2_received = true; | 5477 msg2_received = true; |
| 5481 if (msg1_received && msg2_received) | 5478 if (msg1_received && msg2_received) |
| 5482 break; | 5479 break; |
| 5483 } | 5480 } |
| 5484 }; | 5481 }; |
| 5485 | 5482 |
| 5486 // Process A should fire a blur event, and process B should fire a focus | 5483 // Process A should fire a blur event, and process B should fire a focus |
| 5487 // event. Wait for both events. | 5484 // event. Wait for both events. |
| 5488 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", | 5485 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", |
| 5489 "\"child1-got-focus\""); | 5486 "\"child1-got-focus\""); |
| 5490 | 5487 |
| 5491 // The B subframe should now be focused in the browser process. | 5488 // The B subframe should now be focused in the browser process. |
| 5492 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); | 5489 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); |
| 5493 | 5490 |
| 5494 // Now, execute window.focus on the C subframe from A main frame. This | 5491 // Now, execute window.focus on the C subframe from A main frame. This |
| 5495 // checks that we can shift focus from one remote frame to another. | 5492 // checks that we can shift focus from one remote frame to another. |
| 5496 EXPECT_TRUE(ExecuteScript(root, "frames[1].focus()")); | 5493 ExecuteScriptAsync(root, "frames[1].focus()"); |
| 5497 | 5494 |
| 5498 // Wait for the two subframes (B and C) to fire blur and focus events. | 5495 // Wait for the two subframes (B and C) to fire blur and focus events. |
| 5499 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", | 5496 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", |
| 5500 "\"child2-got-focus\""); | 5497 "\"child2-got-focus\""); |
| 5501 | 5498 |
| 5502 // The C subframe should now be focused. | 5499 // The C subframe should now be focused. |
| 5503 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); | 5500 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); |
| 5504 | 5501 |
| 5505 // window.focus the main frame from the C subframe. | 5502 // window.focus the main frame from the C subframe. |
| 5506 EXPECT_TRUE(ExecuteScript(child2, "parent.focus()")); | 5503 ExecuteScriptAsync(child2, "parent.focus()"); |
| 5507 | 5504 |
| 5508 // Wait for the C subframe to blur and main frame to focus. | 5505 // Wait for the C subframe to blur and main frame to focus. |
| 5509 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", | 5506 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", |
| 5510 "\"main-got-focus\""); | 5507 "\"main-got-focus\""); |
| 5511 | 5508 |
| 5512 // The main frame should now be focused. | 5509 // The main frame should now be focused. |
| 5513 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 5510 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 5514 } | 5511 } |
| 5515 | 5512 |
| 5516 // There are no cursors on Android. | 5513 // There are no cursors on Android. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5640 " domAutomationController.setAutomationId(0);" | 5637 " domAutomationController.setAutomationId(0);" |
| 5641 " domAutomationController.send('wheel: ' + wheel_count);" | 5638 " domAutomationController.send('wheel: ' + wheel_count);" |
| 5642 "}" | 5639 "}" |
| 5643 "function scroll_handler(e) {" | 5640 "function scroll_handler(e) {" |
| 5644 " domAutomationController.setAutomationId(0);" | 5641 " domAutomationController.setAutomationId(0);" |
| 5645 " domAutomationController.send('scroll: ' + wheel_count);" | 5642 " domAutomationController.send('scroll: ' + wheel_count);" |
| 5646 "}" | 5643 "}" |
| 5647 "scroll_div = document.getElementById('scrollable_div');" | 5644 "scroll_div = document.getElementById('scrollable_div');" |
| 5648 "scroll_div.addEventListener('wheel', wheel_handler);" | 5645 "scroll_div.addEventListener('wheel', wheel_handler);" |
| 5649 "scroll_div.addEventListener('scroll', scroll_handler);" | 5646 "scroll_div.addEventListener('scroll', scroll_handler);" |
| 5650 "domAutomationController.setAutomationId(0);" | |
| 5651 "domAutomationController.send('wheel handler installed');" | |
| 5652 "document.body.style.background = 'black';"; | 5647 "document.body.style.background = 'black';"; |
| 5653 | 5648 |
| 5654 content::DOMMessageQueue msg_queue; | 5649 content::DOMMessageQueue msg_queue; |
| 5655 std::string reply; | 5650 std::string reply; |
| 5656 EXPECT_TRUE(ExecuteScript(rfh, script)); | 5651 EXPECT_TRUE(ExecuteScript(rfh, script)); |
| 5657 | 5652 |
| 5658 // Wait until renderer's compositor thread is synced. Otherwise the event | 5653 // Wait until renderer's compositor thread is synced. Otherwise the event |
| 5659 // handler won't be installed when the event arrives. | 5654 // handler won't be installed when the event arrives. |
| 5660 { | 5655 { |
| 5661 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost()); | 5656 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost()); |
| (...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7846 EXPECT_EQ(1U, root->child_count()); | 7841 EXPECT_EQ(1U, root->child_count()); |
| 7847 | 7842 |
| 7848 // Ensure the RenderViewHost for the SiteInstance of the child is considered | 7843 // Ensure the RenderViewHost for the SiteInstance of the child is considered |
| 7849 // in swapped out state. | 7844 // in swapped out state. |
| 7850 RenderViewHostImpl* rvh = contents->GetFrameTree()->GetRenderViewHost( | 7845 RenderViewHostImpl* rvh = contents->GetFrameTree()->GetRenderViewHost( |
| 7851 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 7846 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 7852 EXPECT_TRUE(rvh->is_swapped_out_); | 7847 EXPECT_TRUE(rvh->is_swapped_out_); |
| 7853 | 7848 |
| 7854 // Have the child frame navigate its parent to its SiteInstance. | 7849 // Have the child frame navigate its parent to its SiteInstance. |
| 7855 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 7850 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 7856 std::string script = base::StringPrintf( | 7851 std::string script = |
| 7857 "window.domAutomationController.send(" | 7852 base::StringPrintf("parent.location = '%s';", b_url.spec().c_str()); |
| 7858 "parent.location = '%s');", | |
| 7859 b_url.spec().c_str()); | |
| 7860 | 7853 |
| 7861 // Ensure the child has received a user gesture, so that it has permission | 7854 // Ensure the child has received a user gesture, so that it has permission |
| 7862 // to framebust. | 7855 // to framebust. |
| 7863 SimulateMouseClick( | 7856 SimulateMouseClick( |
| 7864 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 7857 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| 7865 TestFrameNavigationObserver frame_observer(root); | 7858 TestFrameNavigationObserver frame_observer(root); |
| 7866 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 7859 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 7867 frame_observer.Wait(); | 7860 frame_observer.Wait(); |
| 7868 EXPECT_EQ(b_url, root->current_url()); | 7861 EXPECT_EQ(b_url, root->current_url()); |
| 7869 | 7862 |
| (...skipping 2916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10786 SimpleTap(gfx::Point(point_outside_iframe.x(), point_outside_iframe.y())); | 10779 SimpleTap(gfx::Point(point_outside_iframe.x(), point_outside_iframe.y())); |
| 10787 selection_controller_client->Wait(); | 10780 selection_controller_client->Wait(); |
| 10788 | 10781 |
| 10789 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, | 10782 EXPECT_EQ(ui::TouchSelectionController::INACTIVE, |
| 10790 parent_view->touch_selection_controller()->active_status()); | 10783 parent_view->touch_selection_controller()->active_status()); |
| 10791 } | 10784 } |
| 10792 | 10785 |
| 10793 #endif // defined(OS_ANDROID) | 10786 #endif // defined(OS_ANDROID) |
| 10794 | 10787 |
| 10795 } // namespace content | 10788 } // namespace content |
| OLD | NEW |