Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / gpu / shader_disk_cache_unittest.cc
blob15894ef6713a963170ef153d97026aec5bc56c18
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.
5 #include "base/files/scoped_temp_dir.h"
6 #include "base/threading/thread.h"
7 #include "content/browser/browser_thread_impl.h"
8 #include "content/browser/gpu/shader_disk_cache.h"
9 #include "content/public/test/test_browser_thread_bundle.h"
10 #include "net/base/test_completion_callback.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace content {
14 namespace {
16 const int kDefaultClientId = 42;
17 const char kCacheKey[] = "key";
18 const char kCacheValue[] = "cached value";
20 } // namespace
22 class ShaderDiskCacheTest : public testing::Test {
23 public:
24 ShaderDiskCacheTest()
25 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
28 ~ShaderDiskCacheTest() override {}
30 const base::FilePath& cache_path() { return temp_dir_.path(); }
32 void InitCache() {
33 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
34 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId,
35 cache_path());
38 private:
39 void TearDown() override {
40 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId);
43 base::ScopedTempDir temp_dir_;
44 content::TestBrowserThreadBundle thread_bundle_;
46 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheTest);
49 TEST_F(ShaderDiskCacheTest, ClearsCache) {
50 InitCache();
52 scoped_refptr<ShaderDiskCache> cache =
53 ShaderCacheFactory::GetInstance()->Get(kDefaultClientId);
54 ASSERT_TRUE(cache.get() != NULL);
56 net::TestCompletionCallback available_cb;
57 int rv = cache->SetAvailableCallback(available_cb.callback());
58 ASSERT_EQ(net::OK, available_cb.GetResult(rv));
59 EXPECT_EQ(0, cache->Size());
61 cache->Cache(kCacheKey, kCacheValue);
63 net::TestCompletionCallback complete_cb;
64 rv = cache->SetCacheCompleteCallback(complete_cb.callback());
65 ASSERT_EQ(net::OK, complete_cb.GetResult(rv));
66 EXPECT_EQ(1, cache->Size());
68 base::Time time;
69 net::TestCompletionCallback clear_cb;
70 rv = cache->Clear(time, time, clear_cb.callback());
71 ASSERT_EQ(net::OK, clear_cb.GetResult(rv));
72 EXPECT_EQ(0, cache->Size());
75 } // namespace content