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

Side by Side Diff: url/url_util_unittest.cc

Issue 2895953002: Update dangling markup mitigations. (Closed)
Patch Set: Test. Created 3 years, 7 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
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "url/third_party/mozilla/url_parse.h" 9 #include "url/third_party/mozilla/url_parse.h"
10 #include "url/url_canon.h" 10 #include "url/url_canon.h"
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 Parsed resolved_parsed; 367 Parsed resolved_parsed;
368 368
369 bool valid = ResolveRelative(base, strlen(base), 369 bool valid = ResolveRelative(base, strlen(base),
370 base_parsed, rel, 370 base_parsed, rel,
371 strlen(rel), NULL, &output, 371 strlen(rel), NULL, &output,
372 &resolved_parsed); 372 &resolved_parsed);
373 EXPECT_TRUE(valid); 373 EXPECT_TRUE(valid);
374 EXPECT_FALSE(resolved_parsed.ref.is_valid()); 374 EXPECT_FALSE(resolved_parsed.ref.is_valid());
375 } 375 }
376 376
377 TEST(URLUtilTest, RelativeWhitespaceRemoved) { 377 TEST(URLUtilTest, PotentiallyDanglingMarkup) {
378 struct ResolveRelativeCase { 378 struct ResolveRelativeCase {
379 const char* base; 379 const char* base;
380 const char* rel; 380 const char* rel;
381 bool whitespace_removed; 381 bool potentially_dangling_markup;
382 const char* out; 382 const char* out;
383 } cases[] = { 383 } cases[] = {
384 {"https://example.com/", "/path", false, "https://example.com/path"}, 384 {"https://example.com/", "/path<", false, "https://example.com/path%3C"},
385 {"https://example.com/", "\n/path", true, "https://example.com/path"}, 385 {"https://example.com/", "\n/path<", true, "https://example.com/path%3C"},
386 {"https://example.com/", "\r/path", true, "https://example.com/path"}, 386 {"https://example.com/", "\r/path<", true, "https://example.com/path%3C"},
387 {"https://example.com/", "\t/path", true, "https://example.com/path"}, 387 {"https://example.com/", "\t/path<", true, "https://example.com/path%3C"},
388 {"https://example.com/", "/pa\nth", true, "https://example.com/path"}, 388 {"https://example.com/", "/pa\nth<", true, "https://example.com/path%3C"},
389 {"https://example.com/", "/pa\rth", true, "https://example.com/path"}, 389 {"https://example.com/", "/pa\rth<", true, "https://example.com/path%3C"},
390 {"https://example.com/", "/pa\tth", true, "https://example.com/path"}, 390 {"https://example.com/", "/pa\tth<", true, "https://example.com/path%3C"},
391 {"https://example.com/", "/path\n", true, "https://example.com/path"}, 391 {"https://example.com/", "/path\n<", true, "https://example.com/path%3C"},
392 {"https://example.com/", "/path\r", true, "https://example.com/path"}, 392 {"https://example.com/", "/path\r<", true, "https://example.com/path%3C"},
393 {"https://example.com/", "/path\r", true, "https://example.com/path"}, 393 {"https://example.com/", "/path\r<", true, "https://example.com/path%3C"},
394 {"https://example.com/", "\n/<path", true, "https://example.com/%3Cpath"},
395 {"https://example.com/", "\r/<path", true, "https://example.com/%3Cpath"},
396 {"https://example.com/", "\t/<path", true, "https://example.com/%3Cpath"},
397 {"https://example.com/", "/<pa\nth", true, "https://example.com/%3Cpath"},
398 {"https://example.com/", "/<pa\rth", true, "https://example.com/%3Cpath"},
399 {"https://example.com/", "/<pa\tth", true, "https://example.com/%3Cpath"},
400 {"https://example.com/", "/<path\n", true, "https://example.com/%3Cpath"},
401 {"https://example.com/", "/<path\r", true, "https://example.com/%3Cpath"},
402 {"https://example.com/", "/<path\r", true, "https://example.com/%3Cpath"},
394 }; 403 };
395 404
396 for (const auto& test : cases) { 405 for (const auto& test : cases) {
397 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.rel); 406 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.rel);
398 Parsed base_parsed; 407 Parsed base_parsed;
399 ParseStandardURL(test.base, strlen(test.base), &base_parsed); 408 ParseStandardURL(test.base, strlen(test.base), &base_parsed);
400 409
401 std::string resolved; 410 std::string resolved;
402 StdStringCanonOutput output(&resolved); 411 StdStringCanonOutput output(&resolved);
403 Parsed resolved_parsed; 412 Parsed resolved_parsed;
404 bool valid = 413 bool valid =
405 ResolveRelative(test.base, strlen(test.base), base_parsed, test.rel, 414 ResolveRelative(test.base, strlen(test.base), base_parsed, test.rel,
406 strlen(test.rel), NULL, &output, &resolved_parsed); 415 strlen(test.rel), NULL, &output, &resolved_parsed);
407 ASSERT_TRUE(valid); 416 ASSERT_TRUE(valid);
408 output.Complete(); 417 output.Complete();
409 418
410 EXPECT_EQ(test.whitespace_removed, resolved_parsed.whitespace_removed); 419 EXPECT_EQ(test.potentially_dangling_markup,
420 resolved_parsed.potentially_dangling_markup);
411 EXPECT_EQ(test.out, resolved); 421 EXPECT_EQ(test.out, resolved);
412 } 422 }
413 } 423 }
414 424
415 TEST(URLUtilTest, TestDomainIs) { 425 TEST(URLUtilTest, TestDomainIs) {
416 const struct { 426 const struct {
417 const char* canonicalized_host; 427 const char* canonicalized_host;
418 const char* lower_ascii_domain; 428 const char* lower_ascii_domain;
419 bool expected_domain_is; 429 bool expected_domain_is;
420 } kTestCases[] = { 430 } kTestCases[] = {
(...skipping 28 matching lines...) Expand all
449 << test_case.canonicalized_host << ", " 459 << test_case.canonicalized_host << ", "
450 << test_case.lower_ascii_domain << ")"); 460 << test_case.lower_ascii_domain << ")");
451 461
452 EXPECT_EQ( 462 EXPECT_EQ(
453 test_case.expected_domain_is, 463 test_case.expected_domain_is,
454 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); 464 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain));
455 } 465 }
456 } 466 }
457 467
458 } // namespace url 468 } // namespace url
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698