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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 EXPECT_TRUE(Match(body_request_)); | 312 EXPECT_TRUE(Match(body_request_)); |
313 EXPECT_EQ(200, callback_response_->status_code); | 313 EXPECT_EQ(200, callback_response_->status_code); |
314 EXPECT_STREQ("OK", callback_response_->status_text.c_str()); | 314 EXPECT_STREQ("OK", callback_response_->status_text.c_str()); |
315 EXPECT_STREQ("http://example.com/body.html", | 315 EXPECT_STREQ("http://example.com/body.html", |
316 callback_response_->url.spec().c_str()); | 316 callback_response_->url.spec().c_str()); |
317 std::string response_body; | 317 std::string response_body; |
318 CopyBody(callback_response_data_.get(), &response_body); | 318 CopyBody(callback_response_data_.get(), &response_body); |
319 EXPECT_STREQ(expected_blob_data_.c_str(), response_body.c_str()); | 319 EXPECT_STREQ(expected_blob_data_.c_str(), response_body.c_str()); |
320 } | 320 } |
321 | 321 |
| 322 TEST_P(ServiceWorkerCacheTestP, Vary) { |
| 323 body_request_.headers["vary_foo"] = "foo"; |
| 324 body_response_.headers["vary"] = "vary_foo"; |
| 325 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 326 EXPECT_TRUE(Match(body_request_)); |
| 327 |
| 328 body_request_.headers["vary_foo"] = "bar"; |
| 329 EXPECT_FALSE(Match(body_request_)); |
| 330 |
| 331 body_request_.headers.erase("vary_foo"); |
| 332 EXPECT_FALSE(Match(body_request_)); |
| 333 } |
| 334 |
| 335 TEST_P(ServiceWorkerCacheTestP, NoVaryButDiffHeaders) { |
| 336 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 337 EXPECT_TRUE(Match(body_request_)); |
| 338 |
| 339 body_request_.headers["zoo"] = "zoo"; |
| 340 EXPECT_TRUE(Match(body_request_)); |
| 341 } |
| 342 |
| 343 TEST_P(ServiceWorkerCacheTestP, VaryMultiple) { |
| 344 body_request_.headers["vary_foo"] = "foo"; |
| 345 body_request_.headers["vary_bar"] = "bar"; |
| 346 body_response_.headers["vary"] = " vary_foo , vary_bar"; |
| 347 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 348 EXPECT_TRUE(Match(body_request_)); |
| 349 |
| 350 body_request_.headers["vary_bar"] = "foo"; |
| 351 EXPECT_FALSE(Match(body_request_)); |
| 352 |
| 353 body_request_.headers.erase("vary_bar"); |
| 354 EXPECT_FALSE(Match(body_request_)); |
| 355 } |
| 356 |
| 357 TEST_P(ServiceWorkerCacheTestP, VaryNewHeader) { |
| 358 body_request_.headers["vary_foo"] = "foo"; |
| 359 body_response_.headers["vary"] = " vary_foo, vary_bar"; |
| 360 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 361 EXPECT_TRUE(Match(body_request_)); |
| 362 |
| 363 body_request_.headers["vary_bar"] = "bar"; |
| 364 EXPECT_FALSE(Match(body_request_)); |
| 365 } |
| 366 |
| 367 TEST_P(ServiceWorkerCacheTestP, VaryStar) { |
| 368 body_response_.headers["vary"] = "*"; |
| 369 EXPECT_TRUE(Put(body_request_, body_response_)); |
| 370 EXPECT_FALSE(Match(body_request_)); |
| 371 } |
| 372 |
322 TEST_P(ServiceWorkerCacheTestP, EmptyKeys) { | 373 TEST_P(ServiceWorkerCacheTestP, EmptyKeys) { |
323 EXPECT_TRUE(Keys()); | 374 EXPECT_TRUE(Keys()); |
324 EXPECT_EQ(0u, callback_strings_.size()); | 375 EXPECT_EQ(0u, callback_strings_.size()); |
325 } | 376 } |
326 | 377 |
327 TEST_P(ServiceWorkerCacheTestP, TwoKeys) { | 378 TEST_P(ServiceWorkerCacheTestP, TwoKeys) { |
328 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); | 379 EXPECT_TRUE(Put(no_body_request_, no_body_response_)); |
329 EXPECT_TRUE(Put(body_request_, body_response_)); | 380 EXPECT_TRUE(Put(body_request_, body_response_)); |
330 EXPECT_TRUE(Keys()); | 381 EXPECT_TRUE(Keys()); |
331 EXPECT_EQ(2u, callback_strings_.size()); | 382 EXPECT_EQ(2u, callback_strings_.size()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 ASSERT_TRUE(Delete(body_request_)); | 447 ASSERT_TRUE(Delete(body_request_)); |
397 } | 448 } |
398 } | 449 } |
399 #endif // OS_WIN | 450 #endif // OS_WIN |
400 | 451 |
401 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, | 452 INSTANTIATE_TEST_CASE_P(ServiceWorkerCacheTest, |
402 ServiceWorkerCacheTestP, | 453 ServiceWorkerCacheTestP, |
403 ::testing::Values(false, true)); | 454 ::testing::Values(false, true)); |
404 | 455 |
405 } // namespace content | 456 } // namespace content |
OLD | NEW |