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

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

Issue 2847003003: Fix SitePerProcessBrowserTest.ProcessTransferAfterError to not requiring modifying the mock HostRes… (Closed)
Patch Set: remove unnecessary include Created 3 years, 7 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
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>
(...skipping 20 matching lines...) Expand all
31 #include "content/browser/frame_host/cross_process_frame_connector.h" 31 #include "content/browser/frame_host/cross_process_frame_connector.h"
32 #include "content/browser/frame_host/frame_navigation_entry.h" 32 #include "content/browser/frame_host/frame_navigation_entry.h"
33 #include "content/browser/frame_host/frame_tree.h" 33 #include "content/browser/frame_host/frame_tree.h"
34 #include "content/browser/frame_host/interstitial_page_impl.h" 34 #include "content/browser/frame_host/interstitial_page_impl.h"
35 #include "content/browser/frame_host/navigation_controller_impl.h" 35 #include "content/browser/frame_host/navigation_controller_impl.h"
36 #include "content/browser/frame_host/navigation_entry_impl.h" 36 #include "content/browser/frame_host/navigation_entry_impl.h"
37 #include "content/browser/frame_host/navigator.h" 37 #include "content/browser/frame_host/navigator.h"
38 #include "content/browser/frame_host/render_frame_proxy_host.h" 38 #include "content/browser/frame_host/render_frame_proxy_host.h"
39 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" 39 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
40 #include "content/browser/gpu/compositor_util.h" 40 #include "content/browser/gpu/compositor_util.h"
41 #include "content/browser/loader/navigation_url_loader_network_service.h"
41 #include "content/browser/loader/resource_dispatcher_host_impl.h" 42 #include "content/browser/loader/resource_dispatcher_host_impl.h"
42 #include "content/browser/renderer_host/input/input_router_impl.h" 43 #include "content/browser/renderer_host/input/input_router_impl.h"
43 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h" 44 #include "content/browser/renderer_host/input/synthetic_tap_gesture.h"
44 #include "content/browser/renderer_host/render_view_host_impl.h" 45 #include "content/browser/renderer_host/render_view_host_impl.h"
45 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 46 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
46 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 47 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
47 #include "content/browser/web_contents/web_contents_impl.h" 48 #include "content/browser/web_contents/web_contents_impl.h"
48 #include "content/common/child_process_messages.h" 49 #include "content/common/child_process_messages.h"
49 #include "content/common/frame_messages.h" 50 #include "content/common/frame_messages.h"
50 #include "content/common/input/synthetic_tap_gesture_params.h" 51 #include "content/common/input/synthetic_tap_gesture_params.h"
(...skipping 13 matching lines...) Expand all
64 #include "content/public/common/url_constants.h" 65 #include "content/public/common/url_constants.h"
65 #include "content/public/test/browser_test_utils.h" 66 #include "content/public/test/browser_test_utils.h"
66 #include "content/public/test/content_browser_test_utils.h" 67 #include "content/public/test/content_browser_test_utils.h"
67 #include "content/public/test/test_frame_navigation_observer.h" 68 #include "content/public/test/test_frame_navigation_observer.h"
68 #include "content/public/test/test_navigation_observer.h" 69 #include "content/public/test/test_navigation_observer.h"
69 #include "content/public/test/test_utils.h" 70 #include "content/public/test/test_utils.h"
70 #include "content/shell/browser/shell.h" 71 #include "content/shell/browser/shell.h"
71 #include "content/test/content_browser_test_utils_internal.h" 72 #include "content/test/content_browser_test_utils_internal.h"
72 #include "ipc/ipc.mojom.h" 73 #include "ipc/ipc.mojom.h"
73 #include "ipc/ipc_security_test_util.h" 74 #include "ipc/ipc_security_test_util.h"
75 #include "mojo/public/cpp/bindings/strong_binding.h"
74 #include "net/dns/mock_host_resolver.h" 76 #include "net/dns/mock_host_resolver.h"
75 #include "net/test/embedded_test_server/embedded_test_server.h" 77 #include "net/test/embedded_test_server/embedded_test_server.h"
76 #include "net/test/embedded_test_server/http_request.h" 78 #include "net/test/embedded_test_server/http_request.h"
77 #include "net/test/embedded_test_server/http_response.h" 79 #include "net/test/embedded_test_server/http_response.h"
78 #include "testing/gmock/include/gmock/gmock.h" 80 #include "testing/gmock/include/gmock/gmock.h"
79 #include "testing/gtest/include/gtest/gtest.h" 81 #include "testing/gtest/include/gtest/gtest.h"
80 #include "third_party/WebKit/public/platform/WebFeaturePolicy.h" 82 #include "third_party/WebKit/public/platform/WebFeaturePolicy.h"
81 #include "third_party/WebKit/public/platform/WebInputEvent.h" 83 #include "third_party/WebKit/public/platform/WebInputEvent.h"
82 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" 84 #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
83 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 85 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
(...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 } 2390 }
2389 2391
2390 // Stop the test server and try to navigate the remote frame. 2392 // Stop the test server and try to navigate the remote frame.
2391 { 2393 {
2392 GURL url = embedded_test_server()->GetURL("bar.com", "/title3.html"); 2394 GURL url = embedded_test_server()->GetURL("bar.com", "/title3.html");
2393 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); 2395 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
2394 NavigateIframeToURL(shell()->web_contents(), "child-0", url); 2396 NavigateIframeToURL(shell()->web_contents(), "child-0", url);
2395 } 2397 }
2396 } 2398 }
2397 2399
2400 namespace {
2401 class FailingURLLoaderImpl : public mojom::URLLoader {
2402 public:
2403 explicit FailingURLLoaderImpl(mojom::URLLoaderClientPtr client) {
2404 ResourceRequestCompletionStatus status;
2405 status.error_code = net::ERR_NOT_IMPLEMENTED;
2406 client->OnComplete(status);
2407 }
2408
2409 void FollowRedirect() override {}
2410 void SetPriority(net::RequestPriority priority,
2411 int32_t intra_priority_value) override {}
2412 };
2413
2414 class FailingLoadFactory : public mojom::URLLoaderFactory {
2415 public:
2416 FailingLoadFactory() {}
2417 ~FailingLoadFactory() override {}
2418
2419 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader,
2420 int32_t routing_id,
2421 int32_t request_id,
2422 uint32_t options,
2423 const ResourceRequest& request,
2424 mojom::URLLoaderClientPtr client) override {
2425 new FailingURLLoaderImpl(std::move(client));
2426 }
2427 void SyncLoad(int32_t routing_id,
2428 int32_t request_id,
2429 const ResourceRequest& request,
2430 SyncLoadCallback callback) override {}
2431 };
2432 }
2433
2398 // Ensure that a cross-site page ends up in the correct process when it 2434 // Ensure that a cross-site page ends up in the correct process when it
2399 // successfully loads after earlier encountering a network error for it. 2435 // successfully loads after earlier encountering a network error for it.
2400 // See https://crbug.com/560511. 2436 // See https://crbug.com/560511.
2401 // TODO(creis): Make the net error page show in the correct process as well, 2437 // TODO(creis): Make the net error page show in the correct process as well,
2402 // per https://crbug.com/588314. 2438 // per https://crbug.com/588314.
2403 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ProcessTransferAfterError) { 2439 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, ProcessTransferAfterError) {
2404 GURL main_url(embedded_test_server()->GetURL( 2440 GURL main_url(embedded_test_server()->GetURL(
2405 "a.com", "/cross_site_iframe_factory.html?a(a)")); 2441 "a.com", "/cross_site_iframe_factory.html?a(a)"));
2406 EXPECT_TRUE(NavigateToURL(shell(), main_url)); 2442 EXPECT_TRUE(NavigateToURL(shell(), main_url));
2407 2443
2408 // It is safe to obtain the root frame tree node here, as it doesn't change. 2444 // It is safe to obtain the root frame tree node here, as it doesn't change.
2409 FrameTreeNode* root = web_contents()->GetFrameTree()->root(); 2445 FrameTreeNode* root = web_contents()->GetFrameTree()->root();
2410 FrameTreeNode* child = root->child_at(0); 2446 FrameTreeNode* child = root->child_at(0);
2411 GURL url_a = child->current_url(); 2447 GURL url_a = child->current_url();
2412 2448
2413 // Disable host resolution in the test server and try to navigate the subframe 2449 // Disable host resolution in the test server and try to navigate the subframe
2414 // cross-site, which will lead to a committed net error. 2450 // cross-site, which will lead to a committed net error.
2415 GURL url_b = embedded_test_server()->GetURL("b.com", "/title3.html"); 2451 GURL url_b = embedded_test_server()->GetURL("b.com", "/title3.html");
2416 host_resolver()->ClearRules(); 2452 bool network_service = base::CommandLine::ForCurrentProcess()->HasSwitch(
2453 switches::kEnableNetworkService);
2454 mojom::URLLoaderFactoryPtr failing_factory;
2455 mojo::MakeStrongBinding(base::MakeUnique<FailingLoadFactory>(),
2456 mojo::MakeRequest(&failing_factory));
2457 if (network_service) {
2458 NavigationURLLoaderNetworkService::OverrideURLLoaderFactoryForTesting(
2459 std::move(failing_factory));
2460 } else {
2461 host_resolver()->ClearRules();
2462 }
2463
2417 TestNavigationObserver observer(shell()->web_contents()); 2464 TestNavigationObserver observer(shell()->web_contents());
2418 NavigateIframeToURL(shell()->web_contents(), "child-0", url_b); 2465 NavigateIframeToURL(shell()->web_contents(), "child-0", url_b);
2419 EXPECT_FALSE(observer.last_navigation_succeeded()); 2466 EXPECT_FALSE(observer.last_navigation_succeeded());
2420 EXPECT_EQ(url_b, observer.last_navigation_url()); 2467 EXPECT_EQ(url_b, observer.last_navigation_url());
2421 EXPECT_EQ(2, shell()->web_contents()->GetController().GetEntryCount()); 2468 EXPECT_EQ(2, shell()->web_contents()->GetController().GetEntryCount());
2422 2469
2423 // PlzNavigate: Ensure that we have created a new process for the subframe. 2470 // PlzNavigate: Ensure that we have created a new process for the subframe.
2424 if (IsBrowserSideNavigationEnabled()) { 2471 if (IsBrowserSideNavigationEnabled()) {
2425 EXPECT_EQ( 2472 EXPECT_EQ(
2426 " Site A ------------ proxies for B\n" 2473 " Site A ------------ proxies for B\n"
(...skipping 12 matching lines...) Expand all
2439 // last successful url should be empty (since the frame only loaded an error 2486 // last successful url should be empty (since the frame only loaded an error
2440 // page). 2487 // page).
2441 if (IsBrowserSideNavigationEnabled()) 2488 if (IsBrowserSideNavigationEnabled())
2442 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url()); 2489 EXPECT_EQ(GURL(), child->current_frame_host()->last_successful_url());
2443 else 2490 else
2444 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url()); 2491 EXPECT_EQ(url_a, child->current_frame_host()->last_successful_url());
2445 EXPECT_EQ(url_b, child->current_url()); 2492 EXPECT_EQ(url_b, child->current_url());
2446 EXPECT_EQ("null", child->current_origin().Serialize()); 2493 EXPECT_EQ("null", child->current_origin().Serialize());
2447 2494
2448 // Try again after re-enabling host resolution. 2495 // Try again after re-enabling host resolution.
2449 host_resolver()->AddRule("*", "127.0.0.1"); 2496 if (!network_service)
2497 host_resolver()->AddRule("*", "127.0.0.1");
Charlie Reis 2017/04/28 18:08:14 Shouldn't there be an else branch here? How would
jam 2017/04/28 18:09:53 The URLLoaderFactory set above is only used for on
Charlie Reis 2017/04/28 18:14:52 Oh, ok. That seems a bit non-obvious, but glad it
jam 2017/04/28 19:25:24 This was documented in the test method; but point
2498
2450 NavigateIframeToURL(shell()->web_contents(), "child-0", url_b); 2499 NavigateIframeToURL(shell()->web_contents(), "child-0", url_b);
2451 EXPECT_TRUE(observer.last_navigation_succeeded()); 2500 EXPECT_TRUE(observer.last_navigation_succeeded());
2452 EXPECT_EQ(url_b, observer.last_navigation_url()); 2501 EXPECT_EQ(url_b, observer.last_navigation_url());
2453 2502
2454 // The FrameTreeNode should have updated its URL and origin. 2503 // The FrameTreeNode should have updated its URL and origin.
2455 EXPECT_EQ(url_b, child->current_frame_host()->last_successful_url()); 2504 EXPECT_EQ(url_b, child->current_frame_host()->last_successful_url());
2456 EXPECT_EQ(url_b, child->current_url()); 2505 EXPECT_EQ(url_b, child->current_url());
2457 EXPECT_EQ(url_b.GetOrigin().spec(), 2506 EXPECT_EQ(url_b.GetOrigin().spec(),
2458 child->current_origin().Serialize() + '/'); 2507 child->current_origin().Serialize() + '/');
2459 2508
(...skipping 7187 matching lines...) Expand 10 before | Expand all | Expand 10 after
9647 // certain paths. Call SetDelayedRequestsForPath to delay requests, then 9696 // certain paths. Call SetDelayedRequestsForPath to delay requests, then
9648 // SetUpEmbeddedTestServer to register handlers and start the server. 9697 // SetUpEmbeddedTestServer to register handlers and start the server.
9649 class RequestDelayingSitePerProcessBrowserTest 9698 class RequestDelayingSitePerProcessBrowserTest
9650 : public SitePerProcessBrowserTest { 9699 : public SitePerProcessBrowserTest {
9651 public: 9700 public:
9652 RequestDelayingSitePerProcessBrowserTest() 9701 RequestDelayingSitePerProcessBrowserTest()
9653 : test_server_(base::MakeUnique<net::EmbeddedTestServer>()) {} 9702 : test_server_(base::MakeUnique<net::EmbeddedTestServer>()) {}
9654 9703
9655 // Must be called after any calls to SetDelayedRequestsForPath. 9704 // Must be called after any calls to SetDelayedRequestsForPath.
9656 void SetUpEmbeddedTestServer() { 9705 void SetUpEmbeddedTestServer() {
9657 host_resolver()->AddRule("*", "127.0.0.1");
9658 SetupCrossSiteRedirector(test_server_.get()); 9706 SetupCrossSiteRedirector(test_server_.get());
9659 test_server_->RegisterRequestHandler(base::Bind( 9707 test_server_->RegisterRequestHandler(base::Bind(
9660 &RequestDelayingSitePerProcessBrowserTest::HandleMockResource, 9708 &RequestDelayingSitePerProcessBrowserTest::HandleMockResource,
9661 base::Unretained(this))); 9709 base::Unretained(this)));
9662 ASSERT_TRUE(test_server_->Start()); 9710 ASSERT_TRUE(test_server_->Start());
9663 } 9711 }
9664 9712
9665 // Delays |num_delayed| requests with URLs whose path parts match |path|. When 9713 // Delays |num_delayed| requests with URLs whose path parts match |path|. When
9666 // the |num_delayed| + 1 request matching the path comes in, the rest are 9714 // the |num_delayed| + 1 request matching the path comes in, the rest are
9667 // unblocked. 9715 // unblocked.
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
9993 names.insert(root->children[0]->frame_entry->frame_unique_name()); 10041 names.insert(root->children[0]->frame_entry->frame_unique_name());
9994 } 10042 }
9995 10043
9996 // More than one entry in the set means that the subframe frame navigation 10044 // More than one entry in the set means that the subframe frame navigation
9997 // entries didn't have a consistent unique name. This will break history 10045 // entries didn't have a consistent unique name. This will break history
9998 // navigations =( 10046 // navigations =(
9999 EXPECT_THAT(names, SizeIs(1)) << "Mismatched names for subframe!"; 10047 EXPECT_THAT(names, SizeIs(1)) << "Mismatched names for subframe!";
10000 } 10048 }
10001 10049
10002 } // namespace content 10050 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/navigation_url_loader_network_service.cc ('k') | content/public/test/browser_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698