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

Side by Side Diff: chrome/browser/nacl_host/pnacl_file_host_unittest.cc

Issue 9158005: RFC: Add an interface for having the browser open a pnacl support file (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add a test, do some tweaks. Created 8 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 | Annotate | Revision Log
OLDNEW
(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/file_util.h"
10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h"
12 #include "base/synchronization/lock.h"
13 #include "chrome/common/chrome_paths.h"
14
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 using pnacl_file_host::PnaclCanOpenFile;
18
19 namespace {
20
21 class PnaclFileHostTest : public ::testing::Test {
22 public:
23 PnaclFileHostTest() {
24 }
25 virtual ~PnaclFileHostTest() {
26 }
27 // NOTE: because we override the DIR_PNACL_COMPONENT in both
28 // tests, these tests cannot be run concurrently.
29 base::Lock test_lock_;
30 private:
31 DISALLOW_COPY_AND_ASSIGN(PnaclFileHostTest);
32 };
33
34 } // namespace
35
36 // Try to pass a few funny filenames with a dummy pnacl directory set.
37 TEST_F(PnaclFileHostTest, TestFilenamesWithPnaclPath) {
38 base::AutoLock auto_lock(test_lock_);
39 FilePath kDummyPnaclPath("dummy_pnacl_path");
40 ASSERT_TRUE(PathService::Override(chrome::DIR_PNACL_COMPONENT,
41 kDummyPnaclPath));
42 ASSERT_TRUE(PathService::Get(chrome::DIR_PNACL_COMPONENT,
43 &kDummyPnaclPath));
44 FilePath out_path;
45 EXPECT_TRUE(PnaclCanOpenFile("manifest.json", &out_path));
46 FilePath expected_path = kDummyPnaclPath.Append("manifest.json");
47 EXPECT_EQ(out_path, expected_path);
48
49 EXPECT_TRUE(PnaclCanOpenFile("x86-32/llc", &out_path));
50 expected_path = kDummyPnaclPath.Append("x86-32/llc");
51 EXPECT_EQ(out_path, expected_path);
52
53 EXPECT_FALSE(PnaclCanOpenFile("", &out_path));
54 EXPECT_FALSE(PnaclCanOpenFile(".", &out_path));
55 EXPECT_FALSE(PnaclCanOpenFile("..", &out_path));
56 #if defined(OS_WIN)
57 EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path));
58 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path));
59 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path));
60 #else
61 EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path));
62 EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path));
63 EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path));
64 EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path));
65 #endif
66
67 const char non_ascii[] = "\xff\xfe";
68 EXPECT_FALSE(PnaclCanOpenFile(non_ascii, &out_path));
69 }
70
71 // Place a dummy file, open it, and make sure we can still delete it while
72 // it is open (in case we need the Pnacl upgrader to GC old versions
73 // of Pnacl).
74 TEST_F(PnaclFileHostTest, TestOpenAndDelete) {
75 base::AutoLock auto_lock(test_lock_);
76
77 // Write something to a temporary directory, and try to open it,
78 // and delete while still open.
79
80 ScopedTempDir temp_directory;
81 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
82 FilePath temp_file;
83 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(),
84 &temp_file));
85 ASSERT_TRUE(PathService::Override(chrome::DIR_PNACL_COMPONENT,
86 temp_directory.path()));
87 FilePath full_path;
88 EXPECT_TRUE(PnaclCanOpenFile(temp_file.BaseName().MaybeAsASCII(),
89 &full_path));
90 EXPECT_EQ(full_path, temp_directory.path().Append(temp_file.BaseName()));
91
92 base::PlatformFile open_temp;
93 EXPECT_TRUE(pnacl_file_host::PnaclDoOpenFile(full_path, &open_temp));
94 EXPECT_TRUE(file_util::Delete(full_path, false));
95 EXPECT_TRUE(base::ClosePlatformFile(open_temp));
96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698