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/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/extensions/csp_handler.h" | 9 #include "chrome/common/extensions/csp_handler.h" |
10 #include "chrome/common/extensions/extension_manifest_constants.h" | 10 #include "chrome/common/extensions/extension_manifest_constants.h" |
11 #include "chrome/common/extensions/incognito_handler.h" | 11 #include "chrome/common/extensions/incognito_handler.h" |
12 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 12 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
13 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 13 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 namespace errors = extension_manifest_errors; | 16 namespace errors = extension_manifest_errors; |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 class PlatformAppsManifestTest : public ExtensionManifestTest { | 20 class PlatformAppsManifestTest : public ExtensionManifestTest { |
21 }; | 21 }; |
22 | 22 |
23 TEST_F(PlatformAppsManifestTest, PlatformApps) { | 23 TEST_F(PlatformAppsManifestTest, PlatformApps) { |
24 scoped_refptr<Extension> extension = | 24 scoped_refptr<Extension> extension = |
25 LoadAndExpectSuccess("init_valid_platform_app.json"); | 25 LoadAndExpectSuccess("init_valid_platform_app.json"); |
26 EXPECT_TRUE(AppIsolationInfo::HasIsolatedStorage(extension)); | 26 EXPECT_TRUE(AppIsolationInfo::HasIsolatedStorage(extension.get())); |
27 EXPECT_TRUE(IncognitoInfo::IsSplitMode(extension)); | 27 EXPECT_TRUE(IncognitoInfo::IsSplitMode(extension.get())); |
28 | 28 |
29 extension = | 29 extension = |
30 LoadAndExpectSuccess("init_valid_platform_app_no_manifest_version.json"); | 30 LoadAndExpectSuccess("init_valid_platform_app_no_manifest_version.json"); |
31 EXPECT_EQ(2, extension->manifest_version()); | 31 EXPECT_EQ(2, extension->manifest_version()); |
32 | 32 |
33 extension = LoadAndExpectSuccess("incognito_valid_platform_app.json"); | 33 extension = LoadAndExpectSuccess("incognito_valid_platform_app.json"); |
34 EXPECT_TRUE(IncognitoInfo::IsSplitMode(extension)); | 34 EXPECT_TRUE(IncognitoInfo::IsSplitMode(extension.get())); |
35 | 35 |
36 Testcase error_testcases[] = { | 36 Testcase error_testcases[] = { |
37 Testcase("init_invalid_platform_app_2.json", | 37 Testcase("init_invalid_platform_app_2.json", |
38 errors::kBackgroundRequiredForPlatformApps), | 38 errors::kBackgroundRequiredForPlatformApps), |
39 Testcase("init_invalid_platform_app_3.json", | 39 Testcase("init_invalid_platform_app_3.json", |
40 errors::kPlatformAppNeedsManifestVersion2), | 40 errors::kPlatformAppNeedsManifestVersion2), |
41 }; | 41 }; |
42 RunTestcases(error_testcases, arraysize(error_testcases), EXPECT_TYPE_ERROR); | 42 RunTestcases(error_testcases, arraysize(error_testcases), EXPECT_TYPE_ERROR); |
43 | 43 |
44 Testcase warning_testcases[] = { | 44 Testcase warning_testcases[] = { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // Whitelisted ones can (this is the ID corresponding to the base 64 encoded | 80 // Whitelisted ones can (this is the ID corresponding to the base 64 encoded |
81 // key in the init_platform_app_csp.json manifest.) | 81 // key in the init_platform_app_csp.json manifest.) |
82 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb"; | 82 std::string test_id = "ahplfneplbnjcflhdgkkjeiglkkfeelb"; |
83 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 83 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
84 switches::kWhitelistedExtensionID, test_id); | 84 switches::kWhitelistedExtensionID, test_id); |
85 scoped_refptr<Extension> extension = | 85 scoped_refptr<Extension> extension = |
86 LoadAndExpectSuccess("init_platform_app_csp.json"); | 86 LoadAndExpectSuccess("init_platform_app_csp.json"); |
87 EXPECT_EQ(0U, extension->install_warnings().size()) | 87 EXPECT_EQ(0U, extension->install_warnings().size()) |
88 << "Unexpected warning " << extension->install_warnings()[0].message; | 88 << "Unexpected warning " << extension->install_warnings()[0].message; |
89 EXPECT_TRUE(extension->is_platform_app()); | 89 EXPECT_TRUE(extension->is_platform_app()); |
90 EXPECT_EQ( | 90 EXPECT_EQ("default-src 'self' https://www.google.com", |
91 "default-src 'self' https://www.google.com", | 91 CSPInfo::GetResourceContentSecurityPolicy(extension.get(), |
92 CSPInfo::GetResourceContentSecurityPolicy(extension, std::string())); | 92 std::string())); |
93 | 93 |
94 // But even whitelisted ones must specify a secure policy. | 94 // But even whitelisted ones must specify a secure policy. |
95 LoadAndExpectError( | 95 LoadAndExpectError( |
96 "init_platform_app_csp_insecure.json", | 96 "init_platform_app_csp_insecure.json", |
97 errors::kInsecureContentSecurityPolicy); | 97 errors::kInsecureContentSecurityPolicy); |
98 } | 98 } |
99 | 99 |
100 TEST_F(PlatformAppsManifestTest, CertainApisRequirePlatformApps) { | 100 TEST_F(PlatformAppsManifestTest, CertainApisRequirePlatformApps) { |
101 // Put APIs here that should be restricted to platform apps, but that haven't | 101 // Put APIs here that should be restricted to platform apps, but that haven't |
102 // yet graduated from experimental. | 102 // yet graduated from experimental. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 135 |
136 // Now try again with the experimental flag set. | 136 // Now try again with the experimental flag set. |
137 CommandLine::ForCurrentProcess()->AppendSwitch( | 137 CommandLine::ForCurrentProcess()->AppendSwitch( |
138 switches::kEnableExperimentalExtensionApis); | 138 switches::kEnableExperimentalExtensionApis); |
139 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 139 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
140 LoadAndExpectSuccess(Manifest(manifests[i].get(), "")); | 140 LoadAndExpectSuccess(Manifest(manifests[i].get(), "")); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 } // namespace extensions | 144 } // namespace extensions |
OLD | NEW |