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

Unified Diff: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp

Issue 2470083002: Part 2.1: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: Rebasing on master Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp b/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
index 71c7bf87612d624963d4d5d876ad0e4ca45db85b..86657a4fdd8a9ca81df5421209ccd30490a40d5e 100644
--- a/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp
@@ -344,4 +344,105 @@ TEST_F(CSPSourceTest, SchemesOnlySubsumes) {
}
}
+TEST_F(CSPSourceTest, IsSimilar) {
+ struct Source {
+ const char* scheme;
+ const char* host;
+ const char* path;
+ const int port;
+ };
+ struct TestCase {
+ const Source a;
+ const Source b;
+ bool isSimilar;
+ } cases[] = {
+ // Similar
+ {{"http", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true},
+ // Schemes
+ {{"https", "example.com", "/", 0},
+ {"https", "example.com", "/", 0},
+ true},
+ {{"https", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true},
+ {{"ws", "example.com", "/", 0}, {"wss", "example.com", "/", 0}, true},
+ // Ports
+ {{"http", "example.com", "/", 90},
+ {"http", "example.com", "/", 90},
+ true},
+ {{"wss", "example.com", "/", 0},
+ {"wss", "example.com", "/", 0},
+ true}, // use default port
+ {{"http", "example.com", "/", 80}, {"http", "example.com", "/", 0}, true},
+ // Paths
+ {{"http", "example.com", "/", 0},
+ {"http", "example.com", "/1.html", 0},
+ true},
+ {{"http", "example.com", "/", 0}, {"http", "example.com", "", 0}, true},
+ {{"http", "example.com", "/", 0},
+ {"http", "example.com", "/a/b/", 0},
+ true},
+ {{"http", "example.com", "/a/", 0},
+ {"http", "example.com", "/a/", 0},
+ true},
+ {{"http", "example.com", "/a/", 0},
+ {"http", "example.com", "/a/b/", 0},
+ true},
+ {{"http", "example.com", "/a/", 0},
+ {"http", "example.com", "/a/b/1.html", 0},
+ true},
+ {{"http", "example.com", "/1.html", 0},
+ {"http", "example.com", "/1.html", 0},
+ true},
+ // Mixed
+ {{"http", "example.com", "/1.html", 90},
+ {"http", "example.com", "/", 90},
+ true},
+ {{"https", "example.com", "/", 0}, {"http", "example.com", "/", 0}, true},
+ {{"http", "example.com", "/a/", 90},
+ {"https", "example.com", "", 90},
+ true},
+ {{"wss", "example.com", "/a/", 90},
+ {"ws", "example.com", "/a/b/", 90},
+ true},
+ {{"https", "example.com", "/a/", 90},
+ {"https", "example.com", "/a/b/", 90},
+ true},
+ // Not Similar
+ {{"http", "example.com", "/a/", 0},
+ {"https", "example.com", "", 90},
+ false},
+ {{"https", "example.com", "/", 0},
+ {"https", "example.com", "/", 90},
+ false},
+ {{"http", "example.com", "/", 0}, {"http", "another.com", "/", 0}, false},
+ {{"wss", "example.com", "/", 0}, {"http", "example.com", "/", 0}, false},
+ {{"wss", "example.com", "/", 0}, {"about", "example.com", "/", 0}, false},
+ {{"http", "example.com", "/", 0},
+ {"about", "example.com", "/", 0},
+ false},
+ {{"http", "example.com", "/1.html", 0},
+ {"http", "example.com", "/2.html", 0},
+ false},
+ {{"http", "example.com", "/a/1.html", 0},
+ {"http", "example.com", "/a/b/", 0},
+ false},
+ {{"http", "example.com", "/", 443},
+ {"about", "example.com", "/", 800},
+ false},
+ };
+
+ for (const auto& test : cases) {
+ CSPSource* returned = new CSPSource(
+ csp.get(), test.a.scheme, test.a.host, test.a.port, test.a.path,
+ CSPSource::NoWildcard, CSPSource::NoWildcard);
+
+ CSPSource* required = new CSPSource(
+ csp.get(), test.b.scheme, test.b.host, test.b.port, test.b.path,
+ CSPSource::NoWildcard, CSPSource::NoWildcard);
+
+ EXPECT_EQ(returned->isSimilar(required), test.isSimilar);
+ // Verify the same test with a and b swapped.
+ EXPECT_EQ(required->isSimilar(returned), test.isSimilar);
+ }
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/CSPSource.cpp ('k') | third_party/WebKit/Source/core/frame/csp/SourceListDirective.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698