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

Side by Side Diff: sandbox/win/src/job_unittest.cc

Issue 71013004: Base: Remove Receive() from ScopedHandle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix delegate_execute for google_chrome_build Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « sandbox/win/src/Wow64.cc ('k') | sandbox/win/src/policy_target_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This file contains unit tests for the job object. 5 // This file contains unit tests for the job object.
6 6
7 #include "base/win/scoped_process_information.h" 7 #include "base/win/scoped_process_information.h"
8 #include "sandbox/win/src/job.h" 8 #include "sandbox/win/src/job.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Tests the method "AssignProcessToJob". 157 // Tests the method "AssignProcessToJob".
158 TEST(JobTest, ProcessInJob) { 158 TEST(JobTest, ProcessInJob) {
159 // Create the job. 159 // Create the job.
160 Job job; 160 Job job;
161 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_UNPROTECTED, L"job_test_process", 0)); 161 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_UNPROTECTED, L"job_test_process", 0));
162 162
163 BOOL result = FALSE; 163 BOOL result = FALSE;
164 164
165 wchar_t notepad[] = L"notepad"; 165 wchar_t notepad[] = L"notepad";
166 STARTUPINFO si = { sizeof(si) }; 166 STARTUPINFO si = { sizeof(si) };
167 base::win::ScopedProcessInformation pi; 167 PROCESS_INFORMATION temp_process_info = {};
168 result = ::CreateProcess(NULL, notepad, NULL, NULL, FALSE, 0, NULL, NULL, &si, 168 result = ::CreateProcess(NULL, notepad, NULL, NULL, FALSE, 0, NULL, NULL, &si,
169 pi.Receive()); 169 &temp_process_info);
170 ASSERT_TRUE(result); 170 ASSERT_TRUE(result);
171 base::win::ScopedProcessInformation pi(temp_process_info);
171 ASSERT_EQ(ERROR_SUCCESS, job.AssignProcessToJob(pi.process_handle())); 172 ASSERT_EQ(ERROR_SUCCESS, job.AssignProcessToJob(pi.process_handle()));
172 173
173 // Get the job handle. 174 // Get the job handle.
174 HANDLE job_handle = job.Detach(); 175 HANDLE job_handle = job.Detach();
175 176
176 // Check if the process is in the job. 177 // Check if the process is in the job.
177 JOBOBJECT_BASIC_PROCESS_ID_LIST jbpidl = {0}; 178 JOBOBJECT_BASIC_PROCESS_ID_LIST jbpidl = {0};
178 DWORD size = sizeof(jbpidl); 179 DWORD size = sizeof(jbpidl);
179 result = ::QueryInformationJobObject(job_handle, 180 result = ::QueryInformationJobObject(job_handle,
180 JobObjectBasicProcessIdList, 181 JobObjectBasicProcessIdList,
181 &jbpidl, size, &size); 182 &jbpidl, size, &size);
182 EXPECT_TRUE(result); 183 EXPECT_TRUE(result);
183 184
184 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses); 185 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses);
185 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList); 186 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList);
186 EXPECT_EQ(pi.process_id(), jbpidl.ProcessIdList[0]); 187 EXPECT_EQ(pi.process_id(), jbpidl.ProcessIdList[0]);
187 188
188 EXPECT_TRUE(::TerminateProcess(pi.process_handle(), 0)); 189 EXPECT_TRUE(::TerminateProcess(pi.process_handle(), 0));
189 190
190 EXPECT_TRUE(::CloseHandle(job_handle)); 191 EXPECT_TRUE(::CloseHandle(job_handle));
191 } 192 }
192 193
193 } // namespace sandbox 194 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/Wow64.cc ('k') | sandbox/win/src/policy_target_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698