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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 ASSERT_EQ(net::OK, rv); | 61 ASSERT_EQ(net::OK, rv); |
62 ASSERT_EQ(net::OK, init_cb.GetResult(rv)); | 62 ASSERT_EQ(net::OK, init_cb.GetResult(rv)); |
63 ASSERT_EQ(0, cache_->Size()); | 63 ASSERT_EQ(0, cache_->Size()); |
64 } | 64 } |
65 | 65 |
66 void PnaclTranslationCacheTest::StoreNexe(const std::string& key, | 66 void PnaclTranslationCacheTest::StoreNexe(const std::string& key, |
67 const std::string& nexe) { | 67 const std::string& nexe) { |
68 net::TestCompletionCallback store_cb; | 68 net::TestCompletionCallback store_cb; |
69 scoped_refptr<net::DrainableIOBuffer> nexe_buf( | 69 scoped_refptr<net::DrainableIOBuffer> nexe_buf( |
70 new net::DrainableIOBuffer(new net::StringIOBuffer(nexe), nexe.size())); | 70 new net::DrainableIOBuffer(new net::StringIOBuffer(nexe), nexe.size())); |
71 cache_->StoreNexe(key, nexe_buf, store_cb.callback()); | 71 cache_->StoreNexe(key, nexe_buf.get(), store_cb.callback()); |
72 // Using ERR_IO_PENDING here causes the callback to wait for the result | 72 // Using ERR_IO_PENDING here causes the callback to wait for the result |
73 // which should be harmless even if it returns OK immediately. This is because | 73 // which should be harmless even if it returns OK immediately. This is because |
74 // we don't plumb the intermediate writing stages all the way out. | 74 // we don't plumb the intermediate writing stages all the way out. |
75 EXPECT_EQ(net::OK, store_cb.GetResult(net::ERR_IO_PENDING)); | 75 EXPECT_EQ(net::OK, store_cb.GetResult(net::ERR_IO_PENDING)); |
76 } | 76 } |
77 | 77 |
78 // Inspired by net::TestCompletionCallback. Instantiate a TestNexeCallback and | 78 // Inspired by net::TestCompletionCallback. Instantiate a TestNexeCallback and |
79 // pass the GetNexeCallback returned by the callback() method to GetNexe. | 79 // pass the GetNexeCallback returned by the callback() method to GetNexe. |
80 // Then call GetResult, which will pump the message loop until it gets a result, | 80 // Then call GetResult, which will pump the message loop until it gets a result, |
81 // return the resulting IOBuffer and fill in the return value | 81 // return the resulting IOBuffer and fill in the return value |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 StoreNexe(test_key, large_buffer); | 219 StoreNexe(test_key, large_buffer); |
220 EXPECT_EQ(1, cache_->Size()); | 220 EXPECT_EQ(1, cache_->Size()); |
221 } | 221 } |
222 | 222 |
223 TEST_F(PnaclTranslationCacheTest, InMemSizeLimit) { | 223 TEST_F(PnaclTranslationCacheTest, InMemSizeLimit) { |
224 InitBackend(true); | 224 InitBackend(true); |
225 scoped_refptr<net::DrainableIOBuffer> large_buffer(new net::DrainableIOBuffer( | 225 scoped_refptr<net::DrainableIOBuffer> large_buffer(new net::DrainableIOBuffer( |
226 new net::StringIOBuffer(std::string(kMaxMemCacheSize + 1, 'a')), | 226 new net::StringIOBuffer(std::string(kMaxMemCacheSize + 1, 'a')), |
227 kMaxMemCacheSize + 1)); | 227 kMaxMemCacheSize + 1)); |
228 net::TestCompletionCallback store_cb; | 228 net::TestCompletionCallback store_cb; |
229 cache_->StoreNexe(test_key, large_buffer, store_cb.callback()); | 229 cache_->StoreNexe(test_key, large_buffer.get(), store_cb.callback()); |
230 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); | 230 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); |
231 base::RunLoop().RunUntilIdle(); // Ensure the entry is closed. | 231 base::RunLoop().RunUntilIdle(); // Ensure the entry is closed. |
232 EXPECT_EQ(0, cache_->Size()); | 232 EXPECT_EQ(0, cache_->Size()); |
233 } | 233 } |
234 | 234 |
235 TEST_F(PnaclTranslationCacheTest, GetOneInMem) { | 235 TEST_F(PnaclTranslationCacheTest, GetOneInMem) { |
236 InitBackend(true); | 236 InitBackend(true); |
237 StoreNexe(test_key, test_store_val); | 237 StoreNexe(test_key, test_store_val); |
238 EXPECT_EQ(1, cache_->Size()); | 238 EXPECT_EQ(1, cache_->Size()); |
239 EXPECT_EQ(0, GetNexe(test_key).compare(test_store_val)); | 239 EXPECT_EQ(0, GetNexe(test_key).compare(test_store_val)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 StoreNexe(test_key, test_store_val); | 277 StoreNexe(test_key, test_store_val); |
278 TestNexeCallback load_cb; | 278 TestNexeCallback load_cb; |
279 std::string nexe; | 279 std::string nexe; |
280 cache_->GetNexe(test_key + "a", load_cb.callback()); | 280 cache_->GetNexe(test_key + "a", load_cb.callback()); |
281 int rv; | 281 int rv; |
282 scoped_refptr<net::DrainableIOBuffer> buf(load_cb.GetResult(&rv)); | 282 scoped_refptr<net::DrainableIOBuffer> buf(load_cb.GetResult(&rv)); |
283 EXPECT_EQ(net::ERR_FAILED, rv); | 283 EXPECT_EQ(net::ERR_FAILED, rv); |
284 } | 284 } |
285 | 285 |
286 } // namespace pnacl | 286 } // namespace pnacl |
OLD | NEW |