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/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "chrome/browser/extensions/external_provider_impl.h" | 42 #include "chrome/browser/extensions/external_provider_impl.h" |
43 #include "chrome/browser/extensions/external_provider_interface.h" | 43 #include "chrome/browser/extensions/external_provider_interface.h" |
44 #include "chrome/browser/extensions/installed_loader.h" | 44 #include "chrome/browser/extensions/installed_loader.h" |
45 #include "chrome/browser/extensions/pack_extension_job.h" | 45 #include "chrome/browser/extensions/pack_extension_job.h" |
46 #include "chrome/browser/extensions/pending_extension_info.h" | 46 #include "chrome/browser/extensions/pending_extension_info.h" |
47 #include "chrome/browser/extensions/pending_extension_manager.h" | 47 #include "chrome/browser/extensions/pending_extension_manager.h" |
48 #include "chrome/browser/extensions/test_extension_system.h" | 48 #include "chrome/browser/extensions/test_extension_system.h" |
49 #include "chrome/browser/extensions/test_management_policy.h" | 49 #include "chrome/browser/extensions/test_management_policy.h" |
50 #include "chrome/browser/extensions/unpacked_installer.h" | 50 #include "chrome/browser/extensions/unpacked_installer.h" |
51 #include "chrome/browser/extensions/updater/extension_updater.h" | 51 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 52 #include "chrome/browser/gpu_blacklist.h" |
| 53 #include "chrome/browser/gpu_util.h" |
| 54 #include "chrome/browser/plugin_prefs_factory.h" |
52 #include "chrome/browser/prefs/browser_prefs.h" | 55 #include "chrome/browser/prefs/browser_prefs.h" |
53 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 56 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
54 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 57 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
55 #include "chrome/common/chrome_constants.h" | 58 #include "chrome/common/chrome_constants.h" |
56 #include "chrome/common/chrome_notification_types.h" | 59 #include "chrome/common/chrome_notification_types.h" |
57 #include "chrome/common/chrome_paths.h" | 60 #include "chrome/common/chrome_paths.h" |
58 #include "chrome/common/chrome_switches.h" | 61 #include "chrome/common/chrome_switches.h" |
59 #include "chrome/common/extensions/extension.h" | 62 #include "chrome/common/extensions/extension.h" |
60 #include "chrome/common/extensions/extension_l10n_util.h" | 63 #include "chrome/common/extensions/extension_l10n_util.h" |
61 #include "chrome/common/extensions/extension_manifest_constants.h" | 64 #include "chrome/common/extensions/extension_manifest_constants.h" |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 } | 713 } |
711 | 714 |
712 enum UpdateState { | 715 enum UpdateState { |
713 FAILED_SILENTLY, | 716 FAILED_SILENTLY, |
714 FAILED, | 717 FAILED, |
715 UPDATED, | 718 UPDATED, |
716 INSTALLED, | 719 INSTALLED, |
717 ENABLED | 720 ENABLED |
718 }; | 721 }; |
719 | 722 |
| 723 void BlackListWebGL() { |
| 724 static const std::string json_blacklist = |
| 725 "{\n" |
| 726 " \"name\": \"gpu blacklist\",\n" |
| 727 " \"version\": \"1.0\",\n" |
| 728 " \"entries\": [\n" |
| 729 " {\n" |
| 730 " \"id\": 1,\n" |
| 731 " \"blacklist\": [\"webgl\"]\n" |
| 732 " }\n" |
| 733 " ]\n" |
| 734 "}"; |
| 735 GpuBlacklist* blacklist = GpuBlacklist::GetInstance(); |
| 736 ASSERT_TRUE(blacklist); |
| 737 ASSERT_TRUE(blacklist->LoadGpuBlacklist(json_blacklist, |
| 738 GpuBlacklist::kAllOs)); |
| 739 blacklist->UpdateGpuDataManager(); |
| 740 } |
| 741 |
720 void UpdateExtension(const std::string& id, const FilePath& in_path, | 742 void UpdateExtension(const std::string& id, const FilePath& in_path, |
721 UpdateState expected_state) { | 743 UpdateState expected_state) { |
722 ASSERT_TRUE(file_util::PathExists(in_path)); | 744 ASSERT_TRUE(file_util::PathExists(in_path)); |
723 | 745 |
724 // We need to copy this to a temporary location because Update() will delete | 746 // We need to copy this to a temporary location because Update() will delete |
725 // it. | 747 // it. |
726 FilePath path = temp_dir_.path(); | 748 FilePath path = temp_dir_.path(); |
727 path = path.Append(in_path.BaseName()); | 749 path = path.Append(in_path.BaseName()); |
728 ASSERT_TRUE(file_util::CopyFile(in_path, path)); | 750 ASSERT_TRUE(file_util::CopyFile(in_path, path)); |
729 | 751 |
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 ASSERT_EQ(good_crx, good->id()); | 2411 ASSERT_EQ(good_crx, good->id()); |
2390 | 2412 |
2391 // Disable it and allow it to run in incognito. These settings should carry | 2413 // Disable it and allow it to run in incognito. These settings should carry |
2392 // over to the updated version. | 2414 // over to the updated version. |
2393 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); | 2415 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); |
2394 service_->SetIsIncognitoEnabled(good->id(), true); | 2416 service_->SetIsIncognitoEnabled(good->id(), true); |
2395 service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); | 2417 service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); |
2396 | 2418 |
2397 path = data_dir_.AppendASCII("good2.crx"); | 2419 path = data_dir_.AppendASCII("good2.crx"); |
2398 UpdateExtension(good_crx, path, INSTALLED); | 2420 UpdateExtension(good_crx, path, INSTALLED); |
2399 ASSERT_EQ(1u, service_->disabled_extensions()->size()); | 2421 ASSERT_EQ(1u, service_->disabled_extensions()->size());\ |
2400 const Extension* good2 = service_->GetExtensionById(good_crx, true); | 2422 const Extension* good2 = service_->GetExtensionById(good_crx, true); |
2401 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2423 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
2402 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); | 2424 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); |
2403 EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( | 2425 EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( |
2404 good2->id())); | 2426 good2->id())); |
2405 } | 2427 } |
2406 | 2428 |
2407 // Tests that updating preserves extension location. | 2429 // Tests that updating preserves extension location. |
2408 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { | 2430 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
2409 InitializeEmptyExtensionService(); | 2431 InitializeEmptyExtensionService(); |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3425 UninstallExtension(good_crx, true); | 3447 UninstallExtension(good_crx, true); |
3426 } | 3448 } |
3427 | 3449 |
3428 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { | 3450 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
3429 InitializeEmptyExtensionService(); | 3451 InitializeEmptyExtensionService(); |
3430 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3452 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
3431 TerminateExtension(good_crx); | 3453 TerminateExtension(good_crx); |
3432 UninstallExtension(good_crx, true); | 3454 UninstallExtension(good_crx, true); |
3433 } | 3455 } |
3434 | 3456 |
| 3457 // An extension disabled because of unsupported requirements should re-enabled |
| 3458 // if updated to a version with supported requirements as long as there are no |
| 3459 // other disable reasons. |
| 3460 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
| 3461 InitializeEmptyExtensionService(); |
| 3462 BlackListWebGL(); |
| 3463 |
| 3464 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3465 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3466 .AppendASCII("v1_good.pem"); |
| 3467 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3468 pem_path, |
| 3469 INSTALL_NEW); |
| 3470 std::string id = extension_v1->id(); |
| 3471 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3472 |
| 3473 PackCRX(path.AppendASCII("v2_bad_requirements"), pem_path, |
| 3474 path.AppendASCII("v2_bad_requirements.crx")); |
| 3475 UpdateExtension(id, path.AppendASCII("v2_bad_requirements.crx"), INSTALLED); |
| 3476 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3477 |
| 3478 PackCRX(path.AppendASCII("v3_good"), pem_path, |
| 3479 path.AppendASCII("v3_good.crx")); |
| 3480 UpdateExtension(id, path.AppendASCII("v3_good.crx"), ENABLED); |
| 3481 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3482 } |
| 3483 |
| 3484 // Extensions disabled through user action should stay disabled. |
| 3485 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
| 3486 InitializeEmptyExtensionService(); |
| 3487 BlackListWebGL(); |
| 3488 |
| 3489 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3490 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3491 .AppendASCII("v1_good.pem"); |
| 3492 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3493 pem_path, |
| 3494 INSTALL_NEW); |
| 3495 std::string id = extension_v1->id(); |
| 3496 service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 3497 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3498 |
| 3499 PackCRX(path.AppendASCII("v2_bad_requirements"), pem_path, |
| 3500 path.AppendASCII("v2_bad_requirements.crx")); |
| 3501 UpdateExtension(id, path.AppendASCII("v2_bad_requirements.crx"), INSTALLED); |
| 3502 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3503 |
| 3504 PackCRX(path.AppendASCII("v3_good"), pem_path, |
| 3505 path.AppendASCII("v3_good.crx")); |
| 3506 UpdateExtension(id, path.AppendASCII("v3_good.crx"), INSTALLED); |
| 3507 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3508 } |
| 3509 |
| 3510 // The extension should not re-enabled because it was disabled from a |
| 3511 // permission increase. |
| 3512 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
| 3513 InitializeEmptyExtensionService(); |
| 3514 BlackListWebGL(); |
| 3515 |
| 3516 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3517 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3518 .AppendASCII("v1_good.pem"); |
| 3519 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3520 pem_path, |
| 3521 INSTALL_NEW); |
| 3522 std::string id = extension_v1->id(); |
| 3523 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3524 |
| 3525 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), pem_path, |
| 3526 path.AppendASCII("v2_bad_requirements_and_permissions.crx")); |
| 3527 UpdateExtension( |
| 3528 id, |
| 3529 path.AppendASCII("v2_bad_requirements_and_permissions.crx"), INSTALLED); |
| 3530 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3531 |
| 3532 PackCRX(path.AppendASCII("v3_bad_permissions"), pem_path, |
| 3533 path.AppendASCII("v3_bad_permissions.crx")); |
| 3534 UpdateExtension(id, path.AppendASCII("v3_bad_permissions.crx"), INSTALLED); |
| 3535 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3536 } |
| 3537 |
| 3538 // Unpacked extensions are not allowed to be installed if they have unsupported |
| 3539 // requirements. |
| 3540 TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
| 3541 InitializeEmptyExtensionService(); |
| 3542 BlackListWebGL(); |
| 3543 |
| 3544 FilePath path = data_dir_.AppendASCII("requirements") |
| 3545 .AppendASCII("v2_bad_requirements"); |
| 3546 extensions::UnpackedInstaller::Create(service_)->Load(path); |
| 3547 loop_.RunAllPending(); |
| 3548 EXPECT_EQ(1u, GetErrors().size()); |
| 3549 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3550 } |
| 3551 |
3435 class ExtensionCookieCallback { | 3552 class ExtensionCookieCallback { |
3436 public: | 3553 public: |
3437 ExtensionCookieCallback() | 3554 ExtensionCookieCallback() |
3438 : result_(false), | 3555 : result_(false), |
3439 weak_factory_(MessageLoop::current()) {} | 3556 weak_factory_(MessageLoop::current()) {} |
3440 | 3557 |
3441 void SetCookieCallback(bool result) { | 3558 void SetCookieCallback(bool result) { |
3442 MessageLoop::current()->PostTask( | 3559 MessageLoop::current()->PostTask( |
3443 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3560 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
3444 result_ = result; | 3561 result_ = result; |
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5418 // This should NOT trigger an alert. | 5535 // This should NOT trigger an alert. |
5419 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5536 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
5420 data_dir_.AppendASCII("hosted_app.crx")); | 5537 data_dir_.AppendASCII("hosted_app.crx")); |
5421 | 5538 |
5422 service_->CheckForExternalUpdates(); | 5539 service_->CheckForExternalUpdates(); |
5423 loop_.RunAllPending(); | 5540 loop_.RunAllPending(); |
5424 | 5541 |
5425 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5542 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); |
5426 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5543 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); |
5427 } | 5544 } |
OLD | NEW |