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

Unified 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: indent-to-first-paren 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/media/cache_util.cc ('k') | webkit/media/webkit_media.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/media/cache_util_unittest.cc
diff --git a/webkit/media/cache_util_unittest.cc b/webkit/media/cache_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d365a2309359210101f28393ed41bcf11d801f7
--- /dev/null
+++ b/webkit/media/cache_util_unittest.cc
@@ -0,0 +1,95 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/media/cache_util.h"
+
+#include <string>
+
+#include "base/stringprintf.h"
+#include "base/string_number_conversions.h"
+#include "base/string_util.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLResponse.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using WebKit::WebString;
+using WebKit::WebURLResponse;
+
+namespace webkit_media {
+
+// Inputs & expected output for GetReasonsForUncacheability.
+struct GRFUTestCase {
+ WebURLResponse::HTTPVersion version;
+ int status_code;
+ const char* headers;
+ const char* expected_reasons;
+};
+
+// Create a new WebURLResponse object.
+static WebURLResponse CreateResponse(const GRFUTestCase& test) {
+ WebURLResponse response;
+ response.initialize();
+ response.setHTTPVersion(test.version);
+ response.setHTTPStatusCode(test.status_code);
+ std::vector<std::string> lines;
+ Tokenize(test.headers, "\n", &lines);
+ for (size_t i = 0; i < lines.size(); ++i) {
+ size_t colon = lines[i].find(": ");
+ response.addHTTPHeaderField(
+ WebString::fromUTF8(lines[i].substr(0, colon)),
+ WebString::fromUTF8(lines[i].substr(colon + 2)));
+ }
+ return response;
+}
+
+TEST(CacheUtilTest, GetReasonsForUncacheability) {
+ const GRFUTestCase tests[] = {
+ {
+ WebURLResponse::HTTP_1_1, 206, "ETag: 'fooblort'", ""
+ },
+ {
+ WebURLResponse::HTTP_1_1, 206, "", "3"
+ },
+ {
+ WebURLResponse::HTTP_1_0, 206, "", "2,3"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200, "cache-control: max-age=42", "4"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200,
+ "Date: Tue, 22 May 2012 23:46:08 GMT\n"
+ "Expires: Tue, 22 May 2012 23:56:08 GMT", "5"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200, "cache-control: must-revalidate", "6"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200, "cache-control: no-cache", "7"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200, "cache-control: no-store", "8"
+ },
+ {
+ WebURLResponse::HTTP_1_1, 200,
+ "cache-control: no-cache\ncache-control: no-store", "7,8"
+ },
+ };
+ for (size_t i = 0; i < arraysize(tests); ++i) {
+ SCOPED_TRACE(StringPrintf("case: %zu, version: %d, code: %d, headers: %s",
+ i, tests[i].version, tests[i].status_code,
+ tests[i].headers));
+ 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
+ GetReasonsForUncacheability(CreateResponse(tests[i]));
+ std::string reasons_str;
+ for (size_t r = 0; r < reasons.size(); ++r) {
+ reasons_str.append(base::IntToString(reasons[r]));
+ if (r + 1 < reasons.size())
+ reasons_str.append(",");
+ }
+ EXPECT_EQ(tests[i].expected_reasons, reasons_str);
+ }
+}
+
+} // namespace webkit_media
« no previous file with comments | « webkit/media/cache_util.cc ('k') | webkit/media/webkit_media.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698