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

Side by Side Diff: components/nacl/browser/pnacl_host_unittest.cc

Issue 409743003: Use content::RunBlockingPoolTask() in tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 3 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/nacl/browser/pnacl_host.h" 5 #include "components/nacl/browser/pnacl_host.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <string>
9
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 12 #include "base/run_loop.h"
11 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
12 #include "components/nacl/browser/pnacl_translation_cache.h" 14 #include "components/nacl/browser/pnacl_translation_cache.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_utils.h"
15 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
16 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
17 20
18 #if defined(OS_WIN) 21 #if defined(OS_WIN)
19 #define snprintf _snprintf 22 #define snprintf _snprintf
20 #endif 23 #endif
21 24
22 namespace pnacl { 25 namespace pnacl {
26 namespace {
27
28 // Size of a buffer used for writing and reading from a file.
29 const size_t kBufferSize = 16u;
30
31 } // namespace
23 32
24 class PnaclHostTest : public testing::Test { 33 class PnaclHostTest : public testing::Test {
25 protected: 34 protected:
26 PnaclHostTest() 35 PnaclHostTest()
27 : host_(NULL), 36 : host_(NULL),
28 temp_callback_count_(0), 37 temp_callback_count_(0),
29 write_callback_count_(0), 38 write_callback_count_(0),
30 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} 39 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {}
31 virtual void SetUp() { 40 virtual void SetUp() {
32 host_ = new PnaclHost(); 41 host_ = new PnaclHost();
33 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 42 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
34 host_->InitForTest(temp_dir_.path(), true); 43 host_->InitForTest(temp_dir_.path(), true);
35 base::RunLoop().RunUntilIdle(); 44 base::RunLoop().RunUntilIdle();
36 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); 45 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_);
37 } 46 }
38 virtual void TearDown() { 47 virtual void TearDown() {
39 EXPECT_EQ(0U, host_->pending_translations()); 48 EXPECT_EQ(0U, host_->pending_translations());
40 // Give the host a chance to de-init the backend, and then delete it. 49 // Give the host a chance to de-init the backend, and then delete it.
41 host_->RendererClosing(0); 50 host_->RendererClosing(0);
42 FlushQueues(); 51 content::RunAllBlockingPoolTasksUntilIdle();
43 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_); 52 EXPECT_EQ(PnaclHost::CacheUninitialized, host_->cache_state_);
44 delete host_; 53 delete host_;
45 } 54 }
46 // Flush the blocking pool first, then any tasks it posted to the IO thread.
47 // Do 2 rounds of flushing, because some operations require 2 trips back and
48 // forth between the threads.
49 void FlushQueues() {
50 content::BrowserThread::GetBlockingPool()->FlushForTesting();
51 base::RunLoop().RunUntilIdle();
52 content::BrowserThread::GetBlockingPool()->FlushForTesting();
53 base::RunLoop().RunUntilIdle();
54 }
55 int GetCacheSize() { return host_->disk_cache_->Size(); } 55 int GetCacheSize() { return host_->disk_cache_->Size(); }
56 int CacheIsInitialized() { 56 int CacheIsInitialized() {
57 return host_->cache_state_ == PnaclHost::CacheReady; 57 return host_->cache_state_ == PnaclHost::CacheReady;
58 } 58 }
59 void ReInitBackend() { 59 void ReInitBackend() {
60 host_->InitForTest(temp_dir_.path(), true); 60 host_->InitForTest(temp_dir_.path(), true);
61 base::RunLoop().RunUntilIdle(); 61 base::RunLoop().RunUntilIdle();
62 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_); 62 EXPECT_EQ(PnaclHost::CacheReady, host_->cache_state_);
63 } 63 }
64 64
65 public: // Required for derived classes to bind this method 65 public: // Required for derived classes to bind this method
66 // Callbacks used by tests which call GetNexeFd. 66 // Callbacks used by tests which call GetNexeFd.
67 // CallbackExpectMiss checks that the fd is valid and a miss is reported, 67 // CallbackExpectMiss checks that the fd is valid and a miss is reported,
68 // and also writes some data into the file, which is read back by 68 // and also writes some data into the file, which is read back by
69 // CallbackExpectHit 69 // CallbackExpectHit
70 void CallbackExpectMiss(const base::File& file, bool is_hit) { 70 void CallbackExpectMiss(const base::File& file, bool is_hit) {
71 EXPECT_FALSE(is_hit); 71 EXPECT_FALSE(is_hit);
72 ASSERT_TRUE(file.IsValid()); 72 ASSERT_TRUE(file.IsValid());
73 base::File::Info info; 73 base::File::Info info;
74 base::File* mutable_file = const_cast<base::File*>(&file); 74 base::File* mutable_file = const_cast<base::File*>(&file);
75 EXPECT_TRUE(mutable_file->GetInfo(&info)); 75 EXPECT_TRUE(mutable_file->GetInfo(&info));
76 EXPECT_FALSE(info.is_directory); 76 EXPECT_FALSE(info.is_directory);
77 EXPECT_EQ(0LL, info.size); 77 EXPECT_EQ(0LL, info.size);
78 char str[16]; 78 char str[kBufferSize];
79 memset(str, 0x0, 16); 79 memset(str, 0x0, kBufferSize);
80 snprintf(str, 16, "testdata%d", ++write_callback_count_); 80 snprintf(str, kBufferSize, "testdata%d", ++write_callback_count_);
81 EXPECT_EQ(16, mutable_file->Write(0, str, 16)); 81 EXPECT_EQ(kBufferSize,
82 static_cast<size_t>(mutable_file->Write(0, str, kBufferSize)));
82 temp_callback_count_++; 83 temp_callback_count_++;
83 } 84 }
84 void CallbackExpectHit(const base::File& file, bool is_hit) { 85 void CallbackExpectHit(const base::File& file, bool is_hit) {
85 EXPECT_TRUE(is_hit); 86 EXPECT_TRUE(is_hit);
86 ASSERT_TRUE(file.IsValid()); 87 ASSERT_TRUE(file.IsValid());
87 base::File::Info info; 88 base::File::Info info;
88 base::File* mutable_file = const_cast<base::File*>(&file); 89 base::File* mutable_file = const_cast<base::File*>(&file);
89 EXPECT_TRUE(mutable_file->GetInfo(&info)); 90 EXPECT_TRUE(mutable_file->GetInfo(&info));
90 EXPECT_FALSE(info.is_directory); 91 EXPECT_FALSE(info.is_directory);
91 EXPECT_EQ(16LL, info.size); 92 EXPECT_EQ(kBufferSize, static_cast<size_t>(info.size));
92 char data[16]; 93 char data[kBufferSize];
93 memset(data, 0x0, 16); 94 memset(data, 0x0, kBufferSize);
94 char str[16]; 95 char str[kBufferSize];
95 memset(str, 0x0, 16); 96 memset(str, 0x0, kBufferSize);
96 snprintf(str, 16, "testdata%d", write_callback_count_); 97 snprintf(str, kBufferSize, "testdata%d", write_callback_count_);
97 EXPECT_EQ(16, mutable_file->Read(0, data, 16)); 98 EXPECT_EQ(kBufferSize,
99 static_cast<size_t>(mutable_file->Read(0, data, kBufferSize)));
98 EXPECT_STREQ(str, data); 100 EXPECT_STREQ(str, data);
99 temp_callback_count_++; 101 temp_callback_count_++;
100 } 102 }
101 103
102 protected: 104 protected:
103 PnaclHost* host_; 105 PnaclHost* host_;
104 int temp_callback_count_; 106 int temp_callback_count_;
105 int write_callback_count_; 107 int write_callback_count_;
106 content::TestBrowserThreadBundle thread_bundle_; 108 content::TestBrowserThreadBundle thread_bundle_;
107 base::ScopedTempDir temp_dir_; 109 base::ScopedTempDir temp_dir_;
(...skipping 20 matching lines...) Expand all
128 base::Bind(expect_hit ? &PnaclHostTest::CallbackExpectHit \ 130 base::Bind(expect_hit ? &PnaclHostTest::CallbackExpectHit \
129 : &PnaclHostTest::CallbackExpectMiss, \ 131 : &PnaclHostTest::CallbackExpectMiss, \
130 base::Unretained(this))); \ 132 base::Unretained(this))); \
131 } while (0) 133 } while (0)
132 134
133 TEST_F(PnaclHostTest, BasicMiss) { 135 TEST_F(PnaclHostTest, BasicMiss) {
134 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 136 nacl::PnaclCacheInfo info = GetTestCacheInfo();
135 // Test cold miss. 137 // Test cold miss.
136 GET_NEXE_FD(0, 0, false, info, false); 138 GET_NEXE_FD(0, 0, false, info, false);
137 EXPECT_EQ(1U, host_->pending_translations()); 139 EXPECT_EQ(1U, host_->pending_translations());
138 FlushQueues(); 140 content::RunAllBlockingPoolTasksUntilIdle();
139 EXPECT_EQ(1U, host_->pending_translations()); 141 EXPECT_EQ(1U, host_->pending_translations());
140 EXPECT_EQ(1, temp_callback_count_); 142 EXPECT_EQ(1, temp_callback_count_);
141 host_->TranslationFinished(0, 0, true); 143 host_->TranslationFinished(0, 0, true);
142 FlushQueues(); 144 content::RunAllBlockingPoolTasksUntilIdle();
143 EXPECT_EQ(0U, host_->pending_translations()); 145 EXPECT_EQ(0U, host_->pending_translations());
144 // Test that a different cache info field also misses. 146 // Test that a different cache info field also misses.
145 info.etag = std::string("something else"); 147 info.etag = std::string("something else");
146 GET_NEXE_FD(0, 0, false, info, false); 148 GET_NEXE_FD(0, 0, false, info, false);
147 FlushQueues(); 149 content::RunAllBlockingPoolTasksUntilIdle();
148 EXPECT_EQ(2, temp_callback_count_); 150 EXPECT_EQ(2, temp_callback_count_);
149 EXPECT_EQ(1U, host_->pending_translations()); 151 EXPECT_EQ(1U, host_->pending_translations());
150 host_->RendererClosing(0); 152 host_->RendererClosing(0);
151 FlushQueues(); 153 content::RunAllBlockingPoolTasksUntilIdle();
152 // Check that the cache has de-initialized after the last renderer goes away. 154 // Check that the cache has de-initialized after the last renderer goes away.
153 EXPECT_FALSE(CacheIsInitialized()); 155 EXPECT_FALSE(CacheIsInitialized());
154 } 156 }
155 157
156 TEST_F(PnaclHostTest, BadArguments) { 158 TEST_F(PnaclHostTest, BadArguments) {
157 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 159 nacl::PnaclCacheInfo info = GetTestCacheInfo();
158 GET_NEXE_FD(0, 0, false, info, false); 160 GET_NEXE_FD(0, 0, false, info, false);
159 EXPECT_EQ(1U, host_->pending_translations()); 161 EXPECT_EQ(1U, host_->pending_translations());
160 host_->TranslationFinished(0, 1, true); // nonexistent translation 162 host_->TranslationFinished(0, 1, true); // nonexistent translation
161 EXPECT_EQ(1U, host_->pending_translations()); 163 EXPECT_EQ(1U, host_->pending_translations());
162 host_->RendererClosing(1); // nonexistent renderer 164 host_->RendererClosing(1); // nonexistent renderer
163 EXPECT_EQ(1U, host_->pending_translations()); 165 EXPECT_EQ(1U, host_->pending_translations());
164 FlushQueues(); 166 content::RunAllBlockingPoolTasksUntilIdle();
165 EXPECT_EQ(1, temp_callback_count_); 167 EXPECT_EQ(1, temp_callback_count_);
166 host_->RendererClosing(0); // close without finishing 168 host_->RendererClosing(0); // close without finishing
167 } 169 }
168 170
169 TEST_F(PnaclHostTest, BasicHit) { 171 TEST_F(PnaclHostTest, BasicHit) {
170 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 172 nacl::PnaclCacheInfo info = GetTestCacheInfo();
171 GET_NEXE_FD(0, 0, false, info, false); 173 GET_NEXE_FD(0, 0, false, info, false);
172 FlushQueues(); 174 content::RunAllBlockingPoolTasksUntilIdle();
173 EXPECT_EQ(1, temp_callback_count_); 175 EXPECT_EQ(1, temp_callback_count_);
174 host_->TranslationFinished(0, 0, true); 176 host_->TranslationFinished(0, 0, true);
175 FlushQueues(); 177 content::RunAllBlockingPoolTasksUntilIdle();
176 GET_NEXE_FD(0, 1, false, info, true); 178 GET_NEXE_FD(0, 1, false, info, true);
177 FlushQueues(); 179 content::RunAllBlockingPoolTasksUntilIdle();
178 EXPECT_EQ(2, temp_callback_count_); 180 EXPECT_EQ(2, temp_callback_count_);
179 EXPECT_EQ(0U, host_->pending_translations()); 181 EXPECT_EQ(0U, host_->pending_translations());
180 } 182 }
181 183
182 TEST_F(PnaclHostTest, TranslationErrors) { 184 TEST_F(PnaclHostTest, TranslationErrors) {
183 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 185 nacl::PnaclCacheInfo info = GetTestCacheInfo();
184 GET_NEXE_FD(0, 0, false, info, false); 186 GET_NEXE_FD(0, 0, false, info, false);
185 // Early abort, before temp file request returns 187 // Early abort, before temp file request returns
186 host_->TranslationFinished(0, 0, false); 188 host_->TranslationFinished(0, 0, false);
187 FlushQueues(); 189 content::RunAllBlockingPoolTasksUntilIdle();
188 EXPECT_EQ(0U, host_->pending_translations()); 190 EXPECT_EQ(0U, host_->pending_translations());
189 EXPECT_EQ(0, temp_callback_count_); 191 EXPECT_EQ(0, temp_callback_count_);
190 // The backend will have been freed when the query comes back and there 192 // The backend will have been freed when the query comes back and there
191 // are no pending translations. 193 // are no pending translations.
192 EXPECT_FALSE(CacheIsInitialized()); 194 EXPECT_FALSE(CacheIsInitialized());
193 ReInitBackend(); 195 ReInitBackend();
194 // Check that another request for the same info misses successfully. 196 // Check that another request for the same info misses successfully.
195 GET_NEXE_FD(0, 0, false, info, false); 197 GET_NEXE_FD(0, 0, false, info, false);
196 FlushQueues(); 198 content::RunAllBlockingPoolTasksUntilIdle();
197 host_->TranslationFinished(0, 0, true); 199 host_->TranslationFinished(0, 0, true);
198 FlushQueues(); 200 content::RunAllBlockingPoolTasksUntilIdle();
199 EXPECT_EQ(1, temp_callback_count_); 201 EXPECT_EQ(1, temp_callback_count_);
200 EXPECT_EQ(0U, host_->pending_translations()); 202 EXPECT_EQ(0U, host_->pending_translations());
201 203
202 // Now try sending the error after the temp file request returns 204 // Now try sending the error after the temp file request returns
203 info.abi_version = 222; 205 info.abi_version = 222;
204 GET_NEXE_FD(0, 0, false, info, false); 206 GET_NEXE_FD(0, 0, false, info, false);
205 FlushQueues(); 207 content::RunAllBlockingPoolTasksUntilIdle();
206 EXPECT_EQ(2, temp_callback_count_); 208 EXPECT_EQ(2, temp_callback_count_);
207 host_->TranslationFinished(0, 0, false); 209 host_->TranslationFinished(0, 0, false);
208 FlushQueues(); 210 content::RunAllBlockingPoolTasksUntilIdle();
209 EXPECT_EQ(0U, host_->pending_translations()); 211 EXPECT_EQ(0U, host_->pending_translations());
210 // Check another successful miss 212 // Check another successful miss
211 GET_NEXE_FD(0, 0, false, info, false); 213 GET_NEXE_FD(0, 0, false, info, false);
212 FlushQueues(); 214 content::RunAllBlockingPoolTasksUntilIdle();
213 EXPECT_EQ(3, temp_callback_count_); 215 EXPECT_EQ(3, temp_callback_count_);
214 host_->TranslationFinished(0, 0, false); 216 host_->TranslationFinished(0, 0, false);
215 EXPECT_EQ(0U, host_->pending_translations()); 217 EXPECT_EQ(0U, host_->pending_translations());
216 } 218 }
217 219
218 TEST_F(PnaclHostTest, OverlappedMissesAfterTempReturn) { 220 TEST_F(PnaclHostTest, OverlappedMissesAfterTempReturn) {
219 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 221 nacl::PnaclCacheInfo info = GetTestCacheInfo();
220 GET_NEXE_FD(0, 0, false, info, false); 222 GET_NEXE_FD(0, 0, false, info, false);
221 FlushQueues(); 223 content::RunAllBlockingPoolTasksUntilIdle();
222 EXPECT_EQ(1, temp_callback_count_); 224 EXPECT_EQ(1, temp_callback_count_);
223 EXPECT_EQ(1U, host_->pending_translations()); 225 EXPECT_EQ(1U, host_->pending_translations());
224 // Test that a second request for the same nexe while the first one is still 226 // Test that a second request for the same nexe while the first one is still
225 // outstanding eventually hits. 227 // outstanding eventually hits.
226 GET_NEXE_FD(0, 1, false, info, true); 228 GET_NEXE_FD(0, 1, false, info, true);
227 FlushQueues(); 229 content::RunAllBlockingPoolTasksUntilIdle();
228 EXPECT_EQ(2U, host_->pending_translations()); 230 EXPECT_EQ(2U, host_->pending_translations());
229 // The temp file should not be returned to the second request until after the 231 // The temp file should not be returned to the second request until after the
230 // first is finished translating. 232 // first is finished translating.
231 EXPECT_EQ(1, temp_callback_count_); 233 EXPECT_EQ(1, temp_callback_count_);
232 host_->TranslationFinished(0, 0, true); 234 host_->TranslationFinished(0, 0, true);
233 FlushQueues(); 235 content::RunAllBlockingPoolTasksUntilIdle();
234 EXPECT_EQ(2, temp_callback_count_); 236 EXPECT_EQ(2, temp_callback_count_);
235 EXPECT_EQ(0U, host_->pending_translations()); 237 EXPECT_EQ(0U, host_->pending_translations());
236 } 238 }
237 239
238 TEST_F(PnaclHostTest, OverlappedMissesBeforeTempReturn) { 240 TEST_F(PnaclHostTest, OverlappedMissesBeforeTempReturn) {
239 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 241 nacl::PnaclCacheInfo info = GetTestCacheInfo();
240 GET_NEXE_FD(0, 0, false, info, false); 242 GET_NEXE_FD(0, 0, false, info, false);
241 // Send the 2nd fd request before the first one returns a temp file. 243 // Send the 2nd fd request before the first one returns a temp file.
242 GET_NEXE_FD(0, 1, false, info, true); 244 GET_NEXE_FD(0, 1, false, info, true);
243 FlushQueues(); 245 content::RunAllBlockingPoolTasksUntilIdle();
244 EXPECT_EQ(1, temp_callback_count_); 246 EXPECT_EQ(1, temp_callback_count_);
245 EXPECT_EQ(2U, host_->pending_translations()); 247 EXPECT_EQ(2U, host_->pending_translations());
246 FlushQueues(); 248 content::RunAllBlockingPoolTasksUntilIdle();
247 EXPECT_EQ(2U, host_->pending_translations()); 249 EXPECT_EQ(2U, host_->pending_translations());
248 EXPECT_EQ(1, temp_callback_count_); 250 EXPECT_EQ(1, temp_callback_count_);
249 host_->TranslationFinished(0, 0, true); 251 host_->TranslationFinished(0, 0, true);
250 FlushQueues(); 252 content::RunAllBlockingPoolTasksUntilIdle();
251 EXPECT_EQ(2, temp_callback_count_); 253 EXPECT_EQ(2, temp_callback_count_);
252 EXPECT_EQ(0U, host_->pending_translations()); 254 EXPECT_EQ(0U, host_->pending_translations());
253 } 255 }
254 256
255 TEST_F(PnaclHostTest, OverlappedHitsBeforeTempReturn) { 257 TEST_F(PnaclHostTest, OverlappedHitsBeforeTempReturn) {
256 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 258 nacl::PnaclCacheInfo info = GetTestCacheInfo();
257 // Store one in the cache and complete it. 259 // Store one in the cache and complete it.
258 GET_NEXE_FD(0, 0, false, info, false); 260 GET_NEXE_FD(0, 0, false, info, false);
259 FlushQueues(); 261 content::RunAllBlockingPoolTasksUntilIdle();
260 EXPECT_EQ(1, temp_callback_count_); 262 EXPECT_EQ(1, temp_callback_count_);
261 host_->TranslationFinished(0, 0, true); 263 host_->TranslationFinished(0, 0, true);
262 FlushQueues(); 264 content::RunAllBlockingPoolTasksUntilIdle();
263 EXPECT_EQ(0U, host_->pending_translations()); 265 EXPECT_EQ(0U, host_->pending_translations());
264 GET_NEXE_FD(0, 0, false, info, true); 266 GET_NEXE_FD(0, 0, false, info, true);
265 // Request the second before the first temp file returns. 267 // Request the second before the first temp file returns.
266 GET_NEXE_FD(0, 1, false, info, true); 268 GET_NEXE_FD(0, 1, false, info, true);
267 FlushQueues(); 269 content::RunAllBlockingPoolTasksUntilIdle();
268 EXPECT_EQ(3, temp_callback_count_); 270 EXPECT_EQ(3, temp_callback_count_);
269 EXPECT_EQ(0U, host_->pending_translations()); 271 EXPECT_EQ(0U, host_->pending_translations());
270 } 272 }
271 273
272 TEST_F(PnaclHostTest, OverlappedHitsAfterTempReturn) { 274 TEST_F(PnaclHostTest, OverlappedHitsAfterTempReturn) {
273 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 275 nacl::PnaclCacheInfo info = GetTestCacheInfo();
274 // Store one in the cache and complete it. 276 // Store one in the cache and complete it.
275 GET_NEXE_FD(0, 0, false, info, false); 277 GET_NEXE_FD(0, 0, false, info, false);
276 FlushQueues(); 278 content::RunAllBlockingPoolTasksUntilIdle();
277 EXPECT_EQ(1, temp_callback_count_); 279 EXPECT_EQ(1, temp_callback_count_);
278 host_->TranslationFinished(0, 0, true); 280 host_->TranslationFinished(0, 0, true);
279 FlushQueues(); 281 content::RunAllBlockingPoolTasksUntilIdle();
280 EXPECT_EQ(0U, host_->pending_translations()); 282 EXPECT_EQ(0U, host_->pending_translations());
281 GET_NEXE_FD(0, 0, false, info, true); 283 GET_NEXE_FD(0, 0, false, info, true);
282 FlushQueues(); 284 content::RunAllBlockingPoolTasksUntilIdle();
283 GET_NEXE_FD(0, 1, false, info, true); 285 GET_NEXE_FD(0, 1, false, info, true);
284 FlushQueues(); 286 content::RunAllBlockingPoolTasksUntilIdle();
285 EXPECT_EQ(3, temp_callback_count_); 287 EXPECT_EQ(3, temp_callback_count_);
286 EXPECT_EQ(0U, host_->pending_translations()); 288 EXPECT_EQ(0U, host_->pending_translations());
287 } 289 }
288 290
289 TEST_F(PnaclHostTest, OverlappedMissesRendererClosing) { 291 TEST_F(PnaclHostTest, OverlappedMissesRendererClosing) {
290 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 292 nacl::PnaclCacheInfo info = GetTestCacheInfo();
291 GET_NEXE_FD(0, 0, false, info, false); 293 GET_NEXE_FD(0, 0, false, info, false);
292 // Send the 2nd fd request from a different renderer. 294 // Send the 2nd fd request from a different renderer.
293 // Test that it eventually gets an fd after the first renderer closes. 295 // Test that it eventually gets an fd after the first renderer closes.
294 GET_NEXE_FD(1, 1, false, info, false); 296 GET_NEXE_FD(1, 1, false, info, false);
295 FlushQueues(); 297 content::RunAllBlockingPoolTasksUntilIdle();
296 EXPECT_EQ(1, temp_callback_count_); 298 EXPECT_EQ(1, temp_callback_count_);
297 EXPECT_EQ(2U, host_->pending_translations()); 299 EXPECT_EQ(2U, host_->pending_translations());
298 FlushQueues(); 300 content::RunAllBlockingPoolTasksUntilIdle();
299 EXPECT_EQ(2U, host_->pending_translations()); 301 EXPECT_EQ(2U, host_->pending_translations());
300 EXPECT_EQ(1, temp_callback_count_); 302 EXPECT_EQ(1, temp_callback_count_);
301 host_->RendererClosing(0); 303 host_->RendererClosing(0);
302 FlushQueues(); 304 content::RunAllBlockingPoolTasksUntilIdle();
303 EXPECT_EQ(2, temp_callback_count_); 305 EXPECT_EQ(2, temp_callback_count_);
304 EXPECT_EQ(1U, host_->pending_translations()); 306 EXPECT_EQ(1U, host_->pending_translations());
305 host_->RendererClosing(1); 307 host_->RendererClosing(1);
306 } 308 }
307 309
308 TEST_F(PnaclHostTest, Incognito) { 310 TEST_F(PnaclHostTest, Incognito) {
309 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 311 nacl::PnaclCacheInfo info = GetTestCacheInfo();
310 GET_NEXE_FD(0, 0, true, info, false); 312 GET_NEXE_FD(0, 0, true, info, false);
311 FlushQueues(); 313 content::RunAllBlockingPoolTasksUntilIdle();
312 EXPECT_EQ(1, temp_callback_count_); 314 EXPECT_EQ(1, temp_callback_count_);
313 host_->TranslationFinished(0, 0, true); 315 host_->TranslationFinished(0, 0, true);
314 FlushQueues(); 316 content::RunAllBlockingPoolTasksUntilIdle();
315 // Check that an incognito translation is not stored in the cache 317 // Check that an incognito translation is not stored in the cache
316 GET_NEXE_FD(0, 0, false, info, false); 318 GET_NEXE_FD(0, 0, false, info, false);
317 FlushQueues(); 319 content::RunAllBlockingPoolTasksUntilIdle();
318 EXPECT_EQ(2, temp_callback_count_); 320 EXPECT_EQ(2, temp_callback_count_);
319 host_->TranslationFinished(0, 0, true); 321 host_->TranslationFinished(0, 0, true);
320 FlushQueues(); 322 content::RunAllBlockingPoolTasksUntilIdle();
321 // Check that an incognito translation can hit from a normal one. 323 // Check that an incognito translation can hit from a normal one.
322 GET_NEXE_FD(0, 0, true, info, true); 324 GET_NEXE_FD(0, 0, true, info, true);
323 FlushQueues(); 325 content::RunAllBlockingPoolTasksUntilIdle();
324 EXPECT_EQ(3, temp_callback_count_); 326 EXPECT_EQ(3, temp_callback_count_);
325 } 327 }
326 328
327 TEST_F(PnaclHostTest, IncognitoOverlappedMiss) { 329 TEST_F(PnaclHostTest, IncognitoOverlappedMiss) {
328 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 330 nacl::PnaclCacheInfo info = GetTestCacheInfo();
329 GET_NEXE_FD(0, 0, true, info, false); 331 GET_NEXE_FD(0, 0, true, info, false);
330 GET_NEXE_FD(0, 1, false, info, false); 332 GET_NEXE_FD(0, 1, false, info, false);
331 FlushQueues(); 333 content::RunAllBlockingPoolTasksUntilIdle();
332 // Check that both translations have returned misses, (i.e. that the 334 // Check that both translations have returned misses, (i.e. that the
333 // second one has not blocked on the incognito one) 335 // second one has not blocked on the incognito one)
334 EXPECT_EQ(2, temp_callback_count_); 336 EXPECT_EQ(2, temp_callback_count_);
335 host_->TranslationFinished(0, 0, true); 337 host_->TranslationFinished(0, 0, true);
336 host_->TranslationFinished(0, 1, true); 338 host_->TranslationFinished(0, 1, true);
337 FlushQueues(); 339 content::RunAllBlockingPoolTasksUntilIdle();
338 EXPECT_EQ(0U, host_->pending_translations()); 340 EXPECT_EQ(0U, host_->pending_translations());
339 341
340 // Same test, but issue the 2nd request after the first has returned a miss. 342 // Same test, but issue the 2nd request after the first has returned a miss.
341 info.abi_version = 222; 343 info.abi_version = 222;
342 GET_NEXE_FD(0, 0, true, info, false); 344 GET_NEXE_FD(0, 0, true, info, false);
343 FlushQueues(); 345 content::RunAllBlockingPoolTasksUntilIdle();
344 EXPECT_EQ(3, temp_callback_count_); 346 EXPECT_EQ(3, temp_callback_count_);
345 GET_NEXE_FD(0, 1, false, info, false); 347 GET_NEXE_FD(0, 1, false, info, false);
346 FlushQueues(); 348 content::RunAllBlockingPoolTasksUntilIdle();
347 EXPECT_EQ(4, temp_callback_count_); 349 EXPECT_EQ(4, temp_callback_count_);
348 host_->RendererClosing(0); 350 host_->RendererClosing(0);
349 } 351 }
350 352
351 TEST_F(PnaclHostTest, IncognitoSecondOverlappedMiss) { 353 TEST_F(PnaclHostTest, IncognitoSecondOverlappedMiss) {
352 // If the non-incognito request comes first, it should 354 // If the non-incognito request comes first, it should
353 // behave exactly like OverlappedMissBeforeTempReturn 355 // behave exactly like OverlappedMissBeforeTempReturn
354 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 356 nacl::PnaclCacheInfo info = GetTestCacheInfo();
355 GET_NEXE_FD(0, 0, false, info, false); 357 GET_NEXE_FD(0, 0, false, info, false);
356 // Send the 2nd fd request before the first one returns a temp file. 358 // Send the 2nd fd request before the first one returns a temp file.
357 GET_NEXE_FD(0, 1, true, info, true); 359 GET_NEXE_FD(0, 1, true, info, true);
358 FlushQueues(); 360 content::RunAllBlockingPoolTasksUntilIdle();
359 EXPECT_EQ(1, temp_callback_count_); 361 EXPECT_EQ(1, temp_callback_count_);
360 EXPECT_EQ(2U, host_->pending_translations()); 362 EXPECT_EQ(2U, host_->pending_translations());
361 FlushQueues(); 363 content::RunAllBlockingPoolTasksUntilIdle();
362 EXPECT_EQ(2U, host_->pending_translations()); 364 EXPECT_EQ(2U, host_->pending_translations());
363 EXPECT_EQ(1, temp_callback_count_); 365 EXPECT_EQ(1, temp_callback_count_);
364 host_->TranslationFinished(0, 0, true); 366 host_->TranslationFinished(0, 0, true);
365 FlushQueues(); 367 content::RunAllBlockingPoolTasksUntilIdle();
366 EXPECT_EQ(2, temp_callback_count_); 368 EXPECT_EQ(2, temp_callback_count_);
367 EXPECT_EQ(0U, host_->pending_translations()); 369 EXPECT_EQ(0U, host_->pending_translations());
368 } 370 }
369 371
370 // Test that pexes with the no-store header do not get cached. 372 // Test that pexes with the no-store header do not get cached.
371 TEST_F(PnaclHostTest, CacheControlNoStore) { 373 TEST_F(PnaclHostTest, CacheControlNoStore) {
372 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 374 nacl::PnaclCacheInfo info = GetTestCacheInfo();
373 info.has_no_store_header = true; 375 info.has_no_store_header = true;
374 GET_NEXE_FD(0, 0, false, info, false); 376 GET_NEXE_FD(0, 0, false, info, false);
375 FlushQueues(); 377 content::RunAllBlockingPoolTasksUntilIdle();
376 EXPECT_EQ(1, temp_callback_count_); 378 EXPECT_EQ(1, temp_callback_count_);
377 host_->TranslationFinished(0, 0, true); 379 host_->TranslationFinished(0, 0, true);
378 FlushQueues(); 380 content::RunAllBlockingPoolTasksUntilIdle();
379 EXPECT_EQ(0U, host_->pending_translations()); 381 EXPECT_EQ(0U, host_->pending_translations());
380 EXPECT_EQ(0, GetCacheSize()); 382 EXPECT_EQ(0, GetCacheSize());
381 } 383 }
382 384
383 // Test that no-store pexes do not wait, but do duplicate translations 385 // Test that no-store pexes do not wait, but do duplicate translations
384 TEST_F(PnaclHostTest, NoStoreOverlappedMiss) { 386 TEST_F(PnaclHostTest, NoStoreOverlappedMiss) {
385 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 387 nacl::PnaclCacheInfo info = GetTestCacheInfo();
386 info.has_no_store_header = true; 388 info.has_no_store_header = true;
387 GET_NEXE_FD(0, 0, false, info, false); 389 GET_NEXE_FD(0, 0, false, info, false);
388 GET_NEXE_FD(0, 1, false, info, false); 390 GET_NEXE_FD(0, 1, false, info, false);
389 FlushQueues(); 391 content::RunAllBlockingPoolTasksUntilIdle();
390 // Check that both translations have returned misses, (i.e. that the 392 // Check that both translations have returned misses, (i.e. that the
391 // second one has not blocked on the first one) 393 // second one has not blocked on the first one)
392 EXPECT_EQ(2, temp_callback_count_); 394 EXPECT_EQ(2, temp_callback_count_);
393 host_->TranslationFinished(0, 0, true); 395 host_->TranslationFinished(0, 0, true);
394 host_->TranslationFinished(0, 1, true); 396 host_->TranslationFinished(0, 1, true);
395 FlushQueues(); 397 content::RunAllBlockingPoolTasksUntilIdle();
396 EXPECT_EQ(0U, host_->pending_translations()); 398 EXPECT_EQ(0U, host_->pending_translations());
397 399
398 // Same test, but issue the 2nd request after the first has returned a miss. 400 // Same test, but issue the 2nd request after the first has returned a miss.
399 info.abi_version = 222; 401 info.abi_version = 222;
400 GET_NEXE_FD(0, 0, false, info, false); 402 GET_NEXE_FD(0, 0, false, info, false);
401 FlushQueues(); 403 content::RunAllBlockingPoolTasksUntilIdle();
402 EXPECT_EQ(3, temp_callback_count_); 404 EXPECT_EQ(3, temp_callback_count_);
403 GET_NEXE_FD(0, 1, false, info, false); 405 GET_NEXE_FD(0, 1, false, info, false);
404 FlushQueues(); 406 content::RunAllBlockingPoolTasksUntilIdle();
405 EXPECT_EQ(4, temp_callback_count_); 407 EXPECT_EQ(4, temp_callback_count_);
406 host_->RendererClosing(0); 408 host_->RendererClosing(0);
407 } 409 }
408 410
409 TEST_F(PnaclHostTest, ClearTranslationCache) { 411 TEST_F(PnaclHostTest, ClearTranslationCache) {
410 nacl::PnaclCacheInfo info = GetTestCacheInfo(); 412 nacl::PnaclCacheInfo info = GetTestCacheInfo();
411 // Add 2 entries in the cache 413 // Add 2 entries in the cache
412 GET_NEXE_FD(0, 0, false, info, false); 414 GET_NEXE_FD(0, 0, false, info, false);
413 info.abi_version = 222; 415 info.abi_version = 222;
414 GET_NEXE_FD(0, 1, false, info, false); 416 GET_NEXE_FD(0, 1, false, info, false);
415 FlushQueues(); 417 content::RunAllBlockingPoolTasksUntilIdle();
416 EXPECT_EQ(2, temp_callback_count_); 418 EXPECT_EQ(2, temp_callback_count_);
417 host_->TranslationFinished(0, 0, true); 419 host_->TranslationFinished(0, 0, true);
418 host_->TranslationFinished(0, 1, true); 420 host_->TranslationFinished(0, 1, true);
419 FlushQueues(); 421 content::RunAllBlockingPoolTasksUntilIdle();
420 EXPECT_EQ(0U, host_->pending_translations()); 422 EXPECT_EQ(0U, host_->pending_translations());
421 EXPECT_EQ(2, GetCacheSize()); 423 EXPECT_EQ(2, GetCacheSize());
422 net::TestCompletionCallback cb; 424 net::TestCompletionCallback cb;
423 // Since we are using a memory backend, the clear should happen immediately. 425 // Since we are using a memory backend, the clear should happen immediately.
424 host_->ClearTranslationCacheEntriesBetween( 426 host_->ClearTranslationCacheEntriesBetween(
425 base::Time(), base::Time(), base::Bind(cb.callback(), 0)); 427 base::Time(), base::Time(), base::Bind(cb.callback(), 0));
426 // Check that the translation cache has been cleared before flushing the 428 // Check that the translation cache has been cleared before flushing the
427 // queues, because the backend will be freed once it is. 429 // queues, because the backend will be freed once it is.
428 EXPECT_EQ(0, GetCacheSize()); 430 EXPECT_EQ(0, GetCacheSize());
429 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING)); 431 EXPECT_EQ(0, cb.GetResult(net::ERR_IO_PENDING));
(...skipping 18 matching lines...) Expand all
448 // Since there's no easy way to pump message queues one message at a time, we 450 // Since there's no easy way to pump message queues one message at a time, we
449 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then 451 // have to simulate what would happen if 1 DeInitIfsafe task gets queued, then
450 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before 452 // a GetNexeFd gets queued, and then another DeInitIfSafe gets queued before
451 // the first one runs. We can just shortcut and call DeInitIfSafe while the 453 // the first one runs. We can just shortcut and call DeInitIfSafe while the
452 // cache is still initializing. 454 // cache is still initializing.
453 DeInit(); 455 DeInit();
454 base::RunLoop().RunUntilIdle(); 456 base::RunLoop().RunUntilIdle();
455 } 457 }
456 458
457 } // namespace pnacl 459 } // namespace pnacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698