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

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

Issue 2541843002: Part 5.1: Is policy list subsumed under subsuming policy? (Closed)
Patch Set: Created 4 years 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/MediaListDirectiveTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/MediaListDirectiveTest.cpp b/third_party/WebKit/Source/core/frame/csp/MediaListDirectiveTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6c7bc2c2d2c57d94e0988e7eb55f825dc5d22c13
--- /dev/null
+++ b/third_party/WebKit/Source/core/frame/csp/MediaListDirectiveTest.cpp
@@ -0,0 +1,122 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/frame/csp/MediaListDirective.h"
+
+#include "core/frame/csp/ContentSecurityPolicy.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blink {
+
+class MediaListDirectiveTest : public ::testing::Test {
+ public:
+ MediaListDirectiveTest() : csp(ContentSecurityPolicy::create()) {}
+
+ protected:
+ Persistent<ContentSecurityPolicy> csp;
+};
+
+TEST_F(MediaListDirectiveTest, GetIntersect) {
+ MediaListDirective A(
+ "plugin-types",
+ "application/x-shockwave-flash application/pdf text/plain", csp.get());
Mike West 2016/12/06 13:39:07 Can you check that we have a sane behavior when |A
+
+ struct TestCase {
+ const char* policyB;
+ const std::vector<const char*> expected;
+ } cases[] = {
+ {"text/plain", {"text/plain"}},
Mike West 2016/12/06 13:39:07 Can you add an empty list?
+ {"application/pdf", {"application/pdf"}},
+ {"application/x-shockwave-flash", {"application/x-shockwave-flash"}},
+ {"application/x-shockwave-flash text/plain",
Mike West 2016/12/06 13:39:07 Nit: Can you add tests that reverse the order, jus
+ {"application/x-shockwave-flash", "text/plain"}},
+ {"application/pdf text/plain", {"text/plain", "application/pdf"}},
+ {"application/x-shockwave-flash application/pdf text/plain",
+ {"application/x-shockwave-flash", "application/pdf", "text/plain"}},
Mike West 2016/12/06 13:39:07 Can you add some things like `text/`, `text/*`, an
amalika 2016/12/06 13:54:19 Just to make sure: None of these will be valid, ri
+ };
+
+ for (const auto& test : cases) {
+ MediaListDirective B("plugin-types", test.policyB, csp.get());
+
+ HashSet<String> result = A.getIntersect(B.m_pluginTypes);
+ EXPECT_EQ(result.size(), test.expected.size());
+
+ for (const auto& type : test.expected)
+ EXPECT_TRUE(result.contains(type));
+ }
+}
+
+TEST_F(MediaListDirectiveTest, Subsumes) {
+ MediaListDirective A(
+ "plugin-types",
+ "application/x-shockwave-flash application/pdf text/plain", csp.get());
Mike West 2016/12/06 13:39:07 Same general comments. Empty lists, wildcards, ord
+
+ struct TestCase {
+ const std::vector<const char*> policiesB;
+ bool subsumed;
+ bool subsumedByEmptyA;
+ } cases[] = {
+ // `A` subsumes `policiesB`.
+ {{""}, true, true},
+ {{"text/plain"}, true, false},
+ {{"application/pdf"}, true, false},
+ {{"application/x-shockwave-flash"}, true, false},
+ {{"application/x-shockwave-flash text/plain"}, true, false},
+ {{"application/pdf text/plain"}, true, false},
+ {{"application/x-shockwave-flash text/plain application/pdf"},
+ true,
+ false},
+ {{"application/x-shockwave-flash text "}, true, false},
+ {{"application/x-shockwave-flash text/plain "
+ "application/x-blink-test-plugin",
+ "application/x-shockwave-flash text/plain"},
+ true,
+ false},
+ {{"application/x-shockwave-flash text/plain "
+ "application/x-blink-test-plugin",
+ "text/plain"},
+ true,
+ false},
+ {{"application/x-blink-test-plugin", "text/plain"}, true, true},
+ {{"application/x-shockwave-flash",
+ "text/plain application/x-shockwave-flash"},
+ true,
+ false},
+ {{"application/x-shockwave-flash text/plain",
+ "application/x-blink-test-plugin", "text/plain"},
+ true,
+ true},
+ // `A` does not subsumes `policiesB`.
+ {{}, false, false},
+ {{"application/x-blink-test-plugin"}, false, false},
+ {{"application/x-shockwave-flash text/plain "
+ "application/x-blink-test-plugin"},
+ false,
+ false},
+ {{"application/x-shockwave-flash text application/x-blink-test-plugin"},
+ false,
+ false},
+ {{"application/x-invalid-type text application/"}, false, false},
+ {{"application/x-blink-test-plugin text application/",
+ "application/x-blink-test-plugin"},
+ false,
+ false},
+ };
+
+ MediaListDirective emptyA("plugin-types", "", csp.get());
+ EXPECT_TRUE(emptyA.subsumes({&emptyA}));
+
+ for (const auto& test : cases) {
+ std::vector<MediaListDirective*> policiesB;
+ for (const auto& policy : test.policiesB) {
+ policiesB.push_back(
+ new MediaListDirective("plugin-types", policy, csp.get()));
+ }
+
+ EXPECT_EQ(A.subsumes(policiesB), test.subsumed);
+ EXPECT_EQ(emptyA.subsumes(policiesB), test.subsumedByEmptyA);
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698