| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 | 226 |
| 227 void ResponseAndErrorCallback( | 227 void ResponseAndErrorCallback( |
| 228 base::RunLoop* run_loop, | 228 base::RunLoop* run_loop, |
| 229 ServiceWorkerCache::ErrorType error, | 229 ServiceWorkerCache::ErrorType error, |
| 230 scoped_ptr<ServiceWorkerResponse> response, | 230 scoped_ptr<ServiceWorkerResponse> response, |
| 231 scoped_ptr<storage::BlobDataHandle> body_handle) { | 231 scoped_ptr<storage::BlobDataHandle> body_handle) { |
| 232 callback_error_ = error; | 232 callback_error_ = error; |
| 233 callback_response_ = response.Pass(); | 233 callback_response_ = response.Pass(); |
| 234 | 234 |
| 235 callback_response_data_.reset(); |
| 235 if (error == ServiceWorkerCache::ErrorTypeOK && | 236 if (error == ServiceWorkerCache::ErrorTypeOK && |
| 236 !callback_response_->blob_uuid.empty()) { | 237 !callback_response_->blob_uuid.empty()) { |
| 237 callback_response_data_ = body_handle.Pass(); | 238 callback_response_data_ = body_handle.Pass(); |
| 238 } | 239 } |
| 239 | 240 |
| 240 run_loop->Quit(); | 241 run_loop->Quit(); |
| 241 } | 242 } |
| 242 | 243 |
| 243 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { | 244 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { |
| 244 storage::BlobData* data = blob_handle->data(); | 245 storage::BlobData* data = blob_handle->data(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 base::Unretained(this), | 357 base::Unretained(this), |
| 357 base::Unretained(loop.get()))); | 358 base::Unretained(loop.get()))); |
| 358 // The handle should be held by the cache now so the deref here should be | 359 // The handle should be held by the cache now so the deref here should be |
| 359 // okay. | 360 // okay. |
| 360 blob_handle_.reset(); | 361 blob_handle_.reset(); |
| 361 loop->Run(); | 362 loop->Run(); |
| 362 | 363 |
| 363 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); | 364 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); |
| 364 } | 365 } |
| 365 | 366 |
| 367 TEST_P(ServiceWorkerCacheTestP, PutReplace) { |
| 368 EXPECT_TRUE(Put(body_request_, no_body_response_)); |
| 369 EXPECT_TRUE(Match(body_request_)); |
| 370 EXPECT_FALSE(callback_response_data_); |
| 371 |
| 372 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 373 EXPECT_TRUE(Match(body_request_)); |
| 374 EXPECT_TRUE(callback_response_data_); |
| 375 |
| 376 EXPECT_TRUE(Put(body_request_, no_body_response_)); |
| 377 EXPECT_TRUE(Match(body_request_)); |
| 378 EXPECT_FALSE(callback_response_data_); |
| 379 } |
| 380 |
| 366 TEST_P(ServiceWorkerCacheTestP, MatchNoBody) { | 381 TEST_P(ServiceWorkerCacheTestP, MatchNoBody) { |
| 367 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 382 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 368 EXPECT_TRUE(Match(no_body_request_)); | 383 EXPECT_TRUE(Match(no_body_request_)); |
| 369 EXPECT_EQ(200, callback_response_->status_code); | 384 EXPECT_EQ(200, callback_response_->status_code); |
| 370 EXPECT_STREQ("OK", callback_response_->status_text.c_str()); | 385 EXPECT_STREQ("OK", callback_response_->status_text.c_str()); |
| 371 EXPECT_STREQ("http://example.com/no_body.html", | 386 EXPECT_STREQ("http://example.com/no_body.html", |
| 372 callback_response_->url.spec().c_str()); | 387 callback_response_->url.spec().c_str()); |
| 373 EXPECT_STREQ("", callback_response_->blob_uuid.c_str()); | 388 EXPECT_STREQ("", callback_response_->blob_uuid.c_str()); |
| 374 EXPECT_EQ(0u, callback_response_->blob_size); | 389 EXPECT_EQ(0u, callback_response_->blob_size); |
| 375 } | 390 } |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 EXPECT_EQ(0, cache_->MemoryBackedSize()); | 624 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 610 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 625 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 611 EXPECT_EQ(0, cache_->MemoryBackedSize()); | 626 EXPECT_EQ(0, cache_->MemoryBackedSize()); |
| 612 } | 627 } |
| 613 | 628 |
| 614 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 629 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
| 615 ServiceWorkerCacheTestP, | 630 ServiceWorkerCacheTestP, |
| 616 ::testing::Values(false, true)); | 631 ::testing::Values(false, true)); |
| 617 | 632 |
| 618 } // namespace content | 633 } // namespace content |
| OLD | NEW |