OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "chrome/browser/extensions/external_install_ui.h" | 49 #include "chrome/browser/extensions/external_install_ui.h" |
50 #include "chrome/browser/extensions/external_policy_loader.h" | 50 #include "chrome/browser/extensions/external_policy_loader.h" |
51 #include "chrome/browser/extensions/external_pref_loader.h" | 51 #include "chrome/browser/extensions/external_pref_loader.h" |
52 #include "chrome/browser/extensions/external_provider_impl.h" | 52 #include "chrome/browser/extensions/external_provider_impl.h" |
53 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" | 53 #include "chrome/browser/extensions/fake_safe_browsing_database_manager.h" |
54 #include "chrome/browser/extensions/install_observer.h" | 54 #include "chrome/browser/extensions/install_observer.h" |
55 #include "chrome/browser/extensions/install_tracker.h" | 55 #include "chrome/browser/extensions/install_tracker.h" |
56 #include "chrome/browser/extensions/install_tracker_factory.h" | 56 #include "chrome/browser/extensions/install_tracker_factory.h" |
57 #include "chrome/browser/extensions/installed_loader.h" | 57 #include "chrome/browser/extensions/installed_loader.h" |
58 #include "chrome/browser/extensions/pack_extension_job.h" | 58 #include "chrome/browser/extensions/pack_extension_job.h" |
| 59 #include "chrome/browser/extensions/test_blacklist.h" |
59 #include "chrome/browser/extensions/test_extension_system.h" | 60 #include "chrome/browser/extensions/test_extension_system.h" |
60 #include "chrome/browser/extensions/unpacked_installer.h" | 61 #include "chrome/browser/extensions/unpacked_installer.h" |
61 #include "chrome/browser/extensions/updater/extension_updater.h" | 62 #include "chrome/browser/extensions/updater/extension_updater.h" |
62 #include "chrome/browser/prefs/browser_prefs.h" | 63 #include "chrome/browser/prefs/browser_prefs.h" |
63 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 64 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
64 #include "chrome/browser/prefs/pref_service_syncable.h" | 65 #include "chrome/browser/prefs/pref_service_syncable.h" |
65 #include "chrome/browser/sync/profile_sync_service.h" | 66 #include "chrome/browser/sync/profile_sync_service.h" |
66 #include "chrome/browser/sync/profile_sync_service_factory.h" | 67 #include "chrome/browser/sync/profile_sync_service_factory.h" |
67 #include "chrome/common/chrome_constants.h" | 68 #include "chrome/common/chrome_constants.h" |
68 #include "chrome/common/chrome_paths.h" | 69 #include "chrome/common/chrome_paths.h" |
(...skipping 3285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3354 Extension::NO_FLAGS, false); | 3355 Extension::NO_FLAGS, false); |
3355 UpdateExtension(good->id(), path, ENABLED); | 3356 UpdateExtension(good->id(), path, ENABLED); |
3356 | 3357 |
3357 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); | 3358 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(kGoodId)); |
3358 } | 3359 } |
3359 | 3360 |
3360 #if defined(ENABLE_BLACKLIST_TESTS) | 3361 #if defined(ENABLE_BLACKLIST_TESTS) |
3361 // Tests blacklisting then unblacklisting extensions after the service has been | 3362 // Tests blacklisting then unblacklisting extensions after the service has been |
3362 // initialized. | 3363 // initialized. |
3363 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { | 3364 TEST_F(ExtensionServiceTest, SetUnsetBlacklistInPrefs) { |
3364 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( | 3365 extensions::TestBlacklist test_blacklist; |
3365 new FakeSafeBrowsingDatabaseManager(true)); | |
3366 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); | |
3367 | |
3368 // A profile with 3 extensions installed: good0, good1, and good2. | 3366 // A profile with 3 extensions installed: good0, good1, and good2. |
3369 InitializeGoodInstalledExtensionService(); | 3367 InitializeGoodInstalledExtensionService(); |
| 3368 test_blacklist.Attach(service_->blacklist_); |
3370 service_->Init(); | 3369 service_->Init(); |
3371 | 3370 |
3372 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); | 3371 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
3373 const extensions::ExtensionSet& enabled_extensions = | 3372 const extensions::ExtensionSet& enabled_extensions = |
3374 registry->enabled_extensions(); | 3373 registry->enabled_extensions(); |
3375 const extensions::ExtensionSet& blacklisted_extensions = | 3374 const extensions::ExtensionSet& blacklisted_extensions = |
3376 registry->blacklisted_extensions(); | 3375 registry->blacklisted_extensions(); |
3377 | 3376 |
3378 EXPECT_TRUE(enabled_extensions.Contains(good0) && | 3377 EXPECT_TRUE(enabled_extensions.Contains(good0) && |
3379 !blacklisted_extensions.Contains(good0)); | 3378 !blacklisted_extensions.Contains(good0)); |
3380 EXPECT_TRUE(enabled_extensions.Contains(good1) && | 3379 EXPECT_TRUE(enabled_extensions.Contains(good1) && |
3381 !blacklisted_extensions.Contains(good1)); | 3380 !blacklisted_extensions.Contains(good1)); |
3382 EXPECT_TRUE(enabled_extensions.Contains(good2) && | 3381 EXPECT_TRUE(enabled_extensions.Contains(good2) && |
3383 !blacklisted_extensions.Contains(good2)); | 3382 !blacklisted_extensions.Contains(good2)); |
3384 | 3383 |
3385 EXPECT_FALSE(IsPrefExist(good0, "blacklist")); | 3384 EXPECT_FALSE(IsPrefExist(good0, "blacklist")); |
3386 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); | 3385 EXPECT_FALSE(IsPrefExist(good1, "blacklist")); |
3387 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); | 3386 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
3388 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 3387 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
3389 | 3388 |
3390 // Blacklist good0 and good1 (and an invalid extension ID). | 3389 // Blacklist good0 and good1 (and an invalid extension ID). |
3391 blacklist_db->SetUnsafe(good0, good1, "invalid_id").NotifyUpdate(); | 3390 test_blacklist.SetBlacklistState( |
| 3391 good0, extensions::BLACKLISTED_MALWARE, true); |
| 3392 test_blacklist.SetBlacklistState( |
| 3393 good1, extensions::BLACKLISTED_MALWARE, true); |
| 3394 test_blacklist.SetBlacklistState( |
| 3395 "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
3392 base::RunLoop().RunUntilIdle(); | 3396 base::RunLoop().RunUntilIdle(); |
3393 | 3397 |
3394 EXPECT_TRUE(!enabled_extensions.Contains(good0) && | 3398 EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
3395 blacklisted_extensions.Contains(good0)); | 3399 blacklisted_extensions.Contains(good0)); |
3396 EXPECT_TRUE(!enabled_extensions.Contains(good1) && | 3400 EXPECT_TRUE(!enabled_extensions.Contains(good1) && |
3397 blacklisted_extensions.Contains(good1)); | 3401 blacklisted_extensions.Contains(good1)); |
3398 EXPECT_TRUE(enabled_extensions.Contains(good2) && | 3402 EXPECT_TRUE(enabled_extensions.Contains(good2) && |
3399 !blacklisted_extensions.Contains(good2)); | 3403 !blacklisted_extensions.Contains(good2)); |
3400 | 3404 |
3401 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); | 3405 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
3402 EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); | 3406 EXPECT_TRUE(ValidateBooleanPref(good1, "blacklist", true)); |
3403 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); | 3407 EXPECT_FALSE(IsPrefExist(good2, "blacklist")); |
3404 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); | 3408 EXPECT_FALSE(IsPrefExist("invalid_id", "blacklist")); |
3405 | 3409 |
3406 // Un-blacklist good1 and blacklist good2. | 3410 // Un-blacklist good1 and blacklist good2. |
3407 blacklist_db->SetUnsafe(good0, good2, "invalid_id").NotifyUpdate(); | 3411 test_blacklist.Clear(false); |
| 3412 test_blacklist.SetBlacklistState( |
| 3413 good0, extensions::BLACKLISTED_MALWARE, true); |
| 3414 test_blacklist.SetBlacklistState( |
| 3415 good2, extensions::BLACKLISTED_MALWARE, true); |
| 3416 test_blacklist.SetBlacklistState( |
| 3417 "invalid_id", extensions::BLACKLISTED_MALWARE, true); |
3408 base::RunLoop().RunUntilIdle(); | 3418 base::RunLoop().RunUntilIdle(); |
3409 | 3419 |
3410 EXPECT_TRUE(!enabled_extensions.Contains(good0) && | 3420 EXPECT_TRUE(!enabled_extensions.Contains(good0) && |
3411 blacklisted_extensions.Contains(good0)); | 3421 blacklisted_extensions.Contains(good0)); |
3412 EXPECT_TRUE(enabled_extensions.Contains(good1) && | 3422 EXPECT_TRUE(enabled_extensions.Contains(good1) && |
3413 !blacklisted_extensions.Contains(good1)); | 3423 !blacklisted_extensions.Contains(good1)); |
3414 EXPECT_TRUE(!enabled_extensions.Contains(good2) && | 3424 EXPECT_TRUE(!enabled_extensions.Contains(good2) && |
3415 blacklisted_extensions.Contains(good2)); | 3425 blacklisted_extensions.Contains(good2)); |
3416 | 3426 |
3417 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); | 3427 EXPECT_TRUE(ValidateBooleanPref(good0, "blacklist", true)); |
(...skipping 22 matching lines...) Expand all Loading... |
3440 // decide to install this silently. Somebody should fix these tests, all | 3450 // decide to install this silently. Somebody should fix these tests, all |
3441 // 6,000 lines of them. Hah! | 3451 // 6,000 lines of them. Hah! |
3442 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); | 3452 InstallCRX(path, INSTALL_FAILED, Extension::WAS_INSTALLED_BY_DEFAULT); |
3443 EXPECT_EQ(0u, service_->extensions()->size()); | 3453 EXPECT_EQ(0u, service_->extensions()->size()); |
3444 } | 3454 } |
3445 #endif // defined(ENABLE_BLACKLIST_TESTS) | 3455 #endif // defined(ENABLE_BLACKLIST_TESTS) |
3446 | 3456 |
3447 #if defined(ENABLE_BLACKLIST_TESTS) | 3457 #if defined(ENABLE_BLACKLIST_TESTS) |
3448 // Unload blacklisted extension on policy change. | 3458 // Unload blacklisted extension on policy change. |
3449 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { | 3459 TEST_F(ExtensionServiceTest, UnloadBlacklistedExtensionPolicy) { |
3450 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( | 3460 extensions::TestBlacklist test_blacklist; |
3451 new FakeSafeBrowsingDatabaseManager(true)); | |
3452 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); | |
3453 | 3461 |
3454 // A profile with no extensions installed. | 3462 // A profile with no extensions installed. |
3455 InitializeEmptyExtensionService(); | 3463 InitializeEmptyExtensionService(); |
| 3464 test_blacklist.Attach(service_->blacklist_); |
3456 | 3465 |
3457 base::FilePath path = data_dir_.AppendASCII("good.crx"); | 3466 base::FilePath path = data_dir_.AppendASCII("good.crx"); |
3458 | 3467 |
3459 const Extension* good = InstallCRX(path, INSTALL_NEW); | 3468 const Extension* good = InstallCRX(path, INSTALL_NEW); |
3460 EXPECT_EQ(good_crx, good->id()); | 3469 EXPECT_EQ(good_crx, good->id()); |
3461 UpdateExtension(good_crx, path, FAILED_SILENTLY); | 3470 UpdateExtension(good_crx, path, FAILED_SILENTLY); |
3462 EXPECT_EQ(1u, service_->extensions()->size()); | 3471 EXPECT_EQ(1u, service_->extensions()->size()); |
3463 | 3472 |
3464 base::ListValue whitelist; | 3473 base::ListValue whitelist; |
3465 PrefService* prefs = service_->extension_prefs()->pref_service(); | 3474 PrefService* prefs = service_->extension_prefs()->pref_service(); |
3466 whitelist.Append(new base::StringValue(good_crx)); | 3475 whitelist.Append(new base::StringValue(good_crx)); |
3467 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); | 3476 prefs->Set(prefs::kExtensionInstallAllowList, whitelist); |
3468 | 3477 |
3469 blacklist_db->SetUnsafe(good_crx).NotifyUpdate(); | 3478 test_blacklist.SetBlacklistState( |
| 3479 good_crx, extensions::BLACKLISTED_MALWARE, true); |
3470 base::RunLoop().RunUntilIdle(); | 3480 base::RunLoop().RunUntilIdle(); |
3471 | 3481 |
3472 // The good_crx is blacklisted and the whitelist doesn't negate it. | 3482 // The good_crx is blacklisted and the whitelist doesn't negate it. |
3473 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); | 3483 ASSERT_TRUE(ValidateBooleanPref(good_crx, "blacklist", true)); |
3474 EXPECT_EQ(0u, service_->extensions()->size()); | 3484 EXPECT_EQ(0u, service_->extensions()->size()); |
3475 } | 3485 } |
3476 #endif // defined(ENABLE_BLACKLIST_TESTS) | 3486 #endif // defined(ENABLE_BLACKLIST_TESTS) |
3477 | 3487 |
3478 #if defined(ENABLE_BLACKLIST_TESTS) | 3488 #if defined(ENABLE_BLACKLIST_TESTS) |
3479 // Tests that a blacklisted extension is eventually unloaded on startup, if it | 3489 // Tests that a blacklisted extension is eventually unloaded on startup, if it |
3480 // wasn't already. | 3490 // wasn't already. |
3481 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { | 3491 TEST_F(ExtensionServiceTest, WillNotLoadBlacklistedExtensionsFromDirectory) { |
3482 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( | 3492 extensions::TestBlacklist test_blacklist; |
3483 new FakeSafeBrowsingDatabaseManager(true)); | |
3484 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); | |
3485 | 3493 |
3486 // A profile with 3 extensions installed: good0, good1, and good2. | 3494 // A profile with 3 extensions installed: good0, good1, and good2. |
3487 InitializeGoodInstalledExtensionService(); | 3495 InitializeGoodInstalledExtensionService(); |
| 3496 test_blacklist.Attach(service_->blacklist_); |
3488 | 3497 |
3489 // Blacklist good1 before the service initializes. | 3498 // Blacklist good1 before the service initializes. |
3490 blacklist_db->SetUnsafe(good1); | 3499 test_blacklist.SetBlacklistState( |
| 3500 good1, extensions::BLACKLISTED_MALWARE, false); |
3491 | 3501 |
3492 // Load extensions. | 3502 // Load extensions. |
3493 service_->Init(); | 3503 service_->Init(); |
3494 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet | 3504 ASSERT_EQ(3u, loaded_.size()); // hasn't had time to blacklist yet |
3495 | 3505 |
3496 base::RunLoop().RunUntilIdle(); | 3506 base::RunLoop().RunUntilIdle(); |
3497 | 3507 |
3498 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); | 3508 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
3499 ASSERT_EQ(1u, registry->blacklisted_extensions().size()); | 3509 ASSERT_EQ(1u, registry->blacklisted_extensions().size()); |
3500 ASSERT_EQ(2u, registry->enabled_extensions().size()); | 3510 ASSERT_EQ(2u, registry->enabled_extensions().size()); |
3501 | 3511 |
3502 ASSERT_TRUE(registry->enabled_extensions().Contains(good0)); | 3512 ASSERT_TRUE(registry->enabled_extensions().Contains(good0)); |
3503 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); | 3513 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); |
3504 ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); | 3514 ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); |
3505 } | 3515 } |
3506 #endif // defined(ENABLE_BLACKLIST_TESTS) | 3516 #endif // defined(ENABLE_BLACKLIST_TESTS) |
3507 | 3517 |
3508 #if defined(ENABLE_BLACKLIST_TESTS) | 3518 #if defined(ENABLE_BLACKLIST_TESTS) |
3509 // Tests extensions blacklisted in prefs on startup; one still blacklisted by | 3519 // Tests extensions blacklisted in prefs on startup; one still blacklisted by |
3510 // safe browsing, the other not. The not-blacklisted one should recover. | 3520 // safe browsing, the other not. The not-blacklisted one should recover. |
3511 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { | 3521 TEST_F(ExtensionServiceTest, BlacklistedInPrefsFromStartup) { |
3512 scoped_refptr<FakeSafeBrowsingDatabaseManager> blacklist_db( | 3522 extensions::TestBlacklist test_blacklist; |
3513 new FakeSafeBrowsingDatabaseManager(true)); | |
3514 Blacklist::ScopedDatabaseManagerForTest scoped_blacklist_db(blacklist_db); | |
3515 | 3523 |
3516 InitializeGoodInstalledExtensionService(); | 3524 InitializeGoodInstalledExtensionService(); |
| 3525 test_blacklist.Attach(service_->blacklist_); |
3517 service_->extension_prefs()->SetExtensionBlacklisted(good0, true); | 3526 service_->extension_prefs()->SetExtensionBlacklisted(good0, true); |
3518 service_->extension_prefs()->SetExtensionBlacklisted(good1, true); | 3527 service_->extension_prefs()->SetExtensionBlacklisted(good1, true); |
3519 | 3528 |
3520 blacklist_db->SetUnsafe(good1); | 3529 test_blacklist.SetBlacklistState( |
| 3530 good1, extensions::BLACKLISTED_MALWARE, false); |
3521 | 3531 |
3522 service_->Init(); | 3532 service_->Init(); |
3523 | 3533 |
3524 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); | 3534 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get()); |
3525 ASSERT_EQ(2u, registry->blacklisted_extensions().size()); | 3535 ASSERT_EQ(2u, registry->blacklisted_extensions().size()); |
3526 ASSERT_EQ(1u, registry->enabled_extensions().size()); | 3536 ASSERT_EQ(1u, registry->enabled_extensions().size()); |
3527 | 3537 |
3528 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good0)); | 3538 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good0)); |
3529 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); | 3539 ASSERT_TRUE(registry->blacklisted_extensions().Contains(good1)); |
3530 ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); | 3540 ASSERT_TRUE(registry->enabled_extensions().Contains(good2)); |
(...skipping 3247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6778 // ReconcileKnownDisabled(). | 6788 // ReconcileKnownDisabled(). |
6779 service_->EnableExtension(good2); | 6789 service_->EnableExtension(good2); |
6780 service_->ReconcileKnownDisabled(); | 6790 service_->ReconcileKnownDisabled(); |
6781 expected_extensions.insert(good2); | 6791 expected_extensions.insert(good2); |
6782 expected_disabled_extensions.erase(good2); | 6792 expected_disabled_extensions.erase(good2); |
6783 | 6793 |
6784 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); | 6794 EXPECT_EQ(expected_extensions, service_->extensions()->GetIDs()); |
6785 EXPECT_EQ(expected_disabled_extensions, | 6795 EXPECT_EQ(expected_disabled_extensions, |
6786 service_->disabled_extensions()->GetIDs()); | 6796 service_->disabled_extensions()->GetIDs()); |
6787 } | 6797 } |
OLD | NEW |