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/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/common/extensions/extension_manifest_constants.h" | 11 #include "chrome/common/extensions/extension_manifest_constants.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace errors = extension_manifest_errors; | 14 namespace errors = extension_manifest_errors; |
15 | 15 |
16 TEST_F(ExtensionManifestTest, PlatformApps) { | 16 TEST_F(ExtensionManifestTest, PlatformApps) { |
17 // A minimal platform app. | 17 // A minimal platform app. |
18 LoadAndExpectError("init_valid_platform_app.json", | 18 LoadAndExpectError("init_valid_platform_app.json", |
19 errors::kPlatformAppFlagRequired); | 19 errors::kPlatformAppFlagRequired); |
20 | 20 |
21 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps); | 21 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps); |
22 | 22 |
23 scoped_refptr<extensions::Extension> extension = | 23 scoped_refptr<extensions::Extension> extension = |
24 LoadAndExpectSuccess("init_valid_platform_app.json"); | 24 LoadAndExpectSuccess("init_valid_platform_app.json"); |
25 EXPECT_TRUE(extension->is_storage_isolated()); | 25 EXPECT_TRUE(extension->is_storage_isolated()); |
26 | 26 |
27 extension = LoadAndExpectSuccess("init_invalid_platform_app_1.json"); | 27 LoadAndExpectWarning( |
28 ASSERT_TRUE(extension); | 28 "init_invalid_platform_app_1.json", |
29 ASSERT_EQ(1u, extension->install_warnings().size()); | 29 "'app.launch' is not allowed for specified package type " |
30 EXPECT_EQ("'app.launch' is not allowed for specified package type " | 30 "(theme, app, etc.)."); |
31 "(theme, app, etc.).", | |
32 extension->install_warnings()[0]); | |
33 | 31 |
34 LoadAndExpectError( | 32 Testcase error_testcases[] = { |
35 "init_invalid_platform_app_2.json", | 33 Testcase("init_invalid_platform_app_2.json", |
36 extension_manifest_errors::kBackgroundRequiredForPlatformApps); | 34 errors::kBackgroundRequiredForPlatformApps), |
| 35 Testcase("init_invalid_platform_app_3.json", |
| 36 errors::kPlatformAppNeedsManifestVersion2), |
| 37 }; |
| 38 RunTestcases(error_testcases, arraysize(error_testcases), EXPECT_TYPE_ERROR); |
37 | 39 |
38 LoadAndExpectError( | 40 Testcase warning_testcases[] = { |
39 "init_invalid_platform_app_3.json", | 41 Testcase( |
40 extension_manifest_errors::kPlatformAppNeedsManifestVersion2); | 42 "init_invalid_platform_app_1.json", |
| 43 "'app.launch' is not allowed for specified package type " |
| 44 "(theme, app, etc.)."), |
| 45 Testcase( |
| 46 "init_invalid_platform_app_4.json", |
| 47 "'background' is not allowed for specified package type " |
| 48 "(theme, app, etc.)."), |
| 49 Testcase( |
| 50 "init_invalid_platform_app_5.json", |
| 51 "'background' is not allowed for specified package type " |
| 52 "(theme, app, etc.).") |
| 53 }; |
| 54 RunTestcases( |
| 55 warning_testcases, arraysize(warning_testcases), EXPECT_TYPE_WARNING); |
41 } | 56 } |
42 | 57 |
43 TEST_F(ExtensionManifestTest, CertainApisRequirePlatformApps) { | 58 TEST_F(ExtensionManifestTest, CertainApisRequirePlatformApps) { |
44 // Put APIs here that should be restricted to platform apps, but that haven't | 59 // Put APIs here that should be restricted to platform apps, but that haven't |
45 // yet graduated from experimental. | 60 // yet graduated from experimental. |
46 const char* kPlatformAppExperimentalApis[] = { | 61 const char* kPlatformAppExperimentalApis[] = { |
47 "dns", | 62 "dns", |
48 "serial", | 63 "serial", |
49 "socket", | 64 "socket", |
50 }; | 65 }; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 113 |
99 // Finally, we should succeed with both experimental and platform-app flags | 114 // Finally, we should succeed with both experimental and platform-app flags |
100 // set. | 115 // set. |
101 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps); | 116 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnablePlatformApps); |
102 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 117 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
103 const char* api_name = kPlatformAppExperimentalApis[i]; | 118 const char* api_name = kPlatformAppExperimentalApis[i]; |
104 FilePath file_path = temp_dir.path().AppendASCII(api_name); | 119 FilePath file_path = temp_dir.path().AppendASCII(api_name); |
105 LoadAndExpectSuccess(file_path.MaybeAsASCII().c_str()); | 120 LoadAndExpectSuccess(file_path.MaybeAsASCII().c_str()); |
106 } | 121 } |
107 } | 122 } |
OLD | NEW |