| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/content_security_policy/csp_source_list.h" | 5 #include "content/common/content_security_policy/csp_source_list.h" |
| 6 #include "content/common/content_security_policy/csp_context.h" | 6 #include "content/common/content_security_policy/csp_context.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 TEST(CSPSourceList, AllowNone) { | 85 TEST(CSPSourceList, AllowNone) { |
| 86 CSPContext context; | 86 CSPContext context; |
| 87 context.SetSelf(url::Origin(GURL("http://example.com"))); | 87 context.SetSelf(url::Origin(GURL("http://example.com"))); |
| 88 CSPSourceList source_list(false, // allow_self | 88 CSPSourceList source_list(false, // allow_self |
| 89 false, // allow_star: | 89 false, // allow_star: |
| 90 std::vector<CSPSource>()); // source_list | 90 std::vector<CSPSource>()); // source_list |
| 91 EXPECT_FALSE(Allow(source_list, GURL("http://example.com"), &context)); | 91 EXPECT_FALSE(Allow(source_list, GURL("http://example.com"), &context)); |
| 92 EXPECT_FALSE(Allow(source_list, GURL("https://example.test/"), &context)); | 92 EXPECT_FALSE(Allow(source_list, GURL("https://example.test/"), &context)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST(CSPSourceTest, SelfIsUnique) { |
| 96 // Policy: 'self' |
| 97 CSPSourceList source_list(true, // allow_self |
| 98 false, // allow_star: |
| 99 std::vector<CSPSource>()); // source_list |
| 100 CSPContext context; |
| 101 |
| 102 context.SetSelf(url::Origin(GURL("http://a.com"))); |
| 103 EXPECT_TRUE(Allow(source_list, GURL("http://a.com"), &context)); |
| 104 EXPECT_FALSE(Allow(source_list, GURL("data:text/html,hello"), &context)); |
| 105 |
| 106 context.SetSelf(url::Origin(GURL("data:text/html,<iframe src=[...]>"))); |
| 107 EXPECT_FALSE(Allow(source_list, GURL("http://a.com"), &context)); |
| 108 EXPECT_FALSE(Allow(source_list, GURL("data:text/html,hello"), &context)); |
| 109 } |
| 110 |
| 95 } // namespace content | 111 } // namespace content |
| OLD | NEW |