OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 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 "content/child/web_url_loader_impl.h" |
| 6 #include "net/base/net_errors.h" |
| 7 #include "net/http/http_response_headers.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" |
| 10 #include "webkit/common/resource_response_info.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 TEST(GetInfoFromDataURLTest, Simple) { |
| 15 webkit_glue::ResourceResponseInfo info; |
| 16 std::string data; |
| 17 int error_code; |
| 18 GetInfoFromDataURL(GURL("data:,Hello"), &info, &data, &error_code); |
| 19 |
| 20 ASSERT_EQ(net::OK, error_code); |
| 21 |
| 22 EXPECT_EQ("Hello", data); |
| 23 |
| 24 EXPECT_FALSE(info.load_timing.request_start.is_null()); |
| 25 EXPECT_FALSE(info.load_timing.request_start_time.is_null()); |
| 26 EXPECT_FALSE(info.request_time.is_null()); |
| 27 EXPECT_FALSE(info.response_time.is_null()); |
| 28 |
| 29 scoped_refptr<net::HttpResponseHeaders> headers = info.headers; |
| 30 const net::HttpVersion& version = headers->GetParsedHttpVersion(); |
| 31 EXPECT_EQ(1, version.major_value()); |
| 32 EXPECT_EQ(1, version.minor_value()); |
| 33 EXPECT_EQ("OK", headers->GetStatusText()); |
| 34 std::string value; |
| 35 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value)); |
| 36 EXPECT_EQ(value, "text/plain;charset=US-ASCII"); |
| 37 value.clear(); |
| 38 EXPECT_TRUE( |
| 39 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value)); |
| 40 EXPECT_EQ(value, "*"); |
| 41 EXPECT_TRUE( |
| 42 headers->GetNormalizedHeader("Access-Control-Allow-Credentials", &value)); |
| 43 EXPECT_EQ(value, "true"); |
| 44 |
| 45 EXPECT_EQ("text/plain", info.mime_type); |
| 46 EXPECT_EQ("US-ASCII", info.charset); |
| 47 EXPECT_TRUE(info.security_info.empty()); |
| 48 EXPECT_EQ(5, info.content_length); |
| 49 EXPECT_EQ(0, info.encoded_data_length); |
| 50 } |
| 51 |
| 52 TEST(GetInfoFromDataURLTest, InvalidInput) { |
| 53 webkit_glue::ResourceResponseInfo info; |
| 54 std::string data; |
| 55 int error_code; |
| 56 GetInfoFromDataURL(GURL("bogus"), &info, &data, &error_code); |
| 57 EXPECT_EQ(net::ERR_INVALID_URL, error_code); |
| 58 } |
| 59 |
| 60 TEST(GetInfoFromDataURLTest, InvalidMimeType) { |
| 61 webkit_glue::ResourceResponseInfo info; |
| 62 std::string data; |
| 63 int error_code; |
| 64 // MIME type contains delimiters. Must be rejected. |
| 65 GetInfoFromDataURL(GURL("data:f(o/b)r,test"), &info, &data, &error_code); |
| 66 EXPECT_EQ(net::ERR_INVALID_URL, error_code); |
| 67 } |
| 68 |
| 69 TEST(GetInfoFromDataURLTest, InvalidCharset) { |
| 70 webkit_glue::ResourceResponseInfo info; |
| 71 std::string data; |
| 72 int error_code; |
| 73 // MIME type contains delimiters. Must be rejected. |
| 74 GetInfoFromDataURL( |
| 75 GURL("data:text/html;charset=(),test"), &info, &data, &error_code); |
| 76 EXPECT_EQ(net::ERR_INVALID_URL, error_code); |
| 77 } |
| 78 |
| 79 } // namespace content |
OLD | NEW |