Chromium Code Reviews| 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> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | |
| 13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | |
| 16 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 17 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
| 18 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/pattern.h" | 21 #include "base/strings/pattern.h" |
| 20 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
| 23 #include "base/threading/sequenced_task_runner_handle.h" | 25 #include "base/threading/sequenced_task_runner_handle.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 37 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" | 39 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 38 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 40 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 39 #include "content/browser/web_contents/web_contents_impl.h" | 41 #include "content/browser/web_contents/web_contents_impl.h" |
| 40 #include "content/common/child_process_messages.h" | 42 #include "content/common/child_process_messages.h" |
| 41 #include "content/common/frame_messages.h" | 43 #include "content/common/frame_messages.h" |
| 42 #include "content/common/input/synthetic_tap_gesture_params.h" | 44 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 43 #include "content/common/input/touch_action.h" | 45 #include "content/common/input/touch_action.h" |
| 44 #include "content/common/input_messages.h" | 46 #include "content/common/input_messages.h" |
| 45 #include "content/common/renderer.mojom.h" | 47 #include "content/common/renderer.mojom.h" |
| 46 #include "content/common/view_messages.h" | 48 #include "content/common/view_messages.h" |
| 49 #include "content/public/browser/browser_thread.h" | |
| 47 #include "content/public/browser/interstitial_page_delegate.h" | 50 #include "content/public/browser/interstitial_page_delegate.h" |
| 48 #include "content/public/browser/navigation_handle.h" | 51 #include "content/public/browser/navigation_handle.h" |
| 49 #include "content/public/browser/notification_observer.h" | 52 #include "content/public/browser/notification_observer.h" |
| 50 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/notification_types.h" | 54 #include "content/public/browser/notification_types.h" |
| 52 #include "content/public/browser/resource_dispatcher_host.h" | 55 #include "content/public/browser/resource_dispatcher_host.h" |
| 53 #include "content/public/common/browser_side_navigation_policy.h" | 56 #include "content/public/common/browser_side_navigation_policy.h" |
| 54 #include "content/public/common/content_switches.h" | 57 #include "content/public/common/content_switches.h" |
| 55 #include "content/public/common/url_constants.h" | 58 #include "content/public/common/url_constants.h" |
| 56 #include "content/public/test/browser_test_utils.h" | 59 #include "content/public/test/browser_test_utils.h" |
| 57 #include "content/public/test/content_browser_test_utils.h" | 60 #include "content/public/test/content_browser_test_utils.h" |
| 58 #include "content/public/test/test_frame_navigation_observer.h" | 61 #include "content/public/test/test_frame_navigation_observer.h" |
| 59 #include "content/public/test/test_navigation_observer.h" | 62 #include "content/public/test/test_navigation_observer.h" |
| 60 #include "content/public/test/test_utils.h" | 63 #include "content/public/test/test_utils.h" |
| 61 #include "content/shell/browser/shell.h" | 64 #include "content/shell/browser/shell.h" |
| 62 #include "content/test/content_browser_test_utils_internal.h" | 65 #include "content/test/content_browser_test_utils_internal.h" |
| 63 #include "ipc/ipc.mojom.h" | 66 #include "ipc/ipc.mojom.h" |
| 64 #include "ipc/ipc_security_test_util.h" | 67 #include "ipc/ipc_security_test_util.h" |
| 65 #include "net/dns/mock_host_resolver.h" | 68 #include "net/dns/mock_host_resolver.h" |
| 66 #include "net/test/embedded_test_server/embedded_test_server.h" | 69 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 70 #include "net/test/embedded_test_server/http_request.h" | |
| 67 #include "testing/gtest/include/gtest/gtest.h" | 71 #include "testing/gtest/include/gtest/gtest.h" |
| 68 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 72 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 69 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" | 73 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" |
| 70 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 74 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 71 #include "ui/display/display_switches.h" | 75 #include "ui/display/display_switches.h" |
| 72 #include "ui/display/screen.h" | 76 #include "ui/display/screen.h" |
| 73 #include "ui/events/base_event_utils.h" | 77 #include "ui/events/base_event_utils.h" |
| 74 #include "ui/events/event.h" | 78 #include "ui/events/event.h" |
| 75 #include "ui/events/event_utils.h" | 79 #include "ui/events/event_utils.h" |
| 76 #include "ui/events/latency_info.h" | 80 #include "ui/events/latency_info.h" |
| 77 #include "ui/gfx/geometry/point.h" | 81 #include "ui/gfx/geometry/point.h" |
| 78 #include "ui/native_theme/native_theme_switches.h" | 82 #include "ui/native_theme/native_theme_switches.h" |
| 79 | 83 |
| 80 #if defined(USE_AURA) | 84 #if defined(USE_AURA) |
| 81 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 85 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 82 #endif | 86 #endif |
| 83 | 87 |
| 84 #if defined(OS_MACOSX) | 88 #if defined(OS_MACOSX) |
| 85 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" | 89 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" |
| 86 #endif | 90 #endif |
| 87 | 91 |
| 88 namespace content { | 92 namespace content { |
| 89 | 93 |
| 90 namespace { | 94 namespace { |
| 91 | 95 |
| 96 // This class offloads a "complete" closure to the underlying test fixture, | |
| 97 // which can call it at any time to finish a request. | |
| 98 class DelayedResponse : public net::test_server::BasicHttpResponse { | |
| 99 public: | |
| 100 DelayedResponse(SitePerProcessBrowserTest* test_harness) | |
| 101 : test_harness_(test_harness) {} | |
| 102 void SendResponse( | |
| 103 const net::test_server::SendBytesCallback& send, | |
| 104 const net::test_server::SendCompleteCallback& done) override { | |
| 105 test_harness_->AddDelayedResponse(send, done); | |
| 106 } | |
| 107 | |
| 108 private: | |
| 109 SitePerProcessBrowserTest* test_harness_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(DelayedResponse); | |
| 112 }; | |
| 113 | |
| 92 // Helper function to send a postMessage and wait for a reply message. The | 114 // Helper function to send a postMessage and wait for a reply message. The |
| 93 // |post_message_script| is executed on the |sender_ftn| frame, and the sender | 115 // |post_message_script| is executed on the |sender_ftn| frame, and the sender |
| 94 // frame is expected to post |reply_status| from the DOMAutomationController | 116 // frame is expected to post |reply_status| from the DOMAutomationController |
| 95 // when it receives a reply. | 117 // when it receives a reply. |
| 96 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, | 118 void PostMessageAndWaitForReply(FrameTreeNode* sender_ftn, |
| 97 const std::string& post_message_script, | 119 const std::string& post_message_script, |
| 98 const std::string& reply_status) { | 120 const std::string& reply_status) { |
| 99 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or | 121 // Subtle: msg_queue needs to be declared before the ExecuteScript below, or |
| 100 // else it might miss the message of interest. See https://crbug.com/518729. | 122 // else it might miss the message of interest. See https://crbug.com/518729. |
| 101 DOMMessageQueue msg_queue; | 123 DOMMessageQueue msg_queue; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 // InterstitialPageDelegate: | 567 // InterstitialPageDelegate: |
| 546 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } | 568 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } |
| 547 }; | 569 }; |
| 548 | 570 |
| 549 } // namespace | 571 } // namespace |
| 550 | 572 |
| 551 // | 573 // |
| 552 // SitePerProcessBrowserTest | 574 // SitePerProcessBrowserTest |
| 553 // | 575 // |
| 554 | 576 |
| 555 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 577 SitePerProcessBrowserTest::SitePerProcessBrowserTest(){}; |
| 556 }; | 578 SitePerProcessBrowserTest::~SitePerProcessBrowserTest(){}; |
| 579 | |
| 580 void SitePerProcessBrowserTest::AddDelayedResponse( | |
| 581 const net::test_server::SendBytesCallback& send, | |
| 582 const net::test_server::SendCompleteCallback& done) { | |
| 583 send_response_closures_.push_back(base::Bind(send, "", done)); | |
|
mmenke
2017/01/30 23:03:51
I think you should document what "base::Bind(send,
Charlie Harrison
2017/01/31 20:19:31
Done.
| |
| 584 } | |
| 585 | |
| 586 void SitePerProcessBrowserTest::MaybeStartRequests() { | |
| 587 int sum = 0; | |
| 588 for (auto it : delayed_requests_for_path_) { | |
|
mmenke
2017/01/30 23:03:51
delayed_requests_for_path_ seems a bit confusing.
Charlie Harrison
2017/01/31 20:19:31
Done.
| |
| 589 sum += it.second; | |
|
mmenke
2017/01/30 23:03:51
if (it.second > 0)
return;
Charlie Harrison
2017/01/31 20:19:32
Done.
| |
| 590 } | |
| 591 if (sum == 0) { | |
| 592 for (const auto it : send_response_closures_) { | |
| 593 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, it); | |
|
mmenke
2017/01/30 23:03:51
This isn't threadsafe. DelayedResponse is called
Charlie Harrison
2017/01/31 20:19:31
I thought this would be okay because send_response
| |
| 594 } | |
| 595 } | |
| 596 } | |
| 557 | 597 |
| 558 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 598 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| 559 return visualizer_.DepictFrameTree(node); | 599 return visualizer_.DepictFrameTree(node); |
| 560 } | 600 } |
| 561 | 601 |
| 562 void SitePerProcessBrowserTest::SetUpCommandLine( | 602 void SitePerProcessBrowserTest::SetUpCommandLine( |
| 563 base::CommandLine* command_line) { | 603 base::CommandLine* command_line) { |
| 564 IsolateAllSitesForTesting(command_line); | 604 IsolateAllSitesForTesting(command_line); |
| 565 #if !defined(OS_ANDROID) | 605 #if !defined(OS_ANDROID) |
| 566 // TODO(bokan): Needed for scrollability check in | 606 // TODO(bokan): Needed for scrollability check in |
| 567 // FrameOwnerPropertiesPropagationScrolling. crbug.com/662196. | 607 // FrameOwnerPropertiesPropagationScrolling. crbug.com/662196. |
| 568 command_line->AppendSwitch(switches::kDisableOverlayScrollbar); | 608 command_line->AppendSwitch(switches::kDisableOverlayScrollbar); |
| 569 #endif | 609 #endif |
| 570 }; | 610 }; |
| 571 | 611 |
| 612 std::unique_ptr<net::test_server::HttpResponse> | |
| 613 SitePerProcessBrowserTest::HandleMockResource( | |
|
mmenke
2017/01/30 23:03:51
Think this needs documentation.
Charlie Harrison
2017/01/31 20:19:32
Done.
| |
| 614 const net::test_server::HttpRequest& request) { | |
| 615 auto it = delayed_requests_for_path_.find(request.GetURL().path()); | |
| 616 if (it == delayed_requests_for_path_.end()) | |
| 617 return nullptr; | |
| 618 | |
| 619 // If there are requests to delay for this path, make a delayed request which | |
| 620 // will be finished later. Otherwise fall through to the bottom and send an | |
| 621 // empty response. | |
| 622 if (it->second) { | |
| 623 --it->second; | |
| 624 return base::MakeUnique<DelayedResponse>(this); | |
| 625 } | |
| 626 MaybeStartRequests(); | |
| 627 return std::unique_ptr<net::test_server::BasicHttpResponse>(); | |
| 628 } | |
| 629 | |
| 572 void SitePerProcessBrowserTest::SetUpOnMainThread() { | 630 void SitePerProcessBrowserTest::SetUpOnMainThread() { |
| 573 host_resolver()->AddRule("*", "127.0.0.1"); | 631 host_resolver()->AddRule("*", "127.0.0.1"); |
| 574 SetupCrossSiteRedirector(embedded_test_server()); | 632 SetupCrossSiteRedirector(embedded_test_server()); |
| 633 // Allows for arbitrary "barrier" style delaying of requests matching certain | |
| 634 // paths. | |
| 635 embedded_test_server()->RegisterRequestHandler(base::Bind( | |
| 636 &SitePerProcessBrowserTest::HandleMockResource, base::Unretained(this))); | |
| 575 ASSERT_TRUE(embedded_test_server()->Start()); | 637 ASSERT_TRUE(embedded_test_server()->Start()); |
| 576 } | 638 } |
| 577 | 639 |
| 640 void SitePerProcessBrowserTest::SetDelayedRequestsForPath(std::string path, | |
|
mmenke
2017/01/30 23:03:51
nit: const std::string& path?
mmenke
2017/01/30 23:03:51
Think this needs documentation.
Charlie Harrison
2017/01/31 20:19:31
Added docs to the header.
Charlie Harrison
2017/01/31 20:19:31
Done.
| |
| 641 int num_delayed) { | |
| 642 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 643 delayed_requests_for_path_[path] = num_delayed; | |
| 644 } | |
| 645 | |
| 578 // | 646 // |
| 579 // SitePerProcessHighDPIBrowserTest | 647 // SitePerProcessHighDPIBrowserTest |
| 580 // | 648 // |
| 581 | 649 |
| 582 | 650 |
| 583 class SitePerProcessHighDPIBrowserTest : public SitePerProcessBrowserTest { | 651 class SitePerProcessHighDPIBrowserTest : public SitePerProcessBrowserTest { |
| 584 public: | 652 public: |
| 585 const double kDeviceScaleFactor = 2.0; | 653 const double kDeviceScaleFactor = 2.0; |
| 586 | 654 |
| 587 SitePerProcessHighDPIBrowserTest() {} | 655 SitePerProcessHighDPIBrowserTest() {} |
| (...skipping 8588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9176 EXPECT_TRUE(NavigateToURL( | 9244 EXPECT_TRUE(NavigateToURL( |
| 9177 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); | 9245 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); |
| 9178 | 9246 |
| 9179 // Pretend that a.com just requested a context menu. This used to cause a | 9247 // Pretend that a.com just requested a context menu. This used to cause a |
| 9180 // because the RenderWidgetHostView is destroyed when the frame is swapped and | 9248 // because the RenderWidgetHostView is destroyed when the frame is swapped and |
| 9181 // added to pending delete list. | 9249 // added to pending delete list. |
| 9182 rfh->OnMessageReceived( | 9250 rfh->OnMessageReceived( |
| 9183 FrameHostMsg_ContextMenu(rfh->GetRoutingID(), ContextMenuParams())); | 9251 FrameHostMsg_ContextMenu(rfh->GetRoutingID(), ContextMenuParams())); |
| 9184 } | 9252 } |
| 9185 | 9253 |
| 9254 // Regression tests for crbug.com/678206, where the request throttling in | |
|
nasko
2017/01/31 15:50:34
nit: https://
Charlie Harrison
2017/01/31 20:19:32
Done.
| |
| 9255 // ResourceScheduler was not updated for OOPIFs. This resulted in a single hung | |
| 9256 // delayable request (e.g. video) starving all other delayable requests. | |
|
mmenke
2017/01/30 23:03:51
Think this needs more details on how the tests act
Charlie Harrison
2017/01/31 20:19:32
Done.
| |
| 9257 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 9258 DelayableSubframeRequestsOneFrame) { | |
| 9259 std::string path = "/mock-video.mp4"; | |
| 9260 SetDelayedRequestsForPath(path, 2); | |
|
mmenke
2017/01/30 23:03:51
Not safe to do this after setting up the test serv
Charlie Harrison
2017/01/31 20:19:32
Ensured that the test server is not started until
| |
| 9261 GURL url(embedded_test_server()->GetURL( | |
| 9262 "a.com", base::StringPrintf("/site_isolation/" | |
| 9263 "subframes_with_resources.html?urls=%s&" | |
| 9264 "numSubresources=3", | |
| 9265 path.c_str()))); | |
| 9266 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 9267 bool result; | |
| 9268 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); | |
| 9269 EXPECT_TRUE(result); | |
| 9270 | |
| 9271 } | |
| 9272 | |
| 9273 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, | |
| 9274 DelayableSubframeRequestsTwoFrames) { | |
| 9275 std::string path0 = "/mock-video0.mp4"; | |
| 9276 std::string path1 = "/mock-video1.mp4"; | |
| 9277 SetDelayedRequestsForPath(path0, 2); | |
| 9278 SetDelayedRequestsForPath(path1, 2); | |
| 9279 GURL url(embedded_test_server()->GetURL( | |
| 9280 "a.com", base::StringPrintf("/site_isolation/" | |
| 9281 "subframes_with_resources.html?urls=%s,%s&" | |
| 9282 "numSubresources=3", | |
| 9283 path0.c_str(), path1.c_str()))); | |
| 9284 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 9285 bool result; | |
| 9286 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); | |
| 9287 EXPECT_TRUE(result); | |
|
nasko
2017/01/31 15:50:34
How do those tests manifest when they fail? Timeou
Charlie Harrison
2017/01/31 20:19:31
They will time out, I've updated the description.
| |
| 9288 } | |
| 9289 | |
| 9186 } // namespace content | 9290 } // namespace content |
| OLD | NEW |