| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/media/cache_util.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/stringprintf.h" |
| 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon
se.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 using WebKit::WebString; |
| 17 using WebKit::WebURLResponse; |
| 18 |
| 19 namespace webkit_media { |
| 20 |
| 21 // Inputs & expected output for GetReasonsForUncacheability. |
| 22 struct GRFUTestCase { |
| 23 WebURLResponse::HTTPVersion version; |
| 24 int status_code; |
| 25 const char* headers; |
| 26 uint32 expected_reasons; |
| 27 }; |
| 28 |
| 29 // Create a new WebURLResponse object. |
| 30 static WebURLResponse CreateResponse(const GRFUTestCase& test) { |
| 31 WebURLResponse response; |
| 32 response.initialize(); |
| 33 response.setHTTPVersion(test.version); |
| 34 response.setHTTPStatusCode(test.status_code); |
| 35 std::vector<std::string> lines; |
| 36 Tokenize(test.headers, "\n", &lines); |
| 37 for (size_t i = 0; i < lines.size(); ++i) { |
| 38 size_t colon = lines[i].find(": "); |
| 39 response.addHTTPHeaderField( |
| 40 WebString::fromUTF8(lines[i].substr(0, colon)), |
| 41 WebString::fromUTF8(lines[i].substr(colon + 2))); |
| 42 } |
| 43 return response; |
| 44 } |
| 45 |
| 46 TEST(CacheUtilTest, GetReasonsForUncacheability) { |
| 47 enum { kNoReasons = 0 }; |
| 48 |
| 49 const GRFUTestCase tests[] = { |
| 50 { |
| 51 WebURLResponse::HTTP_1_1, 206, "ETag: 'fooblort'", kNoReasons |
| 52 }, |
| 53 { |
| 54 WebURLResponse::HTTP_1_1, 206, "", kNoStrongValidatorOnPartialResponse |
| 55 }, |
| 56 { |
| 57 WebURLResponse::HTTP_1_0, 206, "", |
| 58 kPre11PartialResponse | kNoStrongValidatorOnPartialResponse |
| 59 }, |
| 60 { |
| 61 WebURLResponse::HTTP_1_1, 200, "cache-control: max-age=42", kShortMaxAge |
| 62 }, |
| 63 { |
| 64 WebURLResponse::HTTP_1_1, 200, |
| 65 "Date: Tue, 22 May 2012 23:46:08 GMT\n" |
| 66 "Expires: Tue, 22 May 2012 23:56:08 GMT", kExpiresTooSoon |
| 67 }, |
| 68 { |
| 69 WebURLResponse::HTTP_1_1, 200, "cache-control: must-revalidate", |
| 70 kHasMustRevalidate |
| 71 }, |
| 72 { |
| 73 WebURLResponse::HTTP_1_1, 200, "cache-control: no-cache", kNoCache |
| 74 }, |
| 75 { |
| 76 WebURLResponse::HTTP_1_1, 200, "cache-control: no-store", kNoStore |
| 77 }, |
| 78 { |
| 79 WebURLResponse::HTTP_1_1, 200, |
| 80 "cache-control: no-cache\ncache-control: no-store", kNoCache | kNoStore |
| 81 }, |
| 82 }; |
| 83 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 84 SCOPED_TRACE(StringPrintf("case: %zu, version: %d, code: %d, headers: %s", |
| 85 i, tests[i].version, tests[i].status_code, |
| 86 tests[i].headers)); |
| 87 std::vector<UncacheableReason> reasons = |
| 88 GetReasonsForUncacheability(CreateResponse(tests[i])); |
| 89 uint32 actual_reasons = 0; |
| 90 for (size_t r = 0; r < reasons.size(); ++r) |
| 91 actual_reasons |= reasons[r]; |
| 92 EXPECT_EQ(actual_reasons, tests[i].expected_reasons); |
| 93 } |
| 94 } |
| 95 |
| 96 } // namespace webkit_media |
| OLD | NEW |