OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 cache_ = ServiceWorkerCache::CreateMemoryCache( | 69 cache_ = ServiceWorkerCache::CreateMemoryCache( |
70 url_request_context, | 70 url_request_context, |
71 blob_storage_context->context()->AsWeakPtr()); | 71 blob_storage_context->context()->AsWeakPtr()); |
72 } else { | 72 } else { |
73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 73 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
74 cache_ = ServiceWorkerCache::CreatePersistentCache( | 74 cache_ = ServiceWorkerCache::CreatePersistentCache( |
75 temp_dir_.path(), | 75 temp_dir_.path(), |
76 url_request_context, | 76 url_request_context, |
77 blob_storage_context->context()->AsWeakPtr()); | 77 blob_storage_context->context()->AsWeakPtr()); |
78 } | 78 } |
79 CreateBackend(); | |
80 } | 79 } |
81 | 80 |
82 virtual void TearDown() OVERRIDE { | 81 virtual void TearDown() OVERRIDE { |
83 base::RunLoop().RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
84 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 83 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
85 base::RunLoop().RunUntilIdle(); | 84 base::RunLoop().RunUntilIdle(); |
86 cache_.reset(); | 85 cache_.reset(); |
87 base::RunLoop().RunUntilIdle(); | 86 base::RunLoop().RunUntilIdle(); |
88 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); | 87 disk_cache::SimpleBackendImpl::FlushWorkerPoolForTesting(); |
89 base::RunLoop().RunUntilIdle(); | 88 base::RunLoop().RunUntilIdle(); |
(...skipping 26 matching lines...) Expand all Loading... |
116 body_response_ = ServiceWorkerResponse(GURL("http://example.com/body.html"), | 115 body_response_ = ServiceWorkerResponse(GURL("http://example.com/body.html"), |
117 200, | 116 200, |
118 "OK", | 117 "OK", |
119 headers, | 118 headers, |
120 blob_handle_->uuid()); | 119 blob_handle_->uuid()); |
121 | 120 |
122 no_body_response_ = ServiceWorkerResponse( | 121 no_body_response_ = ServiceWorkerResponse( |
123 GURL("http://example.com/no_body.html"), 200, "OK", headers, ""); | 122 GURL("http://example.com/no_body.html"), 200, "OK", headers, ""); |
124 } | 123 } |
125 | 124 |
126 void CreateBackend() { | |
127 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | |
128 cache_->CreateBackend(base::Bind(&ServiceWorkerCacheTest::ErrorTypeCallback, | |
129 base::Unretained(this), | |
130 base::Unretained(loop.get()))); | |
131 loop->Run(); | |
132 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); | |
133 } | |
134 | |
135 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest( | 125 scoped_ptr<ServiceWorkerFetchRequest> CopyFetchRequest( |
136 const ServiceWorkerFetchRequest& request) { | 126 const ServiceWorkerFetchRequest& request) { |
137 return make_scoped_ptr(new ServiceWorkerFetchRequest(request.url, | 127 return make_scoped_ptr(new ServiceWorkerFetchRequest(request.url, |
138 request.method, | 128 request.method, |
139 request.headers, | 129 request.headers, |
140 request.referrer, | 130 request.referrer, |
141 request.is_reload)); | 131 request.is_reload)); |
142 } | 132 } |
143 | 133 |
144 scoped_ptr<ServiceWorkerResponse> CopyFetchResponse( | 134 scoped_ptr<ServiceWorkerResponse> CopyFetchResponse( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 }; | 276 }; |
287 | 277 |
288 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { | 278 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { |
289 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 279 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
290 } | 280 } |
291 | 281 |
292 TEST_P(ServiceWorkerCacheTestP, PutBody) { | 282 TEST_P(ServiceWorkerCacheTestP, PutBody) { |
293 EXPECT_TRUE(Put(body_request_, body_response_)); | 283 EXPECT_TRUE(Put(body_request_, body_response_)); |
294 } | 284 } |
295 | 285 |
296 TEST_P(ServiceWorkerCacheTestP, PutBodyDropBlobRef) { | 286 TEST_F(ServiceWorkerCacheTest, PutBodyDropBlobRef) { |
297 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 287 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
298 cache_->Put(CopyFetchRequest(body_request_), | 288 cache_->Put(CopyFetchRequest(body_request_), |
299 CopyFetchResponse(body_response_), | 289 CopyFetchResponse(body_response_), |
300 base::Bind(&ServiceWorkerCacheTestP::ErrorTypeCallback, | 290 base::Bind(&ServiceWorkerCacheTestP::ErrorTypeCallback, |
301 base::Unretained(this), | 291 base::Unretained(this), |
302 base::Unretained(loop.get()))); | 292 base::Unretained(loop.get()))); |
303 // The handle should be held by the cache now so the deref here should be | 293 // The handle should be held by the cache now so the deref here should be |
304 // okay. | 294 // okay. |
305 blob_handle_.reset(); | 295 blob_handle_.reset(); |
306 loop->Run(); | 296 loop->Run(); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 ASSERT_TRUE(Delete(body_request_)); | 396 ASSERT_TRUE(Delete(body_request_)); |
407 } | 397 } |
408 } | 398 } |
409 #endif // OS_WIN | 399 #endif // OS_WIN |
410 | 400 |
411 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 401 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
412 ServiceWorkerCacheTestP, | 402 ServiceWorkerCacheTestP, |
413 ::testing::Values(false, true)); | 403 ::testing::Values(false, true)); |
414 | 404 |
415 } // namespace content | 405 } // namespace content |
OLD | NEW |