Chromium Code Reviews| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 GetMockResponse(request->url().path(), &headers, &body); | 71 GetMockResponse(request->url().path(), &headers, &body); |
| 72 return new net::URLRequestTestJob( | 72 return new net::URLRequestTestJob( |
| 73 request, network_delegate, headers, body, true); | 73 request, network_delegate, headers, body, true); |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 static void GetMockResponse(const std::string& path, | 77 static void GetMockResponse(const std::string& path, |
| 78 std::string* headers, | 78 std::string* headers, |
| 79 std::string* body) { | 79 std::string* body) { |
| 80 const char ok_headers[] = | 80 const char ok_headers[] = |
| 81 "HTTP/1.1 200 OK\0" | 81 "HTTP/1.1 200 OK\n" |
| 82 "\0"; | 82 "\n"; |
| 83 const char error_headers[] = | 83 const char error_headers[] = |
| 84 "HTTP/1.1 500 BOO HOO\0" | 84 "HTTP/1.1 500 BOO HOO\n" |
| 85 "\0"; | 85 "\n"; |
| 86 const char manifest_headers[] = | 86 const char manifest_headers[] = |
| 87 "HTTP/1.1 200 OK\0" | 87 "HTTP/1.1 200 OK\n" |
| 88 "Content-type: text/cache-manifest\0" | 88 "Content-type: text/cache-manifest\n" |
| 89 "\0"; | 89 "\n"; |
| 90 const char not_modified_headers[] = | 90 const char not_modified_headers[] = |
| 91 "HTTP/1.1 304 NOT MODIFIED\0" | 91 "HTTP/1.1 304 NOT MODIFIED\n" |
| 92 "\0"; | 92 "\n"; |
| 93 const char gone_headers[] = | 93 const char gone_headers[] = |
| 94 "HTTP/1.1 410 GONE\0" | 94 "HTTP/1.1 410 GONE\n" |
| 95 "\0"; | 95 "\n"; |
| 96 const char not_found_headers[] = | 96 const char not_found_headers[] = |
| 97 "HTTP/1.1 404 NOT FOUND\0" | 97 "HTTP/1.1 404 NOT FOUND\n" |
| 98 "\0"; | 98 "\n"; |
| 99 const char no_store_headers[] = | 99 const char no_store_headers[] = |
| 100 "HTTP/1.1 200 OK\0" | 100 "HTTP/1.1 200 OK\n" |
| 101 "Cache-Control: no-store\0" | 101 "Cache-Control: no-store\n" |
| 102 "\0"; | 102 "\n"; |
| 103 | 103 |
| 104 if (path == "/files/missing-mime-manifest") { | 104 if (path == "/files/missing-mime-manifest") { |
| 105 (*headers) = std::string(ok_headers, arraysize(ok_headers)); | 105 (*headers) = std::string(ok_headers, arraysize(ok_headers)); |
| 106 (*body) = "CACHE MANIFEST\n"; | 106 (*body) = "CACHE MANIFEST\n"; |
| 107 } else if (path == "/files/bad-manifest") { | 107 } else if (path == "/files/bad-manifest") { |
| 108 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); | 108 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); |
| 109 (*body) = "BAD CACHE MANIFEST"; | 109 (*body) = "BAD CACHE MANIFEST"; |
| 110 } else if (path == "/files/empty1") { | 110 } else if (path == "/files/empty1") { |
| 111 (*headers) = std::string(ok_headers, arraysize(ok_headers)); | 111 (*headers) = std::string(ok_headers, arraysize(ok_headers)); |
| 112 (*body) = ""; | 112 (*body) = ""; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 } | 403 } |
| 404 } | 404 } |
| 405 | 405 |
| 406 int GetResponseCode() const override { return response_code_; } | 406 int GetResponseCode() const override { return response_code_; } |
| 407 | 407 |
| 408 private: | 408 private: |
| 409 ~RetryRequestTestJob() override {} | 409 ~RetryRequestTestJob() override {} |
| 410 | 410 |
| 411 static std::string retry_headers() { | 411 static std::string retry_headers() { |
| 412 const char no_retry_after[] = | 412 const char no_retry_after[] = |
| 413 "HTTP/1.1 503 BOO HOO\0" | 413 "HTTP/1.1 503 BOO HOO\n" |
| 414 "\0"; | 414 "\n"; |
| 415 const char nonzero[] = | 415 const char nonzero[] = |
| 416 "HTTP/1.1 503 BOO HOO\0" | 416 "HTTP/1.1 503 BOO HOO\n" |
| 417 "Retry-After: 60\0" | 417 "Retry-After: 60\n" |
| 418 "\0"; | 418 "\n"; |
| 419 const char retry_after_0[] = | 419 const char retry_after_0[] = |
| 420 "HTTP/1.1 503 BOO HOO\0" | 420 "HTTP/1.1 503 BOO HOO\n" |
| 421 "Retry-After: 0\0" | 421 "Retry-After: 0\n" |
| 422 "\0"; | 422 "\n"; |
| 423 | 423 |
| 424 switch (retry_after_) { | 424 switch (retry_after_) { |
| 425 case NO_RETRY_AFTER: | 425 case NO_RETRY_AFTER: |
| 426 return std::string(no_retry_after, arraysize(no_retry_after)); | 426 return std::string(no_retry_after, arraysize(no_retry_after)); |
| 427 case NONZERO_RETRY_AFTER: | 427 case NONZERO_RETRY_AFTER: |
| 428 return std::string(nonzero, arraysize(nonzero)); | 428 return std::string(nonzero, arraysize(nonzero)); |
| 429 case RETRY_AFTER_0: | 429 case RETRY_AFTER_0: |
| 430 default: | 430 default: |
| 431 return std::string(retry_after_0, arraysize(retry_after_0)); | 431 return std::string(retry_after_0, arraysize(retry_after_0)); |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 | 434 |
| 435 static std::string manifest_headers() { | 435 static std::string manifest_headers() { |
| 436 const char headers[] = | 436 const char headers[] = |
| 437 "HTTP/1.1 200 OK\0" | 437 "HTTP/1.1 200 OK\r\n" |
| 438 "Content-type: text/cache-manifest\0" | 438 "Content-type: text/cache-manifest\r\n" |
| 439 "\0"; | 439 "\r\n"; |
|
mmenke
2015/10/27 16:49:31
\n for consistency?
martijnc
2015/10/27 21:10:15
Done.
| |
| 440 return std::string(headers, arraysize(headers)); | 440 return std::string(headers, arraysize(headers)); |
| 441 } | 441 } |
| 442 | 442 |
| 443 static std::string data() { | 443 static std::string data() { |
| 444 return std::string("CACHE MANIFEST\r" | 444 return std::string("CACHE MANIFEST\r" |
| 445 "http://retry\r"); // must be same as kRetryUrl | 445 "http://retry\r"); // must be same as kRetryUrl |
| 446 } | 446 } |
| 447 | 447 |
| 448 RetryRequestTestJob(net::URLRequest* request, | 448 RetryRequestTestJob(net::URLRequest* request, |
| 449 net::NetworkDelegate* network_delegate, | 449 net::NetworkDelegate* network_delegate, |
| (...skipping 3271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3721 | 3721 |
| 3722 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3722 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
| 3723 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3723 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
| 3724 } | 3724 } |
| 3725 | 3725 |
| 3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
| 3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
| 3728 } | 3728 } |
| 3729 | 3729 |
| 3730 } // namespace content | 3730 } // namespace content |
| OLD | NEW |