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, IsGeneratedUsingFromURL) { | |
725 // These are pattern styles which might be generated from FromURL(). | |
726 EXPECT_TRUE(ContentSettingsPattern::FromString("[*.]example.com") | |
727 .IsGeneratedUsingFromURL()); | |
728 EXPECT_TRUE(ContentSettingsPattern::FromString("[*.]google.com:80") | |
729 .IsGeneratedUsingFromURL()); | |
730 EXPECT_TRUE(ContentSettingsPattern::FromString("https://[*.]google.com:443") | |
731 .IsGeneratedUsingFromURL()); | |
732 // These patterns either have an empty host, or have no domain wildcard, so | |
733 // they can not be generated from FromURL(). | |
734 EXPECT_FALSE( | |
735 ContentSettingsPattern::FromString("*").IsGeneratedUsingFromURL()); | |
736 EXPECT_FALSE( | |
737 ContentSettingsPattern::FromString("[*.]").IsGeneratedUsingFromURL()); | |
738 EXPECT_FALSE( | |
739 ContentSettingsPattern::FromString("http://*").IsGeneratedUsingFromURL()); | |
740 EXPECT_FALSE(ContentSettingsPattern::FromString("http://*:8080") | |
741 .IsGeneratedUsingFromURL()); | |
742 EXPECT_FALSE(ContentSettingsPattern::FromString("*://www.google.com:8080") | |
743 .IsGeneratedUsingFromURL()); | |
744 EXPECT_FALSE(ContentSettingsPattern::FromString("www.example.com:8080") | |
745 .IsGeneratedUsingFromURL()); | |
746 EXPECT_FALSE(ContentSettingsPattern::FromString("www.google.com/*") | |
747 .IsGeneratedUsingFromURL()); | |
748 EXPECT_FALSE( | |
749 ContentSettingsPattern::FromString("google").IsGeneratedUsingFromURL()); | |
750 EXPECT_FALSE(ContentSettingsPattern::FromString("https://www.google.com") | |
751 .IsGeneratedUsingFromURL()); | |
752 EXPECT_FALSE(ContentSettingsPattern::FromString("https://www.google.com:443") | |
753 .IsGeneratedUsingFromURL()); | |
754 EXPECT_FALSE(ContentSettingsPattern::FromString("https://[*.]google.com") | |
755 .IsGeneratedUsingFromURL()); | |
raymes
2016/06/20 04:03:26
We should make sure that the tests cover each of t
lshang
2016/06/23 01:32:32
Done.
| |
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()); | |
raymes
2016/06/20 04:03:26
does expect_eq work, if you get rid of the call to
lshang
2016/06/23 01:32:32
Done.
| |
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()); | |
raymes
2016/06/20 04:03:26
We should also test a case with a port wildcard
lshang
2016/06/23 01:32:32
Https patterns generated using FromURL() should al
raymes
2016/06/27 07:23:29
Ahh that makes sense
| |
774 } | |
OLD | NEW |