OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/cache_storage/cache_storage.h" | 5 #include "content/browser/cache_storage/cache_storage.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
14 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
15 #include "storage/browser/quota/quota_manager_proxy.h" | 16 #include "storage/browser/quota/quota_manager_proxy.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 namespace { | 21 namespace { |
21 const char kOrigin[] = "http://example.com/"; | 22 const char kOrigin[] = "http://example.com/"; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} | 67 : browser_thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP) {} |
67 | 68 |
68 void SetUp() override { | 69 void SetUp() override { |
69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 70 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
70 test_cache_storage_.reset(new TestCacheStorage(temp_dir_.path())); | 71 test_cache_storage_.reset(new TestCacheStorage(temp_dir_.path())); |
71 } | 72 } |
72 | 73 |
73 bool OpenCache(const std::string& cache_name) { | 74 bool OpenCache(const std::string& cache_name) { |
74 bool callback_called = false; | 75 bool callback_called = false; |
75 test_cache_storage_->OpenCache( | 76 test_cache_storage_->OpenCache( |
76 cache_name, base::Bind(&CacheStorageTest::OpenCacheCallback, | 77 base::UTF8ToUTF16(cache_name), |
77 base::Unretained(this), &callback_called)); | 78 base::Bind(&CacheStorageTest::OpenCacheCallback, base::Unretained(this), |
| 79 &callback_called)); |
78 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
79 EXPECT_TRUE(callback_called); | 81 EXPECT_TRUE(callback_called); |
80 return callback_error_ == CACHE_STORAGE_OK; | 82 return callback_error_ == CACHE_STORAGE_OK; |
81 } | 83 } |
82 | 84 |
83 void OpenCacheCallback(bool* callback_called, | 85 void OpenCacheCallback(bool* callback_called, |
84 const scoped_refptr<CacheStorageCache>& cache, | 86 const scoped_refptr<CacheStorageCache>& cache, |
85 CacheStorageError error) { | 87 CacheStorageError error) { |
86 *callback_called = true; | 88 *callback_called = true; |
87 callback_cache_ = cache; | 89 callback_cache_ = cache; |
(...skipping 24 matching lines...) Expand all Loading... |
112 // next time it's opened will require the cache to be created again and | 114 // next time it's opened will require the cache to be created again and |
113 // preserved. | 115 // preserved. |
114 callback_cache_ = nullptr; | 116 callback_cache_ = nullptr; |
115 EXPECT_TRUE(OpenCache("foo")); | 117 EXPECT_TRUE(OpenCache("foo")); |
116 EXPECT_TRUE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); | 118 EXPECT_TRUE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); |
117 test_cache_storage_->RunPreservedCacheCallback(); | 119 test_cache_storage_->RunPreservedCacheCallback(); |
118 EXPECT_FALSE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); | 120 EXPECT_FALSE(test_cache_storage_->IsPreservingCache(callback_cache_.get())); |
119 } | 121 } |
120 | 122 |
121 } // namespace content | 123 } // namespace content |
OLD | NEW |