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

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, 3 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
« no previous file with comments | « net/url_request/url_request_data_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/memory/ref_counted.h"
8 #include "net/base/net_errors.h"
9 #include "net/http/http_response_headers.h"
10 #include "net/http/http_version.h"
11 #include "net/url_request/url_request_data_job.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "url/gurl.h"
14
15 namespace net {
16
17 TEST(BuildResponseTest, Simple) {
18 std::string mime_type;
19 std::string charset;
20 std::string data;
21 scoped_refptr<net::HttpResponseHeaders> headers(
22 new net::HttpResponseHeaders(std::string()));
23
24 ASSERT_EQ(
25 net::OK,
26 URLRequestDataJob::BuildResponse(
27 GURL("data:,Hello"), &mime_type, &charset, &data, headers.get()));
28
29 EXPECT_EQ("text/plain", mime_type);
30 EXPECT_EQ("US-ASCII", charset);
31 EXPECT_EQ("Hello", data);
32
33 const net::HttpVersion& version = headers->GetParsedHttpVersion();
34 EXPECT_EQ(1, version.major_value());
35 EXPECT_EQ(1, version.minor_value());
36 EXPECT_EQ("OK", headers->GetStatusText());
37 std::string value;
38 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
39 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
40 value.clear();
41 EXPECT_TRUE(
42 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
43 EXPECT_EQ(value, "*");
44 }
45
46 TEST(BuildResponseTest, InvalidInput) {
47 std::string mime_type;
48 std::string charset;
49 std::string data;
50 scoped_refptr<net::HttpResponseHeaders> headers(
51 new net::HttpResponseHeaders(std::string()));
52
53 EXPECT_EQ(
54 net::ERR_INVALID_URL,
55 URLRequestDataJob::BuildResponse(
56 GURL("bogus"), &mime_type, &charset, &data, headers.get()));
57 }
58
59 TEST(BuildResponseTest, InvalidMimeType) {
60 std::string mime_type;
61 std::string charset;
62 std::string data;
63 scoped_refptr<net::HttpResponseHeaders> headers(
64 new net::HttpResponseHeaders(std::string()));
65
66 // MIME type contains delimiters. Must be rejected.
67 EXPECT_EQ(
68 net::ERR_INVALID_URL,
69 URLRequestDataJob::BuildResponse(
70 GURL("data:f(o/b)r,test"),
71 &mime_type, &charset, &data, headers.get()));
72 }
73
74 TEST(BuildResponseTest, InvalidCharset) {
75 std::string mime_type;
76 std::string charset;
77 std::string data;
78 scoped_refptr<net::HttpResponseHeaders> headers(
79 new net::HttpResponseHeaders(std::string()));
80
81 // MIME type contains delimiters. Must be rejected.
82 EXPECT_EQ(
83 net::ERR_INVALID_URL,
84 URLRequestDataJob::BuildResponse(
85 GURL("data:text/html;charset=(),test"),
86 &mime_type, &charset, &data, headers.get()));
87 }
88
89 } // namespace net
OLDNEW
« no previous file with comments | « 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