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

Side by Side Diff: content/browser/service_worker/service_worker_cache_unittest.cc

Issue 545533002: Move ServiceWorkerCache backend creation to a lazy init function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no_pointers_keys
Patch Set: Nits Created 6 years, 3 months 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
« no previous file with comments | « content/browser/service_worker/service_worker_cache_storage.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/service_worker/service_worker_cache.h" 5 #include "content/browser/service_worker/service_worker_cache.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 cache_ = ServiceWorkerCache::CreateMemoryCache( 68 cache_ = ServiceWorkerCache::CreateMemoryCache(
69 url_request_context, 69 url_request_context,
70 blob_storage_context->context()->AsWeakPtr()); 70 blob_storage_context->context()->AsWeakPtr());
71 } else { 71 } else {
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
73 cache_ = ServiceWorkerCache::CreatePersistentCache( 73 cache_ = ServiceWorkerCache::CreatePersistentCache(
74 temp_dir_.path(), 74 temp_dir_.path(),
75 url_request_context, 75 url_request_context,
76 blob_storage_context->context()->AsWeakPtr()); 76 blob_storage_context->context()->AsWeakPtr());
77 } 77 }
78 CreateBackend();
79 } 78 }
80 79
81 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) { 80 void CreateRequests(ChromeBlobStorageContext* blob_storage_context) {
82 std::map<std::string, std::string> headers; 81 std::map<std::string, std::string> headers;
83 headers.insert(std::make_pair("a", "a")); 82 headers.insert(std::make_pair("a", "a"));
84 headers.insert(std::make_pair("b", "b")); 83 headers.insert(std::make_pair("b", "b"));
85 body_request_ = ServiceWorkerFetchRequest( 84 body_request_ = ServiceWorkerFetchRequest(
86 GURL("http://example.com/body.html"), "GET", headers, GURL(""), false); 85 GURL("http://example.com/body.html"), "GET", headers, GURL(""), false);
87 no_body_request_ = 86 no_body_request_ =
88 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), 87 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"),
(...skipping 16 matching lines...) Expand all
105 body_response_ = ServiceWorkerResponse(GURL("http://example.com/body.html"), 104 body_response_ = ServiceWorkerResponse(GURL("http://example.com/body.html"),
106 200, 105 200,
107 "OK", 106 "OK",
108 headers, 107 headers,
109 blob_handle_->uuid()); 108 blob_handle_->uuid());
110 109
111 no_body_response_ = ServiceWorkerResponse( 110 no_body_response_ = ServiceWorkerResponse(
112 GURL("http://example.com/no_body.html"), 200, "OK", headers, ""); 111 GURL("http://example.com/no_body.html"), 200, "OK", headers, "");
113 } 112 }
114 113
115 void CreateBackend() {
116 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
117 cache_->CreateBackend(base::Bind(&ServiceWorkerCacheTest::ErrorTypeCallback,
118 base::Unretained(this),
119 base::Unretained(loop.get())));
120 loop->Run();
121 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_);
122 }
123
124 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest( 114 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest(
125 const ServiceWorkerFetchRequest& request) { 115 const ServiceWorkerFetchRequest& request) {
126 return make_scoped_ptr(new ServiceWorkerFetchRequest(request.url, 116 return make_scoped_ptr(new ServiceWorkerFetchRequest(request.url,
127 request.method, 117 request.method,
128 request.headers, 118 request.headers,
129 request.referrer, 119 request.referrer,
130 request.is_reload)); 120 request.is_reload));
131 } 121 }
132 122
133 scoped_ptr<ServiceWorkerResponse> CopyFetchResponse( 123 scoped_ptr<ServiceWorkerResponse> CopyFetchResponse(
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 }; 265 };
276 266
277 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { 267 TEST_P(ServiceWorkerCacheTestP, PutNoBody) {
278 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 268 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
279 } 269 }
280 270
281 TEST_P(ServiceWorkerCacheTestP, PutBody) { 271 TEST_P(ServiceWorkerCacheTestP, PutBody) {
282 EXPECT_TRUE(Put(body_request_, body_response_)); 272 EXPECT_TRUE(Put(body_request_, body_response_));
283 } 273 }
284 274
285 TEST_P(ServiceWorkerCacheTestP, PutBodyDropBlobRef) { 275 TEST_F(ServiceWorkerCacheTest, PutBodyDropBlobRef) {
286 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); 276 scoped_ptr<base::RunLoop> loop(new base::RunLoop());
287 cache_->Put(CopyFetchRequest(body_request_), 277 cache_->Put(CopyFetchRequest(body_request_),
288 CopyFetchResponse(body_response_), 278 CopyFetchResponse(body_response_),
289 base::Bind(&ServiceWorkerCacheTestP::ErrorTypeCallback, 279 base::Bind(&ServiceWorkerCacheTestP::ErrorTypeCallback,
290 base::Unretained(this), 280 base::Unretained(this),
291 base::Unretained(loop.get()))); 281 base::Unretained(loop.get())));
292 // The handle should be held by the cache now so the deref here should be 282 // The BlobHandle needs to be held onto by the caller until either the
michaeln1 2014/09/05 23:28:49 That's too bad. Not suggesting this for this cl,
jkarlin 2014/09/09 19:14:34 Done.
293 // okay. 283 // callback returns or the cache is deleted, otherwise Put() fails as shown
284 // here.
294 blob_handle_.reset(); 285 blob_handle_.reset();
295 loop->Run(); 286 loop->Run();
296 287
297 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); 288 EXPECT_EQ(ServiceWorkerCache::ErrorTypeStorage, callback_error_);
298 } 289 }
299 290
300 TEST_P(ServiceWorkerCacheTestP, MatchNoBody) { 291 TEST_P(ServiceWorkerCacheTestP, MatchNoBody) {
301 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); 292 EXPECT_TRUE(Put(no_body_request_, no_body_response_));
302 EXPECT_TRUE(Match(no_body_request_)); 293 EXPECT_TRUE(Match(no_body_request_));
303 EXPECT_EQ(200, callback_response_->status_code); 294 EXPECT_EQ(200, callback_response_->status_code);
304 EXPECT_STREQ("OK", callback_response_->status_text.c_str()); 295 EXPECT_STREQ("OK", callback_response_->status_text.c_str());
305 EXPECT_STREQ("http://example.com/no_body.html", 296 EXPECT_STREQ("http://example.com/no_body.html",
306 callback_response_->url.spec().c_str()); 297 callback_response_->url.spec().c_str());
307 } 298 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 ASSERT_TRUE(Delete(body_request_)); 386 ASSERT_TRUE(Delete(body_request_));
396 } 387 }
397 } 388 }
398 #endif // OS_WIN 389 #endif // OS_WIN
399 390
400 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, 391 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest,
401 ServiceWorkerCacheTestP, 392 ServiceWorkerCacheTestP,
402 ::testing::Values(false, true)); 393 ::testing::Values(false, true));
403 394
404 } // namespace content 395 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_cache_storage.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698