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

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: 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 class TestClosureCallback {
21 public:
22 TestClosureCallback()
23 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
24 base::Bind(&TestClosureCallback::StopWaiting,
25 base::Unretained(this)))) {
26 }
27
28 void WaitForResult() {
29 wait_run_loop_.reset(new base::RunLoop());
30 wait_run_loop_->Run();
31 }
32
33 const base::Closure& callback() { return callback_; }
34
35 private:
36 void StopWaiting() {
37 wait_run_loop_->Quit();
38 }
39
40 base::Closure callback_;
41 scoped_ptr<base::RunLoop> wait_run_loop_;
42
43 DISALLOW_COPY_AND_ASSIGN(TestClosureCallback);
44 };
45
46 const int kDefaultClientId = 42;
47 const char kCacheKey[] = "key";
48 const char kCacheValue[] = "cached value";
49
50 } // namespace
51
52 class StoragePartitionShaderClearTest : public testing::Test {
53 public:
54 StoragePartitionShaderClearTest() :
55 ui_thread_(BrowserThread::UI, &message_loop_),
56 cache_thread_(BrowserThread::CACHE, &message_loop_),
57 io_thread_(BrowserThread::IO, &message_loop_) {
58 }
59
60 virtual ~StoragePartitionShaderClearTest() {}
61
62 const base::FilePath& cache_path() { return temp_dir_.path(); }
63
64 virtual void SetUp() OVERRIDE {
65 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
66 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId,
67 cache_path());
68
69 cache_ = ShaderCacheFactory::GetInstance()->Get(kDefaultClientId);
70 ASSERT_TRUE(cache_.get() != NULL);
71 }
72
73 void InitCache() {
74 net::TestCompletionCallback available_cb;
75 int rv = cache_->SetAvailableCallback(available_cb.callback());
76 ASSERT_EQ(net::OK, available_cb.GetResult(rv));
77 EXPECT_EQ(0, cache_->Size());
78
79 cache_->Cache(kCacheKey, kCacheValue);
80
81 net::TestCompletionCallback complete_cb;
82
83 rv = cache_->SetCacheCompleteCallback(complete_cb.callback());
84 ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
85 }
86
87 size_t Size() { return cache_->Size(); }
88
89 MessageLoop* message_loop() { return &message_loop_; }
90
91 private:
92 virtual void TearDown() OVERRIDE {
93 cache_ = NULL;
94 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId);
95 }
96
97 base::ScopedTempDir temp_dir_;
98 MessageLoopForIO message_loop_;
99 TestBrowserThread ui_thread_;
100 TestBrowserThread cache_thread_;
101 TestBrowserThread io_thread_;
102
103 scoped_refptr<ShaderDiskCache> cache_;
104 };
105
106 void ClearData(content::StoragePartitionImpl* sp,
107 const base::Closure& cb) {
108 base::Time time;
109 sp->AsyncClearDataBetween(content::StoragePartition::kShaderStorage,
110 time, time, cb);
111 }
112
113 TEST_F(StoragePartitionShaderClearTest, ClearShaderCache) {
114 InitCache();
115 EXPECT_EQ(1u, Size());
116
117 TestClosureCallback clear_cb;
118 StoragePartitionImpl sp(cache_path(), NULL, NULL, NULL, NULL, NULL, NULL);
119 message_loop()->PostTask(FROM_HERE,
120 base::Bind(&ClearData, &sp, clear_cb.callback()));
121 clear_cb.WaitForResult();
122 EXPECT_EQ(0u, Size());
123 }
124
125 } // 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