OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/test/multiprocess_test.h" | 10 #include "base/test/multiprocess_test.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 return 0; | 31 return 0; |
32 } | 32 } |
33 | 33 |
34 class StartupInformationTest : public base::MultiProcessTest {}; | 34 class StartupInformationTest : public base::MultiProcessTest {}; |
35 | 35 |
36 // Verify that only the explicitly specified event is inherited. | 36 // Verify that only the explicitly specified event is inherited. |
37 TEST_F(StartupInformationTest, InheritStdOut) { | 37 TEST_F(StartupInformationTest, InheritStdOut) { |
38 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 38 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
39 return; | 39 return; |
40 | 40 |
41 base::win::ScopedProcessInformation process_info; | |
42 base::win::StartupInformation startup_info; | 41 base::win::StartupInformation startup_info; |
43 | 42 |
44 HANDLE section = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, | 43 HANDLE section = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, |
45 PAGE_READWRITE, 0, kSectionSize, | 44 PAGE_READWRITE, 0, kSectionSize, |
46 kSectionName); | 45 kSectionName); |
47 ASSERT_TRUE(section); | 46 ASSERT_TRUE(section); |
48 | 47 |
49 HANDLE* events = reinterpret_cast<HANDLE*>(::MapViewOfFile(section, | 48 HANDLE* events = reinterpret_cast<HANDLE*>(::MapViewOfFile(section, |
50 FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, kSectionSize)); | 49 FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, kSectionSize)); |
51 | 50 |
52 // Make two inheritable events. | 51 // Make two inheritable events. |
53 SECURITY_ATTRIBUTES security_attributes = { sizeof(security_attributes), | 52 SECURITY_ATTRIBUTES security_attributes = { sizeof(security_attributes), |
54 NULL, true }; | 53 NULL, true }; |
55 events[0] = ::CreateEvent(&security_attributes, false, false, NULL); | 54 events[0] = ::CreateEvent(&security_attributes, false, false, NULL); |
56 ASSERT_TRUE(events[0]); | 55 ASSERT_TRUE(events[0]); |
57 events[1] = ::CreateEvent(&security_attributes, false, false, NULL); | 56 events[1] = ::CreateEvent(&security_attributes, false, false, NULL); |
58 ASSERT_TRUE(events[1]); | 57 ASSERT_TRUE(events[1]); |
59 | 58 |
60 ASSERT_TRUE(startup_info.InitializeProcThreadAttributeList(1)); | 59 ASSERT_TRUE(startup_info.InitializeProcThreadAttributeList(1)); |
61 ASSERT_TRUE(startup_info.UpdateProcThreadAttribute( | 60 ASSERT_TRUE(startup_info.UpdateProcThreadAttribute( |
62 PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &events[0], | 61 PROC_THREAD_ATTRIBUTE_HANDLE_LIST, &events[0], |
63 sizeof(events[0]))); | 62 sizeof(events[0]))); |
64 | 63 |
65 std::wstring cmd_line = | 64 std::wstring cmd_line = |
66 this->MakeCmdLine("FireInheritedEvents", false).GetCommandLineString(); | 65 this->MakeCmdLine("FireInheritedEvents", false).GetCommandLineString(); |
67 | 66 |
| 67 PROCESS_INFORMATION temp_process_info = {}; |
68 ASSERT_TRUE(::CreateProcess(NULL, const_cast<wchar_t*>(cmd_line.c_str()), | 68 ASSERT_TRUE(::CreateProcess(NULL, const_cast<wchar_t*>(cmd_line.c_str()), |
69 NULL, NULL, true, EXTENDED_STARTUPINFO_PRESENT, | 69 NULL, NULL, true, EXTENDED_STARTUPINFO_PRESENT, |
70 NULL, NULL, startup_info.startup_info(), | 70 NULL, NULL, startup_info.startup_info(), |
71 process_info.Receive())) << ::GetLastError(); | 71 &temp_process_info)) << ::GetLastError(); |
| 72 base::win::ScopedProcessInformation process_info(temp_process_info); |
| 73 |
72 // Only the first event should be signalled | 74 // Only the first event should be signalled |
73 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForMultipleObjects(2, events, false, | 75 EXPECT_EQ(WAIT_OBJECT_0, ::WaitForMultipleObjects(2, events, false, |
74 4000)); | 76 4000)); |
75 } | 77 } |
76 | 78 |
OLD | NEW |