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/file_path.h" |
| 9 #include "base/path_service.h" |
| 10 #include "chrome/common/chrome_paths.h" |
| 11 |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 using pnacl_file_host::PnaclCanOpenFile; |
| 15 |
| 16 // Try to pass a few funny filenames with a dummy pnacl directory set. |
| 17 TEST(PnaclFileHostTest, TestFilenamesWithPnaclPath) { |
| 18 FilePath kDummyPnaclPath(FILE_PATH_LITERAL("dummy_pnacl_path")); |
| 19 ASSERT_TRUE(PathService::Override(chrome::DIR_PNACL_COMPONENT, |
| 20 kDummyPnaclPath)); |
| 21 ASSERT_TRUE(PathService::Get(chrome::DIR_PNACL_COMPONENT, |
| 22 &kDummyPnaclPath)); |
| 23 FilePath out_path; |
| 24 EXPECT_TRUE(PnaclCanOpenFile("manifest.json", &out_path)); |
| 25 FilePath expected_path = kDummyPnaclPath.Append( |
| 26 FILE_PATH_LITERAL("manifest.json")); |
| 27 EXPECT_EQ(out_path, expected_path); |
| 28 |
| 29 EXPECT_TRUE(PnaclCanOpenFile("x86-32/llc", &out_path)); |
| 30 expected_path = kDummyPnaclPath.Append(FILE_PATH_LITERAL("x86-32/llc")); |
| 31 EXPECT_EQ(out_path, expected_path); |
| 32 |
| 33 EXPECT_FALSE(PnaclCanOpenFile("", &out_path)); |
| 34 EXPECT_FALSE(PnaclCanOpenFile(".", &out_path)); |
| 35 EXPECT_FALSE(PnaclCanOpenFile("..", &out_path)); |
| 36 #if defined(OS_WIN) |
| 37 EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path)); |
| 38 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path)); |
| 39 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path)); |
| 40 #else |
| 41 EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path)); |
| 42 EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path)); |
| 43 EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path)); |
| 44 EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path)); |
| 45 #endif |
| 46 |
| 47 const char non_ascii[] = "\xff\xfe"; |
| 48 EXPECT_FALSE(PnaclCanOpenFile(non_ascii, &out_path)); |
| 49 } |
OLD | NEW |