OLD | NEW |
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_translation_cache.h" | 5 #include "components/nacl/browser/pnacl_translation_cache.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "components/nacl/common/pnacl_types.h" | 11 #include "components/nacl/common/pnacl_types.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
15 #include "net/base/test_completion_callback.h" | 15 #include "net/base/test_completion_callback.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
| 18 // For fine-grained suppression on flaky tests. |
| 19 #if defined(OS_WIN) |
| 20 #include "base/win/windows_version.h" |
| 21 #endif |
| 22 |
18 using content::BrowserThread; | 23 using content::BrowserThread; |
19 using base::FilePath; | 24 using base::FilePath; |
20 | 25 |
21 namespace pnacl { | 26 namespace pnacl { |
22 | 27 |
23 const int kTestDiskCacheSize = 16 * 1024 * 1024; | 28 const int kTestDiskCacheSize = 16 * 1024 * 1024; |
24 | 29 |
25 class PnaclTranslationCacheTest : public testing::Test { | 30 class PnaclTranslationCacheTest : public testing::Test { |
26 protected: | 31 protected: |
27 PnaclTranslationCacheTest() | 32 PnaclTranslationCacheTest() |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 } | 211 } |
207 | 212 |
208 TEST_F(PnaclTranslationCacheTest, StoreSmallOnDisk) { | 213 TEST_F(PnaclTranslationCacheTest, StoreSmallOnDisk) { |
209 // Test that a single store puts something in the disk backend | 214 // Test that a single store puts something in the disk backend |
210 InitBackend(false); | 215 InitBackend(false); |
211 StoreNexe(test_key, test_store_val); | 216 StoreNexe(test_key, test_store_val); |
212 EXPECT_EQ(1, cache_->Size()); | 217 EXPECT_EQ(1, cache_->Size()); |
213 } | 218 } |
214 | 219 |
215 TEST_F(PnaclTranslationCacheTest, StoreLargeOnDisk) { | 220 TEST_F(PnaclTranslationCacheTest, StoreLargeOnDisk) { |
| 221 #if defined(OS_WIN) |
| 222 // Flaky on XP bot http://crbug.com/468741 |
| 223 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 224 return; |
| 225 #endif |
216 // Test a value too large(?) for a single I/O operation | 226 // Test a value too large(?) for a single I/O operation |
217 InitBackend(false); | 227 InitBackend(false); |
218 const std::string large_buffer(kLargeNexeSize, 'a'); | 228 const std::string large_buffer(kLargeNexeSize, 'a'); |
219 StoreNexe(test_key, large_buffer); | 229 StoreNexe(test_key, large_buffer); |
220 EXPECT_EQ(1, cache_->Size()); | 230 EXPECT_EQ(1, cache_->Size()); |
221 } | 231 } |
222 | 232 |
223 TEST_F(PnaclTranslationCacheTest, InMemSizeLimit) { | 233 TEST_F(PnaclTranslationCacheTest, InMemSizeLimit) { |
224 InitBackend(true); | 234 InitBackend(true); |
225 scoped_refptr<net::DrainableIOBuffer> large_buffer(new net::DrainableIOBuffer( | 235 scoped_refptr<net::DrainableIOBuffer> large_buffer(new net::DrainableIOBuffer( |
(...skipping 14 matching lines...) Expand all Loading... |
240 } | 250 } |
241 | 251 |
242 TEST_F(PnaclTranslationCacheTest, GetOneOnDisk) { | 252 TEST_F(PnaclTranslationCacheTest, GetOneOnDisk) { |
243 InitBackend(false); | 253 InitBackend(false); |
244 StoreNexe(test_key, test_store_val); | 254 StoreNexe(test_key, test_store_val); |
245 EXPECT_EQ(1, cache_->Size()); | 255 EXPECT_EQ(1, cache_->Size()); |
246 EXPECT_EQ(0, GetNexe(test_key).compare(test_store_val)); | 256 EXPECT_EQ(0, GetNexe(test_key).compare(test_store_val)); |
247 } | 257 } |
248 | 258 |
249 TEST_F(PnaclTranslationCacheTest, GetLargeOnDisk) { | 259 TEST_F(PnaclTranslationCacheTest, GetLargeOnDisk) { |
| 260 #if defined(OS_WIN) |
| 261 // Flaky on XP bot http://crbug.com/468741 |
| 262 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 263 return; |
| 264 #endif |
250 InitBackend(false); | 265 InitBackend(false); |
251 const std::string large_buffer(kLargeNexeSize, 'a'); | 266 const std::string large_buffer(kLargeNexeSize, 'a'); |
252 StoreNexe(test_key, large_buffer); | 267 StoreNexe(test_key, large_buffer); |
253 EXPECT_EQ(1, cache_->Size()); | 268 EXPECT_EQ(1, cache_->Size()); |
254 EXPECT_EQ(0, GetNexe(test_key).compare(large_buffer)); | 269 EXPECT_EQ(0, GetNexe(test_key).compare(large_buffer)); |
255 } | 270 } |
256 | 271 |
257 TEST_F(PnaclTranslationCacheTest, StoreTwice) { | 272 TEST_F(PnaclTranslationCacheTest, StoreTwice) { |
258 // Test that storing twice with the same key overwrites | 273 // Test that storing twice with the same key overwrites |
259 InitBackend(true); | 274 InitBackend(true); |
(...skipping 17 matching lines...) Expand all Loading... |
277 StoreNexe(test_key, test_store_val); | 292 StoreNexe(test_key, test_store_val); |
278 TestNexeCallback load_cb; | 293 TestNexeCallback load_cb; |
279 std::string nexe; | 294 std::string nexe; |
280 cache_->GetNexe(test_key + "a", load_cb.callback()); | 295 cache_->GetNexe(test_key + "a", load_cb.callback()); |
281 int rv; | 296 int rv; |
282 scoped_refptr<net::DrainableIOBuffer> buf(load_cb.GetResult(&rv)); | 297 scoped_refptr<net::DrainableIOBuffer> buf(load_cb.GetResult(&rv)); |
283 EXPECT_EQ(net::ERR_FAILED, rv); | 298 EXPECT_EQ(net::ERR_FAILED, rv); |
284 } | 299 } |
285 | 300 |
286 } // namespace pnacl | 301 } // namespace pnacl |
OLD | NEW |