Files.app: Stop to use file system URLs having externalfile:// scheme origin internally.
[chromium-blink-merge.git] / net / url_request / url_request_data_job_unittest.cc
blob81903be2516828c7772a99ea50afd0f760f16e61
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<net::HttpResponseHeaders> headers(
22 new net::HttpResponseHeaders(std::string()));
24 ASSERT_EQ(
25 net::OK,
26 URLRequestDataJob::BuildResponse(
27 GURL("data:,Hello"), &mime_type, &charset, &data, headers.get()));
29 EXPECT_EQ("text/plain", mime_type);
30 EXPECT_EQ("US-ASCII", charset);
31 EXPECT_EQ("Hello", data);
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, "*");
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()));
53 EXPECT_EQ(
54 net::ERR_INVALID_URL,
55 URLRequestDataJob::BuildResponse(
56 GURL("bogus"), &mime_type, &charset, &data, headers.get()));
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()));
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()));
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()));
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()));
89 } // namespace net