Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include <stdio.h> |
michael@0 | 6 | |
michael@0 | 7 | #include "base/file_util.h" |
michael@0 | 8 | #include "base/win/windows_version.h" |
michael@0 | 9 | #include "sandbox/win/tests/common/controller.h" |
michael@0 | 10 | #include "testing/gtest/include/gtest/gtest.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace sandbox { |
michael@0 | 13 | |
michael@0 | 14 | SBOX_TESTS_COMMAND int HandleInheritanceTests_PrintToStdout(int argc, |
michael@0 | 15 | wchar_t** argv) { |
michael@0 | 16 | printf("Example output to stdout\n"); |
michael@0 | 17 | return SBOX_TEST_SUCCEEDED; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | TEST(HandleInheritanceTests, TestStdoutInheritance) { |
michael@0 | 21 | wchar_t temp_directory[MAX_PATH]; |
michael@0 | 22 | wchar_t temp_file_name[MAX_PATH]; |
michael@0 | 23 | ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); |
michael@0 | 24 | ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u); |
michael@0 | 25 | |
michael@0 | 26 | SECURITY_ATTRIBUTES attrs = {}; |
michael@0 | 27 | attrs.nLength = sizeof(attrs); |
michael@0 | 28 | attrs.lpSecurityDescriptor = NULL; |
michael@0 | 29 | attrs.bInheritHandle = TRUE; |
michael@0 | 30 | HANDLE file_handle = CreateFile( |
michael@0 | 31 | temp_file_name, GENERIC_WRITE, |
michael@0 | 32 | FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, |
michael@0 | 33 | &attrs, OPEN_EXISTING, 0, NULL); |
michael@0 | 34 | EXPECT_NE(file_handle, INVALID_HANDLE_VALUE); |
michael@0 | 35 | |
michael@0 | 36 | TestRunner runner; |
michael@0 | 37 | EXPECT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStdoutHandle(file_handle)); |
michael@0 | 38 | int result = runner.RunTest(L"HandleInheritanceTests_PrintToStdout"); |
michael@0 | 39 | EXPECT_EQ(SBOX_TEST_SUCCEEDED, result); |
michael@0 | 40 | EXPECT_TRUE(::CloseHandle(file_handle)); |
michael@0 | 41 | |
michael@0 | 42 | std::string data; |
michael@0 | 43 | EXPECT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data)); |
michael@0 | 44 | // Redirection uses a feature that was added in Windows Vista. |
michael@0 | 45 | if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
michael@0 | 46 | EXPECT_EQ("Example output to stdout\r\n", data); |
michael@0 | 47 | } else { |
michael@0 | 48 | EXPECT_EQ("", data); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | EXPECT_TRUE(::DeleteFile(temp_file_name)); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | } |