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

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

Issue 2655393004: Make ResourceScheduler work in OOPIF (Closed)
Patch Set: self review 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 void AddDelayedResponse(const net::test_server::SendBytesCallback& send,
9202 const net::test_server::SendCompleteCallback& done) {
mmenke 2017/02/01 20:21:40 Comment that this is called on the test server's t
Charlie Harrison 2017/02/01 22:22:33 Done.
Charlie Harrison 2017/02/01 22:22:34 Done.
9203 // Just create a closure that closes the socket without sending a response.
9204 // This will propagate an error to the underlying request.
9205 send_response_closures_.push_back(base::Bind(send, "", done));
9206 }
mmenke 2017/02/01 20:21:40 This can be private (Inner classes can access even
Charlie Harrison 2017/02/01 22:22:34 Done.
9207
9208 // Must be called after any calls to SetDelayedRequestsForPath.
9209 void SetUpEmbeddedTestServer() {
9210 host_resolver()->AddRule("*", "127.0.0.1");
9211 SetupCrossSiteRedirector(test_server_.get());
9212 test_server_->RegisterRequestHandler(base::Bind(
9213 &RequestDelayingSitePerProcessBrowserTest::HandleMockResource,
9214 base::Unretained(this)));
9215 ASSERT_TRUE(test_server_->Start());
9216 }
9217
9218 protected:
mmenke 2017/02/01 20:21:40 no need for protected - it doesn't really do anyth
Charlie Harrison 2017/02/01 22:22:35 Done.
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) {
mmenke 2017/02/01 20:21:40 DCHECK that the test_server isn't started?
Charlie Harrison 2017/02/01 22:22:35 Done.
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);
mmenke 2017/02/01 20:21:40 This DCHECK passes? The TestServer uses its own t
Charlie Harrison 2017/02/01 22:22:34 Me too, I am investigating why. For now I removed
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
mmenke 2017/02/01 20:21:40 nit: reflow comment.
Charlie Harrison 2017/02/01 22:22:34 Done.
9245 // will be finished later. Otherwise fall through to the bottom and send an
9246 // empty response.
9247 if (it->second) {
mmenke 2017/02/01 20:21:40 nit: > 0, to make it clear this is an int we're l
Charlie Harrison 2017/02/01 22:22:34 Done.
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.
mmenke 2017/02/01 20:21:40 Again, mention thread this is called on.
Charlie Harrison 2017/02/01 22:22:35 Done.
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);
mmenke 2017/02/01 20:21:40 Why does this need to use PostTask?
Charlie Harrison 2017/02/01 22:22:35 It doesn't need to.
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.
mmenke 2017/02/01 20:21:40 I'm having trouble following this comment. Maybe:
Charlie Harrison 2017/02/01 22:22:34 Much better. Changed.
9270 class DelayedResponse : public net::test_server::BasicHttpResponse {
9271 public:
9272 DelayedResponse(RequestDelayingSitePerProcessBrowserTest* test_harness)
mmenke 2017/02/01 20:21:40 explicit
Charlie Harrison 2017/02/01 22:22:34 Done.
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_;
mmenke 2017/02/01 20:21:41 include <string>
Charlie Harrison 2017/02/01 22:22:34 <string> is in the header.
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 +
mmenke 2017/02/01 20:21:40 nit: This paragraph uses N here and n below.
Charlie Harrison 2017/02/01 22:22:34 Changed to "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
mmenke 2017/02/01 20:21:40 nit: n + 1 request seems a bit confusing - it cou
Charlie Harrison 2017/02/01 22:22:34 Changed to n + 1st.
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
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