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

Side by Side Diff: net/base/data_url_unittest.cc

Issue 338503006: Allow data urls to have a fragment part. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix review issues Created 6 years, 6 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
« net/base/data_url.cc ('K') | « net/base/data_url.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 "US-ASCII", 162 "US-ASCII",
163 "hello world" }, 163 "hello world" },
164 164
165 // Bad encoding (truncated). 165 // Bad encoding (truncated).
166 { "data:;base64,aGVsbG8gd29yb", 166 { "data:;base64,aGVsbG8gd29yb",
167 false, 167 false,
168 "", 168 "",
169 "", 169 "",
170 "" }, 170 "" },
171 171
172 // TODO(darin): add more interesting tests 172 // Simple fragment (valid).
173 { "data:,test#foo",
174 true,
175 "text/plain",
176 "US-ASCII",
177 "test" },
178
179 // Fragment base64 (valid).
180 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==#target",
181 true,
182 "text/html",
183 "US-ASCII",
184 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
185
186 // Fragment escaped base64 (invalid).
187 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==%23target",
188 false,
189 "",
190 "",
191 "" },
192
193 // html fragment (valid).
194 { "data:text/html,%3C!doctype%20html%3E%3Cstyle%3Ediv%20%7B%20background-col or:%20red;%20width:%20200px;%20height:200px;%20%7D%20:target%20%7B%20background- color:%20green;%20%7D%3C/style%3E%3Cdiv%20id='target'%3E%3C/div%3E#target",
195 true,
196 "text/html",
197 "US-ASCII",
198 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
199
200 // svg with media type extension (valid).
201 { "data:image/svg+xml;foo=bar,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%2 2%20viewBox=%220%200%20100%20100%22%3E%3Cstyle%3E:target%20%7B%20fill:%20blue%20 %7D%3C/style%3E%3Ccircle%20id=%22target%22%20cx=%2250%22%20cy=%2250%22%20r=%2250 %22%20fill=%22green%22/%3E%3C/svg%3E",
202 true,
203 "image/svg+xml",
204 "US-ASCII",
205 "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><style >:target { fill: blue }</style><circle id=\"target\" cx=\"50\" cy=\"50\" r=\"50\ " fill=\"green\"/></svg>" },
206
207 // svg fragment (valid).
208 { "data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20view Box=%220%200%20100%20100%22%3E%3Cstyle%3E:target%20%7B%20fill:%20blue%20%7D%3C/s tyle%3E%3Ccircle%20id=%22target%22%20cx=%2250%22%20cy=%2250%22%20r=%2250%22%20fi ll=%22green%22/%3E%3C/svg%3E#target",
209 true,
210 "image/svg+xml",
211 "US-ASCII",
212 "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><style >:target { fill: blue }</style><circle id=\"target\" cx=\"50\" cy=\"50\" r=\"50\ " fill=\"green\"/></svg>" },
213
214 // html fragment escaped (valid).
215 { "data:text/html,%3C!doctype%20html%3E%3Cstyle%3Ediv%20%7B%20background-col or:%20red;%20width:%20200px;%20height:200px;%20%7D%20:target%20%7B%20background- color:%20green;%20%7D%3C/style%3E%3Cdiv%20id='target'%3E%3C/div%3E%23target",
216 true,
217 "text/html",
218 "US-ASCII",
219 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>#tar get" },
220
221 // Query base64 (valid).
222 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==?foo=bar",
223 true,
224 "text/html",
225 "US-ASCII",
226 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
227
228 // Query escaped base64 (invalid).
229 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==%3ffoo=bar" ,
230 false,
231 "",
232 "",
233 "" },
234
235 // Query (valid).
236 { "data:text/html,%3C!doctype%20html%3E%3Cdiv%3E%3C/div%3E?foo=bar",
237 true,
238 "text/html",
239 "US-ASCII",
240 "<!doctype html><div></div>" },
241
242 // Query escaped (valid).
243 { "data:text/html,%3C!doctype%20html%3E%3Cdiv%3E%3C/div%3E%3ffoo=bar",
244 true,
245 "text/html",
246 "US-ASCII",
247 "<!doctype html><div></div>?foo=bar" },
248
249
250 // base64 as parameter (should be ignored).
251 { "data:text/plain;base64=paramvalue,test",
252 true,
253 "text/plain",
254 "US-ASCII",
255 "test" },
256
257 // base64 extension in wrong position.
258 { "data:text/plain;base64;x=y,dGVzdA==",
259 true,
260 "text/plain",
261 "US-ASCII",
262 "test" },
263
264 // TODO(darin): add more interesting tests
173 }; 265 };
174 266
175 for (size_t i = 0; i < arraysize(tests); ++i) { 267 for (size_t i = 0; i < arraysize(tests); ++i) {
176 std::string mime_type; 268 std::string mime_type;
177 std::string charset; 269 std::string charset;
178 std::string data; 270 std::string data;
179 bool ok = 271 bool ok =
180 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); 272 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data);
181 EXPECT_EQ(ok, tests[i].is_valid); 273 EXPECT_EQ(ok, tests[i].is_valid);
182 if (tests[i].is_valid) { 274 if (tests[i].is_valid) {
183 EXPECT_EQ(tests[i].mime_type, mime_type); 275 EXPECT_EQ(tests[i].mime_type, mime_type);
184 EXPECT_EQ(tests[i].charset, charset); 276 EXPECT_EQ(tests[i].charset, charset);
185 EXPECT_EQ(tests[i].data, data); 277 EXPECT_EQ(tests[i].data, data);
186 } 278 }
187 } 279 }
188 } 280 }
OLDNEW
« net/base/data_url.cc ('K') | « net/base/data_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698