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

Side by Side Diff: components/browser_watcher/exit_code_watcher_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 (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "components/browser_watcher/exit_code_watcher_win.h" 5 #include "components/browser_watcher/exit_code_watcher_win.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 23 matching lines...) Expand all
34 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(INFINITE)); 34 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(INFINITE));
35 return 1; 35 return 1;
36 } 36 }
37 37
38 class ScopedSleeperProcess { 38 class ScopedSleeperProcess {
39 public: 39 public:
40 ScopedSleeperProcess() : is_killed_(false) { 40 ScopedSleeperProcess() : is_killed_(false) {
41 } 41 }
42 42
43 ~ScopedSleeperProcess() { 43 ~ScopedSleeperProcess() {
44 if (process_.IsValid()) { 44 if (spawn_child_.process.IsValid()) {
45 process_.Terminate(-1, false); 45 spawn_child_.process.Terminate(-1, false);
46 EXPECT_TRUE(process_.WaitForExit(nullptr)); 46 EXPECT_TRUE(spawn_child_.process.WaitForExit(nullptr));
47 } 47 }
48 } 48 }
49 49
50 void Launch() { 50 void Launch() {
51 ASSERT_FALSE(process_.IsValid()); 51 ASSERT_FALSE(spawn_child_.process.IsValid());
52 52
53 base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine()); 53 base::CommandLine cmd_line(base::GetMultiProcessTestChildBaseCommandLine());
54 base::LaunchOptions options; 54 base::LaunchOptions options;
55 options.start_hidden = true; 55 options.start_hidden = true;
56 process_ = base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options); 56 spawn_child_ =
57 ASSERT_TRUE(process_.IsValid()); 57 base::SpawnMultiProcessTestChild("Sleeper", cmd_line, options);
58 ASSERT_TRUE(spawn_child_.process.IsValid());
58 } 59 }
59 60
60 void Kill(int exit_code, bool wait) { 61 void Kill(int exit_code, bool wait) {
61 ASSERT_TRUE(process_.IsValid()); 62 ASSERT_TRUE(spawn_child_.process.IsValid());
62 ASSERT_FALSE(is_killed_); 63 ASSERT_FALSE(is_killed_);
63 process_.Terminate(exit_code, false); 64 spawn_child_.process.Terminate(exit_code, false);
64 int seen_exit_code = 0; 65 int seen_exit_code = 0;
65 EXPECT_TRUE(process_.WaitForExit(&seen_exit_code)); 66 EXPECT_TRUE(spawn_child_.process.WaitForExit(&seen_exit_code));
66 EXPECT_EQ(exit_code, seen_exit_code); 67 EXPECT_EQ(exit_code, seen_exit_code);
67 is_killed_ = true; 68 is_killed_ = true;
68 } 69 }
69 70
70 const base::Process& process() const { return process_; } 71 const base::Process& process() const { return spawn_child_.process; }
71 72
72 private: 73 private:
73 base::Process process_; 74 base::SpawnChildResult spawn_child_;
74 bool is_killed_; 75 bool is_killed_;
75 }; 76 };
76 77
77 class ExitCodeWatcherTest : public testing::Test { 78 class ExitCodeWatcherTest : public testing::Test {
78 public: 79 public:
79 typedef testing::Test Super; 80 typedef testing::Test Super;
80 81
81 static const int kExitCode = 0xCAFEBABE; 82 static const int kExitCode = 0xCAFEBABE;
82 83
83 ExitCodeWatcherTest() : cmd_line_(base::CommandLine::NO_PROGRAM) {} 84 ExitCodeWatcherTest() : cmd_line_(base::CommandLine::NO_PROGRAM) {}
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Kill the sleeper, and make sure it's exited before we continue. 167 // Kill the sleeper, and make sure it's exited before we continue.
167 ASSERT_NO_FATAL_FAILURE(sleeper.Kill(kExitCode, true)); 168 ASSERT_NO_FATAL_FAILURE(sleeper.Kill(kExitCode, true));
168 169
169 watcher.WaitForExit(); 170 watcher.WaitForExit();
170 EXPECT_EQ(kExitCode, watcher.exit_code()); 171 EXPECT_EQ(kExitCode, watcher.exit_code());
171 172
172 VerifyWroteExitCode(sleeper.process().Pid(), kExitCode); 173 VerifyWroteExitCode(sleeper.process().Pid(), kExitCode);
173 } 174 }
174 175
175 } // namespace browser_watcher 176 } // namespace browser_watcher
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698