OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const char* ref; | 68 const char* ref; |
69 bool hasRef; | 69 bool hasRef; |
70 } cases[] = { | 70 } cases[] = { |
71 {"http://www.google.com/foo/blah?bar=baz#ref", "http", "www.google.com",
0, "", 0, "blah", "bar=baz", "ref", true}, | 71 {"http://www.google.com/foo/blah?bar=baz#ref", "http", "www.google.com",
0, "", 0, "blah", "bar=baz", "ref", true}, |
72 {"http://foo.com:1234/foo/bar/", "http", "foo.com", 1234, "", 0, "bar",
0, 0, false}, | 72 {"http://foo.com:1234/foo/bar/", "http", "foo.com", 1234, "", 0, "bar",
0, 0, false}, |
73 {"http://www.google.com?#", "http", "www.google.com", 0, "", 0, 0, "", "
", true}, | 73 {"http://www.google.com?#", "http", "www.google.com", 0, "", 0, 0, "", "
", true}, |
74 {"https://me:pass@google.com:23#foo", "https", "google.com", 23, "me", "
pass", 0, 0, "foo", true}, | 74 {"https://me:pass@google.com:23#foo", "https", "google.com", 23, "me", "
pass", 0, 0, "foo", true}, |
75 {"javascript:hello!//world", "javascript", "", 0, "", 0, "world", 0, 0,
false}, | 75 {"javascript:hello!//world", "javascript", "", 0, "", 0, "world", 0, 0,
false}, |
76 }; | 76 }; |
77 | 77 |
78 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 78 for (size_t i = 0; i < arraysize(cases); i++) { |
79 // UTF-8 | 79 // UTF-8 |
80 blink::KURL kurl(blink::ParsedURLString, cases[i].url); | 80 blink::KURL kurl(blink::ParsedURLString, cases[i].url); |
81 | 81 |
82 EXPECT_EQ(cases[i].protocol, kurl.protocol()); | 82 EXPECT_EQ(cases[i].protocol, kurl.protocol()); |
83 EXPECT_EQ(cases[i].host, kurl.host()); | 83 EXPECT_EQ(cases[i].host, kurl.host()); |
84 EXPECT_EQ(cases[i].port, kurl.port()); | 84 EXPECT_EQ(cases[i].port, kurl.port()); |
85 EXPECT_EQ(cases[i].user, kurl.user()); | 85 EXPECT_EQ(cases[i].user, kurl.user()); |
86 EXPECT_EQ(cases[i].pass, kurl.pass()); | 86 EXPECT_EQ(cases[i].pass, kurl.pass()); |
87 EXPECT_EQ(cases[i].lastPathComponent, kurl.lastPathComponent()); | 87 EXPECT_EQ(cases[i].lastPathComponent, kurl.lastPathComponent()); |
88 EXPECT_EQ(cases[i].query, kurl.query()); | 88 EXPECT_EQ(cases[i].query, kurl.query()); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 "", "http://:pass@goo.com:92/a?f#b", | 231 "", "http://:pass@goo.com:92/a?f#b", |
232 // pass | 232 // pass |
233 "", "http://goo.com:92/a?f#b", | 233 "", "http://goo.com:92/a?f#b", |
234 // path | 234 // path |
235 "/", "http://goo.com:92/?f#b", | 235 "/", "http://goo.com:92/?f#b", |
236 // query | 236 // query |
237 0, "http://goo.com:92/#b" | 237 0, "http://goo.com:92/#b" |
238 }, | 238 }, |
239 }; | 239 }; |
240 | 240 |
241 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); i++) { | 241 for (size_t i = 0; i < arraysize(cases); i++) { |
242 blink::KURL kurl(blink::ParsedURLString, cases[i].url); | 242 blink::KURL kurl(blink::ParsedURLString, cases[i].url); |
243 | 243 |
244 kurl.setProtocol(cases[i].protocol); | 244 kurl.setProtocol(cases[i].protocol); |
245 EXPECT_STREQ(cases[i].expectedProtocol, kurl.string().utf8().data()); | 245 EXPECT_STREQ(cases[i].expectedProtocol, kurl.string().utf8().data()); |
246 | 246 |
247 kurl.setHost(cases[i].host); | 247 kurl.setHost(cases[i].host); |
248 EXPECT_STREQ(cases[i].expectedHost, kurl.string().utf8().data()); | 248 EXPECT_STREQ(cases[i].expectedHost, kurl.string().utf8().data()); |
249 | 249 |
250 kurl.setPort(cases[i].port); | 250 kurl.setPort(cases[i].port); |
251 EXPECT_STREQ(cases[i].expectedPort, kurl.string().utf8().data()); | 251 EXPECT_STREQ(cases[i].expectedPort, kurl.string().utf8().data()); |
(...skipping 28 matching lines...) Expand all Loading... |
280 {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", " !\"#$%&'()*+,-./
/"}, | 280 {"%20%21%22%23%24%25%26%27%28%29%2a%2B%2C%2D%2e%2f/", " !\"#$%&'()*+,-./
/"}, |
281 {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/
"}, | 281 {"%30%31%32%33%34%35%36%37%38%39%3a%3B%3C%3D%3e%3f/", "0123456789:;<=>?/
"}, |
282 {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/
"}, | 282 {"%40%41%42%43%44%45%46%47%48%49%4a%4B%4C%4D%4e%4f/", "@ABCDEFGHIJKLMNO/
"}, |
283 {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", "PQRSTUVWXYZ[\\]^_
/"}, | 283 {"%50%51%52%53%54%55%56%57%58%59%5a%5B%5C%5D%5e%5f/", "PQRSTUVWXYZ[\\]^_
/"}, |
284 {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/
"}, | 284 {"%60%61%62%63%64%65%66%67%68%69%6a%6B%6C%6D%6e%6f/", "`abcdefghijklmno/
"}, |
285 {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", "pqrstuvwxyz{|}~\x
7f/"}, | 285 {"%70%71%72%73%74%75%76%77%78%79%7a%7B%7C%7D%7e%7f/", "pqrstuvwxyz{|}~\x
7f/"}, |
286 // Test un-UTF-8-ization. | 286 // Test un-UTF-8-ization. |
287 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, | 287 {"%e4%bd%a0%e5%a5%bd", "\xe4\xbd\xa0\xe5\xa5\xbd"}, |
288 }; | 288 }; |
289 | 289 |
290 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(decodeCases); i++) { | 290 for (size_t i = 0; i < arraysize(decodeCases); i++) { |
291 WTF::String input(decodeCases[i].input); | 291 WTF::String input(decodeCases[i].input); |
292 WTF::String str = blink::decodeURLEscapeSequences(input); | 292 WTF::String str = blink::decodeURLEscapeSequences(input); |
293 EXPECT_STREQ(decodeCases[i].output, str.utf8().data()); | 293 EXPECT_STREQ(decodeCases[i].output, str.utf8().data()); |
294 } | 294 } |
295 | 295 |
296 // Our decode should decode %00 | 296 // Our decode should decode %00 |
297 WTF::String zero = blink::decodeURLEscapeSequences("%00"); | 297 WTF::String zero = blink::decodeURLEscapeSequences("%00"); |
298 EXPECT_STRNE("%00", zero.utf8().data()); | 298 EXPECT_STRNE("%00", zero.utf8().data()); |
299 | 299 |
300 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). | 300 // Test the error behavior for invalid UTF-8 (we differ from WebKit here). |
(...skipping 23 matching lines...) Expand all Loading... |
324 {"@ABCDEFGHIJKLMNO", | 324 {"@ABCDEFGHIJKLMNO", |
325 "%40ABCDEFGHIJKLMNO"}, | 325 "%40ABCDEFGHIJKLMNO"}, |
326 {"PQRSTUVWXYZ[\\]^_", | 326 {"PQRSTUVWXYZ[\\]^_", |
327 "PQRSTUVWXYZ%5B%5C%5D%5E_"}, | 327 "PQRSTUVWXYZ%5B%5C%5D%5E_"}, |
328 {"`abcdefghijklmno", | 328 {"`abcdefghijklmno", |
329 "%60abcdefghijklmno"}, | 329 "%60abcdefghijklmno"}, |
330 {"pqrstuvwxyz{|}~\x7f", | 330 {"pqrstuvwxyz{|}~\x7f", |
331 "pqrstuvwxyz%7B%7C%7D~%7F"}, | 331 "pqrstuvwxyz%7B%7C%7D~%7F"}, |
332 }; | 332 }; |
333 | 333 |
334 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) { | 334 for (size_t i = 0; i < arraysize(encode_cases); i++) { |
335 WTF::String input(encode_cases[i].input); | 335 WTF::String input(encode_cases[i].input); |
336 WTF::String expectedOutput(encode_cases[i].output); | 336 WTF::String expectedOutput(encode_cases[i].output); |
337 WTF::String output = blink::encodeWithURLEscapeSequences(input); | 337 WTF::String output = blink::encodeWithURLEscapeSequences(input); |
338 EXPECT_EQ(expectedOutput, output); | 338 EXPECT_EQ(expectedOutput, output); |
339 } | 339 } |
340 | 340 |
341 // Our encode escapes NULLs for safety, so we need to check that too. | 341 // Our encode escapes NULLs for safety, so we need to check that too. |
342 WTF::String input("\x00\x01", 2); | 342 WTF::String input("\x00\x01", 2); |
343 WTF::String reference("%00%01"); | 343 WTF::String reference("%00%01"); |
344 | 344 |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 {"data:text/html;charset=utf-8,<html></html>", ""}, | 690 {"data:text/html;charset=utf-8,<html></html>", ""}, |
691 {"javascript:void(0);", ""}, | 691 {"javascript:void(0);", ""}, |
692 {"about:config", ""}, | 692 {"about:config", ""}, |
693 {"https://www.google.com/", "https://www.google.com/"}, | 693 {"https://www.google.com/", "https://www.google.com/"}, |
694 {"http://me@news.google.com:8888/", "http://news.google.com:8888/"}, | 694 {"http://me@news.google.com:8888/", "http://news.google.com:8888/"}, |
695 {"http://:pass@news.google.com:8888/foo", "http://news.google.com:8888/f
oo"}, | 695 {"http://:pass@news.google.com:8888/foo", "http://news.google.com:8888/f
oo"}, |
696 {"http://me:pass@news.google.com:8888/", "http://news.google.com:8888/"}
, | 696 {"http://me:pass@news.google.com:8888/", "http://news.google.com:8888/"}
, |
697 {"https://www.google.com/a?f#b", "https://www.google.com/a?f"}, | 697 {"https://www.google.com/a?f#b", "https://www.google.com/a?f"}, |
698 }; | 698 }; |
699 | 699 |
700 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(referrerCases); i++) { | 700 for (size_t i = 0; i < arraysize(referrerCases); i++) { |
701 blink::KURL kurl(blink::ParsedURLString, referrerCases[i].input); | 701 blink::KURL kurl(blink::ParsedURLString, referrerCases[i].input); |
702 WTF::String referrer = kurl.strippedForUseAsReferrer(); | 702 WTF::String referrer = kurl.strippedForUseAsReferrer(); |
703 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data()); | 703 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data()); |
704 } | 704 } |
705 } | 705 } |
706 | 706 |
707 } // namespace | 707 } // namespace |
OLD | NEW |