Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: content/browser/site_per_process_browsertest.cc

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

Powered by Google App Engine
This is Rietveld 408576698