OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/extensions/extension_service_unittest.h" | 5 #include "chrome/browser/extensions/extension_service_unittest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/extensions/extension_sync_data.h" | 35 #include "chrome/browser/extensions/extension_sync_data.h" |
36 #include "chrome/browser/extensions/extension_updater.h" | 36 #include "chrome/browser/extensions/extension_updater.h" |
37 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 37 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
38 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 38 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
39 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 39 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
40 #include "chrome/browser/extensions/installed_loader.h" | 40 #include "chrome/browser/extensions/installed_loader.h" |
41 #include "chrome/browser/extensions/pack_extension_job.cc" | 41 #include "chrome/browser/extensions/pack_extension_job.cc" |
42 #include "chrome/browser/extensions/pending_extension_info.h" | 42 #include "chrome/browser/extensions/pending_extension_info.h" |
43 #include "chrome/browser/extensions/pending_extension_manager.h" | 43 #include "chrome/browser/extensions/pending_extension_manager.h" |
44 #include "chrome/browser/extensions/unpacked_installer.h" | 44 #include "chrome/browser/extensions/unpacked_installer.h" |
| 45 #include "chrome/browser/plugin_prefs_factory.h" |
45 #include "chrome/browser/prefs/browser_prefs.h" | 46 #include "chrome/browser/prefs/browser_prefs.h" |
46 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 47 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
47 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 48 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
48 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 49 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
49 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 50 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
50 #include "chrome/common/chrome_notification_types.h" | 51 #include "chrome/common/chrome_notification_types.h" |
51 #include "chrome/common/chrome_paths.h" | 52 #include "chrome/common/chrome_paths.h" |
52 #include "chrome/common/chrome_switches.h" | 53 #include "chrome/common/chrome_switches.h" |
53 #include "chrome/common/extensions/extension.h" | 54 #include "chrome/common/extensions/extension.h" |
54 #include "chrome/common/extensions/extension_constants.h" | 55 #include "chrome/common/extensions/extension_constants.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 const FilePath& pref_file, const FilePath& extensions_install_dir, | 409 const FilePath& pref_file, const FilePath& extensions_install_dir, |
409 bool autoupdate_enabled) { | 410 bool autoupdate_enabled) { |
410 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); | 411 ExtensionTestingProfile* profile = new ExtensionTestingProfile(); |
411 // Create a PrefService that only contains user defined preference values. | 412 // Create a PrefService that only contains user defined preference values. |
412 PrefService* prefs = | 413 PrefService* prefs = |
413 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); | 414 PrefServiceMockBuilder().WithUserFilePrefs(pref_file).Create(); |
414 Profile::RegisterUserPrefs(prefs); | 415 Profile::RegisterUserPrefs(prefs); |
415 browser::RegisterUserPrefs(prefs); | 416 browser::RegisterUserPrefs(prefs); |
416 profile->SetPrefService(prefs); | 417 profile->SetPrefService(prefs); |
417 | 418 |
| 419 PluginPrefsFactory::GetInstance()->ForceRegisterPrefsForTest(prefs); |
| 420 |
418 profile_.reset(profile); | 421 profile_.reset(profile); |
419 | 422 |
420 service_ = profile->CreateExtensionService( | 423 service_ = profile->CreateExtensionService( |
421 CommandLine::ForCurrentProcess(), | 424 CommandLine::ForCurrentProcess(), |
422 extensions_install_dir, | 425 extensions_install_dir, |
423 autoupdate_enabled); | 426 autoupdate_enabled); |
424 service_->set_extensions_enabled(true); | 427 service_->set_extensions_enabled(true); |
425 service_->set_show_extensions_prompts(false); | 428 service_->set_show_extensions_prompts(false); |
426 profile->set_extensions_service(service_); | 429 profile->set_extensions_service(service_); |
427 | 430 |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 ASSERT_TRUE(file_util::PathExists(private_key_path)); | 980 ASSERT_TRUE(file_util::PathExists(private_key_path)); |
978 } | 981 } |
979 | 982 |
980 // The tests are designed so that we never expect to see a packing error. | 983 // The tests are designed so that we never expect to see a packing error. |
981 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { | 984 void PackExtensionTestClient::OnPackFailure(const std::string& error_message) { |
982 FAIL() << "Packing should not fail."; | 985 FAIL() << "Packing should not fail."; |
983 } | 986 } |
984 | 987 |
985 // Test loading good extensions from the profile directory. | 988 // Test loading good extensions from the profile directory. |
986 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { | 989 TEST_F(ExtensionServiceTest, LoadAllExtensionsFromDirectorySuccess) { |
987 base::ShadowingAtExitManager at_exit_manager; | |
988 PluginService::GetInstance()->Init(); | 990 PluginService::GetInstance()->Init(); |
989 | 991 |
990 // Initialize the test dir with a good Preferences/extensions. | 992 // Initialize the test dir with a good Preferences/extensions. |
991 FilePath source_install_dir = data_dir_ | 993 FilePath source_install_dir = data_dir_ |
992 .AppendASCII("good") | 994 .AppendASCII("good") |
993 .AppendASCII("Extensions"); | 995 .AppendASCII("Extensions"); |
994 FilePath pref_path = source_install_dir | 996 FilePath pref_path = source_install_dir |
995 .DirName() | 997 .DirName() |
996 .AppendASCII("Preferences"); | 998 .AppendASCII("Preferences"); |
997 InitializeInstalledExtensionService(pref_path, source_install_dir); | 999 InitializeInstalledExtensionService(pref_path, source_install_dir); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1117 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; | 1119 extension_manifest_errors::kMissingFile)) << GetErrors()[2]; |
1118 | 1120 |
1119 EXPECT_TRUE(MatchPattern(GetErrors()[3], | 1121 EXPECT_TRUE(MatchPattern(GetErrors()[3], |
1120 std::string("Could not load extension from '*'. ") + | 1122 std::string("Could not load extension from '*'. ") + |
1121 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; | 1123 extension_manifest_errors::kManifestUnreadable)) << GetErrors()[3]; |
1122 }; | 1124 }; |
1123 | 1125 |
1124 // Test that partially deleted extensions are cleaned up during startup | 1126 // Test that partially deleted extensions are cleaned up during startup |
1125 // Test loading bad extensions from the profile directory. | 1127 // Test loading bad extensions from the profile directory. |
1126 TEST_F(ExtensionServiceTest, CleanupOnStartup) { | 1128 TEST_F(ExtensionServiceTest, CleanupOnStartup) { |
1127 base::ShadowingAtExitManager at_exit_manager; | |
1128 PluginService::GetInstance()->Init(); | 1129 PluginService::GetInstance()->Init(); |
1129 | 1130 |
1130 FilePath source_install_dir = data_dir_ | 1131 FilePath source_install_dir = data_dir_ |
1131 .AppendASCII("good") | 1132 .AppendASCII("good") |
1132 .AppendASCII("Extensions"); | 1133 .AppendASCII("Extensions"); |
1133 FilePath pref_path = source_install_dir | 1134 FilePath pref_path = source_install_dir |
1134 .DirName() | 1135 .DirName() |
1135 .AppendASCII("Preferences"); | 1136 .AppendASCII("Preferences"); |
1136 | 1137 |
1137 InitializeInstalledExtensionService(pref_path, source_install_dir); | 1138 InitializeInstalledExtensionService(pref_path, source_install_dir); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1453 EXPECT_EQ(expected_api_perms, known_perms->apis()); | 1454 EXPECT_EQ(expected_api_perms, known_perms->apis()); |
1454 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); | 1455 EXPECT_FALSE(known_perms->HasEffectiveFullAccess()); |
1455 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); | 1456 EXPECT_EQ(expected_host_perms, known_perms->effective_hosts()); |
1456 } | 1457 } |
1457 | 1458 |
1458 #if !defined(OS_CHROMEOS) | 1459 #if !defined(OS_CHROMEOS) |
1459 // Tests that the granted permissions full_access bit gets set correctly when | 1460 // Tests that the granted permissions full_access bit gets set correctly when |
1460 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS | 1461 // an extension contains an NPAPI plugin. Don't run this test on Chrome OS |
1461 // since they don't support plugins. | 1462 // since they don't support plugins. |
1462 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { | 1463 TEST_F(ExtensionServiceTest, GrantedFullAccessPermissions) { |
1463 base::ShadowingAtExitManager at_exit_manager; | |
1464 PluginService::GetInstance()->Init(); | 1464 PluginService::GetInstance()->Init(); |
1465 | 1465 |
1466 InitializeEmptyExtensionService(); | 1466 InitializeEmptyExtensionService(); |
1467 | 1467 |
1468 FilePath path = data_dir_ | 1468 FilePath path = data_dir_ |
1469 .AppendASCII("good") | 1469 .AppendASCII("good") |
1470 .AppendASCII("Extensions") | 1470 .AppendASCII("Extensions") |
1471 .AppendASCII(good1) | 1471 .AppendASCII(good1) |
1472 .AppendASCII("2"); | 1472 .AppendASCII("2"); |
1473 | 1473 |
(...skipping 2863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4337 ASSERT_FALSE(AddPendingSyncInstall()); | 4337 ASSERT_FALSE(AddPendingSyncInstall()); |
4338 | 4338 |
4339 // Wait for the external source to install. | 4339 // Wait for the external source to install. |
4340 WaitForCrxInstall(crx_path_, true); | 4340 WaitForCrxInstall(crx_path_, true); |
4341 ASSERT_TRUE(IsCrxInstalled()); | 4341 ASSERT_TRUE(IsCrxInstalled()); |
4342 | 4342 |
4343 // Now that the extension is installed, sync request should fail | 4343 // Now that the extension is installed, sync request should fail |
4344 // because the extension is already installed. | 4344 // because the extension is already installed. |
4345 ASSERT_FALSE(AddPendingSyncInstall()); | 4345 ASSERT_FALSE(AddPendingSyncInstall()); |
4346 } | 4346 } |
OLD | NEW |