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

Unified Diff: content/child/web_url_loader_impl_unittest.cc

Issue 54233002: Make net::DataURL's MIME string check stricter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
Index: content/child/web_url_loader_impl_unittest.cc
diff --git a/content/child/web_url_loader_impl_unittest.cc b/content/child/web_url_loader_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fb0cd76f0df2efccc8ad7a3c4c7e7d73595577cd
--- /dev/null
+++ b/content/child/web_url_loader_impl_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2014 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 "content/child/web_url_loader_impl.h"
+#include "net/base/net_errors.h"
+#include "net/http/http_response_headers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+#include "webkit/common/resource_response_info.h"
+
+namespace content {
+
+TEST(GetInfoFromDataURLTest, Simple) {
+ webkit_glue::ResourceResponseInfo info;
+ std::string data;
+ int error_code;
+ GetInfoFromDataURL(GURL("data:,Hello"), &info, &data, &error_code);
+
+ ASSERT_EQ(net::OK, error_code);
+
+ EXPECT_EQ("Hello", data);
+
+ EXPECT_FALSE(info.load_timing.request_start.is_null());
+ EXPECT_FALSE(info.load_timing.request_start_time.is_null());
+ EXPECT_FALSE(info.request_time.is_null());
+ EXPECT_FALSE(info.response_time.is_null());
+
+ scoped_refptr<net::HttpResponseHeaders> headers = info.headers;
+ const net::HttpVersion& version = headers->GetParsedHttpVersion();
+ EXPECT_EQ(1, version.major_value());
+ EXPECT_EQ(1, version.minor_value());
+ EXPECT_EQ("OK", headers->GetStatusText());
+ std::string value;
+ EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
+ EXPECT_EQ(value, "text/plain;charset=US-ASCII");
+ value.clear();
+ EXPECT_TRUE(
+ headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
+ EXPECT_EQ(value, "*");
+ EXPECT_TRUE(
+ headers->GetNormalizedHeader("Access-Control-Allow-Credentials", &value));
+ EXPECT_EQ(value, "true");
+
+ EXPECT_EQ("text/plain", info.mime_type);
+ EXPECT_EQ("US-ASCII", info.charset);
+ EXPECT_TRUE(info.security_info.empty());
+ EXPECT_EQ(5, info.content_length);
+ EXPECT_EQ(0, info.encoded_data_length);
+}
+
+TEST(GetInfoFromDataURLTest, InvalidInput) {
+ webkit_glue::ResourceResponseInfo info;
+ std::string data;
+ int error_code;
+ GetInfoFromDataURL(GURL("bogus"), &info, &data, &error_code);
+ EXPECT_EQ(net::ERR_INVALID_URL, error_code);
+}
+
+TEST(GetInfoFromDataURLTest, InvalidMimeType) {
+ webkit_glue::ResourceResponseInfo info;
+ std::string data;
+ int error_code;
+ // MIME type contains delimiters. Must be rejected.
+ GetInfoFromDataURL(GURL("data:f(o/b)r,test"), &info, &data, &error_code);
+ EXPECT_EQ(net::ERR_INVALID_URL, error_code);
+}
+
+TEST(GetInfoFromDataURLTest, InvalidCharset) {
+ webkit_glue::ResourceResponseInfo info;
+ std::string data;
+ int error_code;
+ // MIME type contains delimiters. Must be rejected.
+ GetInfoFromDataURL(
+ GURL("data:text/html;charset=(),test"), &info, &data, &error_code);
+ EXPECT_EQ(net::ERR_INVALID_URL, error_code);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698