OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/base/data_url.h" | 6 #include "net/base/data_url.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 "US-ASCII", | 177 "US-ASCII", |
178 "hello world" }, | 178 "hello world" }, |
179 | 179 |
180 // Bad encoding (truncated). | 180 // Bad encoding (truncated). |
181 { "data:;base64,aGVsbG8gd29yb", | 181 { "data:;base64,aGVsbG8gd29yb", |
182 false, | 182 false, |
183 "", | 183 "", |
184 "", | 184 "", |
185 "" }, | 185 "" }, |
186 | 186 |
| 187 // BiDi control characters should be unescaped and preserved as is, and |
| 188 // should not be replaced with % versions. In the below case, \xE2\x80\x8F |
| 189 // is the RTL mark and the parsed text should preserve it as is. |
| 190 { |
| 191 "data:text/plain;charset=utf-8,\xE2\x80\x8Ftest", |
| 192 true, |
| 193 "text/plain", |
| 194 "utf-8", |
| 195 "\xE2\x80\x8Ftest"}, |
| 196 |
| 197 // Same as above but with Arabic text after RTL mark. |
| 198 { |
| 199 "data:text/plain;charset=utf-8," |
| 200 "\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1", |
| 201 true, |
| 202 "text/plain", |
| 203 "utf-8", |
| 204 "\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1"}, |
| 205 |
| 206 // RTL mark encoded as %E2%80%8F should be unescaped too. Note that when |
| 207 // wrapped in a GURL, this URL and the next effectively become the same as |
| 208 // the previous two URLs. |
| 209 { |
| 210 "data:text/plain;charset=utf-8,%E2%80%8Ftest", |
| 211 true, |
| 212 "text/plain", |
| 213 "utf-8", |
| 214 "\xE2\x80\x8Ftest"}, |
| 215 |
| 216 // Same as above but with Arabic text after RTL mark. |
| 217 { |
| 218 "data:text/plain;charset=utf-8," |
| 219 "%E2%80%8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1", |
| 220 true, |
| 221 "text/plain", |
| 222 "utf-8", |
| 223 "\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1"} |
| 224 |
187 // TODO(darin): add more interesting tests | 225 // TODO(darin): add more interesting tests |
188 }; | 226 }; |
189 | 227 |
190 for (size_t i = 0; i < arraysize(tests); ++i) { | 228 for (size_t i = 0; i < arraysize(tests); ++i) { |
191 std::string mime_type; | 229 std::string mime_type; |
192 std::string charset; | 230 std::string charset; |
193 std::string data; | 231 std::string data; |
194 bool ok = | 232 bool ok = |
195 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); | 233 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); |
196 EXPECT_EQ(ok, tests[i].is_valid); | 234 EXPECT_EQ(ok, tests[i].is_valid); |
197 if (tests[i].is_valid) { | 235 if (tests[i].is_valid) { |
198 EXPECT_EQ(tests[i].mime_type, mime_type); | 236 EXPECT_EQ(tests[i].mime_type, mime_type); |
199 EXPECT_EQ(tests[i].charset, charset); | 237 EXPECT_EQ(tests[i].charset, charset); |
200 EXPECT_EQ(tests[i].data, data); | 238 EXPECT_EQ(tests[i].data, data); |
201 } | 239 } |
202 } | 240 } |
203 } | 241 } |
OLD | NEW |