OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 scoped_ptr<base::DictionaryValue> manifest = | 184 scoped_ptr<base::DictionaryValue> manifest = |
185 DictionaryBuilder() | 185 DictionaryBuilder() |
186 .Set("name", kName) | 186 .Set("name", kName) |
187 .Set("version", kVersion) | 187 .Set("version", kVersion) |
188 .Set("manifest_version", 2) | 188 .Set("manifest_version", 2) |
189 .Set("description", "an extension") | 189 .Set("description", "an extension") |
190 .Set("permissions", std::move(ListBuilder().Append("file://*/*"))) | 190 .Set("permissions", std::move(ListBuilder().Append("file://*/*"))) |
191 .Build(); | 191 .Build(); |
192 scoped_ptr<base::DictionaryValue> manifest_copy(manifest->DeepCopy()); | 192 scoped_ptr<base::DictionaryValue> manifest_copy(manifest->DeepCopy()); |
193 scoped_refptr<const Extension> extension = | 193 scoped_refptr<const Extension> extension = |
194 ExtensionBuilder().SetManifest(manifest.Pass()) | 194 ExtensionBuilder() |
195 .SetLocation(Manifest::UNPACKED) | 195 .SetManifest(std::move(manifest)) |
196 .SetPath(data_dir()) | 196 .SetLocation(Manifest::UNPACKED) |
197 .SetID(id) | 197 .SetPath(data_dir()) |
198 .Build(); | 198 .SetID(id) |
| 199 .Build(); |
199 service()->AddExtension(extension.get()); | 200 service()->AddExtension(extension.get()); |
200 ErrorConsole* error_console = ErrorConsole::Get(profile()); | 201 ErrorConsole* error_console = ErrorConsole::Get(profile()); |
201 error_console->ReportError( | 202 error_console->ReportError( |
202 make_scoped_ptr(new RuntimeError( | 203 make_scoped_ptr(new RuntimeError( |
203 extension->id(), | 204 extension->id(), |
204 false, | 205 false, |
205 base::UTF8ToUTF16("source"), | 206 base::UTF8ToUTF16("source"), |
206 base::UTF8ToUTF16("message"), | 207 base::UTF8ToUTF16("message"), |
207 StackTrace(1, StackFrame(1, | 208 StackTrace(1, StackFrame(1, |
208 1, | 209 1, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 EXPECT_EQ(api::developer_private::ERROR_LEVEL_LOG, | 265 EXPECT_EQ(api::developer_private::ERROR_LEVEL_LOG, |
265 runtime_error_verbose.severity); | 266 runtime_error_verbose.severity); |
266 const api::developer_private::ManifestError& manifest_error = | 267 const api::developer_private::ManifestError& manifest_error = |
267 *info->manifest_errors[0]; | 268 *info->manifest_errors[0]; |
268 EXPECT_EQ(extension->id(), manifest_error.extension_id); | 269 EXPECT_EQ(extension->id(), manifest_error.extension_id); |
269 | 270 |
270 // Test an extension that isn't unpacked. | 271 // Test an extension that isn't unpacked. |
271 manifest_copy->SetString("update_url", | 272 manifest_copy->SetString("update_url", |
272 "https://clients2.google.com/service/update2/crx"); | 273 "https://clients2.google.com/service/update2/crx"); |
273 id = crx_file::id_util::GenerateId("beta"); | 274 id = crx_file::id_util::GenerateId("beta"); |
274 extension = ExtensionBuilder().SetManifest(manifest_copy.Pass()) | 275 extension = ExtensionBuilder() |
275 .SetLocation(Manifest::EXTERNAL_PREF) | 276 .SetManifest(std::move(manifest_copy)) |
276 .SetID(id) | 277 .SetLocation(Manifest::EXTERNAL_PREF) |
277 .Build(); | 278 .SetID(id) |
| 279 .Build(); |
278 service()->AddExtension(extension.get()); | 280 service()->AddExtension(extension.get()); |
279 info = GenerateExtensionInfo(extension->id()); | 281 info = GenerateExtensionInfo(extension->id()); |
280 EXPECT_EQ(developer::LOCATION_THIRD_PARTY, info->location); | 282 EXPECT_EQ(developer::LOCATION_THIRD_PARTY, info->location); |
281 EXPECT_FALSE(info->path); | 283 EXPECT_FALSE(info->path); |
282 } | 284 } |
283 | 285 |
284 // Test three generated json outputs. | 286 // Test three generated json outputs. |
285 TEST_F(ExtensionInfoGeneratorUnitTest, GenerateExtensionsJSONData) { | 287 TEST_F(ExtensionInfoGeneratorUnitTest, GenerateExtensionsJSONData) { |
286 // Test Extension1 | 288 // Test Extension1 |
287 base::FilePath extension_path = | 289 base::FilePath extension_path = |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 "all_urls_II", std::move(ListBuilder().Append(kAllHostsPermission))); | 403 "all_urls_II", std::move(ListBuilder().Append(kAllHostsPermission))); |
402 | 404 |
403 // Even though the extension has all_urls permission, the checkbox shouldn't | 405 // Even though the extension has all_urls permission, the checkbox shouldn't |
404 // show up without the switch. | 406 // show up without the switch. |
405 info = GenerateExtensionInfo(all_urls_extension->id()); | 407 info = GenerateExtensionInfo(all_urls_extension->id()); |
406 EXPECT_FALSE(info->run_on_all_urls.is_enabled); | 408 EXPECT_FALSE(info->run_on_all_urls.is_enabled); |
407 EXPECT_TRUE(info->run_on_all_urls.is_active); | 409 EXPECT_TRUE(info->run_on_all_urls.is_active); |
408 } | 410 } |
409 | 411 |
410 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |