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

Side by Side Diff: url/url_util_unittest.cc

Issue 1270443006: Proof-read comments in src/url/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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
« url/gurl.h ('K') | « url/url_util.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/macros.h" 5 #include "base/macros.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "url/third_party/mozilla/url_parse.h" 7 #include "url/third_party/mozilla/url_parse.h"
8 #include "url/url_canon.h" 8 #include "url/url_canon.h"
9 #include "url/url_canon_stdstring.h" 9 #include "url/url_canon_stdstring.h"
10 #include "url/url_test_utils.h" 10 #include "url/url_test_utils.h"
(...skipping 26 matching lines...) Expand all
37 // When there is an empty scheme, it should match the empty scheme. 37 // When there is an empty scheme, it should match the empty scheme.
38 const char kStr3[] = ":foo.com/"; 38 const char kStr3[] = ":foo.com/";
39 EXPECT_TRUE(FindAndCompareScheme( 39 EXPECT_TRUE(FindAndCompareScheme(
40 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme)); 40 kStr3, static_cast<int>(strlen(kStr3)), "", &found_scheme));
41 EXPECT_TRUE(found_scheme == Component(0, 0)); 41 EXPECT_TRUE(found_scheme == Component(0, 0));
42 42
43 // But when there is no scheme, it should fail. 43 // But when there is no scheme, it should fail.
44 EXPECT_FALSE(FindAndCompareScheme("", 0, "", &found_scheme)); 44 EXPECT_FALSE(FindAndCompareScheme("", 0, "", &found_scheme));
45 EXPECT_TRUE(found_scheme == Component()); 45 EXPECT_TRUE(found_scheme == Component());
46 46
47 // When there is a whitespace char in scheme, it should canonicalize the url 47 // When there is a whitespace char in scheme, it should canonicalize the URL
48 // before comparison. 48 // before comparison.
49 const char whtspc_str[] = " \r\n\tjav\ra\nscri\tpt:alert(1)"; 49 const char whtspc_str[] = " \r\n\tjav\ra\nscri\tpt:alert(1)";
50 EXPECT_TRUE(FindAndCompareScheme(whtspc_str, 50 EXPECT_TRUE(FindAndCompareScheme(whtspc_str,
51 static_cast<int>(strlen(whtspc_str)), 51 static_cast<int>(strlen(whtspc_str)),
52 "javascript", &found_scheme)); 52 "javascript", &found_scheme));
53 EXPECT_TRUE(found_scheme == Component(1, 10)); 53 EXPECT_TRUE(found_scheme == Component(1, 10));
54 54
55 // Control characters should be stripped out on the ends, and kept in the 55 // Control characters should be stripped out on the ends, and kept in the
56 // middle. 56 // middle.
57 const char ctrl_str[] = "\02jav\02scr\03ipt:alert(1)"; 57 const char ctrl_str[] = "\02jav\02scr\03ipt:alert(1)";
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 &resolved_parsed); 298 &resolved_parsed);
299 output.Complete(); 299 output.Complete();
300 300
301 EXPECT_EQ(test_data.is_valid, valid) << i; 301 EXPECT_EQ(test_data.is_valid, valid) << i;
302 if (test_data.is_valid && valid) 302 if (test_data.is_valid && valid)
303 EXPECT_EQ(test_data.out, resolved) << i; 303 EXPECT_EQ(test_data.out, resolved) << i;
304 } 304 }
305 } 305 }
306 306
307 TEST(URLUtilTest, TestNoRefComponent) { 307 TEST(URLUtilTest, TestNoRefComponent) {
308 // The hash-mark must be ignored when mailto: scheme is 308 // The hash-mark must be ignored when mailto: scheme is parsed,
309 // parsed, even if the url has a base and relative part. 309 // even if the URL has a base and relative part.
310 const char* base = "mailto://to/"; 310 const char* base = "mailto://to/";
311 const char* rel = "any#body"; 311 const char* rel = "any#body";
312 312
313 Parsed base_parsed; 313 Parsed base_parsed;
314 ParsePathURL(base, strlen(base), false, &base_parsed); 314 ParsePathURL(base, strlen(base), false, &base_parsed);
315 315
316 std::string resolved; 316 std::string resolved;
317 StdStringCanonOutput output(&resolved); 317 StdStringCanonOutput output(&resolved);
318 Parsed resolved_parsed; 318 Parsed resolved_parsed;
319 319
320 bool valid = ResolveRelative(base, strlen(base), 320 bool valid = ResolveRelative(base, strlen(base),
321 base_parsed, rel, 321 base_parsed, rel,
322 strlen(rel), NULL, &output, 322 strlen(rel), NULL, &output,
323 &resolved_parsed); 323 &resolved_parsed);
324 EXPECT_TRUE(valid); 324 EXPECT_TRUE(valid);
325 EXPECT_FALSE(resolved_parsed.ref.is_valid()); 325 EXPECT_FALSE(resolved_parsed.ref.is_valid());
326 } 326 }
327 327
328 } // namespace url 328 } // namespace url
OLDNEW
« url/gurl.h ('K') | « url/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698