Chromium Code Reviews| 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 const char* 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 const GRFUTestCase tests[] = { | |
| 48 { | |
| 49 WebURLResponse::HTTP_1_1, 206, "ETag: 'fooblort'", "" | |
| 50 }, | |
| 51 { | |
| 52 WebURLResponse::HTTP_1_1, 206, "", "3" | |
| 53 }, | |
| 54 { | |
| 55 WebURLResponse::HTTP_1_0, 206, "", "2,3" | |
| 56 }, | |
| 57 { | |
| 58 WebURLResponse::HTTP_1_1, 200, "cache-control: max-age=42", "4" | |
| 59 }, | |
| 60 { | |
| 61 WebURLResponse::HTTP_1_1, 200, | |
| 62 "Date: Tue, 22 May 2012 23:46:08 GMT\n" | |
| 63 "Expires: Tue, 22 May 2012 23:56:08 GMT", "5" | |
| 64 }, | |
| 65 { | |
| 66 WebURLResponse::HTTP_1_1, 200, "cache-control: must-revalidate", "6" | |
| 67 }, | |
| 68 { | |
| 69 WebURLResponse::HTTP_1_1, 200, "cache-control: no-cache", "7" | |
| 70 }, | |
| 71 { | |
| 72 WebURLResponse::HTTP_1_1, 200, "cache-control: no-store", "8" | |
| 73 }, | |
| 74 { | |
| 75 WebURLResponse::HTTP_1_1, 200, | |
| 76 "cache-control: no-cache\ncache-control: no-store", "7,8" | |
| 77 }, | |
| 78 }; | |
| 79 for (size_t i = 0; i < arraysize(tests); ++i) { | |
| 80 SCOPED_TRACE(StringPrintf("case: %zu, version: %d, code: %d, headers: %s", | |
| 81 i, tests[i].version, tests[i].status_code, | |
| 82 tests[i].headers)); | |
| 83 std::vector<UncacheableReason> reasons = | |
|
darin (slow to review)
2012/05/23 20:35:01
just an observation, but if you instead defined th
Ami GONE FROM CHROMIUM
2012/05/23 21:36:50
True, but the reason I didn't do that is because t
| |
| 84 GetReasonsForUncacheability(CreateResponse(tests[i])); | |
| 85 std::string reasons_str; | |
| 86 for (size_t r = 0; r < reasons.size(); ++r) { | |
| 87 reasons_str.append(base::IntToString(reasons[r])); | |
| 88 if (r + 1 < reasons.size()) | |
| 89 reasons_str.append(","); | |
| 90 } | |
| 91 EXPECT_EQ(tests[i].expected_reasons, reasons_str); | |
| 92 } | |
| 93 } | |
| 94 | |
| 95 } // namespace webkit_media | |
| OLD | NEW |