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

Side by Side Diff: chrome/browser/content_settings/content_settings_pattern_unittest.cc

Issue 6969095: Allow invalid patterns for comparison; Make the compare method a order relation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/content_settings/content_settings_pattern.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_pattern.h" 5 #include "chrome/browser/content_settings/content_settings_pattern.h"
6 6
7 #include "googleurl/src/gurl.h" 7 #include "googleurl/src/gurl.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace { 10 namespace {
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 ContentSettingsPattern pattern1 = 366 ContentSettingsPattern pattern1 =
367 Pattern("http://www.google.com"); 367 Pattern("http://www.google.com");
368 EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern1.Compare(pattern1)); 368 EXPECT_EQ(ContentSettingsPattern::IDENTITY, pattern1.Compare(pattern1));
369 EXPECT_EQ(ContentSettingsPattern::IDENTITY, 369 EXPECT_EQ(ContentSettingsPattern::IDENTITY,
370 Pattern("http://www.google.com:80").Compare( 370 Pattern("http://www.google.com:80").Compare(
371 Pattern("http://www.google.com:80"))); 371 Pattern("http://www.google.com:80")));
372 EXPECT_EQ(ContentSettingsPattern::IDENTITY, 372 EXPECT_EQ(ContentSettingsPattern::IDENTITY,
373 Pattern("*://[*.]google.com:*").Compare( 373 Pattern("*://[*.]google.com:*").Compare(
374 Pattern("*://[*.]google.com:*"))); 374 Pattern("*://[*.]google.com:*")));
375 375
376 // Test disjoint patterns. 376 ContentSettingsPattern invalid_pattern1 = ContentSettingsPattern();
377 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 377 ContentSettingsPattern invalid_pattern2 = Pattern("www.google.com*");
378
379 // Compare invalid patterns.
380 EXPECT_TRUE(!invalid_pattern1.IsValid());
381 EXPECT_TRUE(!invalid_pattern2.IsValid());
382 EXPECT_EQ(ContentSettingsPattern::IDENTITY,
383 invalid_pattern1.Compare(invalid_pattern2));
384 EXPECT_TRUE(invalid_pattern1 == invalid_pattern2);
385
386 // Compare a pattern with an IPv4 addresse to a pattern with a domain name.
387 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_POST,
388 Pattern("http://www.google.com").Compare(
389 Pattern("127.0.0.1")));
390 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
391 Pattern("127.0.0.1").Compare(
392 Pattern("http://www.google.com")));
393 EXPECT_TRUE(Pattern("127.0.0.1") > Pattern("http://www.google.com"));
394 EXPECT_TRUE(Pattern("http://www.google.com") < Pattern("127.0.0.1"));
395
396 // Compare a pattern with an IPv6 address to a patterns with a domain name.
397 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_POST,
398 Pattern("http://www.google.com").Compare(
399 Pattern("[::1]")));
400 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
401 Pattern("[::1]").Compare(
402 Pattern("http://www.google.com")));
403 EXPECT_TRUE(Pattern("[::1]") > Pattern("http://www.google.com"));
404 EXPECT_TRUE(Pattern("http://www.google.com") < Pattern("[::1]"));
405
406 // Compare a pattern with an IPv6 addresse to a pattern with an IPv4 addresse.
407 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
408 Pattern("127.0.0.1").Compare(
409 Pattern("[::1]")));
410 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_POST,
411 Pattern("[::1]").Compare(
412 Pattern("127.0.0.1")));
413 EXPECT_TRUE(Pattern("[::1]") < Pattern("127.0.0.1"));
414 EXPECT_TRUE(Pattern("127.0.0.1") > Pattern("[::1]"));
415
416 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
378 Pattern("http://www.google.com").Compare( 417 Pattern("http://www.google.com").Compare(
379 Pattern("http://www.youtube.com"))); 418 Pattern("http://www.youtube.com")));
380 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 419 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
381 Pattern("http://[*.]google.com").Compare( 420 Pattern("http://[*.]google.com").Compare(
382 Pattern("http://[*.]youtube.com"))); 421 Pattern("http://[*.]youtube.com")));
383 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 422
423 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_POST,
384 Pattern("http://[*.]host.com").Compare( 424 Pattern("http://[*.]host.com").Compare(
385 Pattern("http://[*.]evilhost.com"))); 425 Pattern("http://[*.]evilhost.com")));
386 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 426 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_POST,
387 Pattern("*://www.google.com:80").Compare( 427 Pattern("*://www.google.com:80").Compare(
388 Pattern("*://www.google.com:8080"))); 428 Pattern("*://www.google.com:8080")));
389 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 429 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
390 Pattern("https://www.google.com:80").Compare( 430 Pattern("https://www.google.com:80").Compare(
391 Pattern("http://www.google.com:80"))); 431 Pattern("http://www.google.com:80")));
392 432
393 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 433 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
394 Pattern("http://[*.]google.com:90").Compare( 434 Pattern("http://[*.]google.com:90").Compare(
395 Pattern("http://mail.google.com:80"))); 435 Pattern("http://mail.google.com:80")));
396 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 436 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
397 Pattern("https://[*.]google.com:80").Compare( 437 Pattern("https://[*.]google.com:80").Compare(
398 Pattern("http://mail.google.com:80"))); 438 Pattern("http://mail.google.com:80")));
399 EXPECT_EQ(ContentSettingsPattern::DISJOINT, 439 EXPECT_EQ(ContentSettingsPattern::DISJOINT_ORDER_PRE,
400 Pattern("https://mail.google.com:*").Compare( 440 Pattern("https://mail.google.com:*").Compare(
401 Pattern("http://mail.google.com:80"))); 441 Pattern("http://mail.google.com:80")));
402 442
403 // Test patterns with different precedences. 443 // Test patterns with different precedences.
404 EXPECT_EQ(ContentSettingsPattern::PREDECESSOR, 444 EXPECT_EQ(ContentSettingsPattern::PREDECESSOR,
405 Pattern("mail.google.com").Compare( 445 Pattern("mail.google.com").Compare(
406 Pattern("[*.]google.com"))); 446 Pattern("[*.]google.com")));
407 EXPECT_EQ(ContentSettingsPattern::SUCCESSOR, 447 EXPECT_EQ(ContentSettingsPattern::SUCCESSOR,
408 Pattern("[*.]google.com").Compare( 448 Pattern("[*.]google.com").Compare(
409 Pattern("mail.google.com"))); 449 Pattern("mail.google.com")));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // file:/// normalization. 556 // file:/// normalization.
517 EXPECT_STREQ("file:///tmp/test.html", 557 EXPECT_STREQ("file:///tmp/test.html",
518 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); 558 Pattern("file:///tmp/bar/../test.html").ToString().c_str());
519 559
520 // Invalid patterns. 560 // Invalid patterns.
521 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); 561 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str());
522 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); 562 EXPECT_STREQ("", Pattern("example.*").ToString().c_str());
523 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); 563 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str());
524 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); 564 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str());
525 } 565 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/content_settings_pattern.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698