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

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

Issue 1851213002: Remove sandbox on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nacl compile issues Created 4 years, 8 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/win_utils.cc ('k') | sandbox/win/src/window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <windows.h>
6
7 #include "base/win/scoped_handle.h"
8 #include "sandbox/win/src/win_utils.h"
9 #include "sandbox/win/tests/common/test_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 TEST(WinUtils, IsReparsePoint) {
13 using sandbox::IsReparsePoint;
14
15 // Create a temp file because we need write access to it.
16 wchar_t temp_directory[MAX_PATH];
17 wchar_t my_folder[MAX_PATH];
18 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u);
19 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u);
20
21 // Delete the file and create a directory instead.
22 ASSERT_TRUE(::DeleteFile(my_folder));
23 ASSERT_TRUE(::CreateDirectory(my_folder, NULL));
24
25 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT),
26 IsReparsePoint(my_folder));
27
28 base::string16 not_found = base::string16(my_folder) + L"\\foo\\bar";
29 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT),
30 IsReparsePoint(not_found));
31
32 base::string16 new_file = base::string16(my_folder) + L"\\foo";
33 EXPECT_EQ(static_cast<DWORD>(ERROR_NOT_A_REPARSE_POINT),
34 IsReparsePoint(new_file));
35
36 // Replace the directory with a reparse point to %temp%.
37 HANDLE dir = ::CreateFile(my_folder, FILE_ALL_ACCESS,
38 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
39 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
40 EXPECT_NE(INVALID_HANDLE_VALUE, dir);
41
42 base::string16 temp_dir_nt = base::string16(L"\\??\\") + temp_directory;
43 EXPECT_TRUE(SetReparsePoint(dir, temp_dir_nt.c_str()));
44
45 EXPECT_EQ(static_cast<DWORD>(ERROR_SUCCESS), IsReparsePoint(new_file));
46
47 EXPECT_TRUE(DeleteReparsePoint(dir));
48 EXPECT_TRUE(::CloseHandle(dir));
49 EXPECT_TRUE(::RemoveDirectory(my_folder));
50 }
51
52 TEST(WinUtils, SameObject) {
53 using sandbox::SameObject;
54
55 // Create a temp file because we need write access to it.
56 wchar_t temp_directory[MAX_PATH];
57 wchar_t my_folder[MAX_PATH];
58 ASSERT_NE(::GetTempPath(MAX_PATH, temp_directory), 0u);
59 ASSERT_NE(::GetTempFileName(temp_directory, L"test", 0, my_folder), 0u);
60
61 // Delete the file and create a directory instead.
62 ASSERT_TRUE(::DeleteFile(my_folder));
63 ASSERT_TRUE(::CreateDirectory(my_folder, NULL));
64
65 base::string16 folder(my_folder);
66 base::string16 file_name = folder + L"\\foo.txt";
67 const ULONG kSharing = FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE;
68 base::win::ScopedHandle file(CreateFile(
69 file_name.c_str(), GENERIC_WRITE, kSharing, NULL, CREATE_ALWAYS,
70 FILE_FLAG_DELETE_ON_CLOSE, NULL));
71
72 EXPECT_TRUE(file.IsValid());
73 base::string16 file_name_nt1 = base::string16(L"\\??\\") + file_name;
74 base::string16 file_name_nt2 =
75 base::string16(L"\\??\\") + folder + L"\\FOO.txT";
76 EXPECT_TRUE(SameObject(file.Get(), file_name_nt1.c_str()));
77 EXPECT_TRUE(SameObject(file.Get(), file_name_nt2.c_str()));
78
79 file.Close();
80 EXPECT_TRUE(::RemoveDirectory(my_folder));
81 }
82
83 TEST(WinUtils, IsPipe) {
84 using sandbox::IsPipe;
85
86 base::string16 pipe_name = L"\\??\\pipe\\mypipe";
87 EXPECT_TRUE(IsPipe(pipe_name));
88
89 pipe_name = L"\\??\\PiPe\\mypipe";
90 EXPECT_TRUE(IsPipe(pipe_name));
91
92 pipe_name = L"\\??\\pipe";
93 EXPECT_FALSE(IsPipe(pipe_name));
94
95 pipe_name = L"\\??\\_pipe_\\mypipe";
96 EXPECT_FALSE(IsPipe(pipe_name));
97
98 pipe_name = L"\\??\\ABCD\\mypipe";
99 EXPECT_FALSE(IsPipe(pipe_name));
100
101
102 // Written as two strings to prevent trigraph '?' '?' '/'.
103 pipe_name = L"/?" L"?/pipe/mypipe";
104 EXPECT_FALSE(IsPipe(pipe_name));
105
106 pipe_name = L"\\XX\\pipe\\mypipe";
107 EXPECT_FALSE(IsPipe(pipe_name));
108
109 pipe_name = L"\\Device\\NamedPipe\\mypipe";
110 EXPECT_FALSE(IsPipe(pipe_name));
111 }
OLDNEW
« no previous file with comments | « sandbox/win/src/win_utils.cc ('k') | sandbox/win/src/window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698