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" |
11 #include "extensions/common/manifest_constants.h" | 11 #include "extensions/common/manifest_constants.h" |
12 #include "extensions/common/manifest_handlers/csp_info.h" | 12 #include "extensions/common/manifest_handlers/csp_info.h" |
13 #include "extensions/common/manifest_handlers/incognito_info.h" | 13 #include "extensions/common/manifest_handlers/incognito_info.h" |
14 #include "extensions/common/switches.h" | 14 #include "extensions/common/switches.h" |
| 15 #include "extensions/common/test/scoped_command_line_switch.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 namespace errors = manifest_errors; | 20 namespace errors = manifest_errors; |
20 | 21 |
21 class PlatformAppsManifestTest : public ChromeManifestTest { | 22 class PlatformAppsManifestTest : public ChromeManifestTest { |
22 }; | 23 }; |
23 | 24 |
24 TEST_F(PlatformAppsManifestTest, PlatformApps) { | 25 TEST_F(PlatformAppsManifestTest, PlatformApps) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 "but this is a packaged app."), | 62 "but this is a packaged app."), |
62 }; | 63 }; |
63 RunTestcases( | 64 RunTestcases( |
64 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); | 65 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); |
65 } | 66 } |
66 | 67 |
67 TEST_F(PlatformAppsManifestTest, PlatformAppContentSecurityPolicy) { | 68 TEST_F(PlatformAppsManifestTest, PlatformAppContentSecurityPolicy) { |
68 // The whitelisted extension ID is cached the first time it is used, so set it | 69 // 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 // 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 // encoded key in the init_platform_app_csp.json manifest. |
71 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb"; | 72 ScopedCommandLineSwitch command_line(switches::kWhitelistedExtensionID, |
72 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 73 "ahplfneplbnjcflhdgkkjeiglkkfeelb"); |
73 switches::kWhitelistedExtensionID, test_id); | |
74 | 74 |
75 // Normal platform apps can't specify a CSP value. | 75 // Normal platform apps can't specify a CSP value. |
76 Testcase warning_testcases[] = { | 76 Testcase warning_testcases[] = { |
77 Testcase( | 77 Testcase( |
78 "init_platform_app_csp_warning_1.json", | 78 "init_platform_app_csp_warning_1.json", |
79 "'content_security_policy' is only allowed for extensions and legacy " | 79 "'content_security_policy' is only allowed for extensions and legacy " |
80 "packaged apps, but this is a packaged app."), | 80 "packaged apps, but this is a packaged app."), |
81 Testcase( | 81 Testcase( |
82 "init_platform_app_csp_warning_2.json", | 82 "init_platform_app_csp_warning_2.json", |
83 "'app.content_security_policy' is not allowed for specified extension " | 83 "'app.content_security_policy' is not allowed for specified extension " |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 // First try to load without any flags. This should warn for every API. | 136 // First try to load without any flags. This should warn for every API. |
137 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 137 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
138 LoadAndExpectWarning( | 138 LoadAndExpectWarning( |
139 ManifestData(manifests[i].get(), ""), | 139 ManifestData(manifests[i].get(), ""), |
140 "'experimental' requires the 'experimental-extension-apis' " | 140 "'experimental' requires the 'experimental-extension-apis' " |
141 "command line switch to be enabled."); | 141 "command line switch to be enabled."); |
142 } | 142 } |
143 | 143 |
144 // Now try again with the experimental flag set. | 144 // Now try again with the experimental flag set. |
145 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 145 ScopedCommandLineSwitch command_line( |
146 switches::kEnableExperimentalExtensionApis); | 146 switches::kEnableExperimentalExtensionApis); |
147 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 147 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
148 LoadAndExpectSuccess(ManifestData(manifests[i].get(), "")); | 148 LoadAndExpectSuccess(ManifestData(manifests[i].get(), "")); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 } // namespace extensions | 152 } // namespace extensions |
OLD | NEW |