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 <map> | |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 14 #include "base/bind.h" | |
| 15 #include "base/callback.h" | |
| 13 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 14 #include "base/location.h" | 17 #include "base/location.h" |
| 15 #include "base/macros.h" | 18 #include "base/macros.h" |
|
Charlie Harrison
2017/01/31 20:19:32
remove this
| |
| 19 #include "base/memory/ptr_util.h" | |
| 16 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 17 #include "base/sequenced_task_runner.h" | 21 #include "base/sequenced_task_runner.h" |
| 18 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 19 #include "base/strings/pattern.h" | 23 #include "base/strings/pattern.h" |
| 20 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/test/test_timeouts.h" | 26 #include "base/test/test_timeouts.h" |
| 23 #include "base/threading/sequenced_task_runner_handle.h" | 27 #include "base/threading/sequenced_task_runner_handle.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "build/build_config.h" | 29 #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" | 41 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
| 38 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 42 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 39 #include "content/browser/web_contents/web_contents_impl.h" | 43 #include "content/browser/web_contents/web_contents_impl.h" |
| 40 #include "content/common/child_process_messages.h" | 44 #include "content/common/child_process_messages.h" |
| 41 #include "content/common/frame_messages.h" | 45 #include "content/common/frame_messages.h" |
| 42 #include "content/common/input/synthetic_tap_gesture_params.h" | 46 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 43 #include "content/common/input/touch_action.h" | 47 #include "content/common/input/touch_action.h" |
| 44 #include "content/common/input_messages.h" | 48 #include "content/common/input_messages.h" |
| 45 #include "content/common/renderer.mojom.h" | 49 #include "content/common/renderer.mojom.h" |
| 46 #include "content/common/view_messages.h" | 50 #include "content/common/view_messages.h" |
| 51 #include "content/public/browser/browser_thread.h" | |
| 47 #include "content/public/browser/interstitial_page_delegate.h" | 52 #include "content/public/browser/interstitial_page_delegate.h" |
| 48 #include "content/public/browser/navigation_handle.h" | 53 #include "content/public/browser/navigation_handle.h" |
| 49 #include "content/public/browser/notification_observer.h" | 54 #include "content/public/browser/notification_observer.h" |
| 50 #include "content/public/browser/notification_service.h" | 55 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/notification_types.h" | 56 #include "content/public/browser/notification_types.h" |
| 52 #include "content/public/browser/resource_dispatcher_host.h" | 57 #include "content/public/browser/resource_dispatcher_host.h" |
| 53 #include "content/public/common/browser_side_navigation_policy.h" | 58 #include "content/public/common/browser_side_navigation_policy.h" |
| 54 #include "content/public/common/content_switches.h" | 59 #include "content/public/common/content_switches.h" |
| 55 #include "content/public/common/url_constants.h" | 60 #include "content/public/common/url_constants.h" |
| 56 #include "content/public/test/browser_test_utils.h" | 61 #include "content/public/test/browser_test_utils.h" |
| 57 #include "content/public/test/content_browser_test_utils.h" | 62 #include "content/public/test/content_browser_test_utils.h" |
| 58 #include "content/public/test/test_frame_navigation_observer.h" | 63 #include "content/public/test/test_frame_navigation_observer.h" |
| 59 #include "content/public/test/test_navigation_observer.h" | 64 #include "content/public/test/test_navigation_observer.h" |
| 60 #include "content/public/test/test_utils.h" | 65 #include "content/public/test/test_utils.h" |
| 61 #include "content/shell/browser/shell.h" | 66 #include "content/shell/browser/shell.h" |
| 62 #include "content/test/content_browser_test_utils_internal.h" | 67 #include "content/test/content_browser_test_utils_internal.h" |
| 63 #include "ipc/ipc.mojom.h" | 68 #include "ipc/ipc.mojom.h" |
| 64 #include "ipc/ipc_security_test_util.h" | 69 #include "ipc/ipc_security_test_util.h" |
| 65 #include "net/dns/mock_host_resolver.h" | 70 #include "net/dns/mock_host_resolver.h" |
| 66 #include "net/test/embedded_test_server/embedded_test_server.h" | 71 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 72 #include "net/test/embedded_test_server/http_request.h" | |
| 73 #include "net/test/embedded_test_server/http_response.h" | |
| 67 #include "testing/gtest/include/gtest/gtest.h" | 74 #include "testing/gtest/include/gtest/gtest.h" |
| 68 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 75 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 69 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" | 76 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" |
| 70 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 77 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 71 #include "ui/display/display_switches.h" | 78 #include "ui/display/display_switches.h" |
| 72 #include "ui/display/screen.h" | 79 #include "ui/display/screen.h" |
| 73 #include "ui/events/base_event_utils.h" | 80 #include "ui/events/base_event_utils.h" |
| 74 #include "ui/events/event.h" | 81 #include "ui/events/event.h" |
| 75 #include "ui/events/event_utils.h" | 82 #include "ui/events/event_utils.h" |
| 76 #include "ui/events/latency_info.h" | 83 #include "ui/events/latency_info.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 // InterstitialPageDelegate: | 552 // InterstitialPageDelegate: |
| 546 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } | 553 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } |
| 547 }; | 554 }; |
| 548 | 555 |
| 549 } // namespace | 556 } // namespace |
| 550 | 557 |
| 551 // | 558 // |
| 552 // SitePerProcessBrowserTest | 559 // SitePerProcessBrowserTest |
| 553 // | 560 // |
| 554 | 561 |
| 555 SitePerProcessBrowserTest::SitePerProcessBrowserTest() { | 562 SitePerProcessBrowserTest::SitePerProcessBrowserTest(){ |
| 556 }; | 563 }; |
| 557 | 564 |
| 558 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { | 565 std::string SitePerProcessBrowserTest::DepictFrameTree(FrameTreeNode* node) { |
| 559 return visualizer_.DepictFrameTree(node); | 566 return visualizer_.DepictFrameTree(node); |
| 560 } | 567 } |
| 561 | 568 |
| 562 void SitePerProcessBrowserTest::SetUpCommandLine( | 569 void SitePerProcessBrowserTest::SetUpCommandLine( |
| 563 base::CommandLine* command_line) { | 570 base::CommandLine* command_line) { |
| 564 IsolateAllSitesForTesting(command_line); | 571 IsolateAllSitesForTesting(command_line); |
| 565 #if !defined(OS_ANDROID) | 572 #if !defined(OS_ANDROID) |
| (...skipping 8610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9176 EXPECT_TRUE(NavigateToURL( | 9183 EXPECT_TRUE(NavigateToURL( |
| 9177 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); | 9184 shell(), embedded_test_server()->GetURL("b.com", "/title3.html"))); |
| 9178 | 9185 |
| 9179 // Pretend that a.com just requested a context menu. This used to cause a | 9186 // 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 | 9187 // because the RenderWidgetHostView is destroyed when the frame is swapped and |
| 9181 // added to pending delete list. | 9188 // added to pending delete list. |
| 9182 rfh->OnMessageReceived( | 9189 rfh->OnMessageReceived( |
| 9183 FrameHostMsg_ContextMenu(rfh->GetRoutingID(), ContextMenuParams())); | 9190 FrameHostMsg_ContextMenu(rfh->GetRoutingID(), ContextMenuParams())); |
| 9184 } | 9191 } |
| 9185 | 9192 |
| 9193 class RequestDelayingSitePerProcessBrowserTest | |
| 9194 : public SitePerProcessBrowserTest { | |
| 9195 public: | |
| 9196 RequestDelayingSitePerProcessBrowserTest() | |
| 9197 : test_server_(base::MakeUnique<net::EmbeddedTestServer>()) {} | |
| 9198 | |
| 9199 void AddDelayedResponse(const net::test_server::SendBytesCallback& send, | |
| 9200 const net::test_server::SendCompleteCallback& done) { | |
| 9201 // Just create a closure that closes the socket without sending a response. | |
| 9202 // This will propagate an error to the underlying request. | |
| 9203 send_response_closures_.push_back(base::Bind(send, "", done)); | |
| 9204 } | |
| 9205 | |
| 9206 // Must be called after any calls to SetDelayedRequestsForPath. | |
| 9207 void SetUpEmbeddedTestServer() { | |
| 9208 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 9209 SetupCrossSiteRedirector(test_server_.get()); | |
| 9210 // Allows for arbitrary "barrier" style delaying of requests matching | |
| 9211 // certain paths. | |
| 9212 test_server_->RegisterRequestHandler(base::Bind( | |
| 9213 &RequestDelayingSitePerProcessBrowserTest::HandleMockResource, | |
| 9214 base::Unretained(this))); | |
| 9215 ASSERT_TRUE(test_server_->Start()); | |
| 9216 } | |
| 9217 | |
| 9218 protected: | |
| 9219 // Delays |num_delayed| requests with URLs whose path parts match |path|. When | |
| 9220 // the |num_delayed| + 1 request matching the path comes in, the rest are | |
| 9221 // unblocked. | |
| 9222 // Note: must be called on the UI thread before |test_server_| is started. | |
| 9223 void SetDelayedRequestsForPath(const std::string& path, int num_delayed) { | |
| 9224 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 9225 num_remaining_requests_to_delay_for_path_[path] = num_delayed; | |
| 9226 } | |
| 9227 | |
| 9228 private: | |
| 9229 // Custom embedded test server handler. Looks for requests matching | |
| 9230 // num_remaining_requests_to_delay_for_path_, and delays them if necessary. As | |
| 9231 // soon as a single request comes in and: | |
| 9232 // 1) It matches a delayed path | |
| 9233 // 2) No path has any more requests to delay | |
| 9234 // Then we release the barrier and finish all delayed requests. | |
| 9235 std::unique_ptr<net::test_server::HttpResponse> HandleMockResource( | |
| 9236 const net::test_server::HttpRequest& request) { | |
| 9237 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 9238 auto it = | |
| 9239 num_remaining_requests_to_delay_for_path_.find(request.GetURL().path()); | |
| 9240 if (it == num_remaining_requests_to_delay_for_path_.end()) | |
| 9241 return nullptr; | |
| 9242 | |
| 9243 // If there are requests to delay for this path, make a delayed request | |
| 9244 // which | |
| 9245 // will be finished later. Otherwise fall through to the bottom and send an | |
| 9246 // empty response. | |
| 9247 if (it->second) { | |
| 9248 --it->second; | |
| 9249 return base::MakeUnique<DelayedResponse>(this); | |
| 9250 } | |
| 9251 MaybeStartRequests(); | |
| 9252 return std::unique_ptr<net::test_server::BasicHttpResponse>(); | |
| 9253 } | |
| 9254 | |
| 9255 // If there are no more requests to delay, post a series of tasks finishing | |
| 9256 // all the delayed tasks. | |
| 9257 void MaybeStartRequests() { | |
| 9258 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 9259 for (auto it : num_remaining_requests_to_delay_for_path_) { | |
| 9260 if (it.second > 0) | |
| 9261 return; | |
| 9262 } | |
| 9263 for (const auto it : send_response_closures_) { | |
| 9264 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, it); | |
| 9265 } | |
| 9266 } | |
| 9267 | |
| 9268 // This class offloads a "complete" closure to the underlying test fixture, | |
| 9269 // which can call it at any time to finish a request. | |
| 9270 class DelayedResponse : public net::test_server::BasicHttpResponse { | |
| 9271 public: | |
| 9272 DelayedResponse(RequestDelayingSitePerProcessBrowserTest* test_harness) | |
| 9273 : test_harness_(test_harness) {} | |
| 9274 void SendResponse( | |
| 9275 const net::test_server::SendBytesCallback& send, | |
| 9276 const net::test_server::SendCompleteCallback& done) override { | |
| 9277 test_harness_->AddDelayedResponse(send, done); | |
| 9278 } | |
| 9279 | |
| 9280 private: | |
| 9281 RequestDelayingSitePerProcessBrowserTest* test_harness_; | |
| 9282 | |
| 9283 DISALLOW_COPY_AND_ASSIGN(DelayedResponse); | |
| 9284 }; | |
| 9285 | |
| 9286 // Set of closures to call which will complete delayed requests. May only be | |
| 9287 // modified on the test_server_'s thread. | |
| 9288 std::vector<base::Closure> send_response_closures_; | |
| 9289 | |
| 9290 // Map from URL paths to the number of requests to delay for that particular | |
| 9291 // path. Initialized on the UI thread but modified and read on the IO thread | |
| 9292 // after the |test_server_| is started. | |
| 9293 std::map<std::string, int> num_remaining_requests_to_delay_for_path_; | |
| 9294 | |
| 9295 // Don't use embedded_test_server() because this one requires custom | |
| 9296 // initialization. | |
| 9297 std::unique_ptr<net::EmbeddedTestServer> test_server_; | |
| 9298 }; | |
| 9299 | |
| 9300 // Regression tests for https://crbug.com/678206, where the request throttling | |
| 9301 // in ResourceScheduler was not updated for OOPIFs. This resulted in a single | |
| 9302 // hung delayable request (e.g. video) starving all other delayable requests. | |
| 9303 // The tests work by delaying N requests in a cross-domain iframe. Once the n + | |
| 9304 // 1 request goes through to the network stack (ensuring it was not starved), | |
| 9305 // the delayed request completed. | |
| 9306 // | |
| 9307 // If the logic is not correct, these tests will time out, as the n + 1 request | |
| 9308 // will never start. | |
| 9309 IN_PROC_BROWSER_TEST_F(RequestDelayingSitePerProcessBrowserTest, | |
| 9310 DelayableSubframeRequestsOneFrame) { | |
| 9311 std::string path = "/mock-video.mp4"; | |
| 9312 SetDelayedRequestsForPath(path, 2); | |
| 9313 SetUpEmbeddedTestServer(); | |
| 9314 GURL url(embedded_test_server()->GetURL( | |
| 9315 "a.com", base::StringPrintf("/site_isolation/" | |
| 9316 "subframes_with_resources.html?urls=%s&" | |
| 9317 "numSubresources=3", | |
| 9318 path.c_str()))); | |
| 9319 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 9320 bool result; | |
| 9321 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); | |
| 9322 EXPECT_TRUE(result); | |
| 9323 } | |
| 9324 | |
| 9325 IN_PROC_BROWSER_TEST_F(RequestDelayingSitePerProcessBrowserTest, | |
| 9326 DelayableSubframeRequestsTwoFrames) { | |
| 9327 std::string path0 = "/mock-video0.mp4"; | |
| 9328 std::string path1 = "/mock-video1.mp4"; | |
| 9329 SetDelayedRequestsForPath(path0, 2); | |
| 9330 SetDelayedRequestsForPath(path1, 2); | |
| 9331 SetUpEmbeddedTestServer(); | |
| 9332 GURL url(embedded_test_server()->GetURL( | |
| 9333 "a.com", base::StringPrintf("/site_isolation/" | |
| 9334 "subframes_with_resources.html?urls=%s,%s&" | |
| 9335 "numSubresources=3", | |
| 9336 path0.c_str(), path1.c_str()))); | |
| 9337 EXPECT_TRUE(NavigateToURL(shell(), url)); | |
| 9338 bool result; | |
| 9339 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), "createFrames()", &result)); | |
| 9340 EXPECT_TRUE(result); | |
| 9341 } | |
| 9342 | |
| 9186 } // namespace content | 9343 } // namespace content |
| OLD | NEW |