Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / net / url_request / url_request_data_job_unittest.cc
blob8c6d09398cdfc9bcbcacb131e7c1eb6021aa368a
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.
5 #include <string>
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"
15 namespace net {
17 TEST(BuildResponseTest, Simple) {
18 std::string mime_type;
19 std::string charset;
20 std::string data;
21 scoped_refptr<HttpResponseHeaders> headers(
22 new HttpResponseHeaders(std::string()));
24 ASSERT_EQ(OK,
25 URLRequestDataJob::BuildResponse(GURL("data:,Hello"), &mime_type,
26 &charset, &data, headers.get()));
28 EXPECT_EQ("text/plain", mime_type);
29 EXPECT_EQ("US-ASCII", charset);
30 EXPECT_EQ("Hello", data);
32 const HttpVersion& version = headers->GetParsedHttpVersion();
33 EXPECT_EQ(1, version.major_value());
34 EXPECT_EQ(1, version.minor_value());
35 EXPECT_EQ("OK", headers->GetStatusText());
36 std::string value;
37 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
38 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
39 value.clear();
40 EXPECT_TRUE(
41 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
42 EXPECT_EQ(value, "*");
45 TEST(BuildResponseTest, InvalidInput) {
46 std::string mime_type;
47 std::string charset;
48 std::string data;
49 scoped_refptr<HttpResponseHeaders> headers(
50 new HttpResponseHeaders(std::string()));
52 EXPECT_EQ(ERR_INVALID_URL,
53 URLRequestDataJob::BuildResponse(GURL("bogus"), &mime_type,
54 &charset, &data, headers.get()));
57 TEST(BuildResponseTest, InvalidMimeType) {
58 std::string mime_type;
59 std::string charset;
60 std::string data;
61 scoped_refptr<HttpResponseHeaders> headers(
62 new HttpResponseHeaders(std::string()));
64 // MIME type contains delimiters. Must be accepted but Content-Type header
65 // should be generated as if the mediatype was text/plain.
66 EXPECT_EQ(OK, URLRequestDataJob::BuildResponse(GURL("data:f(o/b)r,test"),
67 &mime_type, &charset, &data,
68 headers.get()));
70 std::string value;
71 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
72 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
75 TEST(BuildResponseTest, InvalidCharset) {
76 std::string mime_type;
77 std::string charset;
78 std::string data;
79 scoped_refptr<HttpResponseHeaders> headers(
80 new HttpResponseHeaders(std::string()));
82 // MIME type contains delimiters. Must be rejected.
83 EXPECT_EQ(ERR_INVALID_URL, URLRequestDataJob::BuildResponse(
84 GURL("data:text/html;charset=(),test"),
85 &mime_type, &charset, &data, headers.get()));
88 } // namespace net