| 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 "testing/gtest/include/gtest/gtest.h" |   23 #include "testing/gtest/include/gtest/gtest.h" | 
|   24 #include "testing/multiprocess_func_list.h" |   24 #include "testing/multiprocess_func_list.h" | 
|   25  |   25  | 
 |   26 #if defined(OS_WIN) | 
 |   27 #include "base/win/win_util.h" | 
 |   28 #endif | 
 |   29  | 
|   26 namespace { |   30 namespace { | 
|   27  |   31  | 
|   28 const char kParentHandle[] = "parent-handle"; |   32 const char kParentHandle[] = "parent-handle"; | 
|   29 const char kEventHandle[] = "event-handle"; |   33 const char kEventHandle[] = "event-handle"; | 
|   30 const char kNamedEventSuffix[] = "named-event-suffix"; |   34 const char kNamedEventSuffix[] = "named-event-suffix"; | 
|   31  |   35  | 
|   32 const base::char16 kExitEventBaseName[] = L"ChromeWatcherClientTestExitEvent_"; |   36 const base::char16 kExitEventBaseName[] = L"ChromeWatcherClientTestExitEvent_"; | 
|   33 const base::char16 kInitializeEventBaseName[] = |   37 const base::char16 kInitializeEventBaseName[] = | 
|   34     L"ChromeWatcherClientTestInitializeEvent_"; |   38     L"ChromeWatcherClientTestInitializeEvent_"; | 
|   35  |   39  | 
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  163   } |  167   } | 
|  164  |  168  | 
|  165  private: |  169  private: | 
|  166   // Returns a command line to launch back into ChromeWatcherClientTestProcess. |  170   // Returns a command line to launch back into ChromeWatcherClientTestProcess. | 
|  167   base::CommandLine GenerateCommandLine(HANDLE parent_handle, |  171   base::CommandLine GenerateCommandLine(HANDLE parent_handle, | 
|  168                                         DWORD main_thread_id, |  172                                         DWORD main_thread_id, | 
|  169                                         HANDLE on_initialized_event) { |  173                                         HANDLE on_initialized_event) { | 
|  170     base::CommandLine ret = base::GetMultiProcessTestChildBaseCommandLine(); |  174     base::CommandLine ret = base::GetMultiProcessTestChildBaseCommandLine(); | 
|  171     ret.AppendSwitchASCII(switches::kTestChildProcess, |  175     ret.AppendSwitchASCII(switches::kTestChildProcess, | 
|  172                           "ChromeWatcherClientTestProcess"); |  176                           "ChromeWatcherClientTestProcess"); | 
|  173     ret.AppendSwitchASCII(kEventHandle, |  177     ret.AppendSwitchASCII( | 
|  174                           base::UintToString(reinterpret_cast<unsigned int>( |  178         kEventHandle, | 
|  175                               on_initialized_event))); |  179         base::UintToString(base::win::HandleToUint32(on_initialized_event))); | 
|  176     ret.AppendSwitchASCII( |  180     ret.AppendSwitchASCII( | 
|  177         kParentHandle, |  181         kParentHandle, | 
|  178         base::UintToString(reinterpret_cast<unsigned int>(parent_handle))); |  182         base::UintToString(base::win::HandleToUint32(parent_handle))); | 
|  179  |  183  | 
|  180     // Our child does not actually need the main thread ID, but we verify here |  184     // 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. |  185     // that the correct ID is being passed from the client. | 
|  182     EXPECT_EQ(::GetCurrentThreadId(), main_thread_id); |  186     EXPECT_EQ(::GetCurrentThreadId(), main_thread_id); | 
|  183  |  187  | 
|  184     ret.AppendSwitchASCII(kNamedEventSuffix, |  188     ret.AppendSwitchASCII(kNamedEventSuffix, | 
|  185                           base::UTF16ToASCII(NamedEventSuffix())); |  189                           base::UTF16ToASCII(NamedEventSuffix())); | 
|  186     return ret; |  190     return ret; | 
|  187   } |  191   } | 
|  188  |  192  | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  267   // Give a broken implementation a chance to exit unexpectedly. |  271   // Give a broken implementation a chance to exit unexpectedly. | 
|  268   ASSERT_FALSE(thread().WaitForResultWithTimeout( |  272   ASSERT_FALSE(thread().WaitForResultWithTimeout( | 
|  269       base::TimeDelta::FromMilliseconds(100), &result)); |  273       base::TimeDelta::FromMilliseconds(100), &result)); | 
|  270   ASSERT_TRUE(SignalExit()); |  274   ASSERT_TRUE(SignalExit()); | 
|  271   ASSERT_FALSE(thread().WaitForResult()); |  275   ASSERT_FALSE(thread().WaitForResult()); | 
|  272   int exit_code = 0; |  276   int exit_code = 0; | 
|  273   ASSERT_TRUE( |  277   ASSERT_TRUE( | 
|  274       thread().client().WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); |  278       thread().client().WaitForExitWithTimeout(base::TimeDelta(), &exit_code)); | 
|  275   ASSERT_EQ(0, exit_code); |  279   ASSERT_EQ(0, exit_code); | 
|  276 } |  280 } | 
| OLD | NEW |