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

Side by Side Diff: chrome/browser/process_singleton_win_unittest.cc

Issue 2733323002: Changing multiprocess test SpawnChild to return a struct. (Closed)
Patch Set: Synced Created 3 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/process_singleton.h" 5 #include "chrome/browser/process_singleton.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ASSERT_NO_FATAL_FAILURE(base::MultiProcessTest::SetUp()); 154 ASSERT_NO_FATAL_FAILURE(base::MultiProcessTest::SetUp());
155 155
156 // Drop the process finder notification timeout to one second for testing. 156 // Drop the process finder notification timeout to one second for testing.
157 old_notification_timeout_ = chrome::SetNotificationTimeoutForTesting( 157 old_notification_timeout_ = chrome::SetNotificationTimeoutForTesting(
158 base::TimeDelta::FromSeconds(1)); 158 base::TimeDelta::FromSeconds(1));
159 } 159 }
160 160
161 void TearDown() override { 161 void TearDown() override {
162 chrome::SetNotificationTimeoutForTesting(old_notification_timeout_); 162 chrome::SetNotificationTimeoutForTesting(old_notification_timeout_);
163 163
164 if (browser_victim_.IsValid()) { 164 if (browser_victim_.process.IsValid()) {
165 EXPECT_TRUE(::SetEvent(continue_event_.Get())); 165 EXPECT_TRUE(::SetEvent(continue_event_.Get()));
166 EXPECT_TRUE(browser_victim_.WaitForExit(nullptr)); 166 EXPECT_TRUE(browser_victim_.process.WaitForExit(nullptr));
167 } 167 }
168 168
169 base::MultiProcessTest::TearDown(); 169 base::MultiProcessTest::TearDown();
170 } 170 }
171 171
172 void LaunchHungBrowserProcess(WindowOption window_option) { 172 void LaunchHungBrowserProcess(WindowOption window_option) {
173 // Create a unique user data dir to rendezvous on. 173 // Create a unique user data dir to rendezvous on.
174 ASSERT_TRUE(user_data_dir_.CreateUniqueTempDir()); 174 ASSERT_TRUE(user_data_dir_.CreateUniqueTempDir());
175 175
176 // Create the named "ready" event, this is unique to our process. 176 // Create the named "ready" event, this is unique to our process.
(...skipping 11 matching lines...) Expand all
188 ASSERT_TRUE(continue_event_.IsValid()); 188 ASSERT_TRUE(continue_event_.IsValid());
189 189
190 window_option_ = window_option; 190 window_option_ = window_option;
191 191
192 base::LaunchOptions options; 192 base::LaunchOptions options;
193 options.start_hidden = true; 193 options.start_hidden = true;
194 browser_victim_ = 194 browser_victim_ =
195 SpawnChildWithOptions("ProcessSingletonTestProcessMain", options); 195 SpawnChildWithOptions("ProcessSingletonTestProcessMain", options);
196 196
197 // Wait for the ready event (or process exit). 197 // Wait for the ready event (or process exit).
198 HANDLE handles[] = {ready_event.Get(), browser_victim_.Handle()}; 198 HANDLE handles[] = {ready_event.Get(), browser_victim_.process.Handle()};
199 // The wait should always return because either |ready_event| is signaled or 199 // The wait should always return because either |ready_event| is signaled or
200 // |browser_victim_| died unexpectedly or exited on error. 200 // |browser_victim_| died unexpectedly or exited on error.
201 DWORD result = 201 DWORD result =
202 ::WaitForMultipleObjects(arraysize(handles), handles, FALSE, INFINITE); 202 ::WaitForMultipleObjects(arraysize(handles), handles, FALSE, INFINITE);
203 ASSERT_EQ(WAIT_OBJECT_0, result); 203 ASSERT_EQ(WAIT_OBJECT_0, result);
204 } 204 }
205 205
206 base::CommandLine MakeCmdLine(const std::string& procname) override { 206 base::CommandLine MakeCmdLine(const std::string& procname) override {
207 base::CommandLine cmd_line = base::MultiProcessTest::MakeCmdLine(procname); 207 base::CommandLine cmd_line = base::MultiProcessTest::MakeCmdLine(procname);
208 208
(...skipping 12 matching lines...) Expand all
221 // The ready event has been signalled - the process singleton is held by 221 // The ready event has been signalled - the process singleton is held by
222 // the hung sub process. 222 // the hung sub process.
223 test_singleton_.reset(new ProcessSingleton( 223 test_singleton_.reset(new ProcessSingleton(
224 user_data_dir(), base::Bind(&NotificationCallback))); 224 user_data_dir(), base::Bind(&NotificationCallback)));
225 225
226 test_singleton_->OverrideShouldKillRemoteProcessCallbackForTesting( 226 test_singleton_->OverrideShouldKillRemoteProcessCallbackForTesting(
227 base::Bind(&ProcessSingletonTest::MockShouldKillRemoteProcess, 227 base::Bind(&ProcessSingletonTest::MockShouldKillRemoteProcess,
228 base::Unretained(this), allow_kill)); 228 base::Unretained(this), allow_kill));
229 } 229 }
230 230
231 base::Process* browser_victim() { return &browser_victim_; } 231 base::Process* browser_victim() { return &(browser_victim_.process); }
232 const base::FilePath& user_data_dir() const { 232 const base::FilePath& user_data_dir() const {
233 return user_data_dir_.GetPath(); 233 return user_data_dir_.GetPath();
234 } 234 }
235 ProcessSingleton* test_singleton() const { return test_singleton_.get(); } 235 ProcessSingleton* test_singleton() const { return test_singleton_.get(); }
236 bool should_kill_called() const { return should_kill_called_; } 236 bool should_kill_called() const { return should_kill_called_; }
237 237
238 private: 238 private:
239 bool MockShouldKillRemoteProcess(bool allow_kill) { 239 bool MockShouldKillRemoteProcess(bool allow_kill) {
240 should_kill_called_ = true; 240 should_kill_called_ = true;
241 return allow_kill; 241 return allow_kill;
242 } 242 }
243 243
244 base::string16 ready_event_name_; 244 base::string16 ready_event_name_;
245 base::string16 continue_event_name_; 245 base::string16 continue_event_name_;
246 246
247 WindowOption window_option_; 247 WindowOption window_option_;
248 base::ScopedTempDir user_data_dir_; 248 base::ScopedTempDir user_data_dir_;
249 base::Process browser_victim_; 249 base::SpawnChildResult browser_victim_;
250 base::win::ScopedHandle continue_event_; 250 base::win::ScopedHandle continue_event_;
251 251
252 std::unique_ptr<ProcessSingleton> test_singleton_; 252 std::unique_ptr<ProcessSingleton> test_singleton_;
253 253
254 base::TimeDelta old_notification_timeout_; 254 base::TimeDelta old_notification_timeout_;
255 bool should_kill_called_; 255 bool should_kill_called_;
256 256
257 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonTest); 257 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonTest);
258 }; 258 };
259 259
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // visible window. 318 // visible window.
319 EXPECT_TRUE(should_kill_called()); 319 EXPECT_TRUE(should_kill_called());
320 320
321 // Verify that the hung browser has been terminated with the 321 // Verify that the hung browser has been terminated with the
322 // RESULT_CODE_HUNG exit code. 322 // RESULT_CODE_HUNG exit code.
323 int exit_code = 0; 323 int exit_code = 0;
324 EXPECT_TRUE( 324 EXPECT_TRUE(
325 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); 325 browser_victim()->WaitForExitWithTimeout(base::TimeDelta(), &exit_code));
326 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code); 326 EXPECT_EQ(content::RESULT_CODE_HUNG, exit_code);
327 } 327 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698