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

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

Issue 1018043004: Drop queued IPC messages if the child process dies while spawning (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding test Created 5 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #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"
6 #include "content/public/common/content_switches.h" 10 #include "content/public/common/content_switches.h"
7 #include "content/public/test/content_browser_test.h" 11 #include "content/public/test/content_browser_test.h"
8 #include "content/public/test/content_browser_test_utils.h" 12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/public/test/test_navigation_observer.h"
14 #include "content/shell/browser/shell.h"
15
16 namespace {
17
18 class 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 }
9 37
10 namespace content { 38 namespace content {
11 39
12 typedef ContentBrowserTest ChildProcessLauncherBrowserTest; 40 class ChildProcessLauncherBrowserTest : public ContentBrowserTest {};
13 41
14 class StatsTableBrowserTest : public ChildProcessLauncherBrowserTest { 42 class StatsTableBrowserTest : public ChildProcessLauncherBrowserTest {
15 public: 43 public:
16 void SetUpCommandLine(base::CommandLine* command_line) override { 44 void SetUpCommandLine(base::CommandLine* command_line) override {
17 command_line->AppendSwitch(switches::kEnableStatsTable); 45 command_line->AppendSwitch(switches::kEnableStatsTable);
18 } 46 }
19 }; 47 };
20 48
21 IN_PROC_BROWSER_TEST_F(StatsTableBrowserTest, StartWithStatTable) { 49 IN_PROC_BROWSER_TEST_F(StatsTableBrowserTest, StartWithStatTable) {
22 NavigateToURL(shell(), GURL("about:blank")); 50 NavigateToURL(shell(), GURL("about:blank"));
23 } 51 }
24 52
53 IN_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
25 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698