blob: fd50b2c355610b2720083881826aa49204cb8dcf [file] [log] [blame]
morrita7fd88cd2014-10-02 22:48:581// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/command_line.h"
Min Qineb961902019-03-16 08:08:226#include "build/build_config.h"
lfg06aac852015-03-23 22:36:107#include "content/browser/child_process_launcher.h"
8#include "content/browser/renderer_host/render_process_host_impl.h"
9#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicz9e0ce4e2017-09-28 19:09:1510#include "content/public/browser/render_frame_host.h"
lfg06aac852015-03-23 22:36:1011#include "content/public/browser/web_contents.h"
morrita7fd88cd2014-10-02 22:48:5812#include "content/public/common/content_switches.h"
13#include "content/public/test/content_browser_test.h"
14#include "content/public/test/content_browser_test_utils.h"
Lukasz Anforowiczb36b4e22019-06-11 18:37:0315#include "content/public/test/no_renderer_crashes_assertion.h"
lfg06aac852015-03-23 22:36:1016#include "content/public/test/test_navigation_observer.h"
17#include "content/shell/browser/shell.h"
18
19namespace {
20
21class MockChildProcessLauncherClient
22 : public content::ChildProcessLauncher::Client {
23 public:
24 MockChildProcessLauncherClient()
25 : client_(nullptr), simulate_failure_(false) {}
26
27 void OnProcessLaunched() override {
28 if (simulate_failure_)
wfh3adf87d2016-05-03 23:26:0629 client_->OnProcessLaunchFailed(content::LAUNCH_RESULT_FAILURE);
lfg06aac852015-03-23 22:36:1030 else
31 client_->OnProcessLaunched();
Nico Weberfefaa412019-02-11 16:10:1132 }
wfh3adf87d2016-05-03 23:26:0633
34 void OnProcessLaunchFailed(int error_code) override {
35 client_->OnProcessLaunchFailed(error_code);
Nico Weberfefaa412019-02-11 16:10:1136 }
lfg06aac852015-03-23 22:36:1037
Min Qineb961902019-03-16 08:08:2238#if defined(OS_ANDROID)
39 bool CanUseWarmUpConnection() override { return true; }
40#endif
41
lfg06aac852015-03-23 22:36:1042 content::ChildProcessLauncher::Client* client_;
43 bool simulate_failure_;
44};
45
Lukasz Anforowicz9e0ce4e2017-09-28 19:09:1546} // namespace
morrita7fd88cd2014-10-02 22:48:5847
48namespace content {
49
lfg06aac852015-03-23 22:36:1050class ChildProcessLauncherBrowserTest : public ContentBrowserTest {};
morrita7fd88cd2014-10-02 22:48:5851
lfg06aac852015-03-23 22:36:1052IN_PROC_BROWSER_TEST_F(ChildProcessLauncherBrowserTest, ChildSpawnFail) {
53 GURL url("about:blank");
54 Shell* window = shell();
55 MockChildProcessLauncherClient* client(nullptr);
56
57 // Navigate once and simulate a process failing to spawn.
58 TestNavigationObserver nav_observer1(window->web_contents(), 1);
59 client = new MockChildProcessLauncherClient;
60 window->LoadURL(url);
61 client->client_ = static_cast<RenderProcessHostImpl*>(
Lukasz Anforowicz9e0ce4e2017-09-28 19:09:1562 window->web_contents()->GetMainFrame()->GetProcess())
63 ->child_process_launcher_->ReplaceClientForTest(client);
lfg06aac852015-03-23 22:36:1064 client->simulate_failure_ = true;
Lukasz Anforowiczefbb64932019-06-19 15:43:5165 {
66 ScopedAllowRendererCrashes allow_renderer_crashes(shell());
67 nav_observer1.Wait();
68 }
lfg06aac852015-03-23 22:36:1069 delete client;
70 NavigationEntry* last_entry =
71 shell()->web_contents()->GetController().GetLastCommittedEntry();
72 // Make sure we didn't navigate.
73 CHECK(!last_entry);
74
75 // Navigate again and let the process spawn correctly.
76 TestNavigationObserver nav_observer2(window->web_contents(), 1);
77 window->LoadURL(url);
78 nav_observer2.Wait();
79 last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
80 // Make sure that we navigated to the proper URL.
81 CHECK(last_entry && last_entry->GetPageType() == PAGE_TYPE_NORMAL);
82 CHECK(shell()->web_contents()->GetLastCommittedURL() == url);
83
84 // Navigate again, using the same renderer.
85 url = GURL("data:text/html,dataurl");
86 TestNavigationObserver nav_observer3(window->web_contents(), 1);
87 window->LoadURL(url);
88 nav_observer3.Wait();
89 last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
90 // Make sure that we navigated to the proper URL.
91 CHECK(last_entry && last_entry->GetPageType() == PAGE_TYPE_NORMAL);
92 CHECK(shell()->web_contents()->GetLastCommittedURL() == url);
93}
94
morrita7fd88cd2014-10-02 22:48:5895} // namespace content