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

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: one more EXPECT turned into ASSERT 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/files/scoped_temp_dir.h"
9 #include "base/win/scoped_handle.h"
8 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
9 #include "sandbox/win/tests/common/controller.h" 11 #include "sandbox/win/tests/common/controller.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace sandbox { 14 namespace sandbox {
13 15
14 SBOX_TESTS_COMMAND int HandleInheritanceTests_PrintToStdout(int argc, 16 SBOX_TESTS_COMMAND int HandleInheritanceTests_PrintToStdout(int argc,
15 wchar_t** argv) { 17 wchar_t** argv) {
16 printf("Example output to stdout\n"); 18 printf("Example output to stdout\n");
17 return SBOX_TEST_SUCCEEDED; 19 return SBOX_TEST_SUCCEEDED;
18 } 20 }
19 21
20 TEST(HandleInheritanceTests, TestStdoutInheritance) { 22 TEST(HandleInheritanceTests, TestStdoutInheritance) {
21 wchar_t temp_directory[MAX_PATH]; 23 base::ScopedTempDir temp_directory;
22 wchar_t temp_file_name[MAX_PATH]; 24 base::FilePath temp_file_name;
23 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u); 25 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
24 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, temp_file_name), 0u); 26 ASSERT_TRUE(CreateTemporaryFileInDir(temp_directory.path(), &temp_file_name));
25 27
26 SECURITY_ATTRIBUTES attrs = {}; 28 SECURITY_ATTRIBUTES attrs = {};
27 attrs.nLength = sizeof(attrs); 29 attrs.nLength = sizeof(attrs);
28 attrs.lpSecurityDescriptor = NULL;
29 attrs.bInheritHandle = TRUE; 30 attrs.bInheritHandle = TRUE;
30 HANDLE file_handle = CreateFile( 31 base::win::ScopedHandle tmp_handle(
31 temp_file_name, GENERIC_WRITE, 32 CreateFile(temp_file_name.value().c_str(), GENERIC_WRITE,
32 FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE, 33 FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE,
33 &attrs, OPEN_EXISTING, 0, NULL); 34 &attrs, OPEN_EXISTING, 0, NULL));
34 EXPECT_NE(file_handle, INVALID_HANDLE_VALUE); 35 ASSERT_TRUE(tmp_handle.IsValid());
Timur Iskhodzhanov 2015/02/05 08:15:52 Forgot to fix this one in PS5, fixed in PS6.
35 36
36 TestRunner runner; 37 TestRunner runner;
37 EXPECT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStdoutHandle(file_handle)); 38 ASSERT_EQ(SBOX_ALL_OK, runner.GetPolicy()->SetStdoutHandle(tmp_handle.Get()));
38 int result = runner.RunTest(L"HandleInheritanceTests_PrintToStdout"); 39 int result = runner.RunTest(L"HandleInheritanceTests_PrintToStdout");
39 EXPECT_EQ(SBOX_TEST_SUCCEEDED, result); 40 ASSERT_EQ(SBOX_TEST_SUCCEEDED, result);
40 EXPECT_TRUE(::CloseHandle(file_handle));
41 41
42 std::string data; 42 std::string data;
43 EXPECT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data)); 43 ASSERT_TRUE(base::ReadFileToString(base::FilePath(temp_file_name), &data));
44 // Redirection uses a feature that was added in Windows Vista. 44 // Redirection uses a feature that was added in Windows Vista.
45 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { 45 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
46 EXPECT_EQ("Example output to stdout\r\n", data); 46 ASSERT_EQ("Example output to stdout\r\n", data);
47 } else { 47 } else {
48 EXPECT_EQ("", data); 48 ASSERT_EQ("", data);
49 } 49 }
50
51 EXPECT_TRUE(::DeleteFile(temp_file_name));
52 } 50 }
53 51
54 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698