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

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

Issue 12500009: Add the ability to clear the shader disk cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add AsyncClearDataBetween unittest. Created 7 years, 8 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 | « content/browser/storage_partition_impl.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/files/scoped_temp_dir.h"
6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/run_loop.h"
8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/gpu/shader_disk_cache.h"
11 #include "content/browser/storage_partition_impl.h"
12 #include "content/public/browser/storage_partition.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "net/base/test_completion_callback.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace content {
18 namespace {
19
20 int kCallbackTimeout = 1000;
jam 2013/04/04 14:53:31 why are you adding this timeout step? it seems to
dsinclair 2013/04/04 16:04:00 Removed as discussed.
21
22 class TestClosureCallback {
23 public:
24 TestClosureCallback()
25 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
26 base::Bind(&TestClosureCallback::StopWaiting,
27 base::Unretained(this)))) {
28 }
29
30 void WaitForResult() {
31 base::CancelableClosure timeout(
32 base::Bind(&TestClosureCallback::StopWaiting,
33 base::Unretained(this)));
34
35 wait_run_loop_.reset(new base::RunLoop());
36 MessageLoop::current()->PostDelayedTask(FROM_HERE, timeout.callback(),
37 base::TimeDelta::FromMilliseconds(kCallbackTimeout));
38 wait_run_loop_->Run();
39 }
40
41 const base::Closure& callback() { return callback_; }
42
43 private:
44 void StopWaiting() {
45 wait_run_loop_->Quit();
46 }
47
48 base::Closure callback_;
49 scoped_ptr<base::RunLoop> wait_run_loop_;
50
51 DISALLOW_COPY_AND_ASSIGN(TestClosureCallback);
52 };
53
54 const int kDefaultClientId = 42;
55 const char kCacheKey[] = "key";
56 const char kCacheValue[] = "cached value";
57
58 } // namespace
59
60 class StoragePartitionShaderClearTest : public testing::Test {
61 public:
62 StoragePartitionShaderClearTest() :
63 ui_thread_(BrowserThread::UI, &message_loop_),
64 cache_thread_(BrowserThread::CACHE, &message_loop_),
65 io_thread_(BrowserThread::IO, &message_loop_) {
66 }
67
68 virtual ~StoragePartitionShaderClearTest() {}
69
70 const base::FilePath& cache_path() { return temp_dir_.path(); }
71
72 virtual void SetUp() OVERRIDE {
73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
74 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId,
75 cache_path());
76
77 cache_ = ShaderCacheFactory::GetInstance()->Get(kDefaultClientId);
78 ASSERT_TRUE(cache_.get() != NULL);
79 }
80
81 void InitCache() {
82 net::TestCompletionCallback available_cb;
83 int rv = cache_->SetAvailableCallback(available_cb.callback());
84 ASSERT_EQ(net::OK, available_cb.GetResult(rv));
85 EXPECT_EQ(0, cache_->Size());
86
87 cache_->Cache(kCacheKey, kCacheValue);
88
89 net::TestCompletionCallback complete_cb;
90
91 rv = cache_->SetCacheCompleteCallback(complete_cb.callback());
92 ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
93 }
94
95 size_t Size() { return cache_->Size(); }
96
97 MessageLoop* message_loop() { return &message_loop_; }
98
99 private:
100 virtual void TearDown() OVERRIDE {
101 cache_ = NULL;
102 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId);
103 }
104
105 base::ScopedTempDir temp_dir_;
106 MessageLoopForUI message_loop_;
107 TestBrowserThread ui_thread_;
108 TestBrowserThread cache_thread_;
109 TestBrowserThread io_thread_;
110
111 scoped_refptr<ShaderDiskCache> cache_;
112 };
113
114 void ClearData(content::StoragePartitionImpl* sp,
115 const base::Closure& cb) {
116 base::Time time;
117 sp->AsyncClearDataBetween(content::StoragePartition::kShaderStorage,
118 time, time, cb);
119 }
120
121 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
122 InitCache();
123 EXPECT_EQ(1ul, Size());
124
125 TestClosureCallback clear_cb;
126 StoragePartitionImpl sp(cache_path(), NULL, NULL, NULL, NULL, NULL, NULL);
127 message_loop()->PostTask(FROM_HERE,
128 base::Bind(&ClearData, &sp, clear_cb.callback()));
129 clear_cb.WaitForResult();
130 EXPECT_EQ(0ul, Size());
jam 2013/04/04 14:53:31 nit: 0u is enough i think
dsinclair 2013/04/04 16:04:00 Done.
131 }
132
133 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/storage_partition_impl.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698