OLD | NEW |
(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/threading/thread.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/gpu/shader_disk_cache.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "net/base/test_completion_callback.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace content { |
| 16 namespace { |
| 17 |
| 18 const int kDefaultClientId = 42; |
| 19 const char kCacheKey[] = "key"; |
| 20 const char kCacheValue[] = "cached value"; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 class ShaderDiskCacheTest : public testing::Test { |
| 25 public: |
| 26 ShaderDiskCacheTest() |
| 27 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 28 ShaderCacheFactory::InitInstance( |
| 29 base::ThreadTaskRunnerHandle::Get(), |
| 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 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId, |
| 40 cache_path()); |
| 41 } |
| 42 |
| 43 private: |
| 44 void TearDown() override { |
| 45 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId); |
| 46 } |
| 47 |
| 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 = |
| 58 ShaderCacheFactory::GetInstance()->Get(kDefaultClientId); |
| 59 ASSERT_TRUE(cache.get() != NULL); |
| 60 |
| 61 net::TestCompletionCallback available_cb; |
| 62 int rv = cache->SetAvailableCallback(available_cb.callback()); |
| 63 ASSERT_EQ(net::OK, available_cb.GetResult(rv)); |
| 64 EXPECT_EQ(0, cache->Size()); |
| 65 |
| 66 cache->Cache(kCacheKey, kCacheValue); |
| 67 |
| 68 net::TestCompletionCallback complete_cb; |
| 69 rv = cache->SetCacheCompleteCallback(complete_cb.callback()); |
| 70 ASSERT_EQ(net::OK, complete_cb.GetResult(rv)); |
| 71 EXPECT_EQ(1, cache->Size()); |
| 72 |
| 73 base::Time time; |
| 74 net::TestCompletionCallback clear_cb; |
| 75 rv = cache->Clear(time, time, clear_cb.callback()); |
| 76 ASSERT_EQ(net::OK, clear_cb.GetResult(rv)); |
| 77 EXPECT_EQ(0, cache->Size()); |
| 78 }; |
| 79 |
| 80 } // namespace content |
OLD | NEW |