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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/url_request/url_request_data_job.cc ('k') | net/url_request/url_request_error_job.h » ('j') | 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 accepted but Content-Type header
67 // should be generated as if the mediatype was text/plain.
68 EXPECT_EQ(
69 net::OK,
70 URLRequestDataJob::BuildResponse(
71 GURL("data:f(o/b)r,test"),
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");
77 }
78
79 TEST(BuildResponseTest, InvalidCharset) {
80 std::string mime_type;
81 std::string charset;
82 std::string data;
83 scoped_refptr<net::HttpResponseHeaders> headers(
84 new net::HttpResponseHeaders(std::string()));
85
86 // MIME type contains delimiters. Must be rejected.
87 EXPECT_EQ(
88 net::ERR_INVALID_URL,
89 URLRequestDataJob::BuildResponse(
90 GURL("data:text/html;charset=(),test"),
91 &mime_type, &charset, &data, headers.get()));
92 }
93
94 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_data_job.cc ('k') | net/url_request/url_request_error_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698