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

Side by Side Diff: net/url_request/url_request_data_job_unittest.cc

Issue 294193002: Set response headers for data URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #include <string>
2
3 #include "base/memory/ref_counted.h"
4 #include "net/base/net_errors.h"
5 #include "net/http/http_response_headers.h"
6 #include "net/http/http_version.h"
7 #include "net/url_request/url_request_data_job.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
10
11 namespace net {
12
13 TEST(BuildResponseForDataURLTest, Simple) {
14 std::string mime_type;
15 std::string charset;
16 std::string data;
17 scoped_refptr<net::HttpResponseHeaders> headers(
18 new net::HttpResponseHeaders(std::string()));
19
20 ASSERT_EQ(
21 net::OK,
22 BuildResponseForDataURL(
23 GURL("data:,Hello"), &mime_type, &charset, &data, headers.get()));
24
25 EXPECT_EQ("text/plain", mime_type);
26 EXPECT_EQ("US-ASCII", charset);
27 EXPECT_EQ("Hello", data);
28
29 const net::HttpVersion& version = headers->GetParsedHttpVersion();
30 EXPECT_EQ(1, version.major_value());
31 EXPECT_EQ(1, version.minor_value());
32 EXPECT_EQ("OK", headers->GetStatusText());
33 std::string value;
34 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
35 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
36 value.clear();
37 EXPECT_TRUE(
38 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
39 EXPECT_EQ(value, "*");
40 }
41
42 TEST(BuildResponseForDataURLTest, InvalidInput) {
43 std::string mime_type;
44 std::string charset;
45 std::string data;
46 scoped_refptr<net::HttpResponseHeaders> headers(
47 new net::HttpResponseHeaders(std::string()));
48
49 EXPECT_EQ(
50 net::ERR_INVALID_URL,
51 BuildResponseForDataURL(
52 GURL("bogus"), &mime_type, &charset, &data, headers.get()));
53 }
54
55 TEST(BuildResponseForDataURLTest, InvalidMimeType) {
56 std::string mime_type;
57 std::string charset;
58 std::string data;
59 scoped_refptr<net::HttpResponseHeaders> headers(
60 new net::HttpResponseHeaders(std::string()));
61
62 // MIME type contains delimiters. Must be rejected.
63 EXPECT_EQ(
64 net::ERR_INVALID_URL,
65 BuildResponseForDataURL(
66 GURL("data:f(o/b)r,test"),
67 &mime_type, &charset, &data, headers.get()));
68 }
69
70 TEST(BuildResponseForDataURLTest, InvalidCharset) {
71 std::string mime_type;
72 std::string charset;
73 std::string data;
74 scoped_refptr<net::HttpResponseHeaders> headers(
75 new net::HttpResponseHeaders(std::string()));
76
77 // MIME type contains delimiters. Must be rejected.
78 EXPECT_EQ(
79 net::ERR_INVALID_URL,
80 BuildResponseForDataURL(
81 GURL("data:text/html;charset=(),test"),
82 &mime_type, &charset, &data, headers.get()));
83 }
84
85 } // namespace net
OLDNEW
« net/url_request/url_request_data_job.h ('K') | « net/url_request/url_request_data_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698