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

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

Issue 92173002: Merge 237541 "Revert of https://codereview.chromium.org/71013004/" (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1721/src/
Patch Set: 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 PROCESS_INFORMATION temp_process_info = {}; 167 base::win::ScopedProcessInformation pi;
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 &temp_process_info); 169 pi.Receive());
170 ASSERT_TRUE(result); 170 ASSERT_TRUE(result);
171 base::win::ScopedProcessInformation pi(temp_process_info);
172 ASSERT_EQ(ERROR_SUCCESS, job.AssignProcessToJob(pi.process_handle())); 171 ASSERT_EQ(ERROR_SUCCESS, job.AssignProcessToJob(pi.process_handle()));
173 172
174 // Get the job handle. 173 // Get the job handle.
175 HANDLE job_handle = job.Detach(); 174 HANDLE job_handle = job.Detach();
176 175
177 // Check if the process is in the job. 176 // Check if the process is in the job.
178 JOBOBJECT_BASIC_PROCESS_ID_LIST jbpidl = {0}; 177 JOBOBJECT_BASIC_PROCESS_ID_LIST jbpidl = {0};
179 DWORD size = sizeof(jbpidl); 178 DWORD size = sizeof(jbpidl);
180 result = ::QueryInformationJobObject(job_handle, 179 result = ::QueryInformationJobObject(job_handle,
181 JobObjectBasicProcessIdList, 180 JobObjectBasicProcessIdList,
182 &jbpidl, size, &size); 181 &jbpidl, size, &size);
183 EXPECT_TRUE(result); 182 EXPECT_TRUE(result);
184 183
185 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses); 184 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses);
186 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList); 185 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList);
187 EXPECT_EQ(pi.process_id(), jbpidl.ProcessIdList[0]); 186 EXPECT_EQ(pi.process_id(), jbpidl.ProcessIdList[0]);
188 187
189 EXPECT_TRUE(::TerminateProcess(pi.process_handle(), 0)); 188 EXPECT_TRUE(::TerminateProcess(pi.process_handle(), 0));
190 189
191 EXPECT_TRUE(::CloseHandle(job_handle)); 190 EXPECT_TRUE(::CloseHandle(job_handle));
192 } 191 }
193 192
194 } // namespace sandbox 193 } // 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