| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "extensions/common/manifest_constants.h" |
| 6 #include "extensions/common/manifest_handlers/csp_info.h" |
| 7 #include "extensions/common/manifest_test.h" |
| 8 |
| 9 namespace extensions { |
| 10 |
| 11 namespace errors = manifest_errors; |
| 12 |
| 13 using CSPInfoUnitTest = ManifestTest; |
| 14 |
| 15 TEST_F(CSPInfoUnitTest, SandboxedPages) { |
| 16 // Sandboxed pages specified, no custom CSP value. |
| 17 scoped_refptr<Extension> extension1( |
| 18 LoadAndExpectSuccess("sandboxed_pages_valid_1.json")); |
| 19 |
| 20 // No sandboxed pages. |
| 21 scoped_refptr<Extension> extension2( |
| 22 LoadAndExpectSuccess("sandboxed_pages_valid_2.json")); |
| 23 |
| 24 // Sandboxed pages specified with a custom CSP value. |
| 25 scoped_refptr<Extension> extension3( |
| 26 LoadAndExpectSuccess("sandboxed_pages_valid_3.json")); |
| 27 |
| 28 // Sandboxed pages specified with wildcard, no custom CSP value. |
| 29 scoped_refptr<Extension> extension4( |
| 30 LoadAndExpectSuccess("sandboxed_pages_valid_4.json")); |
| 31 |
| 32 // Sandboxed pages specified with filename wildcard, no custom CSP value. |
| 33 scoped_refptr<Extension> extension5( |
| 34 LoadAndExpectSuccess("sandboxed_pages_valid_5.json")); |
| 35 |
| 36 const char kSandboxedCSP[] = |
| 37 "sandbox allow-scripts allow-forms allow-popups allow-modals"; |
| 38 const char kDefaultCSP[] = |
| 39 "script-src 'self' blob: filesystem: chrome-extension-resource:; " |
| 40 "object-src 'self' blob: filesystem:;"; |
| 41 const char kCustomSandboxedCSP[] = |
| 42 "sandbox; script-src: https://www.google.com"; |
| 43 |
| 44 EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 45 extension1.get(), "/test")); |
| 46 EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 47 extension1.get(), "/none")); |
| 48 EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 49 extension2.get(), "/test")); |
| 50 EXPECT_EQ(kCustomSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 51 extension3.get(), "/test")); |
| 52 EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 53 extension3.get(), "/none")); |
| 54 EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 55 extension4.get(), "/test")); |
| 56 EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 57 extension5.get(), "/path/test.ext")); |
| 58 EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| 59 extension5.get(), "/test")); |
| 60 |
| 61 Testcase testcases[] = { |
| 62 Testcase("sandboxed_pages_invalid_1.json", |
| 63 errors::kInvalidSandboxedPagesList), |
| 64 Testcase("sandboxed_pages_invalid_2.json", errors::kInvalidSandboxedPage), |
| 65 Testcase("sandboxed_pages_invalid_3.json", |
| 66 errors::kInvalidSandboxedPagesCSP), |
| 67 Testcase("sandboxed_pages_invalid_4.json", |
| 68 errors::kInvalidSandboxedPagesCSP), |
| 69 Testcase("sandboxed_pages_invalid_5.json", |
| 70 errors::kInvalidSandboxedPagesCSP)}; |
| 71 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); |
| 72 } |
| 73 |
| 74 } // namespace extensions |
| OLD | NEW |