| 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_context.h" | 5 #include "content/common/content_security_policy/csp_context.h" |
| 6 #include "content/common/content_security_policy_header.h" | 6 #include "content/common/content_security_policy_header.h" |
| 7 #include "content/common/navigation_params.h" | 7 #include "content/common/navigation_params.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace content { | 10 namespace content { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 context.AddSchemeToBypassCSP("https"); | 231 context.AddSchemeToBypassCSP("https"); |
| 232 | 232 |
| 233 EXPECT_TRUE(ContentSecurityPolicy::Allow(policy, CSPDirective::FrameSrc, | 233 EXPECT_TRUE(ContentSecurityPolicy::Allow(policy, CSPDirective::FrameSrc, |
| 234 GURL("blob:https://example.com/"), | 234 GURL("blob:https://example.com/"), |
| 235 false, &context, SourceLocation())); | 235 false, &context, SourceLocation())); |
| 236 EXPECT_TRUE(ContentSecurityPolicy::Allow( | 236 EXPECT_TRUE(ContentSecurityPolicy::Allow( |
| 237 policy, CSPDirective::FrameSrc, GURL("blob:https://not-example.com/"), | 237 policy, CSPDirective::FrameSrc, GURL("blob:https://not-example.com/"), |
| 238 false, &context, SourceLocation())); | 238 false, &context, SourceLocation())); |
| 239 } | 239 } |
| 240 | 240 |
| 241 TEST(ContentSecurityPolicy, ShouldUpgradeInsecureRequest) { |
| 242 std::vector<std::string> report_end_points; // empty |
| 243 CSPSource source("https", "example.com", false, url::PORT_UNSPECIFIED, false, |
| 244 ""); |
| 245 CSPSourceList source_list(false, false, {source}); |
| 246 ContentSecurityPolicy policy( |
| 247 EmptyCspHeader(), {CSPDirective(CSPDirective::DefaultSrc, source_list)}, |
| 248 report_end_points); |
| 249 |
| 250 EXPECT_FALSE(ContentSecurityPolicy::ShouldUpgradeInsecureRequest(policy)); |
| 251 |
| 252 policy.directives.push_back( |
| 253 CSPDirective(CSPDirective::UpgradeInsecureRequests, CSPSourceList())); |
| 254 EXPECT_TRUE(ContentSecurityPolicy::ShouldUpgradeInsecureRequest(policy)); |
| 255 } |
| 256 |
| 241 } // namespace content | 257 } // namespace content |
| OLD | NEW |