Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: webkit/media/cache_util_unittest.cc

Issue 10387200: Suppress pause-and-buffer behavior when the HTTP response won't satisfy future requests via cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Extracted GetReasonsForUncacheability and added tests. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 struct GTFUTestCase {
scherkus (not reviewing) 2012/05/23 01:16:03 does GTFU mean "Get Treasons For Uncacheability"?
Ami GONE FROM CHROMIUM 2012/05/23 01:27:28 s/Treasons/Reasons/ Yes.
rvargas (doing something else) 2012/05/23 02:04:12 ?
Ami GONE FROM CHROMIUM 2012/05/23 03:55:23 Oops, renamed & doco'd.
22 WebURLResponse::HTTPVersion version;
23 int status_code;
24 const char* headers;
25 const char* expected_reasons;
26 };
27
28 // Create a new WebURLResponse object.
29 static WebURLResponse CreateResponse(const GTFUTestCase& test) {
30 WebURLResponse response;
31 response.initialize();
32 response.setHTTPVersion(test.version);
33 response.setHTTPStatusCode(test.status_code);
34 std::vector<std::string> lines;
35 Tokenize(test.headers, "\n", &lines);
36 for (size_t i = 0; i < lines.size(); ++i) {
37 size_t colon = lines[i].find(": ");
38 response.addHTTPHeaderField(
39 WebString::fromUTF8(lines[i].substr(0, colon)),
40 WebString::fromUTF8(lines[i].substr(colon + 2)));
41 }
42 return response;
43 }
44
45 TEST(CacheUtilTest, GetReasonsForUncacheability) {
46 const GTFUTestCase tests[] = {
47 {
48 WebURLResponse::HTTP_1_1, 206, "ETag: 'fooblort'", ""
49 },
50 {
51 WebURLResponse::HTTP_1_1, 206, "", "3"
52 },
53 {
54 WebURLResponse::HTTP_1_0, 206, "", "2,3"
55 },
56 {
57 WebURLResponse::HTTP_1_1, 200, "cache-control: max-age=42", "4"
58 },
59 {
60 WebURLResponse::HTTP_1_1, 200,
61 "Date: Tue, 22 May 2012 23:46:08 GMT\n"
62 "Expires: Tue, 22 May 2012 23:56:08 GMT", "5"
63 },
64 {
65 WebURLResponse::HTTP_1_1, 200, "cache-control: must-revalidate", "6"
66 },
67 {
68 WebURLResponse::HTTP_1_1, 200, "cache-control: no-cache", "7"
69 },
70 {
71 WebURLResponse::HTTP_1_1, 200, "cache-control: no-store", "8"
72 },
73 {
74 WebURLResponse::HTTP_1_1, 200,
75 "cache-control: no-cache\ncache-control: no-store", "7,8"
76 },
77 };
78 for (size_t i = 0; i < arraysize(tests); ++i) {
79 SCOPED_TRACE(StringPrintf("case: %zu, version: %d, code: %d, headers: %s",
80 i, tests[i].version, tests[i].status_code,
81 tests[i].headers));
82 std::vector<UncacheableReason> reasons =
83 GetReasonsForUncacheability(CreateResponse(tests[i]));
84 std::string reasons_str;
85 for (size_t r = 0; r < reasons.size(); ++r) {
86 reasons_str.append(base::IntToString(reasons[r]));
87 if (r + 1 < reasons.size())
88 reasons_str.append(",");
89 }
90 EXPECT_EQ(tests[i].expected_reasons, reasons_str);
91 }
92 }
93
94 } // namespace webkit_media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698