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

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/OriginAccessEntryTest.cpp

Issue 1607243002: Add 'OriginAccessEntry::matchDomain'. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
Patch Set: Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi n)); 84 EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origi n));
85 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO rigin(*origin)); 85 EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesO rigin(*origin));
86 } 86 }
87 87
88 TEST(OriginAccessEntryTest, AllowSubdomainsTest) 88 TEST(OriginAccessEntryTest, AllowSubdomainsTest)
89 { 89 {
90 struct TestCase { 90 struct TestCase {
91 const char* protocol; 91 const char* protocol;
92 const char* host; 92 const char* host;
93 const char* origin; 93 const char* origin;
94 OriginAccessEntry::MatchResult expected; 94 OriginAccessEntry::MatchResult expectedOrigin;
95 OriginAccessEntry::MatchResult expectedDomain;
95 } inputs[] = { 96 } inputs[] = {
96 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin }, 97 { "http", "example.com", "http://example.com/", OriginAccessEntry::Match esOrigin, OriginAccessEntry::MatchesOrigin },
97 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin }, 98 { "http", "example.com", "http://www.example.com/", OriginAccessEntry::M atchesOrigin, OriginAccessEntry::MatchesOrigin },
98 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin }, 99 { "http", "example.com", "http://www.www.example.com/", OriginAccessEntr y::MatchesOrigin, OriginAccessEntry::MatchesOrigin },
99 { "http", "www.example.com", "http://example.com/", OriginAccessEntry::D oesNotMatchOrigin }, 100 { "http", "www.example.com", "http://example.com/", OriginAccessEntry::D oesNotMatchOrigin, OriginAccessEntry::DoesNotMatchOrigin },
100 { "http", "www.example.com", "http://www.example.com/", OriginAccessEntr y::MatchesOrigin }, 101 { "http", "www.example.com", "http://www.example.com/", OriginAccessEntr y::MatchesOrigin, OriginAccessEntry::MatchesOrigin },
101 { "http", "www.example.com", "http://www.www.example.com/", OriginAccess Entry::MatchesOrigin }, 102 { "http", "www.example.com", "http://www.www.example.com/", OriginAccess Entry::MatchesOrigin, OriginAccessEntry::MatchesOrigin },
102 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix }, 103 { "http", "com", "http://example.com/", OriginAccessEntry::MatchesOrigin ButIsPublicSuffix, OriginAccessEntry::MatchesOriginButIsPublicSuffix },
103 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix }, 104 { "http", "com", "http://www.example.com/", OriginAccessEntry::MatchesOr iginButIsPublicSuffix, OriginAccessEntry::MatchesOriginButIsPublicSuffix },
104 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix }, 105 { "http", "com", "http://www.www.example.com/", OriginAccessEntry::Match esOriginButIsPublicSuffix, OriginAccessEntry::MatchesOriginButIsPublicSuffix },
105 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin }, 106 { "https", "example.com", "http://example.com/", OriginAccessEntry::Does NotMatchOrigin, OriginAccessEntry::MatchesOrigin },
106 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin }, 107 { "https", "example.com", "http://www.example.com/", OriginAccessEntry:: DoesNotMatchOrigin, OriginAccessEntry::MatchesOrigin },
107 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin }, 108 { "https", "example.com", "http://www.www.example.com/", OriginAccessEnt ry::DoesNotMatchOrigin, OriginAccessEntry::MatchesOrigin },
108 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin }, 109 { "http", "example.com", "http://beispiel.de/", OriginAccessEntry::DoesN otMatchOrigin, OriginAccessEntry::DoesNotMatchOrigin },
109 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin }, 110 { "http", "example.com", "https://beispiel.de/", OriginAccessEntry::Does NotMatchOrigin, OriginAccessEntry::DoesNotMatchOrigin },
110 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin }, 111 { "http", "", "http://example.com/", OriginAccessEntry::MatchesOrigin, O riginAccessEntry::MatchesOrigin },
111 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin }, 112 { "http", "", "http://beispiel.de/", OriginAccessEntry::MatchesOrigin, O riginAccessEntry::MatchesOrigin },
113 { "https", "", "http://beispiel.de/", OriginAccessEntry::DoesNotMatchOri gin, OriginAccessEntry::MatchesOrigin },
112 }; 114 };
113 115
114 OriginAccessEntryTestPlatform platform; 116 OriginAccessEntryTestPlatform platform;
115 platform.setPublicSuffix("com"); 117 platform.setPublicSuffix("com");
116 118
117 for (const auto& test : inputs) { 119 for (const auto& test : inputs) {
118 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin); 120 SCOPED_TRACE(testing::Message() << "Host: " << test.host << ", Origin: " << test.origin);
119 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); 121 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin);
120 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains); 122 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains);
121 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); 123 EXPECT_EQ(test.expectedOrigin, entry1.matchesOrigin(*originToTest));
124 EXPECT_EQ(test.expectedDomain, entry1.matchesDomain(*originToTest));
122 } 125 }
123 } 126 }
124 127
125 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest) 128 TEST(OriginAccessEntryTest, AllowRegisterableDomainsTest)
126 { 129 {
127 struct TestCase { 130 struct TestCase {
128 const char* protocol; 131 const char* protocol;
129 const char* host; 132 const char* host;
130 const char* origin; 133 const char* origin;
131 OriginAccessEntry::MatchResult expected; 134 OriginAccessEntry::MatchResult expected;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin); 285 RefPtr<SecurityOrigin> originToTest = SecurityOrigin::createFromString(t est.origin);
283 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains); 286 OriginAccessEntry entry1(test.protocol, test.host, OriginAccessEntry::Al lowSubdomains);
284 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest)); 287 EXPECT_EQ(test.expected, entry1.matchesOrigin(*originToTest));
285 288
286 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains); 289 OriginAccessEntry entry2(test.protocol, test.host, OriginAccessEntry::Di sallowSubdomains);
287 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest)); 290 EXPECT_EQ(test.expected, entry2.matchesOrigin(*originToTest));
288 } 291 }
289 } 292 }
290 293
291 } // namespace blink 294 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698