[Mac] PepperFlash default on DEV channel.
[chromium-blink-merge.git] / webkit / media / cache_util_unittest.cc
blob808084aa03982b21d32dadf6171e5d4b2680c492
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.
5 #include "webkit/media/cache_util.h"
7 #include <string>
9 #include "base/format_macros.h"
10 #include "base/stringprintf.h"
11 #include "base/string_number_conversions.h"
12 #include "base/string_util.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 using WebKit::WebString;
18 using WebKit::WebURLResponse;
20 namespace webkit_media {
22 // Inputs & expected output for GetReasonsForUncacheability.
23 struct GRFUTestCase {
24 WebURLResponse::HTTPVersion version;
25 int status_code;
26 const char* headers;
27 uint32 expected_reasons;
30 // Create a new WebURLResponse object.
31 static WebURLResponse CreateResponse(const GRFUTestCase& test) {
32 WebURLResponse response;
33 response.initialize();
34 response.setHTTPVersion(test.version);
35 response.setHTTPStatusCode(test.status_code);
36 std::vector<std::string> lines;
37 Tokenize(test.headers, "\n", &lines);
38 for (size_t i = 0; i < lines.size(); ++i) {
39 size_t colon = lines[i].find(": ");
40 response.addHTTPHeaderField(
41 WebString::fromUTF8(lines[i].substr(0, colon)),
42 WebString::fromUTF8(lines[i].substr(colon + 2)));
44 return response;
47 TEST(CacheUtilTest, GetReasonsForUncacheability) {
48 enum { kNoReasons = 0 };
50 const GRFUTestCase tests[] = {
52 WebURLResponse::HTTP_1_1, 206, "ETag: 'fooblort'", kNoReasons
55 WebURLResponse::HTTP_1_1, 206, "", kNoStrongValidatorOnPartialResponse
58 WebURLResponse::HTTP_1_0, 206, "",
59 kPre11PartialResponse | kNoStrongValidatorOnPartialResponse
62 WebURLResponse::HTTP_1_1, 200, "cache-control: max-Age=42", kShortMaxAge
65 WebURLResponse::HTTP_1_1, 200, "cache-control: max-Age=4200", kNoReasons
68 WebURLResponse::HTTP_1_1, 200,
69 "Date: Tue, 22 May 2012 23:46:08 GMT\n"
70 "Expires: Tue, 22 May 2012 23:56:08 GMT", kExpiresTooSoon
73 WebURLResponse::HTTP_1_1, 200, "cache-control: must-revalidate",
74 kHasMustRevalidate
77 WebURLResponse::HTTP_1_1, 200, "cache-control: no-cache", kNoCache
80 WebURLResponse::HTTP_1_1, 200, "cache-control: no-store", kNoStore
83 WebURLResponse::HTTP_1_1, 200,
84 "cache-control: no-cache\ncache-control: no-store", kNoCache | kNoStore
87 for (size_t i = 0; i < arraysize(tests); ++i) {
88 SCOPED_TRACE(StringPrintf("case: %" PRIuS
89 ", version: %d, code: %d, headers: %s",
90 i, tests[i].version, tests[i].status_code,
91 tests[i].headers));
92 EXPECT_EQ(GetReasonsForUncacheability(CreateResponse(tests[i])),
93 tests[i].expected_reasons);
97 } // namespace webkit_media