| 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 "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
| 12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 using content::BrowserThread; | 16 using content::BrowserThread; |
| 16 | 17 |
| 17 namespace pnacl_cache { | 18 namespace pnacl_cache { |
| 18 | 19 |
| 19 class PNaClTranslationCacheTest : public testing::Test { | 20 class PNaClTranslationCacheTest : public testing::Test { |
| 20 protected: | 21 protected: |
| 21 PNaClTranslationCacheTest() | 22 PNaClTranslationCacheTest() |
| 22 : cache_thread_(BrowserThread::CACHE, &message_loop_), | 23 : cache_thread_(BrowserThread::CACHE, &message_loop_), |
| 23 io_thread_(BrowserThread::IO, &message_loop_) {} | 24 io_thread_(BrowserThread::IO, &message_loop_) {} |
| 24 virtual ~PNaClTranslationCacheTest() {} | 25 virtual ~PNaClTranslationCacheTest() {} |
| 25 virtual void SetUp() { cache_ = new PNaClTranslationCache(); } | 26 virtual void SetUp() { cache_ = new PNaClTranslationCache(); } |
| 26 virtual void TearDown() { delete cache_; } | 27 virtual void TearDown() { |
| 28 // 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 |
| 30 // 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 |
| 32 // here to ensure the task gets processed. |
| 33 base::RunLoop().RunUntilIdle(); |
| 34 delete cache_; |
| 35 } |
| 27 | 36 |
| 28 protected: | 37 protected: |
| 29 PNaClTranslationCache* cache_; | 38 PNaClTranslationCache* cache_; |
| 30 base::MessageLoopForIO message_loop_; | 39 base::MessageLoopForIO message_loop_; |
| 31 content::TestBrowserThread cache_thread_; | 40 content::TestBrowserThread cache_thread_; |
| 32 content::TestBrowserThread io_thread_; | 41 content::TestBrowserThread io_thread_; |
| 33 }; | 42 }; |
| 34 | 43 |
| 35 TEST_F(PNaClTranslationCacheTest, StoreOneInMem) { | 44 TEST_F(PNaClTranslationCacheTest, StoreOneInMem) { |
| 36 net::TestCompletionCallback init_cb; | 45 net::TestCompletionCallback init_cb; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 64 TEST_F(PNaClTranslationCacheTest, InMemSizeLimit) { | 73 TEST_F(PNaClTranslationCacheTest, InMemSizeLimit) { |
| 65 net::TestCompletionCallback init_cb; | 74 net::TestCompletionCallback init_cb; |
| 66 int rv = cache_->InitCache(base::FilePath(), true, init_cb.callback()); | 75 int rv = cache_->InitCache(base::FilePath(), true, init_cb.callback()); |
| 67 EXPECT_EQ(rv, net::OK); | 76 EXPECT_EQ(rv, net::OK); |
| 68 ASSERT_EQ(init_cb.GetResult(rv), net::OK); | 77 ASSERT_EQ(init_cb.GetResult(rv), net::OK); |
| 69 EXPECT_EQ(cache_->Size(), 0); | 78 EXPECT_EQ(cache_->Size(), 0); |
| 70 std::string large_buffer(kMaxMemCacheSize + 1, 'a'); | 79 std::string large_buffer(kMaxMemCacheSize + 1, 'a'); |
| 71 net::TestCompletionCallback store_cb; | 80 net::TestCompletionCallback store_cb; |
| 72 cache_->StoreNexe("1", large_buffer, store_cb.callback()); | 81 cache_->StoreNexe("1", large_buffer, store_cb.callback()); |
| 73 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); | 82 EXPECT_EQ(net::ERR_FAILED, store_cb.GetResult(net::ERR_IO_PENDING)); |
| 83 base::RunLoop().RunUntilIdle(); // Ensure the entry is closed. |
| 84 EXPECT_EQ(0, cache_->Size()); |
| 74 } | 85 } |
| 75 | 86 |
| 76 } // namespace nacl_cache | 87 } // namespace nacl_cache |
| OLD | NEW |