OLD | NEW |
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/app/chrome_watcher_client_win.h" | 5 #include "chrome/app/chrome_watcher_client_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/synchronization/waitable_event.h" | 18 #include "base/synchronization/waitable_event.h" |
19 #include "base/test/multiprocess_test.h" | 19 #include "base/test/multiprocess_test.h" |
20 #include "base/threading/simple_thread.h" | 20 #include "base/threading/simple_thread.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "base/win/scoped_handle.h" | 22 #include "base/win/scoped_handle.h" |
| 23 #include "base/win/win_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "testing/multiprocess_func_list.h" | 25 #include "testing/multiprocess_func_list.h" |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 const char kParentHandle[] = "parent-handle"; | 29 const char kParentHandle[] = "parent-handle"; |
29 const char kEventHandle[] = "event-handle"; | 30 const char kEventHandle[] = "event-handle"; |
30 const char kNamedEventSuffix[] = "named-event-suffix"; | 31 const char kNamedEventSuffix[] = "named-event-suffix"; |
31 | 32 |
32 const base::char16 kExitEventBaseName[] = L"ChromeWatcherClientTestExitEvent_"; | 33 const base::char16 kExitEventBaseName[] = L"ChromeWatcherClientTestExitEvent_"; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 } | 164 } |
164 | 165 |
165 private: | 166 private: |
166 // Returns a command line to launch back into ChromeWatcherClientTestProcess. | 167 // Returns a command line to launch back into ChromeWatcherClientTestProcess. |
167 base::CommandLine GenerateCommandLine(HANDLE parent_handle, | 168 base::CommandLine GenerateCommandLine(HANDLE parent_handle, |
168 DWORD main_thread_id, | 169 DWORD main_thread_id, |
169 HANDLE on_initialized_event) { | 170 HANDLE on_initialized_event) { |
170 base::CommandLine ret = base::GetMultiProcessTestChildBaseCommandLine(); | 171 base::CommandLine ret = base::GetMultiProcessTestChildBaseCommandLine(); |
171 ret.AppendSwitchASCII(switches::kTestChildProcess, | 172 ret.AppendSwitchASCII(switches::kTestChildProcess, |
172 "ChromeWatcherClientTestProcess"); | 173 "ChromeWatcherClientTestProcess"); |
173 ret.AppendSwitchASCII(kEventHandle, | 174 ret.AppendSwitchASCII( |
174 base::UintToString(reinterpret_cast<unsigned int>( | 175 kEventHandle, |
175 on_initialized_event))); | 176 base::UintToString(base::win::HandleToUint32(on_initialized_event))); |
176 ret.AppendSwitchASCII( | 177 ret.AppendSwitchASCII( |
177 kParentHandle, | 178 kParentHandle, |
178 base::UintToString(reinterpret_cast<unsigned int>(parent_handle))); | 179 base::UintToString(base::win::HandleToUint32(parent_handle))); |
179 | 180 |
180 // Our child does not actually need the main thread ID, but we verify here | 181 // Our child does not actually need the main thread ID, but we verify here |
181 // that the correct ID is being passed from the client. | 182 // that the correct ID is being passed from the client. |
182 EXPECT_EQ(::GetCurrentThreadId(), main_thread_id); | 183 EXPECT_EQ(::GetCurrentThreadId(), main_thread_id); |
183 | 184 |
184 ret.AppendSwitchASCII(kNamedEventSuffix, | 185 ret.AppendSwitchASCII(kNamedEventSuffix, |
185 base::UTF16ToASCII(NamedEventSuffix())); | 186 base::UTF16ToASCII(NamedEventSuffix())); |
186 return ret; | 187 return ret; |
187 } | 188 } |
188 | 189 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 // Give a broken implementation a chance to exit unexpectedly. | 268 // Give a broken implementation a chance to exit unexpectedly. |
268 ASSERT_FALSE(thread().WaitForResultWithTimeout( | 269 ASSERT_FALSE(thread().WaitForResultWithTimeout( |
269 base::TimeDelta::FromMilliseconds(100), &result)); | 270 base::TimeDelta::FromMilliseconds(100), &result)); |
270 ASSERT_TRUE(SignalExit()); | 271 ASSERT_TRUE(SignalExit()); |
271 ASSERT_FALSE(thread().WaitForResult()); | 272 ASSERT_FALSE(thread().WaitForResult()); |
272 int exit_code = 0; | 273 int exit_code = 0; |
273 ASSERT_TRUE( | 274 ASSERT_TRUE( |
274 thread().client().WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 275 thread().client().WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |
275 ASSERT_EQ(0, exit_code); | 276 ASSERT_EQ(0, exit_code); |
276 } | 277 } |
OLD | NEW |