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

Side by Side Diff: chrome/browser/nacl_host/pnacl_translation_cache_unittest.cc

Issue 16295020: Fix leak in pnacl translation cache and remove check suppressions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 6 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
« no previous file with comments | « chrome/browser/nacl_host/pnacl_translation_cache.cc ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/pnacl_translation_cache.cc ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698