blob: 9ef655c6fc6ef22dd3bdb12d12e67f58135872d6 [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"
lfg06aac852015-03-23 22:36:106#include "content/browser/child_process_launcher.h"
7#include "content/browser/renderer_host/render_process_host_impl.h"
8#include "content/public/browser/navigation_entry.h"
9#include "content/public/browser/web_contents.h"
morrita7fd88cd2014-10-02 22:48:5810#include "content/public/common/content_switches.h"
11#include "content/public/test/content_browser_test.h"
12#include "content/public/test/content_browser_test_utils.h"
lfg06aac852015-03-23 22:36:1013#include "content/public/test/test_navigation_observer.h"
14#include "content/shell/browser/shell.h"
15
16namespace {
17
18class MockChildProcessLauncherClient
19 : public content::ChildProcessLauncher::Client {
20 public:
21 MockChildProcessLauncherClient()
22 : client_(nullptr), simulate_failure_(false) {}
23
24 void OnProcessLaunched() override {
25 if (simulate_failure_)
26 client_->OnProcessLaunchFailed();
27 else
28 client_->OnProcessLaunched();
29 };
30 void OnProcessLaunchFailed() override { client_->OnProcessLaunchFailed(); };
31
32 content::ChildProcessLauncher::Client* client_;
33 bool simulate_failure_;
34};
35
36}
morrita7fd88cd2014-10-02 22:48:5837
38namespace content {
39
lfg06aac852015-03-23 22:36:1040class ChildProcessLauncherBrowserTest : public ContentBrowserTest {};
morrita7fd88cd2014-10-02 22:48:5841
42class StatsTableBrowserTest : public ChildProcessLauncherBrowserTest {
43 public:
dchengc2282aa2014-10-21 12:07:5844 void SetUpCommandLine(base::CommandLine* command_line) override {
morrita7fd88cd2014-10-02 22:48:5845 command_line->AppendSwitch(switches::kEnableStatsTable);
46 }
47};
48
49IN_PROC_BROWSER_TEST_F(StatsTableBrowserTest, StartWithStatTable) {
50 NavigateToURL(shell(), GURL("about:blank"));
51}
52
lfg06aac852015-03-23 22:36:1053IN_PROC_BROWSER_TEST_F(ChildProcessLauncherBrowserTest, ChildSpawnFail) {
54 GURL url("about:blank");
55 Shell* window = shell();
56 MockChildProcessLauncherClient* client(nullptr);
57
58 // Navigate once and simulate a process failing to spawn.
59 TestNavigationObserver nav_observer1(window->web_contents(), 1);
60 client = new MockChildProcessLauncherClient;
61 window->LoadURL(url);
62 client->client_ = static_cast<RenderProcessHostImpl*>(
63 window->web_contents()->GetRenderProcessHost())
64 ->child_process_launcher_->ReplaceClientForTest(client);
65 client->simulate_failure_ = true;
66 nav_observer1.Wait();
67 delete client;
68 NavigationEntry* last_entry =
69 shell()->web_contents()->GetController().GetLastCommittedEntry();
70 // Make sure we didn't navigate.
71 CHECK(!last_entry);
72
73 // Navigate again and let the process spawn correctly.
74 TestNavigationObserver nav_observer2(window->web_contents(), 1);
75 window->LoadURL(url);
76 nav_observer2.Wait();
77 last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
78 // Make sure that we navigated to the proper URL.
79 CHECK(last_entry && last_entry->GetPageType() == PAGE_TYPE_NORMAL);
80 CHECK(shell()->web_contents()->GetLastCommittedURL() == url);
81
82 // Navigate again, using the same renderer.
83 url = GURL("data:text/html,dataurl");
84 TestNavigationObserver nav_observer3(window->web_contents(), 1);
85 window->LoadURL(url);
86 nav_observer3.Wait();
87 last_entry = shell()->web_contents()->GetController().GetLastCommittedEntry();
88 // Make sure that we navigated to the proper URL.
89 CHECK(last_entry && last_entry->GetPageType() == PAGE_TYPE_NORMAL);
90 CHECK(shell()->web_contents()->GetLastCommittedURL() == url);
91}
92
morrita7fd88cd2014-10-02 22:48:5893} // namespace content