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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/extensions/background_info.h" |
11 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace errors = extension_manifest_errors; | 15 namespace errors = extension_manifest_errors; |
15 | 16 |
16 TEST_F(ExtensionManifestTest, PlatformApps) { | 17 namespace extensions { |
| 18 |
| 19 class ExtensionManifestPlatformAppTest : public ExtensionManifestTest { |
| 20 virtual void SetUp() OVERRIDE { |
| 21 ExtensionManifestTest::SetUp(); |
| 22 std::vector<std::string> background_keys(BackgroundManifestHandler::keys()); |
| 23 linked_ptr<BackgroundManifestHandler> background_handler( |
| 24 new BackgroundManifestHandler); |
| 25 for (size_t i = 0; i < background_keys.size(); ++i) |
| 26 ManifestHandler::Register(background_keys[i], background_handler); |
| 27 } |
| 28 }; |
| 29 |
| 30 TEST_F(ExtensionManifestPlatformAppTest, PlatformApps) { |
17 scoped_refptr<extensions::Extension> extension = | 31 scoped_refptr<extensions::Extension> extension = |
18 LoadAndExpectSuccess("init_valid_platform_app.json"); | 32 LoadAndExpectSuccess("init_valid_platform_app.json"); |
19 EXPECT_TRUE(extension->is_storage_isolated()); | 33 EXPECT_TRUE(extension->is_storage_isolated()); |
20 EXPECT_TRUE(extension->incognito_split_mode()); | 34 EXPECT_TRUE(extension->incognito_split_mode()); |
21 | 35 |
22 extension = | 36 extension = |
23 LoadAndExpectSuccess("init_valid_platform_app_no_manifest_version.json"); | 37 LoadAndExpectSuccess("init_valid_platform_app_no_manifest_version.json"); |
24 EXPECT_EQ(2, extension->manifest_version()); | 38 EXPECT_EQ(2, extension->manifest_version()); |
25 | 39 |
26 extension = LoadAndExpectSuccess("incognito_valid_platform_app.json"); | 40 extension = LoadAndExpectSuccess("incognito_valid_platform_app.json"); |
(...skipping 20 matching lines...) Expand all Loading... |
47 "packaged apps, and this is a packaged app."), | 61 "packaged apps, and this is a packaged app."), |
48 Testcase( | 62 Testcase( |
49 "init_invalid_platform_app_5.json", | 63 "init_invalid_platform_app_5.json", |
50 "'background' is only allowed for extensions, hosted apps and legacy " | 64 "'background' is only allowed for extensions, hosted apps and legacy " |
51 "packaged apps, and this is a packaged app.") | 65 "packaged apps, and this is a packaged app.") |
52 }; | 66 }; |
53 RunTestcases( | 67 RunTestcases( |
54 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); | 68 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); |
55 } | 69 } |
56 | 70 |
57 TEST_F(ExtensionManifestTest, PlatformAppContentSecurityPolicy) { | 71 TEST_F(ExtensionManifestPlatformAppTest, PlatformAppContentSecurityPolicy) { |
58 // Normal platform apps can't specify a CSP value. | 72 // Normal platform apps can't specify a CSP value. |
59 Testcase warning_testcases[] = { | 73 Testcase warning_testcases[] = { |
60 Testcase( | 74 Testcase( |
61 "init_platform_app_csp_warning_1.json", | 75 "init_platform_app_csp_warning_1.json", |
62 "'content_security_policy' is only allowed for extensions and legacy " | 76 "'content_security_policy' is only allowed for extensions and legacy " |
63 "packaged apps, and this is a packaged app."), | 77 "packaged apps, and this is a packaged app."), |
64 Testcase( | 78 Testcase( |
65 "init_platform_app_csp_warning_2.json", | 79 "init_platform_app_csp_warning_2.json", |
66 "'app.content_security_policy' is not allowed for specified extension " | 80 "'app.content_security_policy' is not allowed for specified extension " |
67 "ID.") | 81 "ID.") |
(...skipping 14 matching lines...) Expand all Loading... |
82 EXPECT_EQ( | 96 EXPECT_EQ( |
83 "default-src 'self' https://www.google.com", | 97 "default-src 'self' https://www.google.com", |
84 extension->GetResourceContentSecurityPolicy("")); | 98 extension->GetResourceContentSecurityPolicy("")); |
85 | 99 |
86 // But even whitelisted ones must specify a secure policy. | 100 // But even whitelisted ones must specify a secure policy. |
87 LoadAndExpectError( | 101 LoadAndExpectError( |
88 "init_platform_app_csp_insecure.json", | 102 "init_platform_app_csp_insecure.json", |
89 errors::kInsecureContentSecurityPolicy); | 103 errors::kInsecureContentSecurityPolicy); |
90 } | 104 } |
91 | 105 |
92 TEST_F(ExtensionManifestTest, CertainApisRequirePlatformApps) { | 106 TEST_F(ExtensionManifestPlatformAppTest, CertainApisRequirePlatformApps) { |
93 // Put APIs here that should be restricted to platform apps, but that haven't | 107 // Put APIs here that should be restricted to platform apps, but that haven't |
94 // yet graduated from experimental. | 108 // yet graduated from experimental. |
95 const char* kPlatformAppExperimentalApis[] = { | 109 const char* kPlatformAppExperimentalApis[] = { |
96 "dns", | 110 "dns", |
97 "serial", | 111 "serial", |
98 }; | 112 }; |
99 // TODO(miket): When the first platform-app API leaves experimental, write | 113 // TODO(miket): When the first platform-app API leaves experimental, write |
100 // similar code that tests without the experimental flag. | 114 // similar code that tests without the experimental flag. |
101 | 115 |
102 // This manifest is a skeleton used to build more specific manifests for | 116 // This manifest is a skeleton used to build more specific manifests for |
(...skipping 22 matching lines...) Expand all Loading... |
125 errors::kExperimentalFlagRequired); | 139 errors::kExperimentalFlagRequired); |
126 } | 140 } |
127 | 141 |
128 // Now try again with the experimental flag set. | 142 // Now try again with the experimental flag set. |
129 CommandLine::ForCurrentProcess()->AppendSwitch( | 143 CommandLine::ForCurrentProcess()->AppendSwitch( |
130 switches::kEnableExperimentalExtensionApis); | 144 switches::kEnableExperimentalExtensionApis); |
131 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 145 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
132 LoadAndExpectSuccess(Manifest(manifests[i].get(), "")); | 146 LoadAndExpectSuccess(Manifest(manifests[i].get(), "")); |
133 } | 147 } |
134 } | 148 } |
| 149 |
| 150 } // namespace extensions |
OLD | NEW |