Chromium Code Reviews| Index: extensions/common/manifests_sandboxed_unittest.cc |
| diff --git a/extensions/common/manifests_sandboxed_unittest.cc b/extensions/common/manifests_sandboxed_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c36a2707434ed81cb7c80055031e02391132ba5e |
| --- /dev/null |
| +++ b/extensions/common/manifests_sandboxed_unittest.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/common/manifest_constants.h" |
| +#include "extensions/common/manifest_handlers/csp_info.h" |
| +#include "extensions/common/manifest_test.h" |
| + |
| +namespace extensions { |
| + |
| +namespace errors = manifest_errors; |
| + |
| +class SandboxedPagesManifestTest : public ManifestTest {}; |
|
Devlin
2016/12/14 15:59:54
nit: since you're here, maybe
using SandboxedPages
lazyboy
2016/12/14 19:20:52
Done.
|
| + |
| +TEST_F(SandboxedPagesManifestTest, SandboxedPages) { |
| + // Sandboxed pages specified, no custom CSP value. |
| + scoped_refptr<Extension> extension1( |
| + LoadAndExpectSuccess("sandboxed_pages_valid_1.json")); |
| + |
| + // No sandboxed pages. |
| + scoped_refptr<Extension> extension2( |
| + LoadAndExpectSuccess("sandboxed_pages_valid_2.json")); |
| + |
| + // Sandboxed pages specified with a custom CSP value. |
| + scoped_refptr<Extension> extension3( |
| + LoadAndExpectSuccess("sandboxed_pages_valid_3.json")); |
| + |
| + // Sandboxed pages specified with wildcard, no custom CSP value. |
| + scoped_refptr<Extension> extension4( |
| + LoadAndExpectSuccess("sandboxed_pages_valid_4.json")); |
| + |
| + // Sandboxed pages specified with filename wildcard, no custom CSP value. |
| + scoped_refptr<Extension> extension5( |
| + LoadAndExpectSuccess("sandboxed_pages_valid_5.json")); |
| + |
| + const char kSandboxedCSP[] = |
| + "sandbox allow-scripts allow-forms allow-popups allow-modals"; |
| + const char kDefaultCSP[] = |
| + "script-src 'self' blob: filesystem: chrome-extension-resource:; " |
| + "object-src 'self' blob: filesystem:;"; |
| + const char kCustomSandboxedCSP[] = |
| + "sandbox; script-src: https://www.google.com"; |
| + |
| + EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension1.get(), "/test")); |
| + EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension1.get(), "/none")); |
| + EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension2.get(), "/test")); |
| + EXPECT_EQ(kCustomSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension3.get(), "/test")); |
| + EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension3.get(), "/none")); |
| + EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension4.get(), "/test")); |
| + EXPECT_EQ(kSandboxedCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension5.get(), "/path/test.ext")); |
| + EXPECT_EQ(kDefaultCSP, CSPInfo::GetResourceContentSecurityPolicy( |
| + extension5.get(), "/test")); |
| + |
| + Testcase testcases[] = { |
| + Testcase("sandboxed_pages_invalid_1.json", |
| + errors::kInvalidSandboxedPagesList), |
| + Testcase("sandboxed_pages_invalid_2.json", errors::kInvalidSandboxedPage), |
| + Testcase("sandboxed_pages_invalid_3.json", |
| + errors::kInvalidSandboxedPagesCSP), |
| + Testcase("sandboxed_pages_invalid_4.json", |
| + errors::kInvalidSandboxedPagesCSP), |
| + Testcase("sandboxed_pages_invalid_5.json", |
| + errors::kInvalidSandboxedPagesCSP)}; |
| + RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); |
| +} |
| + |
| +} // namespace extensions |