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

Unified Diff: chrome/browser/nacl_host/pnacl_file_host_unittest.cc

Issue 10662006: Add a NaCl-Private interface for opening files in DIR_PNACL_COMPONENT. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments and rebase Created 8 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/nacl_host/pnacl_file_host_unittest.cc
diff --git a/chrome/browser/nacl_host/pnacl_file_host_unittest.cc b/chrome/browser/nacl_host/pnacl_file_host_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9e83c3be3e139071719aad387e78f94bedbfae6
--- /dev/null
+++ b/chrome/browser/nacl_host/pnacl_file_host_unittest.cc
@@ -0,0 +1,63 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/nacl_host/pnacl_file_host.h"
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/path_service.h"
+#include "chrome/common/chrome_paths.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+using pnacl_file_host::PnaclCanOpenFile;
+
+namespace {
+
+class PnaclFileHostTest : public ::testing::Test {
brettw 2012/07/23 18:09:02 Since this class doesn't do anything you can remov
jvoung (off chromium) 2012/07/23 19:59:04 Done.
+ public:
+ PnaclFileHostTest() {
+ }
+ virtual ~PnaclFileHostTest() {
+ }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(PnaclFileHostTest);
+};
+
+} // namespace
+
+// Try to pass a few funny filenames with a dummy pnacl directory set.
+TEST_F(PnaclFileHostTest, TestFilenamesWithPnaclPath) {
+ FilePath kDummyPnaclPath(FILE_PATH_LITERAL("dummy_pnacl_path"));
+ ASSERT_TRUE(PathService::Override(chrome::DIR_PNACL_COMPONENT,
+ kDummyPnaclPath));
+ ASSERT_TRUE(PathService::Get(chrome::DIR_PNACL_COMPONENT,
+ &kDummyPnaclPath));
+ FilePath out_path;
+ EXPECT_TRUE(PnaclCanOpenFile("manifest.json", &out_path));
+ FilePath expected_path = kDummyPnaclPath.Append(
+ FILE_PATH_LITERAL("manifest.json"));
+ EXPECT_EQ(out_path, expected_path);
+
+ EXPECT_TRUE(PnaclCanOpenFile("x86-32/llc", &out_path));
+ expected_path = kDummyPnaclPath.Append(FILE_PATH_LITERAL("x86-32/llc"));
+ EXPECT_EQ(out_path, expected_path);
+
+ EXPECT_FALSE(PnaclCanOpenFile("", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile(".", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("..", &out_path));
+#if defined(OS_WIN)
+ EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path));
+#else
+ EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path));
+ EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path));
+#endif
+
+ const char non_ascii[] = "\xff\xfe";
+ EXPECT_FALSE(PnaclCanOpenFile(non_ascii, &out_path));
+}

Powered by Google App Engine
This is Rietveld 408576698