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

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

Issue 2253001: Revert 48186, 48196, 48198 (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 years, 7 months 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
« no previous file with comments | « sandbox/src/interception_unittest.cc ('k') | sandbox/src/restricted_token_unittest.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "sandbox/src/job.h" 7 #include "sandbox/src/job.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace sandbox { 10 namespace sandbox {
11 11
12 // Tests the creation and destruction of the job. 12 // Tests the creation and destruction of the job.
13 TEST(JobTest, TestCreation) { 13 TEST(JobTest, TestCreation) {
14 // Scope the creation of Job. 14 // Scope the creation of Job.
15 { 15 {
16 // Create the job. 16 // Create the job.
17 Job job; 17 Job job;
18 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0)); 18 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0));
19 19
20 // check if the job exists. 20 // check if the job exists.
21 HANDLE job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE, 21 HANDLE job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE,
22 L"my_test_job_name"); 22 L"my_test_job_name");
23 ASSERT_NE(reinterpret_cast<HANDLE>(NULL), job_handle); 23 ASSERT_NE(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
24 24
25 if (job_handle) 25 if (job_handle)
26 CloseHandle(job_handle); 26 CloseHandle(job_handle);
27 } 27 }
28 28
29 // Check if the job is destroyed when the object goes out of scope. 29 // Check if the job is destroyed when the object goes out of scope.
30 HANDLE job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE, L"my_test_job_name"); 30 HANDLE job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE, L"my_test_job_name");
31 ASSERT_EQ(reinterpret_cast<HANDLE>(NULL), job_handle); 31 ASSERT_EQ(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
32 ASSERT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError()); 32 ASSERT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
33 } 33 }
34 34
35 // Tests the method "Detach". 35 // Tests the method "Detach".
36 TEST(JobTest, TestDetach) { 36 TEST(JobTest, TestDetach) {
37 HANDLE job_handle; 37 HANDLE job_handle;
38 // Scope the creation of Job. 38 // Scope the creation of Job.
39 { 39 {
40 // Create the job. 40 // Create the job.
41 Job job; 41 Job job;
42 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0)); 42 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0));
43 43
44 job_handle = job.Detach(); 44 job_handle = job.Detach();
45 ASSERT_NE(reinterpret_cast<HANDLE>(NULL), job_handle); 45 ASSERT_NE(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
46 } 46 }
47 47
48 // Check to be sure that the job is still alive even after the object is gone 48 // Check to be sure that the job is still alive even after the object is gone
49 // out of scope. 49 // out of scope.
50 HANDLE job_handle_dup = ::OpenJobObjectW(GENERIC_ALL, FALSE, 50 HANDLE job_handle_dup = ::OpenJobObjectW(GENERIC_ALL, FALSE,
51 L"my_test_job_name"); 51 L"my_test_job_name");
52 ASSERT_NE(reinterpret_cast<HANDLE>(NULL), job_handle_dup); 52 ASSERT_NE(NULL, reinterpret_cast<ULONG_PTR>(job_handle_dup));
53 53
54 // Remove all references. 54 // Remove all references.
55 if (job_handle_dup) 55 if (job_handle_dup)
56 ::CloseHandle(job_handle_dup); 56 ::CloseHandle(job_handle_dup);
57 57
58 if (job_handle) 58 if (job_handle)
59 ::CloseHandle(job_handle); 59 ::CloseHandle(job_handle);
60 60
61 // Check if the jbo is really dead. 61 // Check if the jbo is really dead.
62 job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE, L"my_test_job_name"); 62 job_handle = ::OpenJobObjectW(GENERIC_ALL, FALSE, L"my_test_job_name");
63 ASSERT_EQ(reinterpret_cast<HANDLE>(NULL), job_handle); 63 ASSERT_EQ(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
64 ASSERT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError()); 64 ASSERT_EQ(ERROR_FILE_NOT_FOUND, ::GetLastError());
65 } 65 }
66 66
67 // Tests the ui exceptions 67 // Tests the ui exceptions
68 TEST(JobTest, TestExceptions) { 68 TEST(JobTest, TestExceptions) {
69 HANDLE job_handle; 69 HANDLE job_handle;
70 // Scope the creation of Job. 70 // Scope the creation of Job.
71 { 71 {
72 // Create the job. 72 // Create the job.
73 Job job; 73 Job job;
74 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 74 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name",
75 JOB_OBJECT_UILIMIT_READCLIPBOARD)); 75 JOB_OBJECT_UILIMIT_READCLIPBOARD));
76 76
77 job_handle = job.Detach(); 77 job_handle = job.Detach();
78 ASSERT_NE(reinterpret_cast<HANDLE>(NULL), job_handle); 78 ASSERT_NE(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
79 79
80 JOBOBJECT_BASIC_UI_RESTRICTIONS jbur = {0}; 80 JOBOBJECT_BASIC_UI_RESTRICTIONS jbur = {0};
81 DWORD size = sizeof(jbur); 81 DWORD size = sizeof(jbur);
82 BOOL result = ::QueryInformationJobObject(job_handle, 82 BOOL result = ::QueryInformationJobObject(job_handle,
83 JobObjectBasicUIRestrictions, 83 JobObjectBasicUIRestrictions,
84 &jbur, size, &size); 84 &jbur, size, &size);
85 ASSERT_TRUE(result); 85 ASSERT_TRUE(result);
86 86
87 ASSERT_EQ(jbur.UIRestrictionsClass & JOB_OBJECT_UILIMIT_READCLIPBOARD, 0); 87 ASSERT_EQ(jbur.UIRestrictionsClass & JOB_OBJECT_UILIMIT_READCLIPBOARD, 0);
88 ::CloseHandle(job_handle); 88 ::CloseHandle(job_handle);
89 } 89 }
90 90
91 // Scope the creation of Job. 91 // Scope the creation of Job.
92 { 92 {
93 // Create the job. 93 // Create the job.
94 Job job; 94 Job job;
95 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0)); 95 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0));
96 96
97 job_handle = job.Detach(); 97 job_handle = job.Detach();
98 ASSERT_NE(reinterpret_cast<HANDLE>(NULL), job_handle); 98 ASSERT_NE(NULL, reinterpret_cast<ULONG_PTR>(job_handle));
99 99
100 JOBOBJECT_BASIC_UI_RESTRICTIONS jbur = {0}; 100 JOBOBJECT_BASIC_UI_RESTRICTIONS jbur = {0};
101 DWORD size = sizeof(jbur); 101 DWORD size = sizeof(jbur);
102 BOOL result = ::QueryInformationJobObject(job_handle, 102 BOOL result = ::QueryInformationJobObject(job_handle,
103 JobObjectBasicUIRestrictions, 103 JobObjectBasicUIRestrictions,
104 &jbur, size, &size); 104 &jbur, size, &size);
105 ASSERT_TRUE(result); 105 ASSERT_TRUE(result);
106 106
107 ASSERT_EQ(jbur.UIRestrictionsClass & JOB_OBJECT_UILIMIT_READCLIPBOARD, 107 ASSERT_EQ(jbur.UIRestrictionsClass & JOB_OBJECT_UILIMIT_READCLIPBOARD,
108 JOB_OBJECT_UILIMIT_READCLIPBOARD); 108 JOB_OBJECT_UILIMIT_READCLIPBOARD);
109 ::CloseHandle(job_handle); 109 ::CloseHandle(job_handle);
110 } 110 }
111 } 111 }
112 112
113 // Tests the error case when the job is initialized twice. 113 // Tests the error case when the job is initialized twice.
114 TEST(JobTest, DoubleInit) { 114 TEST(JobTest, DoubleInit) {
115 // Create the job. 115 // Create the job.
116 Job job; 116 Job job;
117 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0)); 117 ASSERT_EQ(ERROR_SUCCESS, job.Init(JOB_LOCKDOWN, L"my_test_job_name", 0));
118 ASSERT_EQ(ERROR_ALREADY_INITIALIZED, job.Init(JOB_LOCKDOWN, L"test", 0)); 118 ASSERT_EQ(ERROR_ALREADY_INITIALIZED, job.Init(JOB_LOCKDOWN, L"test", 0));
119 } 119 }
120 120
121 // Tests the error case when we use a method and the object is not yet 121 // Tests the error case when we use a method and the object is not yet
122 // initialized. 122 // initialized.
123 TEST(JobTest, NoInit) { 123 TEST(JobTest, NoInit) {
124 Job job; 124 Job job;
125 ASSERT_EQ(ERROR_NO_DATA, job.UserHandleGrantAccess(NULL)); 125 ASSERT_EQ(ERROR_NO_DATA, job.UserHandleGrantAccess(NULL));
126 ASSERT_EQ(ERROR_NO_DATA, job.AssignProcessToJob(NULL)); 126 ASSERT_EQ(ERROR_NO_DATA, job.AssignProcessToJob(NULL));
127 ASSERT_EQ(reinterpret_cast<HANDLE>(NULL), job.Detach()); 127 ASSERT_EQ(NULL, reinterpret_cast<ULONG_PTR>(job.Detach()));
128 } 128 }
129 129
130 // Tests the initialization of the job with different security level. 130 // Tests the initialization of the job with different security level.
131 TEST(JobTest, SecurityLevel) { 131 TEST(JobTest, SecurityLevel) {
132 Job job1; 132 Job job1;
133 ASSERT_EQ(ERROR_SUCCESS, job1.Init(JOB_LOCKDOWN, L"job1", 0)); 133 ASSERT_EQ(ERROR_SUCCESS, job1.Init(JOB_LOCKDOWN, L"job1", 0));
134 134
135 Job job2; 135 Job job2;
136 ASSERT_EQ(ERROR_SUCCESS, job2.Init(JOB_RESTRICTED, L"job2", 0)); 136 ASSERT_EQ(ERROR_SUCCESS, job2.Init(JOB_RESTRICTED, L"job2", 0));
137 137
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses); 179 EXPECT_EQ(1, jbpidl.NumberOfAssignedProcesses);
180 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList); 180 EXPECT_EQ(1, jbpidl.NumberOfProcessIdsInList);
181 EXPECT_EQ(pi.dwProcessId, jbpidl.ProcessIdList[0]); 181 EXPECT_EQ(pi.dwProcessId, jbpidl.ProcessIdList[0]);
182 182
183 EXPECT_TRUE(::TerminateProcess(pi.hProcess, 0)); 183 EXPECT_TRUE(::TerminateProcess(pi.hProcess, 0));
184 184
185 EXPECT_TRUE(::CloseHandle(job_handle)); 185 EXPECT_TRUE(::CloseHandle(job_handle));
186 } 186 }
187 187
188 } // namespace sandbox 188 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/src/interception_unittest.cc ('k') | sandbox/src/restricted_token_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698