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

Side by Side Diff: content/browser/storage_partition_impl_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT 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
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 "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 #include "base/message_loop/message_loop_proxy.h" 6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/gpu/shader_disk_cache.h" 10 #include "content/browser/gpu/shader_disk_cache.h"
11 #include "content/browser/storage_partition_impl.h" 11 #include "content/browser/storage_partition_impl.h"
12 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
13 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "net/base/test_completion_callback.h" 14 #include "net/base/test_completion_callback.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace content { 17 namespace content {
18 namespace { 18 namespace {
19 19
20 class TestClosureCallback { 20 class TestClosureCallback {
21 public: 21 public:
22 TestClosureCallback() 22 TestClosureCallback()
23 : callback_(base::Bind( 23 : callback_(base::Bind(
(...skipping 19 matching lines...) Expand all
43 }; 43 };
44 44
45 const int kDefaultClientId = 42; 45 const int kDefaultClientId = 42;
46 const char kCacheKey[] = "key"; 46 const char kCacheKey[] = "key";
47 const char kCacheValue[] = "cached value"; 47 const char kCacheValue[] = "cached value";
48 48
49 } // namespace 49 } // namespace
50 50
51 class StoragePartitionShaderClearTest : public testing::Test { 51 class StoragePartitionShaderClearTest : public testing::Test {
52 public: 52 public:
53 StoragePartitionShaderClearTest() : 53 StoragePartitionShaderClearTest()
54 ui_thread_(BrowserThread::UI, &message_loop_), 54 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
55 cache_thread_(BrowserThread::CACHE, &message_loop_),
56 io_thread_(BrowserThread::IO, &message_loop_) {
57 } 55 }
58 56
59 virtual ~StoragePartitionShaderClearTest() {} 57 virtual ~StoragePartitionShaderClearTest() {}
60 58
61 const base::FilePath& cache_path() { return temp_dir_.path(); } 59 const base::FilePath& cache_path() { return temp_dir_.path(); }
62 60
63 virtual void SetUp() OVERRIDE { 61 virtual void SetUp() OVERRIDE {
64 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 62 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
65 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId, 63 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId,
66 cache_path()); 64 cache_path());
(...skipping 11 matching lines...) Expand all
78 cache_->Cache(kCacheKey, kCacheValue); 76 cache_->Cache(kCacheKey, kCacheValue);
79 77
80 net::TestCompletionCallback complete_cb; 78 net::TestCompletionCallback complete_cb;
81 79
82 rv = cache_->SetCacheCompleteCallback(complete_cb.callback()); 80 rv = cache_->SetCacheCompleteCallback(complete_cb.callback());
83 ASSERT_EQ(net::OK, complete_cb.GetResult(rv)); 81 ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
84 } 82 }
85 83
86 size_t Size() { return cache_->Size(); } 84 size_t Size() { return cache_->Size(); }
87 85
88 base::MessageLoop* message_loop() { return &message_loop_; }
89
90 private: 86 private:
91 virtual void TearDown() OVERRIDE { 87 virtual void TearDown() OVERRIDE {
92 cache_ = NULL; 88 cache_ = NULL;
93 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId); 89 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId);
94 } 90 }
95 91
96 base::ScopedTempDir temp_dir_; 92 base::ScopedTempDir temp_dir_;
97 base::MessageLoopForIO message_loop_; 93 content::TestBrowserThreadBundle thread_bundle_;
98 TestBrowserThread ui_thread_;
99 TestBrowserThread cache_thread_;
100 TestBrowserThread io_thread_;
101 94
102 scoped_refptr<ShaderDiskCache> cache_; 95 scoped_refptr<ShaderDiskCache> cache_;
103 }; 96 };
104 97
105 void ClearData(content::StoragePartitionImpl* sp, 98 void ClearData(content::StoragePartitionImpl* sp,
106 const base::Closure& cb) { 99 const base::Closure& cb) {
107 base::Time time; 100 base::Time time;
108 sp->AsyncClearDataBetween(content::StoragePartition::kShaderStorage, 101 sp->AsyncClearDataBetween(content::StoragePartition::kShaderStorage,
109 time, time, cb); 102 time, time, cb);
110 } 103 }
111 104
112 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) { 105 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
113 InitCache(); 106 InitCache();
114 EXPECT_EQ(1u, Size()); 107 EXPECT_EQ(1u, Size());
115 108
116 TestClosureCallback clear_cb; 109 TestClosureCallback clear_cb;
117 StoragePartitionImpl sp(cache_path(), NULL, NULL, NULL, NULL, NULL, NULL); 110 StoragePartitionImpl sp(cache_path(), NULL, NULL, NULL, NULL, NULL, NULL);
118 message_loop()->PostTask(FROM_HERE, 111 base::MessageLoop::current()->PostTask(
119 base::Bind(&ClearData, &sp, clear_cb.callback())); 112 FROM_HERE,
113 base::Bind(&ClearData, &sp, clear_cb.callback()));
120 clear_cb.WaitForResult(); 114 clear_cb.WaitForResult();
121 EXPECT_EQ(0u, Size()); 115 EXPECT_EQ(0u, Size());
122 } 116 }
123 117
124 } // namespace content 118 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698