OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "googleurl/src/gurl.h" | 6 #include "googleurl/src/gurl.h" |
7 #include "net/base/data_url.h" | 7 #include "net/base/data_url.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 "text/plain", | 62 "text/plain", |
63 "US-ASCII", | 63 "US-ASCII", |
64 "hello world" }, | 64 "hello world" }, |
65 | 65 |
66 { "data:foo/bar;baz=1;charset=kk,boo", | 66 { "data:foo/bar;baz=1;charset=kk,boo", |
67 true, | 67 true, |
68 "foo/bar", | 68 "foo/bar", |
69 "kk", | 69 "kk", |
70 "boo" }, | 70 "boo" }, |
71 | 71 |
| 72 { "data:foo/bar;charset=kk;baz=1,boo", |
| 73 true, |
| 74 "foo/bar", |
| 75 "kk", |
| 76 "boo" }, |
| 77 |
72 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world" | 78 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world" |
73 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E", | 79 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E", |
74 true, | 80 true, |
75 "text/html", | 81 "text/html", |
76 "US-ASCII", | 82 "US-ASCII", |
77 "<html><body><b>hello world</b></body></html>" }, | 83 "<html><body><b>hello world</b></body></html>" }, |
78 | 84 |
79 { "data:text/html,<html><body><b>hello world</b></body></html>", | 85 { "data:text/html,<html><body><b>hello world</b></body></html>", |
80 true, | 86 true, |
81 "text/html", | 87 "text/html", |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 "d4 = 'four';" }, | 135 "d4 = 'four';" }, |
130 | 136 |
131 // Only unescaped whitespace should be stripped in non-base64. | 137 // Only unescaped whitespace should be stripped in non-base64. |
132 // http://b/1157796 | 138 // http://b/1157796 |
133 { "data:img/png,A B %20 %0A C", | 139 { "data:img/png,A B %20 %0A C", |
134 true, | 140 true, |
135 "img/png", | 141 "img/png", |
136 "US-ASCII", | 142 "US-ASCII", |
137 "AB \nC" }, | 143 "AB \nC" }, |
138 | 144 |
| 145 { "data:text/plain;charset=utf-8;base64,SGVsbMO2", |
| 146 true, |
| 147 "text/plain", |
| 148 "utf-8", |
| 149 "Hell\xC3\xB6" }, |
| 150 |
139 // TODO(darin): add more interesting tests | 151 // TODO(darin): add more interesting tests |
140 }; | 152 }; |
141 | 153 |
142 for (size_t i = 0; i < arraysize(tests); ++i) { | 154 for (size_t i = 0; i < arraysize(tests); ++i) { |
143 std::string mime_type; | 155 std::string mime_type; |
144 std::string charset; | 156 std::string charset; |
145 std::string data; | 157 std::string data; |
146 bool ok = | 158 bool ok = |
147 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); | 159 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); |
148 EXPECT_EQ(ok, tests[i].is_valid); | 160 EXPECT_EQ(ok, tests[i].is_valid); |
149 if (tests[i].is_valid) { | 161 if (tests[i].is_valid) { |
150 EXPECT_EQ(tests[i].mime_type, mime_type); | 162 EXPECT_EQ(tests[i].mime_type, mime_type); |
151 EXPECT_EQ(tests[i].charset, charset); | 163 EXPECT_EQ(tests[i].charset, charset); |
152 EXPECT_EQ(tests[i].data, data); | 164 EXPECT_EQ(tests[i].data, data); |
153 } | 165 } |
154 } | 166 } |
155 } | 167 } |
OLD | NEW |