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

Side by Side Diff: url/url_util_unittest.cc

Issue 2890143002: Set 'whitespace_removed' correctly when resolving relative URLs. (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
« no previous file with comments | « url/url_canon_relative.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 <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) {
378 struct ResolveRelativeCase {
379 const char* base;
380 const char* rel;
381 bool whitespace_removed;
382 const char* out;
383 } cases[] = {
384 {"https://example.com/", "/path", false, "https://example.com/path"},
385 {"https://example.com/", "\n/path", true, "https://example.com/path"},
386 {"https://example.com/", "\r/path", true, "https://example.com/path"},
387 {"https://example.com/", "\t/path", true, "https://example.com/path"},
388 {"https://example.com/", "/pa\nth", true, "https://example.com/path"},
389 {"https://example.com/", "/pa\rth", true, "https://example.com/path"},
390 {"https://example.com/", "/pa\tth", true, "https://example.com/path"},
391 {"https://example.com/", "/path\n", true, "https://example.com/path"},
392 {"https://example.com/", "/path\r", true, "https://example.com/path"},
393 {"https://example.com/", "/path\r", true, "https://example.com/path"},
394 };
395
396 for (const auto& test : cases) {
397 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.rel);
398 Parsed base_parsed;
399 ParseStandardURL(test.base, strlen(test.base), &base_parsed);
400
401 std::string resolved;
402 StdStringCanonOutput output(&resolved);
403 Parsed resolved_parsed;
404 bool valid =
405 ResolveRelative(test.base, strlen(test.base), base_parsed, test.rel,
406 strlen(test.rel), NULL, &output, &resolved_parsed);
407 ASSERT_TRUE(valid);
408 output.Complete();
409
410 EXPECT_EQ(test.whitespace_removed, resolved_parsed.whitespace_removed);
411 EXPECT_EQ(test.out, resolved);
412 }
413 }
414
377 TEST(URLUtilTest, TestDomainIs) { 415 TEST(URLUtilTest, TestDomainIs) {
378 const struct { 416 const struct {
379 const char* canonicalized_host; 417 const char* canonicalized_host;
380 const char* lower_ascii_domain; 418 const char* lower_ascii_domain;
381 bool expected_domain_is; 419 bool expected_domain_is;
382 } kTestCases[] = { 420 } kTestCases[] = {
383 {"google.com", "google.com", true}, 421 {"google.com", "google.com", true},
384 {"www.google.com", "google.com", true}, // Subdomain is ignored. 422 {"www.google.com", "google.com", true}, // Subdomain is ignored.
385 {"www.google.com.cn", "google.com", false}, // Different TLD. 423 {"www.google.com.cn", "google.com", false}, // Different TLD.
386 {"www.google.comm", "google.com", false}, 424 {"www.google.comm", "google.com", false},
(...skipping 24 matching lines...) Expand all
411 << test_case.canonicalized_host << ", " 449 << test_case.canonicalized_host << ", "
412 << test_case.lower_ascii_domain << ")"); 450 << test_case.lower_ascii_domain << ")");
413 451
414 EXPECT_EQ( 452 EXPECT_EQ(
415 test_case.expected_domain_is, 453 test_case.expected_domain_is,
416 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); 454 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain));
417 } 455 }
418 } 456 }
419 457
420 } // namespace url 458 } // namespace url
OLDNEW
« no previous file with comments | « url/url_canon_relative.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698