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

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

Issue 51323004: Move most of TestNaClBrowserDelegate to another file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang-format Created 7 years, 1 month 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
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/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/test/scoped_path_override.h" 11 #include "base/test/scoped_path_override.h"
12 #include "base/threading/sequenced_worker_pool.h" 12 #include "base/threading/sequenced_worker_pool.h"
13 #include "chrome/browser/nacl_host/nacl_browser.h" 13 #include "chrome/browser/nacl_host/nacl_browser.h"
14 #include "components/nacl/common/nacl_browser_delegate.h"
15 #include "components/nacl/common/pnacl_types.h" 14 #include "components/nacl/common/pnacl_types.h"
15 #include "components/nacl/common/test_nacl_browser_delegate.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 using nacl_file_host::PnaclCanOpenFile; 20 using nacl_file_host::PnaclCanOpenFile;
21 using nacl_file_host::EnsurePnaclInstalled; 21 using nacl_file_host::EnsurePnaclInstalled;
22 22
23 class TestNaClBrowserDelegate : public NaClBrowserDelegate { 23 class FileHostTestNaclBrowserDelegate : public TestNaClBrowserDelegate {
Mark Seaborn 2013/10/31 02:36:38 Can you fix the spelling to be "NaCl" not "Nacl" h
jvoung (off chromium) 2013/10/31 16:59:55 Done.
24 public: 24 public:
25 25 FileHostTestNaclBrowserDelegate() : should_pnacl_install_succeed_(false) {}
26 TestNaClBrowserDelegate() : should_pnacl_install_succeed_(false) { }
27
28 virtual void ShowNaClInfobar(int render_process_id,
29 int render_view_id,
30 int error_id) OVERRIDE {
31 }
32
33 virtual bool DialogsAreSuppressed() OVERRIDE {
34 return false;
35 }
36
37 virtual bool GetCacheDirectory(base::FilePath* cache_dir) OVERRIDE {
38 return false;
39 }
40
41 virtual bool GetPluginDirectory(base::FilePath* plugin_dir) OVERRIDE {
42 return false;
43 }
44 26
45 virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE { 27 virtual bool GetPnaclDirectory(base::FilePath* pnacl_dir) OVERRIDE {
46 *pnacl_dir = pnacl_path_; 28 *pnacl_dir = pnacl_path_;
47 return true; 29 return true;
48 } 30 }
49 31
50 virtual bool GetUserDirectory(base::FilePath* user_dir) OVERRIDE { 32 virtual void TryInstallPnacl(const base::Callback<void(bool)>& installed)
51 return false; 33 OVERRIDE {
52 }
53
54 virtual std::string GetVersionString() const OVERRIDE {
55 return std::string();
56 }
57
58 virtual ppapi::host::HostFactory* CreatePpapiHostFactory(
59 content::BrowserPpapiHost* ppapi_host) OVERRIDE {
60 return NULL;
61 }
62
63 virtual bool MapUrlToLocalFilePath(const GURL& file_url,
64 bool use_blocking_api,
65 base::FilePath* file_path) OVERRIDE {
66 return false;
67 }
68
69 virtual void SetDebugPatterns(std::string debug_patterns) OVERRIDE {
70 }
71
72 virtual bool URLMatchesDebugPatterns(const GURL& manifest_url) OVERRIDE {
73 return false;
74 }
75
76 virtual void TryInstallPnacl(
77 const base::Callback<void(bool)>& installed) OVERRIDE {
78 installed.Run(should_pnacl_install_succeed_); 34 installed.Run(should_pnacl_install_succeed_);
79 } 35 }
80 36
81 void SetPnaclDirectory(const base::FilePath& pnacl_dir) { 37 void SetPnaclDirectory(const base::FilePath& pnacl_dir) {
82 pnacl_path_ = pnacl_dir; 38 pnacl_path_ = pnacl_dir;
83 } 39 }
84 40
85 // Indicate if we should mock the PNaCl install as succeeding 41 // Indicate if we should mock the PNaCl install as succeeding
86 // or failing for the next test. 42 // or failing for the next test.
87 void SetShouldPnaclInstallSucceed(bool succeed) { 43 void SetShouldPnaclInstallSucceed(bool succeed) {
88 should_pnacl_install_succeed_ = succeed; 44 should_pnacl_install_succeed_ = succeed;
89 } 45 }
90 46
91 private: 47 private:
92 base::FilePath pnacl_path_; 48 base::FilePath pnacl_path_;
93 bool should_pnacl_install_succeed_; 49 bool should_pnacl_install_succeed_;
94 }; 50 };
95 51
96 class NaClFileHostTest : public testing::Test { 52 class NaClFileHostTest : public testing::Test {
97 protected: 53 protected:
98 NaClFileHostTest(); 54 NaClFileHostTest();
99 virtual ~NaClFileHostTest(); 55 virtual ~NaClFileHostTest();
100 56
101 virtual void SetUp() OVERRIDE { 57 virtual void SetUp() OVERRIDE {
102 nacl_browser_delegate_ = new TestNaClBrowserDelegate; 58 nacl_browser_delegate_ = new FileHostTestNaclBrowserDelegate;
103 NaClBrowser::SetDelegate(nacl_browser_delegate_); 59 NaClBrowser::SetDelegate(nacl_browser_delegate_);
104 } 60 }
105 61
106 virtual void TearDown() OVERRIDE { 62 virtual void TearDown() OVERRIDE {
107 NaClBrowser::SetDelegate(NULL); // This deletes nacl_browser_delegate_ 63 NaClBrowser::SetDelegate(NULL); // This deletes nacl_browser_delegate_
108 } 64 }
109 65
110 TestNaClBrowserDelegate* nacl_browser_delegate() { 66 FileHostTestNaclBrowserDelegate* nacl_browser_delegate() {
111 return nacl_browser_delegate_; 67 return nacl_browser_delegate_;
112 } 68 }
113 69
114 bool install_success() { return install_success_; } 70 bool install_success() { return install_success_; }
115 size_t install_call_count() { 71 size_t install_call_count() {
116 return std::count(events_.begin(), events_.end(), INSTALL_DONE); 72 return std::count(events_.begin(), events_.end(), INSTALL_DONE);
117 } 73 }
118 size_t progress_call_count() { 74 size_t progress_call_count() {
119 return std::count(events_.begin(), events_.end(), INSTALL_PROGRESS); 75 return std::count(events_.begin(), events_.end(), INSTALL_PROGRESS);
120 } 76 }
(...skipping 20 matching lines...) Expand all
141 // TODO(jvoung): be able to check that current_progress 97 // TODO(jvoung): be able to check that current_progress
142 // goes up monotonically and hits total_progress at the end, 98 // goes up monotonically and hits total_progress at the end,
143 // when we actually get real progress events. 99 // when we actually get real progress events.
144 } 100 }
145 101
146 private: 102 private:
147 enum EventType { 103 enum EventType {
148 INSTALL_DONE, 104 INSTALL_DONE,
149 INSTALL_PROGRESS 105 INSTALL_PROGRESS
150 }; 106 };
151 TestNaClBrowserDelegate* nacl_browser_delegate_; 107 FileHostTestNaclBrowserDelegate* nacl_browser_delegate_;
152 bool install_success_; 108 bool install_success_;
153 std::vector<EventType> events_; 109 std::vector<EventType> events_;
154 content::TestBrowserThreadBundle thread_bundle_; 110 content::TestBrowserThreadBundle thread_bundle_;
155 DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest); 111 DISALLOW_COPY_AND_ASSIGN(NaClFileHostTest);
156 }; 112 };
157 113
158 NaClFileHostTest::NaClFileHostTest() 114 NaClFileHostTest::NaClFileHostTest()
159 : nacl_browser_delegate_(NULL), 115 : nacl_browser_delegate_(NULL),
160 install_success_(false), 116 install_success_(false),
161 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 117 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 base::Bind(&NaClFileHostTest::CallbackInstall, base::Unretained(this)), 230 base::Bind(&NaClFileHostTest::CallbackInstall, base::Unretained(this)),
275 base::Bind(&NaClFileHostTest::CallbackProgress, base::Unretained(this))); 231 base::Bind(&NaClFileHostTest::CallbackProgress, base::Unretained(this)));
276 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 232 content::BrowserThread::GetBlockingPool()->FlushForTesting();
277 base::RunLoop().RunUntilIdle(); 233 base::RunLoop().RunUntilIdle();
278 234
279 EXPECT_FALSE(install_success()); 235 EXPECT_FALSE(install_success());
280 EXPECT_EQ(1u, install_call_count()); 236 EXPECT_EQ(1u, install_call_count());
281 EXPECT_GE(progress_call_count(), 1u); 237 EXPECT_GE(progress_call_count(), 1u);
282 EXPECT_TRUE(events_in_correct_order()); 238 EXPECT_TRUE(events_in_correct_order());
283 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698