| 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 "chrome/browser/nacl_host/pnacl_translation_cache.h" | 5 #include "chrome/browser/nacl_host/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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 | 17 |
| 18 namespace pnacl_cache { | 18 namespace pnacl_cache { |
| 19 | 19 |
| 20 class PNaClTranslationCacheTest : public testing::Test { | 20 class PNaClTranslationCacheTest : public testing::Test { |
| 21 protected: | 21 protected: |
| 22 PNaClTranslationCacheTest() | 22 PNaClTranslationCacheTest() |
| 23 : cache_thread_(BrowserThread::CACHE, &message_loop_), | 23 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {} |
| 24 io_thread_(BrowserThread::IO, &message_loop_) {} | |
| 25 virtual ~PNaClTranslationCacheTest() {} | 24 virtual ~PNaClTranslationCacheTest() {} |
| 26 virtual void SetUp() { cache_ = new PNaClTranslationCache(); } | 25 virtual void SetUp() { cache_ = new PNaClTranslationCache(); } |
| 27 virtual void TearDown() { | 26 virtual void TearDown() { |
| 28 // The destructor of PNaClTranslationCacheWriteEntry posts a task to the IO | 27 // The destructor of PNaClTranslationCacheWriteEntry posts a task to the IO |
| 29 // thread to close the backend cache entry. We want to make sure the entries | 28 // thread to close the backend cache entry. We want to make sure the entries |
| 30 // are closed before we delete the backend (and in particular the destructor | 29 // are closed before we delete the backend (and in particular the destructor |
| 31 // for the memory backend has a DCHECK to verify this), so we run the loop | 30 // for the memory backend has a DCHECK to verify this), so we run the loop |
| 32 // here to ensure the task gets processed. | 31 // here to ensure the task gets processed. |
| 33 base::RunLoop().RunUntilIdle(); | 32 base::RunLoop().RunUntilIdle(); |
| 34 delete cache_; | 33 delete cache_; |
| 35 } | 34 } |
| 36 | 35 |
| 37 protected: | 36 protected: |
| 38 PNaClTranslationCache* cache_; | 37 PNaClTranslationCache* cache_; |
| 39 base::MessageLoopForIO message_loop_; | 38 content::TestBrowserThreadBundle thread_bundle_; |
| 40 content::TestBrowserThread cache_thread_; | |
| 41 content::TestBrowserThread io_thread_; | |
| 42 }; | 39 }; |
| 43 | 40 |
| 44 TEST_F(PNaClTranslationCacheTest, StoreOneInMem) { | 41 TEST_F(PNaClTranslationCacheTest, StoreOneInMem) { |
| 45 net::TestCompletionCallback init_cb; | 42 net::TestCompletionCallback init_cb; |
| 46 int rv = cache_->InitCache(base::FilePath(), true, init_cb.callback()); | 43 int rv = cache_->InitCache(base::FilePath(), true, init_cb.callback()); |
| 47 EXPECT_EQ(net::OK, rv); | 44 EXPECT_EQ(net::OK, rv); |
| 48 ASSERT_EQ(net::OK, init_cb.GetResult(rv)); | 45 ASSERT_EQ(net::OK, init_cb.GetResult(rv)); |
| 49 net::TestCompletionCallback store_cb; | 46 net::TestCompletionCallback store_cb; |
| 50 EXPECT_EQ(0, cache_->Size()); | 47 EXPECT_EQ(0, cache_->Size()); |
| 51 cache_->StoreNexe("1", "a", store_cb.callback()); | 48 cache_->StoreNexe("1", "a", store_cb.callback()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 78 EXPECT_EQ(cache_->Size(), 0); | 75 EXPECT_EQ(cache_->Size(), 0); |
| 79 std::string large_buffer(kMaxMemCacheSize + 1, 'a'); | 76 std::string large_buffer(kMaxMemCacheSize + 1, 'a'); |
| 80 net::TestCompletionCallback store_cb; | 77 net::TestCompletionCallback store_cb; |
| 81 cache_->StoreNexe("1", large_buffer, store_cb.callback()); | 78 cache_->StoreNexe("1", large_buffer, store_cb.callback()); |
| 82 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); | 79 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); |
| 83 base::RunLoop().RunUntilIdle(); // Ensure the entry is closed. | 80 base::RunLoop().RunUntilIdle(); // Ensure the entry is closed. |
| 84 EXPECT_EQ(0, cache_->Size()); | 81 EXPECT_EQ(0, cache_->Size()); |
| 85 } | 82 } |
| 86 | 83 |
| 87 } // namespace nacl_cache | 84 } // namespace nacl_cache |
| OLD | NEW |