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

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: check for "data" scheme 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 // Bad scheme.
173 { ":text/plain;charset=utf-8;base64,SGVsbMO2",
174 false,
175 "",
176 "",
177 "" },
178
179 // Bad scheme.
180 { ":,",
181 false,
182 "",
183 "",
184 "" },
185
186 // Fragment base64 (valid).
187 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==#target",
188 true,
189 "text/html",
190 "US-ASCII",
191 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
192
193 // 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 // Query base64 (valid).
201 { "data:text/html;base64,PCFkb2N0eXBlIGh0bWw+PHN0eWxlPmRpdiB7IGJhY2tncm91bmQ tY29sb3I6IHJlZDsgd2lkdGg6IDIwMHB4OyBoZWlnaHQ6MjAwcHg7IH0gOnRhcmdldCB7IGJhY2tncm9 1bmQtY29sb3I6IGdyZWVuOyB9PC9zdHlsZT48ZGl2IGlkPSd0YXJnZXQnPjwvZGl2Pg==?foo=bar",
202 true,
203 "text/html",
204 "US-ASCII",
205 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
206
207 // Query (valid).
208 { "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?foo=bar",
209 true,
210 "text/html",
211 "US-ASCII",
212 "<!doctype html><style>div { background-color: red; width: 200px; height: 200px; } :target { background-color: green; }</style><div id='target'></div>" },
213
asanka 2014/06/16 17:45:48 Add a test case for an percent escaped '#'.
asanka 2014/06/16 17:45:48 Would you mind going through http://greenbytes.de/
Erik Dahlström (inactive) 2014/06/17 13:10:21 Will do.
Erik Dahlström (inactive) 2014/06/17 13:10:21 Done.
214 // TODO(darin): add more interesting tests
173 }; 215 };
174 216
175 for (size_t i = 0; i < arraysize(tests); ++i) { 217 for (size_t i = 0; i < arraysize(tests); ++i) {
176 std::string mime_type; 218 std::string mime_type;
177 std::string charset; 219 std::string charset;
178 std::string data; 220 std::string data;
179 bool ok = 221 bool ok =
180 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data); 222 net::DataURL::Parse(GURL(tests[i].url), &mime_type, &charset, &data);
181 EXPECT_EQ(ok, tests[i].is_valid); 223 EXPECT_EQ(ok, tests[i].is_valid);
182 if (tests[i].is_valid) { 224 if (tests[i].is_valid) {
183 EXPECT_EQ(tests[i].mime_type, mime_type); 225 EXPECT_EQ(tests[i].mime_type, mime_type);
184 EXPECT_EQ(tests[i].charset, charset); 226 EXPECT_EQ(tests[i].charset, charset);
185 EXPECT_EQ(tests[i].data, data); 227 EXPECT_EQ(tests[i].data, data);
186 } 228 }
187 } 229 }
188 } 230 }
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