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

Side by Side Diff: content/child/web_url_loader_impl_unittest.cc

Issue 294193002: Set response headers for data URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed #10 Created 6 years, 6 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 // Copyright (c) 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 "content/child/web_url_loader_impl.h"
6 #include "net/base/net_errors.h"
7 #include "net/http/http_response_headers.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/gurl.h"
10 #include "webkit/common/resource_response_info.h"
11
12 namespace content {
13
14 TEST(GetInfoFromDataURLTest, Simple) {
15 ResourceResponseInfo info;
16 std::string data;
17 ASSERT_EQ(net::OK,
18 GetInfoFromDataURL(GURL("data:,Hello"), &info, &data, &error_code);
19
20 EXPECT_EQ("Hello", data);
21
22 EXPECT_FALSE(info.load_timing.request_start.is_null());
23 EXPECT_FALSE(info.load_timing.request_start_time.is_null());
24 EXPECT_FALSE(info.request_time.is_null());
25 EXPECT_FALSE(info.response_time.is_null());
26
27 scoped_refptr<net::HttpResponseHeaders> headers = info.headers;
28 const net::HttpVersion& version = headers->GetParsedHttpVersion();
29 EXPECT_EQ(1, version.major_value());
30 EXPECT_EQ(1, version.minor_value());
31 EXPECT_EQ("OK", headers->GetStatusText());
32 std::string value;
33 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
34 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
35 value.clear();
36 EXPECT_TRUE(
37 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
38 EXPECT_EQ(value, "*");
39
40 EXPECT_EQ("text/plain", info.mime_type);
41 EXPECT_EQ("US-ASCII", info.charset);
42 EXPECT_TRUE(info.security_info.empty());
43 EXPECT_EQ(5, info.content_length);
44 EXPECT_EQ(0, info.encoded_data_length);
45 }
46
47 TEST(GetInfoFromDataURLTest, InvalidInput) {
48 ResourceResponseInfo info;
49 std::string data;
50 EXPECT_EQ(net::ERR_INVALID_URL,
51 GetInfoFromDataURL(GURL("bogus"), &info, &data));
52 }
53
54 TEST(GetInfoFromDataURLTest, InvalidMimeType) {
55 ResourceResponseInfo info;
56 std::string data;
57 // MIME type contains delimiters. Must be rejected.
58 EXPECT_EQ(net::ERR_INVALID_URL,
59 GetInfoFromDataURL(GURL("data:f(o/b)r,test"), &info, &data);
60 }
61
62 TEST(GetInfoFromDataURLTest, InvalidCharset) {
63 ResourceResponseInfo info;
64 std::string data;
65 int error_code;
66 // MIME type contains delimiters. Must be rejected.
67 EXPECT_EQ(
68 net::ERR_INVALID_URL,
69 GetInfoFromDataURL(GURL("data:text/html;charset=(),test"), &info, &data);
70 }
71
72 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698