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

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

Issue 868253011: Make chrome.exe built with ASan/Win work with sandbox enabled (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
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 <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/win/windows_version.h" 8 #include "base/win/windows_version.h"
9 #include "sandbox/win/tests/common/controller.h" 9 #include "sandbox/win/tests/common/controller.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace sandbox { 12 namespace sandbox {
13 13
14 SBOX_TESTS_COMMAND int HandleInheritanceTests_PrintToStdout(int argc, 14 SBOX_TESTS_COMMAND int HandleInheritanceTests_PrintToStdout(int argc,
15 wchar_t** argv) { 15 wchar_t** argv) {
16 printf("Example output to stdout\n"); 16 printf("Example output to stdout\n");
17 return SBOX_TEST_SUCCEEDED; 17 return SBOX_TEST_SUCCEEDED;
18 } 18 }
19 19
20 TEST(HandleInheritanceTests, TestStdoutInheritance) { 20 TEST(HandleInheritanceTests, TestStdoutInheritance) {
21 wchar_t temp_directory[MAX_PATH]; 21 wchar_t temp_directory[MAX_PATH];
22 wchar_t temp_file_name[MAX_PATH]; 22 wchar_t temp_file_name[MAX_PATH];
23 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); 23 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u);
24 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u); 24 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u);
25 25
26 SECURITY_ATTRIBUTES attrs = {}; 26 SECURITY_ATTRIBUTES attrs = {};
27 attrs.nLength = sizeof(attrs); 27 attrs.nLength = sizeof(attrs);
28 attrs.lpSecurityDescriptor = NULL;
Timur Iskhodzhanov 2015/01/30 16:05:30 FYI I think this is redundant
29 attrs.bInheritHandle = TRUE; 28 attrs.bInheritHandle = TRUE;
30 HANDLE file_handle = CreateFile( 29 HANDLE file_handle = CreateFile(
31 temp_file_name, GENERIC_WRITE, 30 temp_file_name, GENERIC_WRITE,
32 FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, 31 FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
33 &attrs, OPEN_EXISTING, 0, NULL); 32 &attrs, OPEN_EXISTING, 0, NULL);
34 EXPECT_NE(file_handle, INVALID_HANDLE_VALUE); 33 EXPECT_NE(file_handle, INVALID_HANDLE_VALUE);
35 34
36 TestRunner runner; 35 TestRunner runner;
37 EXPECT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStdoutHandle(file_handle)); 36 EXPECT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStdoutHandle(file_handle));
38 int result = runner.RunTest(L"HandleInheritanceTests_PrintToStdout"); 37 int result = runner.RunTest(L"HandleInheritanceTests_PrintToStdout");
39 EXPECT_EQ(SBOX_TEST_SUCCEEDED, result); 38 EXPECT_EQ(SBOX_TEST_SUCCEEDED, result);
40 EXPECT_TRUE(::CloseHandle(file_handle)); 39 EXPECT_TRUE(::CloseHandle(file_handle));
41 40
42 std::string data; 41 std::string data;
43 EXPECT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data)); 42 EXPECT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data));
44 // Redirection uses a feature that was added in Windows Vista. 43 // Redirection uses a feature that was added in Windows Vista.
45 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 44 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
46 EXPECT_EQ("Example output to stdout\r\n", data); 45 EXPECT_EQ("Example output to stdout\r\n", data);
47 } else { 46 } else {
48 EXPECT_EQ("", data); 47 EXPECT_EQ("", data);
49 } 48 }
50 49
51 EXPECT_TRUE(::DeleteFile(temp_file_name)); 50 EXPECT_TRUE(::DeleteFile(temp_file_name));
52 } 51 }
53 52
54 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698