| 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" |
| 11 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 11 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 12 #include "content/browser/fileapi/mock_url_request_delegate.h" | 12 #include "content/browser/fileapi/mock_url_request_delegate.h" |
| 13 #include "content/browser/quota/mock_quota_manager_proxy.h" | 13 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 14 #include "content/common/service_worker/service_worker_types.h" | 14 #include "content/common/service_worker/service_worker_types.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/test/test_browser_context.h" | 16 #include "content/public/test/test_browser_context.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "net/url_request/url_request_context.h" | 18 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 19 #include "net/url_request/url_request_context_getter.h" |
| 20 #include "net/url_request/url_request_job_factory_impl.h" | 20 #include "net/url_request/url_request_job_factory_impl.h" |
| 21 #include "storage/browser/blob/blob_data_builder.h" |
| 21 #include "storage/browser/blob/blob_data_handle.h" | 22 #include "storage/browser/blob/blob_data_handle.h" |
| 23 #include "storage/browser/blob/blob_data_snapshot.h" |
| 22 #include "storage/browser/blob/blob_storage_context.h" | 24 #include "storage/browser/blob/blob_storage_context.h" |
| 23 #include "storage/browser/blob/blob_url_request_job_factory.h" | 25 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 24 #include "storage/browser/quota/quota_manager_proxy.h" | 26 #include "storage/browser/quota/quota_manager_proxy.h" |
| 25 #include "storage/common/blob/blob_data.h" | |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 const char kTestData[] = "Hello World"; | 32 const char kTestData[] = "Hello World"; |
| 32 | 33 |
| 33 // Returns a BlobProtocolHandler that uses |blob_storage_context|. Caller owns | 34 // Returns a BlobProtocolHandler that uses |blob_storage_context|. Caller owns |
| 34 // the memory. | 35 // the memory. |
| 35 storage::BlobProtocolHandler* CreateMockBlobProtocolHandler( | 36 storage::BlobProtocolHandler* CreateMockBlobProtocolHandler( |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), | 221 ServiceWorkerFetchRequest(GURL("http://example.com/no_body.html"), |
| 221 "GET", | 222 "GET", |
| 222 headers, | 223 headers, |
| 223 GURL(), | 224 GURL(), |
| 224 false); | 225 false); |
| 225 | 226 |
| 226 std::string expected_response; | 227 std::string expected_response; |
| 227 for (int i = 0; i < 100; ++i) | 228 for (int i = 0; i < 100; ++i) |
| 228 expected_blob_data_ += kTestData; | 229 expected_blob_data_ += kTestData; |
| 229 | 230 |
| 230 scoped_refptr<storage::BlobData> blob_data( | 231 scoped_ptr<storage::BlobDataBuilder> blob_data( |
| 231 new storage::BlobData("blob-id:myblob")); | 232 new storage::BlobDataBuilder("blob-id:myblob")); |
| 232 blob_data->AppendData(expected_blob_data_); | 233 blob_data->AppendData(expected_blob_data_); |
| 233 | 234 |
| 234 blob_handle_ = | 235 blob_handle_ = |
| 235 blob_storage_context->context()->AddFinishedBlob(blob_data.get()); | 236 blob_storage_context->context()->AddFinishedBlob(*blob_data.get()); |
| 236 | 237 |
| 237 body_response_ = | 238 body_response_ = |
| 238 ServiceWorkerResponse(GURL("http://example.com/body.html"), | 239 ServiceWorkerResponse(GURL("http://example.com/body.html"), |
| 239 200, | 240 200, |
| 240 "OK", | 241 "OK", |
| 241 blink::WebServiceWorkerResponseTypeDefault, | 242 blink::WebServiceWorkerResponseTypeDefault, |
| 242 headers, | 243 headers, |
| 243 blob_handle_->uuid(), | 244 blob_handle_->uuid(), |
| 244 expected_blob_data_.size(), | 245 expected_blob_data_.size(), |
| 245 GURL()); | 246 GURL()); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 } | 379 } |
| 379 | 380 |
| 380 void CloseCallback(base::RunLoop* run_loop) { | 381 void CloseCallback(base::RunLoop* run_loop) { |
| 381 EXPECT_FALSE(callback_closed_); | 382 EXPECT_FALSE(callback_closed_); |
| 382 callback_closed_ = true; | 383 callback_closed_ = true; |
| 383 if (run_loop) | 384 if (run_loop) |
| 384 run_loop->Quit(); | 385 run_loop->Quit(); |
| 385 } | 386 } |
| 386 | 387 |
| 387 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { | 388 void CopyBody(storage::BlobDataHandle* blob_handle, std::string* output) { |
| 388 storage::BlobData* data = blob_handle->data(); | 389 scoped_ptr<storage::BlobDataSnapshot> data = blob_handle->CreateSnapshot(); |
| 389 std::vector<storage::BlobData::Item> items = data->items(); | 390 const auto& items = data->items(); |
| 390 for (size_t i = 0, max = items.size(); i < max; ++i) | 391 for (const auto& item : items) { |
| 391 output->append(items[i].bytes(), items[i].length()); | 392 output->append(item->bytes(), item->length()); |
| 393 } |
| 392 } | 394 } |
| 393 | 395 |
| 394 bool VerifyKeys(const std::vector<std::string>& expected_keys) { | 396 bool VerifyKeys(const std::vector<std::string>& expected_keys) { |
| 395 if (expected_keys.size() != callback_strings_.size()) | 397 if (expected_keys.size() != callback_strings_.size()) |
| 396 return false; | 398 return false; |
| 397 | 399 |
| 398 std::set<std::string> found_set; | 400 std::set<std::string> found_set; |
| 399 for (int i = 0, max = callback_strings_.size(); i < max; ++i) | 401 for (int i = 0, max = callback_strings_.size(); i < max; ++i) |
| 400 found_set.insert(callback_strings_[i]); | 402 found_set.insert(callback_strings_[i]); |
| 401 | 403 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 EXPECT_TRUE(callback_closed_); | 908 EXPECT_TRUE(callback_closed_); |
| 907 | 909 |
| 908 VerifyAllOpsFail(); | 910 VerifyAllOpsFail(); |
| 909 } | 911 } |
| 910 | 912 |
| 911 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 913 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
| 912 ServiceWorkerCacheTestP, | 914 ServiceWorkerCacheTestP, |
| 913 ::testing::Values(false, true)); | 915 ::testing::Values(false, true)); |
| 914 | 916 |
| 915 } // namespace content | 917 } // namespace content |
| OLD | NEW |