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 |