| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 "text/plain", | 56 "text/plain", |
| 57 "US-ASCII", | 57 "US-ASCII", |
| 58 "foo" }, | 58 "foo" }, |
| 59 | 59 |
| 60 { "data:;base64,aGVsbG8gd29ybGQ=", | 60 { "data:;base64,aGVsbG8gd29ybGQ=", |
| 61 true, | 61 true, |
| 62 "text/plain", | 62 "text/plain", |
| 63 "US-ASCII", | 63 "US-ASCII", |
| 64 "hello world" }, | 64 "hello world" }, |
| 65 | 65 |
| 66 // Allow invalid mediatype for backward compatibility but set mime_type to |
| 67 // "text/plain" instead of the invalid mediatype. |
| 68 { "data:foo,boo", |
| 69 true, |
| 70 "text/plain", |
| 71 "US-ASCII", |
| 72 "boo" }, |
| 73 |
| 66 { "data:foo/bar;baz=1;charset=kk,boo", | 74 { "data:foo/bar;baz=1;charset=kk,boo", |
| 67 true, | 75 true, |
| 68 "foo/bar", | 76 "foo/bar", |
| 69 "kk", | 77 "kk", |
| 70 "boo" }, | 78 "boo" }, |
| 71 | 79 |
| 72 { "data:foo/bar;charset=kk;baz=1,boo", | 80 { "data:foo/bar;charset=kk;baz=1,boo", |
| 73 true, | 81 true, |
| 74 "foo/bar", | 82 "foo/bar", |
| 75 "kk", | 83 "kk", |
| 76 "boo" }, | 84 "boo" }, |
| 77 | 85 |
| 78 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world" | 86 { "data:text/html,%3Chtml%3E%3Cbody%3E%3Cb%3Ehello%20world" |
| 79 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E", | 87 "%3C%2Fb%3E%3C%2Fbody%3E%3C%2Fhtml%3E", |
| 80 true, | 88 true, |
| 81 "text/html", | 89 "text/html", |
| 82 "US-ASCII", | 90 "US-ASCII", |
| 83 "<html><body><b>hello world</b></body></html>" }, | 91 "<html><body><b>hello world</b></body></html>" }, |
| 84 | 92 |
| 85 { "data:text/html,<html><body><b>hello world</b></body></html>", | 93 { "data:text/html,<html><body><b>hello world</b></body></html>", |
| 86 true, | 94 true, |
| 87 "text/html", | 95 "text/html", |
| 88 "US-ASCII", | 96 "US-ASCII", |
| 89 "<html><body><b>hello world</b></body></html>" }, | 97 "<html><body><b>hello world</b></body></html>" }, |
| 90 | 98 |
| 91 // Bad mime type | 99 // Bad mime type |
| 92 { "data:f(oo/bar;baz=1;charset=kk,boo", | 100 { "data:f(oo/bar;baz=1;charset=kk,boo", |
| 93 false, | 101 true, |
| 94 "", | 102 "text/plain", |
| 95 "", | 103 "kk", |
| 96 "" }, | 104 "boo" }, |
| 97 | 105 |
| 98 // the comma cannot be url-escaped! | 106 // the comma cannot be url-escaped! |
| 99 { "data:%2Cblah", | 107 { "data:%2Cblah", |
| 100 false, | 108 false, |
| 101 "", | 109 "", |
| 102 "", | 110 "", |
| 103 "" }, | 111 "" }, |
| 104 | 112 |
| 105 // invalid base64 content | 113 // invalid base64 content |
| 106 { "data:;base64,aGVs_-_-", | 114 { "data:;base64,aGVs_-_-", |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 bool ok = | 187 bool ok = |
| 180 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); | 188 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); |
| 181 EXPECT_EQ(ok, tests[i].is_valid); | 189 EXPECT_EQ(ok, tests[i].is_valid); |
| 182 if (tests[i].is_valid) { | 190 if (tests[i].is_valid) { |
| 183 EXPECT_EQ(tests[i].mime_type, mime_type); | 191 EXPECT_EQ(tests[i].mime_type, mime_type); |
| 184 EXPECT_EQ(tests[i].charset, charset); | 192 EXPECT_EQ(tests[i].charset, charset); |
| 185 EXPECT_EQ(tests[i].data, data); | 193 EXPECT_EQ(tests[i].data, data); |
| 186 } | 194 } |
| 187 } | 195 } |
| 188 } | 196 } |
| OLD | NEW |