| OLD | NEW |
| 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 ASSERT_EQ("Example output to stdout\r\n", data); | 49 ASSERT_EQ("Example output to stdout\r\n", data); |
| 50 } else { | 50 } else { |
| 51 ASSERT_EQ("", data); | 51 ASSERT_EQ("", data); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 SBOX_TESTS_COMMAND int | 55 SBOX_TESTS_COMMAND int |
| 56 HandleInheritanceTests_ValidInheritedHandle(int argc, wchar_t **argv) { | 56 HandleInheritanceTests_ValidInheritedHandle(int argc, wchar_t **argv) { |
| 57 if (argc != 1) | 57 if (argc != 1) |
| 58 return SBOX_TEST_FAILED_TO_RUN_TEST; | 58 return SBOX_TEST_FAILED_TO_RUN_TEST; |
| 59 base::SharedMemoryHandle handle = nullptr; | 59 HANDLE handle = nullptr; |
| 60 base::StringToUint(argv[0], reinterpret_cast<unsigned int *>(&handle)); | 60 base::StringToUint(argv[0], reinterpret_cast<unsigned int *>(&handle)); |
| 61 | 61 |
| 62 // This handle we inherited must be both valid and closeable. | 62 // This handle we inherited must be both valid and closeable. |
| 63 DWORD flags = 0; | 63 DWORD flags = 0; |
| 64 if (!GetHandleInformation(handle, &flags)) | 64 if (!GetHandleInformation(handle, &flags)) |
| 65 return SBOX_TEST_FAILED; | 65 return SBOX_TEST_FAILED; |
| 66 if ((flags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0) | 66 if ((flags & HANDLE_FLAG_PROTECT_FROM_CLOSE) != 0) |
| 67 return SBOX_TEST_FAILED; | 67 return SBOX_TEST_FAILED; |
| 68 | 68 |
| 69 return SBOX_TEST_SUCCEEDED; | 69 return SBOX_TEST_SUCCEEDED; |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(HandleInheritanceTests, InheritByValue) { | 72 TEST(HandleInheritanceTests, InheritByValue) { |
| 73 // Handle inheritance doesn't work on XP. | 73 // Handle inheritance doesn't work on XP. |
| 74 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 74 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 75 return; | 75 return; |
| 76 | 76 |
| 77 base::SharedMemory test_shared_memory; | 77 base::SharedMemory test_shared_memory; |
| 78 ASSERT_TRUE(test_shared_memory.CreateAnonymous(1000)); | 78 ASSERT_TRUE(test_shared_memory.CreateAnonymous(1000)); |
| 79 ASSERT_TRUE(test_shared_memory.Map(0)); | 79 ASSERT_TRUE(test_shared_memory.Map(0)); |
| 80 | 80 |
| 81 TestRunner runner; | 81 TestRunner runner; |
| 82 void *shared_handle = | 82 void* shared_handle = runner.GetPolicy()->AddHandleToShare( |
| 83 runner.GetPolicy()->AddHandleToShare(test_shared_memory.handle()); | 83 test_shared_memory.handle().GetHandle()); |
| 84 | 84 |
| 85 std::string command_line = | 85 std::string command_line = |
| 86 "HandleInheritanceTests_ValidInheritedHandle " + | 86 "HandleInheritanceTests_ValidInheritedHandle " + |
| 87 base::UintToString(reinterpret_cast<unsigned int>(shared_handle)); | 87 base::UintToString(reinterpret_cast<unsigned int>(shared_handle)); |
| 88 int result = runner.RunTest(base::UTF8ToUTF16(command_line).c_str()); | 88 int result = runner.RunTest(base::UTF8ToUTF16(command_line).c_str()); |
| 89 ASSERT_EQ(SBOX_TEST_SUCCEEDED, result); | 89 ASSERT_EQ(SBOX_TEST_SUCCEEDED, result); |
| 90 } | 90 } |
| 91 | 91 |
| 92 } // namespace sandbox | 92 } // namespace sandbox |
| OLD | NEW |