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

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: Created 6 years, 7 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 webkit_glue::ResourceResponseInfo info;
16 std::string data;
17 int error_code;
18 GetInfoFromDataURL(GURL("data:,Hello"), &info, &data, &error_code);
eroman 2014/05/29 01:23:26 Verify that this returned true.
tyoshino (SeeGerritForStatus) 2014/05/29 07:21:24 Done.
19
20 ASSERT_EQ(net::OK, error_code);
21
22 EXPECT_EQ("Hello", data);
23
24 EXPECT_FALSE(info.load_timing.request_start.is_null());
25 EXPECT_FALSE(info.load_timing.request_start_time.is_null());
26 EXPECT_FALSE(info.request_time.is_null());
27 EXPECT_FALSE(info.response_time.is_null());
28
29 scoped_refptr<net::HttpResponseHeaders> headers = info.headers;
30 const net::HttpVersion& version = headers->GetParsedHttpVersion();
31 EXPECT_EQ(1, version.major_value());
32 EXPECT_EQ(1, version.minor_value());
33 EXPECT_EQ("OK", headers->GetStatusText());
34 std::string value;
35 EXPECT_TRUE(headers->GetNormalizedHeader("Content-Type", &value));
36 EXPECT_EQ(value, "text/plain;charset=US-ASCII");
37 value.clear();
38 EXPECT_TRUE(
39 headers->GetNormalizedHeader("Access-Control-Allow-Origin", &value));
40 EXPECT_EQ(value, "*");
41
42 EXPECT_EQ("text/plain", info.mime_type);
43 EXPECT_EQ("US-ASCII", info.charset);
44 EXPECT_TRUE(info.security_info.empty());
45 EXPECT_EQ(5, info.content_length);
46 EXPECT_EQ(0, info.encoded_data_length);
47 }
48
49 TEST(GetInfoFromDataURLTest, InvalidInput) {
50 webkit_glue::ResourceResponseInfo info;
51 std::string data;
52 int error_code;
53 GetInfoFromDataURL(GURL("bogus"), &info, &data, &error_code);
eroman 2014/05/29 01:23:26 Verify that this returned false.
tyoshino (SeeGerritForStatus) 2014/05/29 07:21:24 Done.
54 EXPECT_EQ(net::ERR_INVALID_URL, error_code);
55 }
56
57 TEST(GetInfoFromDataURLTest, InvalidMimeType) {
58 webkit_glue::ResourceResponseInfo info;
59 std::string data;
60 int error_code;
61 // MIME type contains delimiters. Must be rejected.
62 GetInfoFromDataURL(GURL("data:f(o/b)r,test"), &info, &data, &error_code);
eroman 2014/05/29 01:23:26 Verify that this returned false
tyoshino (SeeGerritForStatus) 2014/05/29 07:21:24 Done.
63 EXPECT_EQ(net::ERR_INVALID_URL, error_code);
64 }
65
66 TEST(GetInfoFromDataURLTest, InvalidCharset) {
67 webkit_glue::ResourceResponseInfo info;
68 std::string data;
69 int error_code;
70 // MIME type contains delimiters. Must be rejected.
71 GetInfoFromDataURL(
eroman 2014/05/29 01:23:26 Verify that returned false
tyoshino (SeeGerritForStatus) 2014/05/29 07:21:24 Done.
72 GURL("data:text/html;charset=(),test"), &info, &data, &error_code);
73 EXPECT_EQ(net::ERR_INVALID_URL, error_code);
74 }
75
76 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698