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

Side by Side Diff: net/http/infinite_cache_unittest.cc

Issue 11359217: Move scoped_temp_dir from base to base/files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/http/infinite_cache.h" 5 #include "net/http/infinite_cache.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "net/base/test_completion_callback.h" 12 #include "net/base/test_completion_callback.h"
13 #include "net/http/http_transaction_unittest.h" 13 #include "net/http/http_transaction_unittest.h"
14 #include "net/http/http_util.h" 14 #include "net/http/http_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using base::Time; 17 using base::Time;
18 using base::TimeDelta; 18 using base::TimeDelta;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 // Now a different URL. 107 // Now a different URL.
108 MockHttpRequest request2(kSimpleGET_Transaction); 108 MockHttpRequest request2(kSimpleGET_Transaction);
109 transaction->OnRequestStart(&request2); 109 transaction->OnRequestStart(&request2);
110 transaction->OnResponseReceived(&response); 110 transaction->OnResponseReceived(&response);
111 transaction.reset(); 111 transaction.reset();
112 EXPECT_EQ(2, cb.GetResult(cache.QueryItemsForTest(cb.callback()))); 112 EXPECT_EQ(2, cb.GetResult(cache.QueryItemsForTest(cb.callback())));
113 } 113 }
114 114
115 TEST(InfiniteCache, Save_Restore) { 115 TEST(InfiniteCache, Save_Restore) {
116 ScopedTempDir dir; 116 base::ScopedTempDir dir;
117 ASSERT_TRUE(dir.CreateUniqueTempDir()); 117 ASSERT_TRUE(dir.CreateUniqueTempDir());
118 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite")); 118 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite"));
119 119
120 scoped_ptr<InfiniteCache> cache(new InfiniteCache); 120 scoped_ptr<InfiniteCache> cache(new InfiniteCache);
121 cache->Init(path); 121 cache->Init(path);
122 net::TestCompletionCallback cb; 122 net::TestCompletionCallback cb;
123 123
124 ProcessRequest(kTypicalGET_Transaction, cache.get()); 124 ProcessRequest(kTypicalGET_Transaction, cache.get());
125 ProcessRequest(kSimpleGET_Transaction, cache.get()); 125 ProcessRequest(kSimpleGET_Transaction, cache.get());
126 ProcessRequest(kETagGET_Transaction, cache.get()); 126 ProcessRequest(kETagGET_Transaction, cache.get());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 ProcessRequest(request, &cache); 158 ProcessRequest(request, &cache);
159 EXPECT_EQ(1, cb.GetResult(cache.QueryItemsForTest(cb.callback()))); 159 EXPECT_EQ(1, cb.GetResult(cache.QueryItemsForTest(cb.callback())));
160 160
161 request.method = "DELETE"; 161 request.method = "DELETE";
162 request.url = kETagGET_Transaction.url; 162 request.url = kETagGET_Transaction.url;
163 ProcessRequest(request, &cache); 163 ProcessRequest(request, &cache);
164 EXPECT_EQ(0, cb.GetResult(cache.QueryItemsForTest(cb.callback()))); 164 EXPECT_EQ(0, cb.GetResult(cache.QueryItemsForTest(cb.callback())));
165 } 165 }
166 166
167 TEST(InfiniteCache, Delete) { 167 TEST(InfiniteCache, Delete) {
168 ScopedTempDir dir; 168 base::ScopedTempDir dir;
169 ASSERT_TRUE(dir.CreateUniqueTempDir()); 169 ASSERT_TRUE(dir.CreateUniqueTempDir());
170 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite")); 170 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite"));
171 171
172 scoped_ptr<InfiniteCache> cache(new InfiniteCache); 172 scoped_ptr<InfiniteCache> cache(new InfiniteCache);
173 cache->Init(path); 173 cache->Init(path);
174 net::TestCompletionCallback cb; 174 net::TestCompletionCallback cb;
175 175
176 ProcessRequest(kTypicalGET_Transaction, cache.get()); 176 ProcessRequest(kTypicalGET_Transaction, cache.get());
177 ProcessRequest(kSimpleGET_Transaction, cache.get()); 177 ProcessRequest(kSimpleGET_Transaction, cache.get());
178 EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); 178 EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
179 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback()))); 179 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback())));
180 EXPECT_TRUE(file_util::PathExists(path)); 180 EXPECT_TRUE(file_util::PathExists(path));
181 181
182 cache.reset(new InfiniteCache); 182 cache.reset(new InfiniteCache);
183 cache->Init(path); 183 cache->Init(path);
184 EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); 184 EXPECT_EQ(2, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
185 EXPECT_EQ(net::OK, cb.GetResult(cache->DeleteData(cb.callback()))); 185 EXPECT_EQ(net::OK, cb.GetResult(cache->DeleteData(cb.callback())));
186 EXPECT_EQ(0, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); 186 EXPECT_EQ(0, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
187 EXPECT_FALSE(file_util::PathExists(path)); 187 EXPECT_FALSE(file_util::PathExists(path));
188 188
189 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback()))); 189 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback())));
190 } 190 }
191 191
192 TEST(InfiniteCache, DeleteBetween) { 192 TEST(InfiniteCache, DeleteBetween) {
193 #if !defined(OS_ANDROID) 193 #if !defined(OS_ANDROID)
194 ScopedTempDir dir; 194 base::ScopedTempDir dir;
195 ASSERT_TRUE(dir.CreateUniqueTempDir()); 195 ASSERT_TRUE(dir.CreateUniqueTempDir());
196 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite")); 196 FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite"));
197 197
198 scoped_ptr<InfiniteCache> cache(new InfiniteCache); 198 scoped_ptr<InfiniteCache> cache(new InfiniteCache);
199 cache->Init(path); 199 cache->Init(path);
200 net::TestCompletionCallback cb; 200 net::TestCompletionCallback cb;
201 201
202 Time::Exploded baseline = {}; 202 Time::Exploded baseline = {};
203 baseline.year = 2012; 203 baseline.year = 2012;
204 baseline.month = 1; 204 baseline.month = 1;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // Make sure the data is deleted from disk. 238 // Make sure the data is deleted from disk.
239 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback()))); 239 EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback())));
240 cache.reset(new InfiniteCache); 240 cache.reset(new InfiniteCache);
241 cache->Init(path); 241 cache->Init(path);
242 242
243 EXPECT_EQ(1, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); 243 EXPECT_EQ(1, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
244 ProcessRequest(kTypicalGET_Transaction, cache.get()); 244 ProcessRequest(kTypicalGET_Transaction, cache.get());
245 EXPECT_EQ(1, cb.GetResult(cache->QueryItemsForTest(cb.callback()))); 245 EXPECT_EQ(1, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
246 #endif // OS_ANDROID 246 #endif // OS_ANDROID
247 } 247 }
OLDNEW
« no previous file with comments | « net/http/http_stream_parser_unittest.cc ('k') | net/spdy/spdy_network_transaction_spdy2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698