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 "components/content_settings/core/common/content_settings_pattern.h" | 5 #include "components/content_settings/core/common/content_settings_pattern.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 // file:/// normalization. | 713 // file:/// normalization. |
714 EXPECT_STREQ("file:///tmp/test.html", | 714 EXPECT_STREQ("file:///tmp/test.html", |
715 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); | 715 Pattern("file:///tmp/bar/../test.html").ToString().c_str()); |
716 | 716 |
717 // Invalid patterns. | 717 // Invalid patterns. |
718 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); | 718 EXPECT_STREQ("", Pattern("*example.com").ToString().c_str()); |
719 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); | 719 EXPECT_STREQ("", Pattern("example.*").ToString().c_str()); |
720 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); | 720 EXPECT_STREQ("", Pattern("*\xC4\x87ira.com").ToString().c_str()); |
721 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); | 721 EXPECT_STREQ("", Pattern("\xC4\x87ira.*").ToString().c_str()); |
722 } | 722 } |
| 723 |
| 724 TEST(ContentSettingsPatternTest, IsGeneratedFromURLDomainScoped) { |
| 725 // These are pattern styles which might be generated from FromURL(). |
| 726 EXPECT_TRUE(ContentSettingsPattern::FromString("[*.]example.com") |
| 727 .IsGeneratedFromURLDomainScoped()); |
| 728 EXPECT_TRUE(ContentSettingsPattern::FromString("[*.]google.com:80") |
| 729 .IsGeneratedFromURLDomainScoped()); |
| 730 EXPECT_TRUE(ContentSettingsPattern::FromString("https://[*.]google.com") |
| 731 .IsGeneratedFromURLDomainScoped()); |
| 732 EXPECT_TRUE(ContentSettingsPattern::FromString("https://[*.]google.com:443") |
| 733 .IsGeneratedFromURLDomainScoped()); |
| 734 // These patterns either have an empty host, or have no domain wildcard, so |
| 735 // they can not be generated from FromURL(). |
| 736 EXPECT_FALSE( |
| 737 ContentSettingsPattern::FromString("*").IsGeneratedFromURLDomainScoped()); |
| 738 EXPECT_FALSE(ContentSettingsPattern::FromString("[*.]") |
| 739 .IsGeneratedFromURLDomainScoped()); |
| 740 EXPECT_FALSE(ContentSettingsPattern::FromString("http://*") |
| 741 .IsGeneratedFromURLDomainScoped()); |
| 742 EXPECT_FALSE(ContentSettingsPattern::FromString("http://*:8080") |
| 743 .IsGeneratedFromURLDomainScoped()); |
| 744 EXPECT_FALSE(ContentSettingsPattern::FromString("*://www.google.com:8080") |
| 745 .IsGeneratedFromURLDomainScoped()); |
| 746 EXPECT_FALSE(ContentSettingsPattern::FromString("www.example.com:8080") |
| 747 .IsGeneratedFromURLDomainScoped()); |
| 748 EXPECT_FALSE(ContentSettingsPattern::FromString("www.google.com/*") |
| 749 .IsGeneratedFromURLDomainScoped()); |
| 750 EXPECT_FALSE(ContentSettingsPattern::FromString("google") |
| 751 .IsGeneratedFromURLDomainScoped()); |
| 752 EXPECT_FALSE(ContentSettingsPattern::FromString("https://www.google.com") |
| 753 .IsGeneratedFromURLDomainScoped()); |
| 754 EXPECT_FALSE(ContentSettingsPattern::FromString("https://www.google.com:443") |
| 755 .IsGeneratedFromURLDomainScoped()); |
| 756 } |
| 757 |
| 758 TEST(ContentSettingsPatternTest, FromDomainToOrigin) { |
| 759 EXPECT_STREQ( |
| 760 "http://example.com:80", |
| 761 ContentSettingsPattern::FromDomainToOrigin(Pattern("[*.]example.com")) |
| 762 .ToString() |
| 763 .c_str()); |
| 764 EXPECT_STREQ( |
| 765 "http://example.com:80", |
| 766 ContentSettingsPattern::FromDomainToOrigin(Pattern("[*.]example.com:80")) |
| 767 .ToString() |
| 768 .c_str()); |
| 769 EXPECT_STREQ("https://example.com:443", |
| 770 ContentSettingsPattern::FromDomainToOrigin( |
| 771 Pattern("https://[*.]example.com:443")) |
| 772 .ToString() |
| 773 .c_str()); |
| 774 } |
OLD | NEW |