| 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/message_loop/message_loop.h" | |
| 8 #include "base/threading/thread.h" | |
| 9 #include "base/threading/thread_task_runner_handle.h" | |
| 10 #include "gpu/ipc/host/shader_disk_cache.h" | |
| 11 #include "net/base/test_completion_callback.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 namespace gpu { | |
| 15 namespace { | |
| 16 | |
| 17 const int kDefaultClientId = 42; | |
| 18 const char kCacheKey[] = "key"; | |
| 19 const char kCacheValue[] = "cached value"; | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 class ShaderDiskCacheTest : public testing::Test { | |
| 24 public: | |
| 25 ShaderDiskCacheTest() | |
| 26 : cache_thread_("CacheThread") { | |
| 27 base::Thread::Options options; | |
| 28 options.message_loop_type = base::MessageLoop::TYPE_IO; | |
| 29 CHECK(cache_thread_.StartWithOptions(options)); | |
| 30 ShaderCacheFactory::InitInstance( | |
| 31 base::ThreadTaskRunnerHandle::Get(), | |
| 32 cache_thread_.task_runner()); | |
| 33 } | |
| 34 | |
| 35 ~ShaderDiskCacheTest() override {} | |
| 36 | |
| 37 const base::FilePath& cache_path() { return temp_dir_.GetPath(); } | |
| 38 | |
| 39 void InitCache() { | |
| 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 41 ShaderCacheFactory::GetInstance()->SetCacheInfo(kDefaultClientId, | |
| 42 cache_path()); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 void TearDown() override { | |
| 47 ShaderCacheFactory::GetInstance()->RemoveCacheInfo(kDefaultClientId); | |
| 48 } | |
| 49 | |
| 50 base::ScopedTempDir temp_dir_; | |
| 51 base::Thread cache_thread_; | |
| 52 base::MessageLoopForIO message_loop_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(ShaderDiskCacheTest); | |
| 55 }; | |
| 56 | |
| 57 TEST_F(ShaderDiskCacheTest, ClearsCache) { | |
| 58 InitCache(); | |
| 59 | |
| 60 scoped_refptr<ShaderDiskCache> cache = | |
| 61 ShaderCacheFactory::GetInstance()->Get(kDefaultClientId); | |
| 62 ASSERT_TRUE(cache.get() != NULL); | |
| 63 | |
| 64 net::TestCompletionCallback available_cb; | |
| 65 int rv = cache->SetAvailableCallback(available_cb.callback()); | |
| 66 ASSERT_EQ(net::OK, available_cb.GetResult(rv)); | |
| 67 EXPECT_EQ(0, cache->Size()); | |
| 68 | |
| 69 cache->Cache(kCacheKey, kCacheValue); | |
| 70 | |
| 71 net::TestCompletionCallback complete_cb; | |
| 72 rv = cache->SetCacheCompleteCallback(complete_cb.callback()); | |
| 73 ASSERT_EQ(net::OK, complete_cb.GetResult(rv)); | |
| 74 EXPECT_EQ(1, cache->Size()); | |
| 75 | |
| 76 base::Time time; | |
| 77 net::TestCompletionCallback clear_cb; | |
| 78 rv = cache->Clear(time, time, clear_cb.callback()); | |
| 79 ASSERT_EQ(net::OK, clear_cb.GetResult(rv)); | |
| 80 EXPECT_EQ(0, cache->Size()); | |
| 81 }; | |
| 82 | |
| 83 } // namespace gpu | |
| OLD | NEW |