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

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

Issue 606443002: Remove implicit HANDLE conversions from sandbox. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/win/src/handle_policy_test.cc ('k') | sandbox/win/src/target_process.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "sandbox/win/src/sync_policy_test.h" 5 #include "sandbox/win/src/sync_policy_test.h"
6 6
7 #include "base/win/scoped_handle.h" 7 #include "base/win/scoped_handle.h"
8 #include "sandbox/win/src/sandbox.h" 8 #include "sandbox/win/src/sandbox.h"
9 #include "sandbox/win/src/sandbox_policy.h" 9 #include "sandbox/win/src/sandbox_policy.h"
10 #include "sandbox/win/src/sandbox_factory.h" 10 #include "sandbox/win/src/sandbox_factory.h"
11 #include "sandbox/win/src/nt_internals.h" 11 #include "sandbox/win/src/nt_internals.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace sandbox { 14 namespace sandbox {
15 15
16 SBOX_TESTS_COMMAND int Event_Open(int argc, wchar_t **argv) { 16 SBOX_TESTS_COMMAND int Event_Open(int argc, wchar_t **argv) {
17 if (argc != 2) 17 if (argc != 2)
18 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND; 18 return SBOX_TEST_FAILED_TO_EXECUTE_COMMAND;
19 19
20 DWORD desired_access = SYNCHRONIZE; 20 DWORD desired_access = SYNCHRONIZE;
21 if (L'f' == argv[0][0]) 21 if (L'f' == argv[0][0])
22 desired_access = EVENT_ALL_ACCESS; 22 desired_access = EVENT_ALL_ACCESS;
23 23
24 base::win::ScopedHandle event_open(::OpenEvent( 24 base::win::ScopedHandle event_open(::OpenEvent(
25 desired_access, FALSE, argv[1])); 25 desired_access, FALSE, argv[1]));
26 DWORD error_open = ::GetLastError(); 26 DWORD error_open = ::GetLastError();
27 27
28 if (event_open.Get()) 28 if (event_open.IsValid())
29 return SBOX_TEST_SUCCEEDED; 29 return SBOX_TEST_SUCCEEDED;
30 30
31 if (ERROR_ACCESS_DENIED == error_open || 31 if (ERROR_ACCESS_DENIED == error_open ||
32 ERROR_BAD_PATHNAME == error_open) 32 ERROR_BAD_PATHNAME == error_open)
33 return SBOX_TEST_DENIED; 33 return SBOX_TEST_DENIED;
34 34
35 return SBOX_TEST_FAILED; 35 return SBOX_TEST_FAILED;
36 } 36 }
37 37
38 SBOX_TESTS_COMMAND int Event_CreateOpen(int argc, wchar_t **argv) { 38 SBOX_TESTS_COMMAND int Event_CreateOpen(int argc, wchar_t **argv) {
(...skipping 11 matching lines...) Expand all
50 if (L't' == argv[1][0]) 50 if (L't' == argv[1][0])
51 initial_state = TRUE; 51 initial_state = TRUE;
52 52
53 base::win::ScopedHandle event_create(::CreateEvent( 53 base::win::ScopedHandle event_create(::CreateEvent(
54 NULL, manual_reset, initial_state, event_name)); 54 NULL, manual_reset, initial_state, event_name));
55 DWORD error_create = ::GetLastError(); 55 DWORD error_create = ::GetLastError();
56 base::win::ScopedHandle event_open; 56 base::win::ScopedHandle event_open;
57 if (event_name) 57 if (event_name)
58 event_open.Set(::OpenEvent(EVENT_ALL_ACCESS, FALSE, event_name)); 58 event_open.Set(::OpenEvent(EVENT_ALL_ACCESS, FALSE, event_name));
59 59
60 if (event_create.Get()) { 60 if (event_create.IsValid()) {
61 DWORD wait = ::WaitForSingleObject(event_create.Get(), 0); 61 DWORD wait = ::WaitForSingleObject(event_create.Get(), 0);
62 if (initial_state && WAIT_OBJECT_0 != wait) 62 if (initial_state && WAIT_OBJECT_0 != wait)
63 return SBOX_TEST_FAILED; 63 return SBOX_TEST_FAILED;
64 64
65 if (!initial_state && WAIT_TIMEOUT != wait) 65 if (!initial_state && WAIT_TIMEOUT != wait)
66 return SBOX_TEST_FAILED; 66 return SBOX_TEST_FAILED;
67 } 67 }
68 68
69 if (event_name) { 69 if (event_name) {
70 // Both event_open and event_create have to be valid. 70 // Both event_open and event_create have to be valid.
71 if (event_open.Get() && event_create) 71 if (event_open.IsValid() && event_create.IsValid())
72 return SBOX_TEST_SUCCEEDED; 72 return SBOX_TEST_SUCCEEDED;
73 73
74 if (event_open.Get() && !event_create || !event_open.Get() && event_create) 74 if (event_open.IsValid() && !event_create.IsValid() ||
75 !event_open.IsValid() && event_create.IsValid())
75 return SBOX_TEST_FAILED; 76 return SBOX_TEST_FAILED;
76 } else { 77 } else {
77 // Only event_create has to be valid. 78 // Only event_create has to be valid.
78 if (event_create.Get()) 79 if (event_create.Get())
79 return SBOX_TEST_SUCCEEDED; 80 return SBOX_TEST_SUCCEEDED;
80 } 81 }
81 82
82 if (ERROR_ACCESS_DENIED == error_create || 83 if (ERROR_ACCESS_DENIED == error_create ||
83 ERROR_BAD_PATHNAME == error_create) 84 ERROR_BAD_PATHNAME == error_create)
84 return SBOX_TEST_DENIED; 85 return SBOX_TEST_DENIED;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_Open s test2")); 138 EXPECT_EQ(SBOX_TEST_SUCCEEDED, runner.RunTest(L"Event_Open s test2"));
138 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open f test3")); 139 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open f test3"));
139 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open s test4")); 140 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_Open s test4"));
140 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f f test5")); 141 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f f test5"));
141 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t f test6")); 142 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t f test6"));
142 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f t test5")); 143 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen f t test5"));
143 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t t test6")); 144 EXPECT_EQ(SBOX_TEST_DENIED, runner.RunTest(L"Event_CreateOpen t t test6"));
144 } 145 }
145 146
146 } // namespace sandbox 147 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/handle_policy_test.cc ('k') | sandbox/win/src/target_process.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698