OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/http/http_response_headers.h" | 9 #include "net/http/http_response_headers.h" |
10 #include "net/http/http_version.h" | 10 #include "net/http/http_version.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 GURL("bogus"), &mime_type, &charset, &data, headers.get())); | 56 GURL("bogus"), &mime_type, &charset, &data, headers.get())); |
57 } | 57 } |
58 | 58 |
59 TEST(BuildResponseTest, InvalidMimeType) { | 59 TEST(BuildResponseTest, InvalidMimeType) { |
60 std::string mime_type; | 60 std::string mime_type; |
61 std::string charset; | 61 std::string charset; |
62 std::string data; | 62 std::string data; |
63 scoped_refptr<net::HttpResponseHeaders> headers( | 63 scoped_refptr<net::HttpResponseHeaders> headers( |
64 new net::HttpResponseHeaders(std::string())); | 64 new net::HttpResponseHeaders(std::string())); |
65 | 65 |
66 // MIME type contains delimiters. Must be rejected. | 66 // MIME type contains delimiters. Must be accepted but Content-Type header |
| 67 // should be generated as if the mediatype was text/plain. |
67 EXPECT_EQ( | 68 EXPECT_EQ( |
68 net::ERR_INVALID_URL, | 69 net::OK, |
69 URLRequestDataJob::BuildResponse( | 70 URLRequestDataJob::BuildResponse( |
70 GURL("data:f(o/b)r,test"), | 71 GURL("data:f(o/b)r,test"), |
71 &mime_type, &charset, &data, headers.get())); | 72 &mime_type, &charset, &data, headers.get())); |
| 73 |
| 74 std::string value; |
| 75 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value)); |
| 76 EXPECT_EQ(value, "text/plain;charset=US-ASCII"); |
72 } | 77 } |
73 | 78 |
74 TEST(BuildResponseTest, InvalidCharset) { | 79 TEST(BuildResponseTest, InvalidCharset) { |
75 std::string mime_type; | 80 std::string mime_type; |
76 std::string charset; | 81 std::string charset; |
77 std::string data; | 82 std::string data; |
78 scoped_refptr<net::HttpResponseHeaders> headers( | 83 scoped_refptr<net::HttpResponseHeaders> headers( |
79 new net::HttpResponseHeaders(std::string())); | 84 new net::HttpResponseHeaders(std::string())); |
80 | 85 |
81 // MIME type contains delimiters. Must be rejected. | 86 // MIME type contains delimiters. Must be rejected. |
82 EXPECT_EQ( | 87 EXPECT_EQ( |
83 net::ERR_INVALID_URL, | 88 net::ERR_INVALID_URL, |
84 URLRequestDataJob::BuildResponse( | 89 URLRequestDataJob::BuildResponse( |
85 GURL("data:text/html;charset=(),test"), | 90 GURL("data:text/html;charset=(),test"), |
86 &mime_type, &charset, &data, headers.get())); | 91 &mime_type, &charset, &data, headers.get())); |
87 } | 92 } |
88 | 93 |
89 } // namespace net | 94 } // namespace net |
OLD | NEW |