OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/memory/linked_ptr.h" | 7 #include "base/memory/linked_ptr.h" |
8 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 8 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
9 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" | 9 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 "packaged apps, but this is a packaged app."), | 58 "packaged apps, but this is a packaged app."), |
59 Testcase("incognito_invalid_platform_app.json", | 59 Testcase("incognito_invalid_platform_app.json", |
60 "'incognito' is only allowed for extensions and legacy packaged apps, " | 60 "'incognito' is only allowed for extensions and legacy packaged apps, " |
61 "but this is a packaged app."), | 61 "but this is a packaged app."), |
62 }; | 62 }; |
63 RunTestcases( | 63 RunTestcases( |
64 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); | 64 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); |
65 } | 65 } |
66 | 66 |
67 TEST_F(PlatformAppsManifestTest, PlatformAppContentSecurityPolicy) { | 67 TEST_F(PlatformAppsManifestTest, PlatformAppContentSecurityPolicy) { |
| 68 // The whitelisted extension ID is cached the first time it is used, so set it |
| 69 // before running the test. This is the ID corresponding to the base 64 |
| 70 // encoded key in the init_platform_app_csp.json manifest. |
| 71 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb"; |
| 72 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 73 switches::kWhitelistedExtensionID, test_id); |
| 74 |
68 // Normal platform apps can't specify a CSP value. | 75 // Normal platform apps can't specify a CSP value. |
69 Testcase warning_testcases[] = { | 76 Testcase warning_testcases[] = { |
70 Testcase( | 77 Testcase( |
71 "init_platform_app_csp_warning_1.json", | 78 "init_platform_app_csp_warning_1.json", |
72 "'content_security_policy' is only allowed for extensions and legacy " | 79 "'content_security_policy' is only allowed for extensions and legacy " |
73 "packaged apps, but this is a packaged app."), | 80 "packaged apps, but this is a packaged app."), |
74 Testcase( | 81 Testcase( |
75 "init_platform_app_csp_warning_2.json", | 82 "init_platform_app_csp_warning_2.json", |
76 "'app.content_security_policy' is not allowed for specified extension " | 83 "'app.content_security_policy' is not allowed for specified extension " |
77 "ID.") | 84 "ID.") |
78 }; | 85 }; |
79 RunTestcases( | 86 RunTestcases( |
80 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); | 87 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); |
81 | 88 |
82 // Whitelisted ones can (this is the ID corresponding to the base 64 encoded | 89 // Whitelisted ones can. |
83 // key in the init_platform_app_csp.json manifest.) | |
84 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb"; | |
85 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
86 switches::kWhitelistedExtensionID, test_id); | |
87 scoped_refptr<Extension> extension = | 90 scoped_refptr<Extension> extension = |
88 LoadAndExpectSuccess("init_platform_app_csp.json"); | 91 LoadAndExpectSuccess("init_platform_app_csp.json"); |
89 EXPECT_EQ(0U, extension->install_warnings().size()) | 92 EXPECT_EQ(0U, extension->install_warnings().size()) |
90 << "Unexpected warning " << extension->install_warnings()[0].message; | 93 << "Unexpected warning " << extension->install_warnings()[0].message; |
91 EXPECT_TRUE(extension->is_platform_app()); | 94 EXPECT_TRUE(extension->is_platform_app()); |
92 EXPECT_EQ("default-src 'self' https://www.google.com;", | 95 EXPECT_EQ("default-src 'self' https://www.google.com;", |
93 CSPInfo::GetResourceContentSecurityPolicy(extension.get(), | 96 CSPInfo::GetResourceContentSecurityPolicy(extension.get(), |
94 std::string())); | 97 std::string())); |
95 | 98 |
96 // But even whitelisted ones must specify a secure policy. | 99 // But even whitelisted ones must specify a secure policy. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 143 |
141 // Now try again with the experimental flag set. | 144 // Now try again with the experimental flag set. |
142 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 145 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
143 switches::kEnableExperimentalExtensionApis); | 146 switches::kEnableExperimentalExtensionApis); |
144 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 147 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
145 LoadAndExpectSuccess(ManifestData(manifests[i].get(), "")); | 148 LoadAndExpectSuccess(ManifestData(manifests[i].get(), "")); |
146 } | 149 } |
147 } | 150 } |
148 | 151 |
149 } // namespace extensions | 152 } // namespace extensions |
OLD | NEW |