| 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 2173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2184 " |--Site D ------- proxies for A\n" | 2184 " |--Site D ------- proxies for A\n" |
| 2185 " +--Site A ------- proxies for D\n" | 2185 " +--Site A ------- proxies for D\n" |
| 2186 " +--Site A -- proxies for D\n" | 2186 " +--Site A -- proxies for D\n" |
| 2187 "Where A = http://a.com/\n" | 2187 "Where A = http://a.com/\n" |
| 2188 " D = http://f00.com/", | 2188 " D = http://f00.com/", |
| 2189 DepictFrameTree(root)); | 2189 DepictFrameTree(root)); |
| 2190 | 2190 |
| 2191 // Navigate the iframe itself to about:blank using a script executing in its | 2191 // Navigate the iframe itself to about:blank using a script executing in its |
| 2192 // own context. It should stay in the same SiteInstance as before, not the | 2192 // own context. It should stay in the same SiteInstance as before, not the |
| 2193 // parent one. | 2193 // parent one. |
| 2194 std::string script( | |
| 2195 "window.domAutomationController.send(" | |
| 2196 "window.location.href = 'about:blank');"); | |
| 2197 TestFrameNavigationObserver frame_observer(child); | 2194 TestFrameNavigationObserver frame_observer(child); |
| 2198 EXPECT_TRUE(ExecuteScript(child, script)); | 2195 ExecuteUnmodifiedScript(child, "window.location.href = 'about:blank';"); |
| 2199 frame_observer.Wait(); | 2196 frame_observer.Wait(); |
| 2200 EXPECT_EQ(about_blank_url, child->current_url()); | 2197 EXPECT_EQ(about_blank_url, child->current_url()); |
| 2201 | 2198 |
| 2202 // Ensure that we have navigated using the top level process. | 2199 // Ensure that we have navigated using the top level process. |
| 2203 EXPECT_EQ( | 2200 EXPECT_EQ( |
| 2204 " Site A ------------ proxies for D\n" | 2201 " Site A ------------ proxies for D\n" |
| 2205 " |--Site D ------- proxies for A\n" | 2202 " |--Site D ------- proxies for A\n" |
| 2206 " +--Site A ------- proxies for D\n" | 2203 " +--Site A ------- proxies for D\n" |
| 2207 " +--Site A -- proxies for D\n" | 2204 " +--Site A -- proxies for D\n" |
| 2208 "Where A = http://a.com/\n" | 2205 "Where A = http://a.com/\n" |
| (...skipping 3236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5445 const char kSetupFocusEvents[] = | 5442 const char kSetupFocusEvents[] = |
| 5446 "window.addEventListener('focus', function() {" | 5443 "window.addEventListener('focus', function() {" |
| 5447 " domAutomationController.setAutomationId(0);" | 5444 " domAutomationController.setAutomationId(0);" |
| 5448 " domAutomationController.send('%s-got-focus');" | 5445 " domAutomationController.send('%s-got-focus');" |
| 5449 "});" | 5446 "});" |
| 5450 "window.addEventListener('blur', function() {" | 5447 "window.addEventListener('blur', function() {" |
| 5451 " domAutomationController.setAutomationId(0);" | 5448 " domAutomationController.setAutomationId(0);" |
| 5452 " domAutomationController.send('%s-lost-focus');" | 5449 " domAutomationController.send('%s-lost-focus');" |
| 5453 "});"; | 5450 "});"; |
| 5454 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); | 5451 std::string script = base::StringPrintf(kSetupFocusEvents, "main", "main"); |
| 5455 EXPECT_TRUE(ExecuteScript(shell(), script)); | 5452 ExecuteUnmodifiedScript(shell(), script); |
| 5456 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); | 5453 script = base::StringPrintf(kSetupFocusEvents, "child1", "child1"); |
| 5457 EXPECT_TRUE(ExecuteScript(child1, script)); | 5454 ExecuteUnmodifiedScript(child1, script); |
| 5458 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); | 5455 script = base::StringPrintf(kSetupFocusEvents, "child2", "child2"); |
| 5459 EXPECT_TRUE(ExecuteScript(child2, script)); | 5456 ExecuteUnmodifiedScript(child2, script); |
| 5460 | 5457 |
| 5461 // Execute window.focus on the B subframe from the A main frame. | 5458 // Execute window.focus on the B subframe from the A main frame. |
| 5462 EXPECT_TRUE(ExecuteScript(root, "frames[0].focus()")); | 5459 ExecuteUnmodifiedScript(root, "frames[0].focus()"); |
| 5463 | 5460 |
| 5464 // Helper to wait for two specified messages to arrive on the specified | 5461 // Helper to wait for two specified messages to arrive on the specified |
| 5465 // DOMMessageQueue, assuming that the two messages can arrive in any order. | 5462 // DOMMessageQueue, assuming that the two messages can arrive in any order. |
| 5466 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, | 5463 auto wait_for_two_messages = [](DOMMessageQueue* msg_queue, |
| 5467 const std::string& msg1, | 5464 const std::string& msg1, |
| 5468 const std::string& msg2) { | 5465 const std::string& msg2) { |
| 5469 bool msg1_received = false; | 5466 bool msg1_received = false; |
| 5470 bool msg2_received = false; | 5467 bool msg2_received = false; |
| 5471 std::string status; | 5468 std::string status; |
| 5472 while (msg_queue->WaitForMessage(&status)) { | 5469 while (msg_queue->WaitForMessage(&status)) { |
| 5473 if (status == msg1) | 5470 if (status == msg1) |
| 5474 msg1_received = true; | 5471 msg1_received = true; |
| 5475 if (status == msg2) | 5472 if (status == msg2) |
| 5476 msg2_received = true; | 5473 msg2_received = true; |
| 5477 if (msg1_received && msg2_received) | 5474 if (msg1_received && msg2_received) |
| 5478 break; | 5475 break; |
| 5479 } | 5476 } |
| 5480 }; | 5477 }; |
| 5481 | 5478 |
| 5482 // Process A should fire a blur event, and process B should fire a focus | 5479 // Process A should fire a blur event, and process B should fire a focus |
| 5483 // event. Wait for both events. | 5480 // event. Wait for both events. |
| 5484 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", | 5481 wait_for_two_messages(&msg_queue, "\"main-lost-focus\"", |
| 5485 "\"child1-got-focus\""); | 5482 "\"child1-got-focus\""); |
| 5486 | 5483 |
| 5487 // The B subframe should now be focused in the browser process. | 5484 // The B subframe should now be focused in the browser process. |
| 5488 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); | 5485 EXPECT_EQ(child1, root->frame_tree()->GetFocusedFrame()); |
| 5489 | 5486 |
| 5490 // Now, execute window.focus on the C subframe from A main frame. This | 5487 // Now, execute window.focus on the C subframe from A main frame. This |
| 5491 // checks that we can shift focus from one remote frame to another. | 5488 // checks that we can shift focus from one remote frame to another. |
| 5492 EXPECT_TRUE(ExecuteScript(root, "frames[1].focus()")); | 5489 ExecuteUnmodifiedScript(root, "frames[1].focus()"); |
| 5493 | 5490 |
| 5494 // Wait for the two subframes (B and C) to fire blur and focus events. | 5491 // Wait for the two subframes (B and C) to fire blur and focus events. |
| 5495 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", | 5492 wait_for_two_messages(&msg_queue, "\"child1-lost-focus\"", |
| 5496 "\"child2-got-focus\""); | 5493 "\"child2-got-focus\""); |
| 5497 | 5494 |
| 5498 // The C subframe should now be focused. | 5495 // The C subframe should now be focused. |
| 5499 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); | 5496 EXPECT_EQ(child2, root->frame_tree()->GetFocusedFrame()); |
| 5500 | 5497 |
| 5501 // window.focus the main frame from the C subframe. | 5498 // window.focus the main frame from the C subframe. |
| 5502 EXPECT_TRUE(ExecuteScript(child2, "parent.focus()")); | 5499 ExecuteUnmodifiedScript(child2, "parent.focus()"); |
| 5503 | 5500 |
| 5504 // Wait for the C subframe to blur and main frame to focus. | 5501 // Wait for the C subframe to blur and main frame to focus. |
| 5505 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", | 5502 wait_for_two_messages(&msg_queue, "\"child2-lost-focus\"", |
| 5506 "\"main-got-focus\""); | 5503 "\"main-got-focus\""); |
| 5507 | 5504 |
| 5508 // The main frame should now be focused. | 5505 // The main frame should now be focused. |
| 5509 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 5506 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
| 5510 } | 5507 } |
| 5511 | 5508 |
| 5512 // There are no cursors on Android. | 5509 // There are no cursors on Android. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5636 " domAutomationController.setAutomationId(0);" | 5633 " domAutomationController.setAutomationId(0);" |
| 5637 " domAutomationController.send('wheel: ' + wheel_count);" | 5634 " domAutomationController.send('wheel: ' + wheel_count);" |
| 5638 "}" | 5635 "}" |
| 5639 "function scroll_handler(e) {" | 5636 "function scroll_handler(e) {" |
| 5640 " domAutomationController.setAutomationId(0);" | 5637 " domAutomationController.setAutomationId(0);" |
| 5641 " domAutomationController.send('scroll: ' + wheel_count);" | 5638 " domAutomationController.send('scroll: ' + wheel_count);" |
| 5642 "}" | 5639 "}" |
| 5643 "scroll_div = document.getElementById('scrollable_div');" | 5640 "scroll_div = document.getElementById('scrollable_div');" |
| 5644 "scroll_div.addEventListener('wheel', wheel_handler);" | 5641 "scroll_div.addEventListener('wheel', wheel_handler);" |
| 5645 "scroll_div.addEventListener('scroll', scroll_handler);" | 5642 "scroll_div.addEventListener('scroll', scroll_handler);" |
| 5646 "domAutomationController.setAutomationId(0);" | |
| 5647 "domAutomationController.send('wheel handler installed');" | |
| 5648 "document.body.style.background = 'black';"; | 5643 "document.body.style.background = 'black';"; |
| 5649 | 5644 |
| 5650 content::DOMMessageQueue msg_queue; | 5645 content::DOMMessageQueue msg_queue; |
| 5651 std::string reply; | 5646 std::string reply; |
| 5652 EXPECT_TRUE(ExecuteScript(rfh, script)); | 5647 EXPECT_TRUE(ExecuteScript(rfh, script)); |
| 5653 | 5648 |
| 5654 // Wait until renderer's compositor thread is synced. Otherwise the event | 5649 // Wait until renderer's compositor thread is synced. Otherwise the event |
| 5655 // handler won't be installed when the event arrives. | 5650 // handler won't be installed when the event arrives. |
| 5656 { | 5651 { |
| 5657 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost()); | 5652 MainThreadFrameObserver observer(rfh->GetRenderWidgetHost()); |
| (...skipping 2183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7841 EXPECT_EQ(1U, root->child_count()); | 7836 EXPECT_EQ(1U, root->child_count()); |
| 7842 | 7837 |
| 7843 // Ensure the RenderViewHost for the SiteInstance of the child is considered | 7838 // Ensure the RenderViewHost for the SiteInstance of the child is considered |
| 7844 // in swapped out state. | 7839 // in swapped out state. |
| 7845 RenderViewHostImpl* rvh = contents->GetFrameTree()->GetRenderViewHost( | 7840 RenderViewHostImpl* rvh = contents->GetFrameTree()->GetRenderViewHost( |
| 7846 root->child_at(0)->current_frame_host()->GetSiteInstance()); | 7841 root->child_at(0)->current_frame_host()->GetSiteInstance()); |
| 7847 EXPECT_TRUE(rvh->is_swapped_out_); | 7842 EXPECT_TRUE(rvh->is_swapped_out_); |
| 7848 | 7843 |
| 7849 // Have the child frame navigate its parent to its SiteInstance. | 7844 // Have the child frame navigate its parent to its SiteInstance. |
| 7850 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); | 7845 GURL b_url(embedded_test_server()->GetURL("b.com", "/title1.html")); |
| 7851 std::string script = base::StringPrintf( | 7846 std::string script = |
| 7852 "window.domAutomationController.send(" | 7847 base::StringPrintf("parent.location = '%s';", b_url.spec().c_str()); |
| 7853 "parent.location = '%s');", | |
| 7854 b_url.spec().c_str()); | |
| 7855 | 7848 |
| 7856 // Ensure the child has received a user gesture, so that it has permission | 7849 // Ensure the child has received a user gesture, so that it has permission |
| 7857 // to framebust. | 7850 // to framebust. |
| 7858 SimulateMouseClick( | 7851 SimulateMouseClick( |
| 7859 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); | 7852 root->child_at(0)->current_frame_host()->GetRenderWidgetHost(), 1, 1); |
| 7860 TestFrameNavigationObserver frame_observer(root); | 7853 TestFrameNavigationObserver frame_observer(root); |
| 7861 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); | 7854 EXPECT_TRUE(ExecuteScript(root->child_at(0), script)); |
| 7862 frame_observer.Wait(); | 7855 frame_observer.Wait(); |
| 7863 EXPECT_EQ(b_url, root->current_url()); | 7856 EXPECT_EQ(b_url, root->current_url()); |
| 7864 | 7857 |
| (...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10479 | 10472 |
| 10480 // The new tab's grandchild frame should reuse the b.com process. | 10473 // The new tab's grandchild frame should reuse the b.com process. |
| 10481 EXPECT_EQ(root->child_at(0)->current_frame_host()->GetProcess(), | 10474 EXPECT_EQ(root->child_at(0)->current_frame_host()->GetProcess(), |
| 10482 new_shell_root->child_at(0) | 10475 new_shell_root->child_at(0) |
| 10483 ->child_at(0) | 10476 ->child_at(0) |
| 10484 ->current_frame_host() | 10477 ->current_frame_host() |
| 10485 ->GetProcess()); | 10478 ->GetProcess()); |
| 10486 } | 10479 } |
| 10487 | 10480 |
| 10488 } // namespace content | 10481 } // namespace content |
| OLD | NEW |