OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/nacl_host/pnacl_file_host.h" | |
6 | |
7 #include "base/basictypes.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/files/scoped_temp_dir.h" | |
10 #include "base/path_service.h" | |
11 #include "base/test/scoped_path_override.h" | |
12 #include "chrome/common/chrome_paths.h" | |
13 | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 | |
16 using pnacl_file_host::PnaclCanOpenFile; | |
17 | |
18 // Try to pass a few funny filenames with a dummy pnacl directory set. | |
19 TEST(PnaclFileHostTest, TestFilenamesWithPnaclPath) { | |
20 base::ScopedTempDir scoped_tmp_dir; | |
21 ASSERT_TRUE(scoped_tmp_dir.CreateUniqueTempDir()); | |
22 | |
23 base::FilePath kDummyPnaclPath = scoped_tmp_dir.path(); | |
24 base::ScopedPathOverride pnach_dir_override(chrome::DIR_PNACL_COMPONENT, | |
25 kDummyPnaclPath); | |
26 ASSERT_TRUE(PathService::Get(chrome::DIR_PNACL_COMPONENT, | |
27 &kDummyPnaclPath)); | |
28 | |
29 // Check allowed strings, and check that the expected prefix is added. | |
30 base::FilePath out_path; | |
31 EXPECT_TRUE(PnaclCanOpenFile("pnacl_json", &out_path)); | |
32 base::FilePath expected_path = kDummyPnaclPath.Append( | |
33 FILE_PATH_LITERAL("pnacl_public_pnacl_json")); | |
34 EXPECT_EQ(out_path, expected_path); | |
35 | |
36 EXPECT_TRUE(PnaclCanOpenFile("x86_32_llc", &out_path)); | |
37 expected_path = kDummyPnaclPath.Append( | |
38 FILE_PATH_LITERAL("pnacl_public_x86_32_llc")); | |
39 EXPECT_EQ(out_path, expected_path); | |
40 | |
41 // Check character ranges. | |
42 EXPECT_FALSE(PnaclCanOpenFile(".xchars", &out_path)); | |
43 EXPECT_FALSE(PnaclCanOpenFile("/xchars", &out_path)); | |
44 EXPECT_FALSE(PnaclCanOpenFile("x/chars", &out_path)); | |
45 EXPECT_FALSE(PnaclCanOpenFile("\\xchars", &out_path)); | |
46 EXPECT_FALSE(PnaclCanOpenFile("x\\chars", &out_path)); | |
47 EXPECT_FALSE(PnaclCanOpenFile("$xchars", &out_path)); | |
48 EXPECT_FALSE(PnaclCanOpenFile("%xchars", &out_path)); | |
49 EXPECT_FALSE(PnaclCanOpenFile("CAPS", &out_path)); | |
50 const char non_ascii[] = "\xff\xfe"; | |
51 EXPECT_FALSE(PnaclCanOpenFile(non_ascii, &out_path)); | |
52 | |
53 // Check file length restriction. | |
54 EXPECT_FALSE(PnaclCanOpenFile("thisstringisactuallywaaaaaaaaaaaaaaaaaaaaaaaa" | |
55 "toolongwaytoolongwaaaaayyyyytoooooooooooooooo" | |
56 "looooooooong", | |
57 &out_path)); | |
58 | |
59 // Other bad files. | |
60 EXPECT_FALSE(PnaclCanOpenFile(std::string(), &out_path)); | |
61 EXPECT_FALSE(PnaclCanOpenFile(".", &out_path)); | |
62 EXPECT_FALSE(PnaclCanOpenFile("..", &out_path)); | |
63 #if defined(OS_WIN) | |
64 EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path)); | |
65 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path)); | |
66 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path)); | |
67 #else | |
68 EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path)); | |
69 EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path)); | |
70 EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path)); | |
71 EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path)); | |
72 #endif | |
73 } | |
OLD | NEW |