OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/nacl_host/nacl_file_host.h" | 5 #include "chrome/browser/nacl_host/nacl_file_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/test/scoped_path_override.h" | 10 #include "base/test/scoped_path_override.h" |
11 #include "components/nacl/browser/nacl_browser.h" | 11 #include "components/nacl/browser/nacl_browser.h" |
12 #include "components/nacl/common/nacl_browser_delegate.h" | 12 #include "components/nacl/common/nacl_browser_delegate.h" |
| 13 #include "components/nacl/common/test_nacl_browser_delegate.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 using nacl_file_host::PnaclCanOpenFile; | 16 using nacl_file_host::PnaclCanOpenFile; |
16 | 17 |
17 class TestNaClBrowserDelegate : public NaClBrowserDelegate { | 18 class FileHostTestNaClBrowserDelegate : public TestNaClBrowserDelegate { |
18 public: | 19 public: |
19 | 20 FileHostTestNaClBrowserDelegate() {} |
20 TestNaClBrowserDelegate() {} | |
21 | |
22 virtual void ShowNaClInfobar(int render_process_id, | |
23 int render_view_id, | |
24 int error_id) OVERRIDE { | |
25 } | |
26 | |
27 virtual bool DialogsAreSuppressed() OVERRIDE { | |
28 return false; | |
29 } | |
30 | |
31 virtual bool GetCacheDirectory(base::FilePath* cache_dir) OVERRIDE { | |
32 return false; | |
33 } | |
34 | |
35 virtual bool GetPluginDirectory(base::FilePath* plugin_dir) OVERRIDE { | |
36 return false; | |
37 } | |
38 | 21 |
39 virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE { | 22 virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE { |
40 *pnacl_dir = pnacl_path_; | 23 *pnacl_dir = pnacl_path_; |
41 return true; | 24 return true; |
42 } | 25 } |
43 | 26 |
44 virtual bool GetUserDirectory(base::FilePath* user_dir) OVERRIDE { | |
45 return false; | |
46 } | |
47 | |
48 virtual std::string GetVersionString() const OVERRIDE { | |
49 return std::string(); | |
50 } | |
51 | |
52 virtual ppapi::host::HostFactory* CreatePpapiHostFactory( | |
53 content::BrowserPpapiHost* ppapi_host) OVERRIDE { | |
54 return NULL; | |
55 } | |
56 | |
57 virtual bool MapUrlToLocalFilePath(const GURL& file_url, | |
58 bool use_blocking_api, | |
59 base::FilePath* file_path) OVERRIDE { | |
60 return false; | |
61 } | |
62 | |
63 virtual void SetDebugPatterns(std::string debug_patterns) OVERRIDE { | |
64 } | |
65 | |
66 virtual bool URLMatchesDebugPatterns(const GURL& manifest_url) OVERRIDE { | |
67 return false; | |
68 } | |
69 | |
70 void SetPnaclDirectory(const base::FilePath& pnacl_dir) { | 27 void SetPnaclDirectory(const base::FilePath& pnacl_dir) { |
71 pnacl_path_ = pnacl_dir; | 28 pnacl_path_ = pnacl_dir; |
72 } | 29 } |
73 | 30 |
74 private: | 31 private: |
75 base::FilePath pnacl_path_; | 32 base::FilePath pnacl_path_; |
76 }; | 33 }; |
77 | 34 |
78 class NaClFileHostTest : public testing::Test { | 35 class NaClFileHostTest : public testing::Test { |
79 protected: | 36 protected: |
80 NaClFileHostTest(); | 37 NaClFileHostTest(); |
81 virtual ~NaClFileHostTest(); | 38 virtual ~NaClFileHostTest(); |
82 | 39 |
83 virtual void SetUp() OVERRIDE { | 40 virtual void SetUp() OVERRIDE { |
84 nacl_browser_delegate_ = new TestNaClBrowserDelegate; | 41 nacl_browser_delegate_ = new FileHostTestNaClBrowserDelegate; |
85 nacl::NaClBrowser::SetDelegate(nacl_browser_delegate_); | 42 nacl::NaClBrowser::SetDelegate(nacl_browser_delegate_); |
86 } | 43 } |
87 | 44 |
88 virtual void TearDown() OVERRIDE { | 45 virtual void TearDown() OVERRIDE { |
89 // This deletes nacl_browser_delegate_. | 46 // This deletes nacl_browser_delegate_. |
90 nacl::NaClBrowser::SetDelegate(NULL); | 47 nacl::NaClBrowser::SetDelegate(NULL); |
91 } | 48 } |
92 | 49 |
93 TestNaClBrowserDelegate* nacl_browser_delegate() { | 50 FileHostTestNaClBrowserDelegate* nacl_browser_delegate() { |
94 return nacl_browser_delegate_; | 51 return nacl_browser_delegate_; |
95 } | 52 } |
96 | 53 |
97 private: | 54 private: |
98 TestNaClBrowserDelegate* nacl_browser_delegate_; | 55 FileHostTestNaClBrowserDelegate* nacl_browser_delegate_; |
99 DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest); | 56 DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest); |
100 }; | 57 }; |
101 | 58 |
102 NaClFileHostTest::NaClFileHostTest() : nacl_browser_delegate_(NULL) {} | 59 NaClFileHostTest::NaClFileHostTest() : nacl_browser_delegate_(NULL) {} |
103 | 60 |
104 NaClFileHostTest::~NaClFileHostTest() { | 61 NaClFileHostTest::~NaClFileHostTest() { |
105 } | 62 } |
106 | 63 |
107 // Try to pass a few funny filenames with a dummy PNaCl directory set. | 64 // Try to pass a few funny filenames with a dummy PNaCl directory set. |
108 TEST_F(NaClFileHostTest, TestFilenamesWithPnaclPath) { | 65 TEST_F(NaClFileHostTest, TestFilenamesWithPnaclPath) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path)); | 110 EXPECT_FALSE(PnaclCanOpenFile("..\\llc", &out_path)); |
154 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path)); | 111 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%", &out_path)); |
155 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path)); | 112 EXPECT_FALSE(PnaclCanOpenFile("%SystemRoot%\\explorer.exe", &out_path)); |
156 #else | 113 #else |
157 EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path)); | 114 EXPECT_FALSE(PnaclCanOpenFile("../llc", &out_path)); |
158 EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path)); | 115 EXPECT_FALSE(PnaclCanOpenFile("/bin/sh", &out_path)); |
159 EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path)); | 116 EXPECT_FALSE(PnaclCanOpenFile("$HOME", &out_path)); |
160 EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path)); | 117 EXPECT_FALSE(PnaclCanOpenFile("$HOME/.bashrc", &out_path)); |
161 #endif | 118 #endif |
162 } | 119 } |
OLD | NEW |