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

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

Issue 109843003: Replace wstring with string16 in sandbox (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/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/policy_low_level.cc ('k') | sandbox/win/src/process_thread_dispatcher.h » ('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 #include "base/win/scoped_process_information.h" 5 #include "base/win/scoped_process_information.h"
6 #include "base/win/windows_version.h" 6 #include "base/win/windows_version.h"
7 #include "sandbox/win/src/sandbox.h" 7 #include "sandbox/win/src/sandbox.h"
8 #include "sandbox/win/src/sandbox_factory.h" 8 #include "sandbox/win/src/sandbox_factory.h"
9 #include "sandbox/win/src/sandbox_utils.h" 9 #include "sandbox/win/src/sandbox_utils.h"
10 #include "sandbox/win/src/target_services.h" 10 #include "sandbox/win/src/target_services.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 TargetPolicy* temp_policy = broker->CreatePolicy(); 222 TargetPolicy* temp_policy = broker->CreatePolicy();
223 temp_policy->CreateAlternateDesktop(false); 223 temp_policy->CreateAlternateDesktop(false);
224 temp_policy->Release(); 224 temp_policy->Release();
225 225
226 ASSERT_TRUE(broker != NULL); 226 ASSERT_TRUE(broker != NULL);
227 227
228 // Get the path to the sandboxed app. 228 // Get the path to the sandboxed app.
229 wchar_t prog_name[MAX_PATH]; 229 wchar_t prog_name[MAX_PATH];
230 GetModuleFileNameW(NULL, prog_name, MAX_PATH); 230 GetModuleFileNameW(NULL, prog_name, MAX_PATH);
231 231
232 std::wstring arguments(L"\""); 232 base::string16 arguments(L"\"");
233 arguments += prog_name; 233 arguments += prog_name;
234 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. 234 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument.
235 235
236 // Launch the app. 236 // Launch the app.
237 ResultCode result = SBOX_ALL_OK; 237 ResultCode result = SBOX_ALL_OK;
238 base::win::ScopedProcessInformation target; 238 base::win::ScopedProcessInformation target;
239 239
240 TargetPolicy* policy = broker->CreatePolicy(); 240 TargetPolicy* policy = broker->CreatePolicy();
241 policy->SetAlternateDesktop(false); 241 policy->SetAlternateDesktop(false);
242 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); 242 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN);
243 PROCESS_INFORMATION temp_process_info = {}; 243 PROCESS_INFORMATION temp_process_info = {};
244 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, 244 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy,
245 &temp_process_info); 245 &temp_process_info);
246 policy->Release(); 246 policy->Release();
247 247
248 EXPECT_EQ(SBOX_ALL_OK, result); 248 EXPECT_EQ(SBOX_ALL_OK, result);
249 if (result == SBOX_ALL_OK) 249 if (result == SBOX_ALL_OK)
250 target.Set(temp_process_info); 250 target.Set(temp_process_info);
251 251
252 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); 252 EXPECT_EQ(1, ::ResumeThread(target.thread_handle()));
253 253
254 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); 254 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000));
255 255
256 EXPECT_NE(::GetThreadDesktop(target.thread_id()), 256 EXPECT_NE(::GetThreadDesktop(target.thread_id()),
257 ::GetThreadDesktop(::GetCurrentThreadId())); 257 ::GetThreadDesktop(::GetCurrentThreadId()));
258 258
259 std::wstring desktop_name = policy->GetAlternateDesktop(); 259 base::string16 desktop_name = policy->GetAlternateDesktop();
260 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE); 260 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE);
261 EXPECT_TRUE(NULL != desk); 261 EXPECT_TRUE(NULL != desk);
262 EXPECT_TRUE(::CloseDesktop(desk)); 262 EXPECT_TRUE(::CloseDesktop(desk));
263 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0)); 263 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0));
264 264
265 ::WaitForSingleObject(target.process_handle(), INFINITE); 265 ::WaitForSingleObject(target.process_handle(), INFINITE);
266 266
267 // Close the desktop handle. 267 // Close the desktop handle.
268 temp_policy = broker->CreatePolicy(); 268 temp_policy = broker->CreatePolicy();
269 temp_policy->DestroyAlternateDesktop(); 269 temp_policy->DestroyAlternateDesktop();
(...skipping 15 matching lines...) Expand all
285 TargetPolicy* temp_policy = broker->CreatePolicy(); 285 TargetPolicy* temp_policy = broker->CreatePolicy();
286 temp_policy->CreateAlternateDesktop(true); 286 temp_policy->CreateAlternateDesktop(true);
287 temp_policy->Release(); 287 temp_policy->Release();
288 288
289 ASSERT_TRUE(broker != NULL); 289 ASSERT_TRUE(broker != NULL);
290 290
291 // Get the path to the sandboxed app. 291 // Get the path to the sandboxed app.
292 wchar_t prog_name[MAX_PATH]; 292 wchar_t prog_name[MAX_PATH];
293 GetModuleFileNameW(NULL, prog_name, MAX_PATH); 293 GetModuleFileNameW(NULL, prog_name, MAX_PATH);
294 294
295 std::wstring arguments(L"\""); 295 base::string16 arguments(L"\"");
296 arguments += prog_name; 296 arguments += prog_name;
297 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument. 297 arguments += L"\" -child 0 wait"; // Don't care about the "state" argument.
298 298
299 // Launch the app. 299 // Launch the app.
300 ResultCode result = SBOX_ALL_OK; 300 ResultCode result = SBOX_ALL_OK;
301 base::win::ScopedProcessInformation target; 301 base::win::ScopedProcessInformation target;
302 302
303 TargetPolicy* policy = broker->CreatePolicy(); 303 TargetPolicy* policy = broker->CreatePolicy();
304 policy->SetAlternateDesktop(true); 304 policy->SetAlternateDesktop(true);
305 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN); 305 policy->SetTokenLevel(USER_INTERACTIVE, USER_LOCKDOWN);
306 PROCESS_INFORMATION temp_process_info = {}; 306 PROCESS_INFORMATION temp_process_info = {};
307 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy, 307 result = broker->SpawnTarget(prog_name, arguments.c_str(), policy,
308 &temp_process_info); 308 &temp_process_info);
309 policy->Release(); 309 policy->Release();
310 310
311 EXPECT_EQ(SBOX_ALL_OK, result); 311 EXPECT_EQ(SBOX_ALL_OK, result);
312 if (result == SBOX_ALL_OK) 312 if (result == SBOX_ALL_OK)
313 target.Set(temp_process_info); 313 target.Set(temp_process_info);
314 314
315 EXPECT_EQ(1, ::ResumeThread(target.thread_handle())); 315 EXPECT_EQ(1, ::ResumeThread(target.thread_handle()));
316 316
317 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000)); 317 EXPECT_EQ(WAIT_TIMEOUT, ::WaitForSingleObject(target.process_handle(), 2000));
318 318
319 EXPECT_NE(::GetThreadDesktop(target.thread_id()), 319 EXPECT_NE(::GetThreadDesktop(target.thread_id()),
320 ::GetThreadDesktop(::GetCurrentThreadId())); 320 ::GetThreadDesktop(::GetCurrentThreadId()));
321 321
322 std::wstring desktop_name = policy->GetAlternateDesktop(); 322 base::string16 desktop_name = policy->GetAlternateDesktop();
323 ASSERT_FALSE(desktop_name.empty()); 323 ASSERT_FALSE(desktop_name.empty());
324 324
325 // Make sure there is a backslash, for the window station name. 325 // Make sure there is a backslash, for the window station name.
326 EXPECT_NE(desktop_name.find_first_of(L'\\'), std::wstring::npos); 326 EXPECT_NE(desktop_name.find_first_of(L'\\'), base::string16::npos);
327 327
328 // Isolate the desktop name. 328 // Isolate the desktop name.
329 desktop_name = desktop_name.substr(desktop_name.find_first_of(L'\\') + 1); 329 desktop_name = desktop_name.substr(desktop_name.find_first_of(L'\\') + 1);
330 330
331 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE); 331 HDESK desk = ::OpenDesktop(desktop_name.c_str(), 0, FALSE, DESKTOP_ENUMERATE);
332 // This should fail if the desktop is really on another window station. 332 // This should fail if the desktop is really on another window station.
333 EXPECT_FALSE(NULL != desk); 333 EXPECT_FALSE(NULL != desk);
334 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0)); 334 EXPECT_TRUE(::TerminateProcess(target.process_handle(), 0));
335 335
336 ::WaitForSingleObject(target.process_handle(), INFINITE); 336 ::WaitForSingleObject(target.process_handle(), INFINITE);
337 337
338 // Close the desktop handle. 338 // Close the desktop handle.
339 temp_policy = broker->CreatePolicy(); 339 temp_policy = broker->CreatePolicy();
340 temp_policy->DestroyAlternateDesktop(); 340 temp_policy->DestroyAlternateDesktop();
341 temp_policy->Release(); 341 temp_policy->Release();
342 } 342 }
343 343
344 } // namespace sandbox 344 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/policy_low_level.cc ('k') | sandbox/win/src/process_thread_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698