| 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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
| 7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 7 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/test_extension_dir.h" | 11 #include "chrome/browser/extensions/test_extension_dir.h" |
| 12 #include "chrome/browser/extensions/test_extension_system.h" | 12 #include "chrome/browser/extensions/test_extension_system.h" |
| 13 #include "chrome/browser/extensions/unpacked_installer.h" | 13 #include "chrome/browser/extensions/unpacked_installer.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/host_desktop.h" | 15 #include "chrome/browser/ui/host_desktop.h" |
| 16 #include "chrome/common/extensions/api/developer_private.h" | 16 #include "chrome/common/extensions/api/developer_private.h" |
| 17 #include "chrome/test/base/test_browser_window.h" | 17 #include "chrome/test/base/test_browser_window.h" |
| 18 #include "components/crx_file/id_util.h" |
| 18 #include "content/public/test/test_web_contents_factory.h" | 19 #include "content/public/test/test_web_contents_factory.h" |
| 19 #include "extensions/browser/extension_prefs.h" | 20 #include "extensions/browser/extension_prefs.h" |
| 20 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
| 21 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 22 #include "extensions/browser/test_extension_registry_observer.h" | 23 #include "extensions/browser/test_extension_registry_observer.h" |
| 23 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_builder.h" |
| 24 #include "extensions/common/extension_set.h" | 26 #include "extensions/common/extension_set.h" |
| 25 #include "extensions/common/manifest_constants.h" | 27 #include "extensions/common/manifest_constants.h" |
| 26 #include "extensions/common/test_util.h" | 28 #include "extensions/common/test_util.h" |
| 29 #include "extensions/common/value_builder.h" |
| 27 | 30 |
| 28 namespace extensions { | 31 namespace extensions { |
| 29 | 32 |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 KeyedService* BuildAPI(content::BrowserContext* context) { | 35 KeyedService* BuildAPI(content::BrowserContext* context) { |
| 33 return new DeveloperPrivateAPI(context); | 36 return new DeveloperPrivateAPI(context); |
| 34 } | 37 } |
| 35 | 38 |
| 36 } // namespace | 39 } // namespace |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 unpacked_args.Append(options.release()); | 368 unpacked_args.Append(options.release()); |
| 366 current_ids = registry()->enabled_extensions().GetIDs(); | 369 current_ids = registry()->enabled_extensions().GetIDs(); |
| 367 EXPECT_FALSE(RunFunction(function, unpacked_args)); | 370 EXPECT_FALSE(RunFunction(function, unpacked_args)); |
| 368 EXPECT_EQ(manifest_errors::kManifestUnreadable, function->GetError()); | 371 EXPECT_EQ(manifest_errors::kManifestUnreadable, function->GetError()); |
| 369 // We should have no new extensions installed. | 372 // We should have no new extensions installed. |
| 370 EXPECT_EQ(0u, base::STLSetDifference<ExtensionIdSet>( | 373 EXPECT_EQ(0u, base::STLSetDifference<ExtensionIdSet>( |
| 371 registry()->enabled_extensions().GetIDs(), | 374 registry()->enabled_extensions().GetIDs(), |
| 372 current_ids).size()); | 375 current_ids).size()); |
| 373 } | 376 } |
| 374 | 377 |
| 378 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateGetExtensionsInfo) { |
| 379 const char kName[] = "extension name"; |
| 380 const char kVersion[] = "1.0.0.1"; |
| 381 std::string id = crx_file::id_util::GenerateId(kName); |
| 382 DictionaryBuilder manifest; |
| 383 manifest.Set("name", kName) |
| 384 .Set("version", kVersion) |
| 385 .Set("manifest_version", 2) |
| 386 .Set("description", "an extension") |
| 387 .Set("permissions", ListBuilder().Append("file://*/*")); |
| 388 scoped_refptr<const Extension> extension = |
| 389 ExtensionBuilder().SetManifest(manifest) |
| 390 .SetLocation(Manifest::UNPACKED) |
| 391 .SetPath(data_dir()) |
| 392 .SetID(id) |
| 393 .Build(); |
| 394 service()->AddExtension(extension.get()); |
| 395 |
| 396 scoped_refptr<UIThreadExtensionFunction> function( |
| 397 new api::DeveloperPrivateGetExtensionsInfoFunction()); |
| 398 EXPECT_TRUE(RunFunction(function, base::ListValue())) << function->GetError(); |
| 399 const base::ListValue* results = function->GetResultList(); |
| 400 ASSERT_EQ(1u, results->GetSize()); |
| 401 const base::ListValue* list = nullptr; |
| 402 ASSERT_TRUE(results->GetList(0u, &list)); |
| 403 ASSERT_EQ(1u, list->GetSize()); |
| 404 const base::Value* value = nullptr; |
| 405 ASSERT_TRUE(list->Get(0u, &value)); |
| 406 scoped_ptr<api::developer_private::ExtensionInfo> info = |
| 407 api::developer_private::ExtensionInfo::FromValue(*value); |
| 408 ASSERT_TRUE(info); |
| 409 EXPECT_EQ(kName, info->name); |
| 410 EXPECT_EQ(id, info->id); |
| 411 EXPECT_EQ(kVersion, info->version); |
| 412 EXPECT_EQ(api::developer_private::EXTENSION_STATE_ENABLED, info->state); |
| 413 EXPECT_EQ(api::developer_private::EXTENSION_TYPE_EXTENSION, info->type); |
| 414 EXPECT_EQ(api::developer_private::RUN_STATE_VALUE_WANTS_STATE, |
| 415 info->file_access); |
| 416 EXPECT_EQ(api::developer_private::RUN_STATE_VALUE_CANT_HAVE_STATE, |
| 417 info->run_on_all_urls); |
| 418 EXPECT_EQ(api::developer_private::LOCATION_UNPACKED, info->location); |
| 419 EXPECT_EQ(api::developer_private::RUN_STATE_VALUE_WANTS_STATE, |
| 420 info->incognito_access); |
| 421 } |
| 422 |
| 375 } // namespace extensions | 423 } // namespace extensions |
| OLD | NEW |