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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 response.headers, | 139 response.headers, |
140 response.blob_uuid)); | 140 response.blob_uuid)); |
141 } | 141 } |
142 | 142 |
143 bool Put(const ServiceWorkerFetchRequest& request, | 143 bool Put(const ServiceWorkerFetchRequest& request, |
144 const ServiceWorkerResponse& response) { | 144 const ServiceWorkerResponse& response) { |
145 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 145 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
146 | 146 |
147 cache_->Put(CopyFetchRequest(request), | 147 cache_->Put(CopyFetchRequest(request), |
148 CopyFetchResponse(response), | 148 CopyFetchResponse(response), |
149 base::Bind(&ServiceWorkerCacheTest::ErrorTypeCallback, | 149 base::Bind(&ServiceWorkerCacheTest::ResponseAndErrorCallback, |
150 base::Unretained(this), | 150 base::Unretained(this), |
151 base::Unretained(loop.get()))); | 151 base::Unretained(loop.get()))); |
152 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() | 152 // TODO(jkarlin): These functions should use base::RunLoop().RunUntilIdle() |
153 // once the cache uses a passed in MessageLoopProxy instead of the CACHE | 153 // once the cache uses a passed in MessageLoopProxy instead of the CACHE |
154 // thread. | 154 // thread. |
155 loop->Run(); | 155 loop->Run(); |
156 | 156 |
157 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; | 157 return callback_error_ == ServiceWorkerCache::ErrorTypeOK; |
158 } | 158 } |
159 | 159 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 std::vector<std::string> callback_strings_; | 270 std::vector<std::string> callback_strings_; |
271 }; | 271 }; |
272 | 272 |
273 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest, | 273 class ServiceWorkerCacheTestP : public ServiceWorkerCacheTest, |
274 public testing::WithParamInterface<bool> { | 274 public testing::WithParamInterface<bool> { |
275 virtual bool MemoryOnly() OVERRIDE { return !GetParam(); } | 275 virtual bool MemoryOnly() OVERRIDE { return !GetParam(); } |
276 }; | 276 }; |
277 | 277 |
278 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { | 278 TEST_P(ServiceWorkerCacheTestP, PutNoBody) { |
279 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 279 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
| 280 EXPECT_TRUE(callback_response_); |
| 281 EXPECT_STREQ(no_body_response_.url.spec().c_str(), |
| 282 callback_response_->url.spec().c_str()); |
| 283 EXPECT_FALSE(callback_response_data_); |
280 } | 284 } |
281 | 285 |
282 TEST_P(ServiceWorkerCacheTestP, PutBody) { | 286 TEST_P(ServiceWorkerCacheTestP, PutBody) { |
283 EXPECT_TRUE(Put(body_request_, body_response_)); | 287 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 288 EXPECT_TRUE(callback_response_); |
| 289 EXPECT_STREQ(body_response_.url.spec().c_str(), |
| 290 callback_response_->url.spec().c_str()); |
| 291 EXPECT_TRUE(callback_response_data_); |
| 292 std::string response_body; |
| 293 CopyBody(callback_response_data_.get(), &response_body); |
| 294 EXPECT_STREQ(expected_blob_data_.c_str(), response_body.c_str()); |
284 } | 295 } |
285 | 296 |
286 TEST_F(ServiceWorkerCacheTest, PutBodyDropBlobRef) { | 297 TEST_F(ServiceWorkerCacheTest, PutBodyDropBlobRef) { |
287 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); | 298 scoped_ptr<base::RunLoop> loop(new base::RunLoop()); |
288 cache_->Put(CopyFetchRequest(body_request_), | 299 cache_->Put(CopyFetchRequest(body_request_), |
289 CopyFetchResponse(body_response_), | 300 CopyFetchResponse(body_response_), |
290 base::Bind(&ServiceWorkerCacheTestP::ErrorTypeCallback, | 301 base::Bind(&ServiceWorkerCacheTestP::ResponseAndErrorCallback, |
291 base::Unretained(this), | 302 base::Unretained(this), |
292 base::Unretained(loop.get()))); | 303 base::Unretained(loop.get()))); |
293 // The handle should be held by the cache now so the deref here should be | 304 // The handle should be held by the cache now so the deref here should be |
294 // okay. | 305 // okay. |
295 blob_handle_.reset(); | 306 blob_handle_.reset(); |
296 loop->Run(); | 307 loop->Run(); |
297 | 308 |
298 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); | 309 EXPECT_EQ(ServiceWorkerCache::ErrorTypeOK, callback_error_); |
299 } | 310 } |
300 | 311 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 request.headers["content-type"] = "foo"; | 490 request.headers["content-type"] = "foo"; |
480 request.headers["Content-Type"] = "bar"; | 491 request.headers["Content-Type"] = "bar"; |
481 EXPECT_EQ("bar", request.headers["content-type"]); | 492 EXPECT_EQ("bar", request.headers["content-type"]); |
482 } | 493 } |
483 | 494 |
484 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 495 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
485 ServiceWorkerCacheTestP, | 496 ServiceWorkerCacheTestP, |
486 ::testing::Values(false, true)); | 497 ::testing::Values(false, true)); |
487 | 498 |
488 } // namespace content | 499 } // namespace content |
OLD | NEW |