| 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/files/scoped_temp_dir.h" | |
| 9 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.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/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 scoped_refptr<extensions::Extension> extension = | 17 scoped_refptr<extensions::Extension> extension = |
| 18 LoadAndExpectSuccess("init_valid_platform_app.json"); | 18 LoadAndExpectSuccess("init_valid_platform_app.json"); |
| 19 EXPECT_TRUE(extension->is_storage_isolated()); | 19 EXPECT_TRUE(extension->is_storage_isolated()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 "serial", | 97 "serial", |
| 98 }; | 98 }; |
| 99 // TODO(miket): When the first platform-app API leaves experimental, write | 99 // TODO(miket): When the first platform-app API leaves experimental, write |
| 100 // similar code that tests without the experimental flag. | 100 // similar code that tests without the experimental flag. |
| 101 | 101 |
| 102 // This manifest is a skeleton used to build more specific manifests for | 102 // This manifest is a skeleton used to build more specific manifests for |
| 103 // testing. The requirements are that (1) it be a valid platform app, and (2) | 103 // testing. The requirements are that (1) it be a valid platform app, and (2) |
| 104 // it contain no permissions dictionary. | 104 // it contain no permissions dictionary. |
| 105 std::string error; | 105 std::string error; |
| 106 scoped_ptr<DictionaryValue> manifest( | 106 scoped_ptr<DictionaryValue> manifest( |
| 107 LoadManifestFile("init_valid_platform_app.json", &error)); | 107 LoadManifest("init_valid_platform_app.json", &error)); |
| 108 | 108 |
| 109 base::ScopedTempDir temp_dir; | 109 std::vector<linked_ptr<DictionaryValue> > manifests; |
| 110 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 111 | |
| 112 // Create each manifest. | 110 // Create each manifest. |
| 113 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 111 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
| 114 const char* api_name = kPlatformAppExperimentalApis[i]; | 112 const char* api_name = kPlatformAppExperimentalApis[i]; |
| 115 | 113 |
| 116 // DictionaryValue will take ownership of this ListValue. | 114 // DictionaryValue will take ownership of this ListValue. |
| 117 ListValue *permissions = new ListValue(); | 115 ListValue *permissions = new ListValue(); |
| 118 permissions->Append(base::Value::CreateStringValue("experimental")); | 116 permissions->Append(base::Value::CreateStringValue("experimental")); |
| 119 permissions->Append(base::Value::CreateStringValue(api_name)); | 117 permissions->Append(base::Value::CreateStringValue(api_name)); |
| 120 manifest->Set("permissions", permissions); | 118 manifest->Set("permissions", permissions); |
| 121 | 119 manifests.push_back(make_linked_ptr(manifest->DeepCopy())); |
| 122 // Each of these files lives in the scoped temp directory, so it will be | |
| 123 // cleaned up at test teardown. | |
| 124 FilePath file_path = temp_dir.path().AppendASCII(api_name); | |
| 125 JSONFileValueSerializer serializer(file_path); | |
| 126 serializer.Serialize(*(manifest.get())); | |
| 127 } | 120 } |
| 128 | 121 |
| 129 // First try to load without any flags. This should fail for every API. | 122 // First try to load without any flags. This should fail for every API. |
| 130 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 123 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
| 131 const char* api_name = kPlatformAppExperimentalApis[i]; | 124 LoadAndExpectError(Manifest(manifests[i].get(), ""), |
| 132 FilePath file_path = temp_dir.path().AppendASCII(api_name); | |
| 133 LoadAndExpectError(file_path.MaybeAsASCII().c_str(), | |
| 134 errors::kExperimentalFlagRequired); | 125 errors::kExperimentalFlagRequired); |
| 135 } | 126 } |
| 136 | 127 |
| 137 // Now try again with the experimental flag set. | 128 // Now try again with the experimental flag set. |
| 138 CommandLine::ForCurrentProcess()->AppendSwitch( | 129 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 139 switches::kEnableExperimentalExtensionApis); | 130 switches::kEnableExperimentalExtensionApis); |
| 140 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { | 131 for (size_t i = 0; i < arraysize(kPlatformAppExperimentalApis); ++i) { |
| 141 const char* api_name = kPlatformAppExperimentalApis[i]; | 132 LoadAndExpectSuccess(Manifest(manifests[i].get(), "")); |
| 142 FilePath file_path = temp_dir.path().AppendASCII(api_name); | |
| 143 LoadAndExpectSuccess(file_path.MaybeAsASCII().c_str()); | |
| 144 } | 133 } |
| 145 } | 134 } |
| OLD | NEW |