Chromium Code Reviews| 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/html;charset=utf-8,<b>\xE2\x80\x8Ftest</b>", | |
|
mmenke
2014/10/17 15:24:43
Any reason not to just use text/plain? Don't thin
meacer
2014/10/17 20:41:54
Done.
| |
| 192 true, | |
| 193 "text/html", | |
| 194 "utf-8", | |
| 195 "<b>\xE2\x80\x8Ftest</b>"}, | |
| 196 | |
| 197 // Same as above but with Arabic text after RTL mark. | |
| 198 { | |
| 199 "data:text/html;charset=utf-8," | |
| 200 "<b>\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1</b>", | |
| 201 true, | |
| 202 "text/html", | |
| 203 "utf-8", | |
| 204 "<b>\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1</b>"}, | |
| 205 | |
| 206 // RTL mark encoded as %E2%80%8F should be unescaped too. | |
| 207 { | |
| 208 "data:text/html;charset=utf-8,<b>%E2%80%8Ftest</b>", | |
|
mmenke
2014/10/17 15:24:44
When this is wrapped in a GURL, this becomes the s
meacer
2014/10/17 20:41:54
Added a note.
| |
| 209 true, | |
| 210 "text/html", | |
| 211 "utf-8", | |
| 212 "<b>\xE2\x80\x8Ftest</b>"}, | |
| 213 | |
| 214 // Same as above but with Arabic text after RTL mark. | |
| 215 { | |
| 216 "data:text/html;charset=utf-8," | |
| 217 "<b>%E2%80%8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1</b>", | |
| 218 true, | |
| 219 "text/html", | |
| 220 "utf-8", | |
| 221 "<b>\xE2\x80\x8F\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1</b>"} | |
| 222 | |
| 187 // TODO(darin): add more interesting tests | 223 // TODO(darin): add more interesting tests |
| 188 }; | 224 }; |
| 189 | 225 |
| 190 for (size_t i = 0; i < arraysize(tests); ++i) { | 226 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 191 std::string mime_type; | 227 std::string mime_type; |
| 192 std::string charset; | 228 std::string charset; |
| 193 std::string data; | 229 std::string data; |
| 194 bool ok = | 230 bool ok = |
| 195 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); | 231 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); |
| 196 EXPECT_EQ(ok, tests[i].is_valid); | 232 EXPECT_EQ(ok, tests[i].is_valid); |
| 197 if (tests[i].is_valid) { | 233 if (tests[i].is_valid) { |
| 198 EXPECT_EQ(tests[i].mime_type, mime_type); | 234 EXPECT_EQ(tests[i].mime_type, mime_type); |
| 199 EXPECT_EQ(tests[i].charset, charset); | 235 EXPECT_EQ(tests[i].charset, charset); |
| 200 EXPECT_EQ(tests[i].data, data); | 236 EXPECT_EQ(tests[i].data, data); |
| 201 } | 237 } |
| 202 } | 238 } |
| 203 } | 239 } |
| OLD | NEW |