OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/frame/csp/MediaListDirective.h" | |
6 | |
7 #include "core/frame/csp/ContentSecurityPolicy.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace blink { | |
11 | |
12 class MediaListDirectiveTest : public ::testing::Test { | |
13 public: | |
14 MediaListDirectiveTest() : csp(ContentSecurityPolicy::create()) {} | |
15 | |
16 protected: | |
17 Persistent<ContentSecurityPolicy> csp; | |
18 }; | |
19 | |
20 TEST_F(MediaListDirectiveTest, GetIntersect) { | |
21 MediaListDirective A( | |
22 "plugin-types", | |
23 "application/x-shockwave-flash application/pdf text/plain", csp.get()); | |
24 MediaListDirective emptyA("plugin-types", "", csp.get()); | |
25 | |
26 struct TestCase { | |
27 const char* policyB; | |
28 const std::vector<const char*> expected; | |
29 } cases[] = { | |
30 {"", {}}, | |
31 {"text/", {}}, | |
32 {"text/*", {}}, | |
33 {"*/plain", {}}, | |
34 {"text/plain */plain", {"text/plain"}}, | |
35 {"text/plain application/*", {"text/plain"}}, | |
36 {"text/plain", {"text/plain"}}, | |
37 {"application/pdf", {"application/pdf"}}, | |
38 {"application/x-shockwave-flash", {"application/x-shockwave-flash"}}, | |
39 {"application/x-shockwave-flash text/plain", | |
40 {"application/x-shockwave-flash", "text/plain"}}, | |
41 {"application/pdf text/plain", {"text/plain", "application/pdf"}}, | |
42 {"application/x-shockwave-flash application/pdf text/plain", | |
43 {"application/x-shockwave-flash", "application/pdf", "text/plain"}}, | |
44 }; | |
45 | |
46 for (const auto& test : cases) { | |
47 MediaListDirective B("plugin-types", test.policyB, csp.get()); | |
48 | |
49 HashSet<String> result = A.getIntersect(B.m_pluginTypes); | |
50 EXPECT_EQ(result.size(), test.expected.size()); | |
51 | |
52 for (const auto& type : test.expected) | |
53 EXPECT_TRUE(result.contains(type)); | |
54 | |
55 // If we change the order of `A` and `B`, intersection should not change. | |
56 result = B.getIntersect(A.m_pluginTypes); | |
57 EXPECT_EQ(result.size(), test.expected.size()); | |
58 | |
59 for (const auto& type : test.expected) | |
60 EXPECT_TRUE(result.contains(type)); | |
61 | |
62 // When `A` is empty, there should not be any intersection. | |
63 result = emptyA.getIntersect(B.m_pluginTypes); | |
64 EXPECT_FALSE(result.size()); | |
65 } | |
66 } | |
67 | |
68 TEST_F(MediaListDirectiveTest, Subsumes) { | |
69 MediaListDirective A( | |
70 "plugin-types", | |
71 "application/x-shockwave-flash application/pdf text/plain text/*", | |
72 csp.get()); | |
73 | |
74 struct TestCase { | |
75 const std::vector<const char*> policiesB; | |
76 bool subsumed; | |
77 bool subsumedByEmptyA; | |
78 } cases[] = { | |
79 // `A` subsumes `policiesB`. | |
80 {{""}, true, true}, | |
81 {{"text/"}, true, true}, | |
82 {{"text/*"}, true, false}, | |
83 {{"application/*"}, false, false}, | |
amalika
2016/12/07 10:13:08
Parsing does not actually validate the `subtype` s
| |
84 {{"application/"}, true, true}, | |
85 {{"*/plain"}, false, false}, | |
86 {{"application"}, true, true}, | |
87 {{"text/plain"}, true, false}, | |
88 {{"application/pdf"}, true, false}, | |
89 {{"application/x-shockwave-flash"}, true, false}, | |
90 {{"application/x-shockwave-flash text/plain"}, true, false}, | |
91 {{"application/pdf text/plain"}, true, false}, | |
92 {{"application/x-shockwave-flash text/plain application/pdf"}, | |
93 true, | |
94 false}, | |
95 {{"application/x-shockwave-flash text "}, true, false}, | |
96 {{"text/* application/x-shockwave-flash"}, true, false}, | |
97 {{"application/ application/x-shockwave-flash"}, true, false}, | |
98 {{"*/plain application/x-shockwave-flash"}, false, false}, | |
99 {{"text/ application/x-shockwave-flash"}, true, false}, | |
100 {{"application application/x-shockwave-flash"}, true, false}, | |
101 {{"application/x-shockwave-flash text/plain " | |
102 "application/x-blink-test-plugin", | |
103 "application/x-shockwave-flash text/plain"}, | |
104 true, | |
105 false}, | |
106 {{"application/x-shockwave-flash text/plain " | |
107 "application/x-blink-test-plugin", | |
108 "text/plain"}, | |
109 true, | |
110 false}, | |
111 {{"application/x-blink-test-plugin", "text/plain"}, true, true}, | |
112 {{"application/x-shockwave-flash", | |
113 "text/plain application/x-shockwave-flash"}, | |
114 true, | |
115 false}, | |
116 {{"application/x-shockwave-flash text/plain", | |
117 "application/x-blink-test-plugin", "text/plain"}, | |
118 true, | |
119 true}, | |
120 // `A` does not subsumes `policiesB`. | |
121 {{}, false, false}, | |
122 {{"application/x-blink-test-plugin"}, false, false}, | |
123 {{"application/x-shockwave-flash text/plain " | |
124 "application/x-blink-test-plugin"}, | |
125 false, | |
126 false}, | |
127 {{"application/x-shockwave-flash text application/x-blink-test-plugin"}, | |
128 false, | |
129 false}, | |
130 {{"application/x-invalid-type text application/"}, false, false}, | |
131 {{"application/x-blink-test-plugin text application/", | |
132 "application/x-blink-test-plugin"}, | |
133 false, | |
134 false}, | |
135 }; | |
136 | |
137 MediaListDirective emptyA("plugin-types", "", csp.get()); | |
138 EXPECT_TRUE(emptyA.subsumes({&emptyA})); | |
139 | |
140 for (const auto& test : cases) { | |
141 std::vector<MediaListDirective*> policiesB; | |
142 for (const auto& policy : test.policiesB) { | |
143 policiesB.push_back( | |
144 new MediaListDirective("plugin-types", policy, csp.get())); | |
145 } | |
146 | |
147 EXPECT_EQ(A.subsumes(policiesB), test.subsumed); | |
148 EXPECT_EQ(emptyA.subsumes(policiesB), test.subsumedByEmptyA); | |
149 } | |
150 } | |
151 | |
152 } // namespace blink | |
OLD | NEW |