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

Side by Side Diff: content/browser/gpu/shader_disk_cache_unittest.cc

Issue 2555693005: gpu: Move ShaderDiskCache into //gpu/ipc/host component. (Closed)
Patch Set: tot merge Created 4 years 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
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/macros.h"
7 #include "base/memory/ptr_util.h"
8 #include "base/threading/thread.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "content/browser/browser_thread_impl.h"
11 #include "content/browser/gpu/shader_disk_cache.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "net/base/test_completion_callback.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace content {
17 namespace {
18
19 const int kDefaultClientId = 42;
20 const char kCacheKey[] = "key";
21 const char kCacheValue[] = "cached value";
22
23 } // namespace
24
25 class ShaderDiskCacheTest : public testing::Test {
26 public:
27 ShaderDiskCacheTest()
28 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
29 factory_ = base::MakeUnique<ShaderCacheFactory>(
30 BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE));
31 }
32
33 ~ShaderDiskCacheTest() override {}
34
35 const base::FilePath& cache_path() { return temp_dir_.GetPath(); }
36
37 void InitCache() {
38 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
39 factory_->SetCacheInfo(kDefaultClientId, cache_path());
40 }
41
42 ShaderCacheFactory* factory() { return factory_.get(); }
43
44 private:
45 void TearDown() override { factory_->RemoveCacheInfo(kDefaultClientId); }
46
47 std::unique_ptr<ShaderCacheFactory> factory_;
48 base::ScopedTempDir temp_dir_;
49 content::TestBrowserThreadBundle thread_bundle_;
50
51 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheTest);
52 };
53
54 TEST_F(ShaderDiskCacheTest, ClearsCache) {
55 InitCache();
56
57 scoped_refptr<ShaderDiskCache> cache = factory()->Get(kDefaultClientId);
58 ASSERT_TRUE(cache.get() != NULL);
59
60 net::TestCompletionCallback available_cb;
61 int rv = cache->SetAvailableCallback(available_cb.callback());
62 ASSERT_EQ(net::OK, available_cb.GetResult(rv));
63 EXPECT_EQ(0, cache->Size());
64
65 cache->Cache(kCacheKey, kCacheValue);
66
67 net::TestCompletionCallback complete_cb;
68 rv = cache->SetCacheCompleteCallback(complete_cb.callback());
69 ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
70 EXPECT_EQ(1, cache->Size());
71
72 base::Time time;
73 net::TestCompletionCallback clear_cb;
74 rv = cache->Clear(time, time, clear_cb.callback());
75 ASSERT_EQ(net::OK, clear_cb.GetResult(rv));
76 EXPECT_EQ(0, cache->Size());
77 };
78
79 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/gpu/shader_disk_cache.cc ('k') | content/browser/storage_partition_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698