| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/content_settings_pattern.h" | 5 #include "chrome/common/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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 EXPECT_STREQ("file:///tmp/test.html", | 413 EXPECT_STREQ("file:///tmp/test.html", |
| 414 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 414 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST(ContentSettingsPatternTest, InvalidPatterns) { | 417 TEST(ContentSettingsPatternTest, InvalidPatterns) { |
| 418 // StubObserver expects an empty pattern top be returned as empty string. | 418 // StubObserver expects an empty pattern top be returned as empty string. |
| 419 EXPECT_FALSE(ContentSettingsPattern().IsValid()); | 419 EXPECT_FALSE(ContentSettingsPattern().IsValid()); |
| 420 EXPECT_STREQ("", ContentSettingsPattern().ToString().c_str()); | 420 EXPECT_STREQ("", ContentSettingsPattern().ToString().c_str()); |
| 421 | 421 |
| 422 // Empty pattern string | 422 // Empty pattern string |
| 423 EXPECT_FALSE(Pattern("").IsValid()); | 423 EXPECT_FALSE(Pattern(std::string()).IsValid()); |
| 424 EXPECT_STREQ("", Pattern("").ToString().c_str()); | 424 EXPECT_STREQ("", Pattern(std::string()).ToString().c_str()); |
| 425 | 425 |
| 426 // Pattern strings with invalid scheme part. | 426 // Pattern strings with invalid scheme part. |
| 427 EXPECT_FALSE(Pattern("ftp://myhost.org").IsValid()); | 427 EXPECT_FALSE(Pattern("ftp://myhost.org").IsValid()); |
| 428 EXPECT_STREQ("", Pattern("ftp://myhost.org").ToString().c_str()); | 428 EXPECT_STREQ("", Pattern("ftp://myhost.org").ToString().c_str()); |
| 429 | 429 |
| 430 // Pattern strings with invalid host part. | 430 // Pattern strings with invalid host part. |
| 431 EXPECT_FALSE(Pattern("*example.com").IsValid()); | 431 EXPECT_FALSE(Pattern("*example.com").IsValid()); |
| 432 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 432 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
| 433 EXPECT_FALSE(Pattern("example.*").IsValid()); | 433 EXPECT_FALSE(Pattern("example.*").IsValid()); |
| 434 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 434 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 623 |
| 624 EXPECT_TRUE(Pattern("[*.]example.com").Matches( | 624 EXPECT_TRUE(Pattern("[*.]example.com").Matches( |
| 625 GURL("http://example.com/"))); | 625 GURL("http://example.com/"))); |
| 626 EXPECT_TRUE(Pattern("[*.]example.com").Matches( | 626 EXPECT_TRUE(Pattern("[*.]example.com").Matches( |
| 627 GURL("http://www.example.com/"))); | 627 GURL("http://www.example.com/"))); |
| 628 EXPECT_TRUE(Pattern("www.example.com").Matches( | 628 EXPECT_TRUE(Pattern("www.example.com").Matches( |
| 629 GURL("http://www.example.com/"))); | 629 GURL("http://www.example.com/"))); |
| 630 EXPECT_TRUE( | 630 EXPECT_TRUE( |
| 631 Pattern("file:///tmp/test.html").Matches( | 631 Pattern("file:///tmp/test.html").Matches( |
| 632 GURL("file:///tmp/test.html"))); | 632 GURL("file:///tmp/test.html"))); |
| 633 EXPECT_FALSE(Pattern("").Matches( | 633 EXPECT_FALSE(Pattern(std::string()).Matches(GURL("http://www.example.com/"))); |
| 634 GURL("http://www.example.com/"))); | |
| 635 EXPECT_FALSE(Pattern("[*.]example.com").Matches( | 634 EXPECT_FALSE(Pattern("[*.]example.com").Matches( |
| 636 GURL("http://example.org/"))); | 635 GURL("http://example.org/"))); |
| 637 EXPECT_FALSE(Pattern("example.com").Matches( | 636 EXPECT_FALSE(Pattern("example.com").Matches( |
| 638 GURL("http://example.org/"))); | 637 GURL("http://example.org/"))); |
| 639 EXPECT_FALSE( | 638 EXPECT_FALSE( |
| 640 Pattern("file:///tmp/test.html").Matches( | 639 Pattern("file:///tmp/test.html").Matches( |
| 641 GURL("file:///tmp/other.html"))); | 640 GURL("file:///tmp/other.html"))); |
| 642 EXPECT_FALSE( | 641 EXPECT_FALSE( |
| 643 Pattern("file:///tmp/test.html").Matches( | 642 Pattern("file:///tmp/test.html").Matches( |
| 644 GURL("http://example.org/"))); | 643 GURL("http://example.org/"))); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 664 // file:/// normalization. | 663 // file:/// normalization. |
| 665 EXPECT_STREQ("file:///tmp/test.html", | 664 EXPECT_STREQ("file:///tmp/test.html", |
| 666 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 665 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
| 667 | 666 |
| 668 // Invalid patterns. | 667 // Invalid patterns. |
| 669 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 668 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
| 670 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 669 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
| 671 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 670 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
| 672 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 671 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
| 673 } | 672 } |
| OLD | NEW |