Chromium Code Reviews| 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()); | |
|
Mike West
2016/12/06 13:39:07
Can you check that we have a sane behavior when |A
| |
| 24 | |
| 25 struct TestCase { | |
| 26 const char* policyB; | |
| 27 const std::vector<const char*> expected; | |
| 28 } cases[] = { | |
| 29 {"text/plain", {"text/plain"}}, | |
|
Mike West
2016/12/06 13:39:07
Can you add an empty list?
| |
| 30 {"application/pdf", {"application/pdf"}}, | |
| 31 {"application/x-shockwave-flash", {"application/x-shockwave-flash"}}, | |
| 32 {"application/x-shockwave-flash text/plain", | |
|
Mike West
2016/12/06 13:39:07
Nit: Can you add tests that reverse the order, jus
| |
| 33 {"application/x-shockwave-flash", "text/plain"}}, | |
| 34 {"application/pdf text/plain", {"text/plain", "application/pdf"}}, | |
| 35 {"application/x-shockwave-flash application/pdf text/plain", | |
| 36 {"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
| |
| 37 }; | |
| 38 | |
| 39 for (const auto& test : cases) { | |
| 40 MediaListDirective B("plugin-types", test.policyB, csp.get()); | |
| 41 | |
| 42 HashSet<String> result = A.getIntersect(B.m_pluginTypes); | |
| 43 EXPECT_EQ(result.size(), test.expected.size()); | |
| 44 | |
| 45 for (const auto& type : test.expected) | |
| 46 EXPECT_TRUE(result.contains(type)); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 TEST_F(MediaListDirectiveTest, Subsumes) { | |
| 51 MediaListDirective A( | |
| 52 "plugin-types", | |
| 53 "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
| |
| 54 | |
| 55 struct TestCase { | |
| 56 const std::vector<const char*> policiesB; | |
| 57 bool subsumed; | |
| 58 bool subsumedByEmptyA; | |
| 59 } cases[] = { | |
| 60 // `A` subsumes `policiesB`. | |
| 61 {{""}, true, true}, | |
| 62 {{"text/plain"}, true, false}, | |
| 63 {{"application/pdf"}, true, false}, | |
| 64 {{"application/x-shockwave-flash"}, true, false}, | |
| 65 {{"application/x-shockwave-flash text/plain"}, true, false}, | |
| 66 {{"application/pdf text/plain"}, true, false}, | |
| 67 {{"application/x-shockwave-flash text/plain application/pdf"}, | |
| 68 true, | |
| 69 false}, | |
| 70 {{"application/x-shockwave-flash text "}, true, false}, | |
| 71 {{"application/x-shockwave-flash text/plain " | |
| 72 "application/x-blink-test-plugin", | |
| 73 "application/x-shockwave-flash text/plain"}, | |
| 74 true, | |
| 75 false}, | |
| 76 {{"application/x-shockwave-flash text/plain " | |
| 77 "application/x-blink-test-plugin", | |
| 78 "text/plain"}, | |
| 79 true, | |
| 80 false}, | |
| 81 {{"application/x-blink-test-plugin", "text/plain"}, true, true}, | |
| 82 {{"application/x-shockwave-flash", | |
| 83 "text/plain application/x-shockwave-flash"}, | |
| 84 true, | |
| 85 false}, | |
| 86 {{"application/x-shockwave-flash text/plain", | |
| 87 "application/x-blink-test-plugin", "text/plain"}, | |
| 88 true, | |
| 89 true}, | |
| 90 // `A` does not subsumes `policiesB`. | |
| 91 {{}, false, false}, | |
| 92 {{"application/x-blink-test-plugin"}, false, false}, | |
| 93 {{"application/x-shockwave-flash text/plain " | |
| 94 "application/x-blink-test-plugin"}, | |
| 95 false, | |
| 96 false}, | |
| 97 {{"application/x-shockwave-flash text application/x-blink-test-plugin"}, | |
| 98 false, | |
| 99 false}, | |
| 100 {{"application/x-invalid-type text application/"}, false, false}, | |
| 101 {{"application/x-blink-test-plugin text application/", | |
| 102 "application/x-blink-test-plugin"}, | |
| 103 false, | |
| 104 false}, | |
| 105 }; | |
| 106 | |
| 107 MediaListDirective emptyA("plugin-types", "", csp.get()); | |
| 108 EXPECT_TRUE(emptyA.subsumes({&emptyA})); | |
| 109 | |
| 110 for (const auto& test : cases) { | |
| 111 std::vector<MediaListDirective*> policiesB; | |
| 112 for (const auto& policy : test.policiesB) { | |
| 113 policiesB.push_back( | |
| 114 new MediaListDirective("plugin-types", policy, csp.get())); | |
| 115 } | |
| 116 | |
| 117 EXPECT_EQ(A.subsumes(policiesB), test.subsumed); | |
| 118 EXPECT_EQ(emptyA.subsumes(policiesB), test.subsumedByEmptyA); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace blink | |
| OLD | NEW |