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

Side by Side Diff: content/common/content_security_policy/csp_source_list_unittest.cc

Issue 2937503002: CSP, PlzNavigate: make clear what happens with unique origins. (Closed)
Patch Set: Add web platform tests. Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698