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" |
52 #include "chrome/browser/plugin_prefs_factory.h" | 54 #include "chrome/browser/plugin_prefs_factory.h" |
53 #include "chrome/browser/prefs/browser_prefs.h" | 55 #include "chrome/browser/prefs/browser_prefs.h" |
54 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 56 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
55 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 57 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
56 #include "chrome/browser/themes/theme_service_factory.h" | 58 #include "chrome/browser/themes/theme_service_factory.h" |
57 #include "chrome/common/chrome_constants.h" | 59 #include "chrome/common/chrome_constants.h" |
58 #include "chrome/common/chrome_notification_types.h" | 60 #include "chrome/common/chrome_notification_types.h" |
59 #include "chrome/common/chrome_paths.h" | 61 #include "chrome/common/chrome_paths.h" |
60 #include "chrome/common/chrome_switches.h" | 62 #include "chrome/common/chrome_switches.h" |
61 #include "chrome/common/extensions/extension.h" | 63 #include "chrome/common/extensions/extension.h" |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 } | 701 } |
700 | 702 |
701 enum UpdateState { | 703 enum UpdateState { |
702 FAILED_SILENTLY, | 704 FAILED_SILENTLY, |
703 FAILED, | 705 FAILED, |
704 UPDATED, | 706 UPDATED, |
705 INSTALLED, | 707 INSTALLED, |
706 ENABLED | 708 ENABLED |
707 }; | 709 }; |
708 | 710 |
| 711 void BlackListWebGL() { |
| 712 static const std::string json_blacklist = |
| 713 "{\n" |
| 714 " \"name\": \"gpu blacklist\",\n" |
| 715 " \"version\": \"1.0\",\n" |
| 716 " \"entries\": [\n" |
| 717 " {\n" |
| 718 " \"id\": 1,\n" |
| 719 " \"blacklist\": [\"webgl\"]\n" |
| 720 " }\n" |
| 721 " ]\n" |
| 722 "}"; |
| 723 GpuBlacklist* blacklist = GpuBlacklist::GetInstance(); |
| 724 ASSERT_TRUE(blacklist); |
| 725 ASSERT_TRUE(blacklist->LoadGpuBlacklist(json_blacklist, |
| 726 GpuBlacklist::kAllOs)); |
| 727 blacklist->UpdateGpuDataManager(); |
| 728 } |
| 729 |
709 void UpdateExtension(const std::string& id, const FilePath& in_path, | 730 void UpdateExtension(const std::string& id, const FilePath& in_path, |
710 UpdateState expected_state) { | 731 UpdateState expected_state) { |
711 ASSERT_TRUE(file_util::PathExists(in_path)); | 732 ASSERT_TRUE(file_util::PathExists(in_path)); |
712 | 733 |
713 // We need to copy this to a temporary location because Update() will delete | 734 // We need to copy this to a temporary location because Update() will delete |
714 // it. | 735 // it. |
715 FilePath path = temp_dir_.path(); | 736 FilePath path = temp_dir_.path(); |
716 path = path.Append(in_path.BaseName()); | 737 path = path.Append(in_path.BaseName()); |
717 ASSERT_TRUE(file_util::CopyFile(in_path, path)); | 738 ASSERT_TRUE(file_util::CopyFile(in_path, path)); |
718 | 739 |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2325 ASSERT_EQ(good_crx, good->id()); | 2346 ASSERT_EQ(good_crx, good->id()); |
2326 | 2347 |
2327 // Disable it and allow it to run in incognito. These settings should carry | 2348 // Disable it and allow it to run in incognito. These settings should carry |
2328 // over to the updated version. | 2349 // over to the updated version. |
2329 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); | 2350 service_->DisableExtension(good->id(), Extension::DISABLE_USER_ACTION); |
2330 service_->SetIsIncognitoEnabled(good->id(), true); | 2351 service_->SetIsIncognitoEnabled(good->id(), true); |
2331 service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); | 2352 service_->extension_prefs()->SetDidExtensionEscalatePermissions(good, true); |
2332 | 2353 |
2333 path = data_dir_.AppendASCII("good2.crx"); | 2354 path = data_dir_.AppendASCII("good2.crx"); |
2334 UpdateExtension(good_crx, path, INSTALLED); | 2355 UpdateExtension(good_crx, path, INSTALLED); |
2335 ASSERT_EQ(1u, service_->disabled_extensions()->size()); | 2356 ASSERT_EQ(1u, service_->disabled_extensions()->size());\ |
2336 const Extension* good2 = service_->GetExtensionById(good_crx, true); | 2357 const Extension* good2 = service_->GetExtensionById(good_crx, true); |
2337 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); | 2358 ASSERT_EQ("1.0.0.1", good2->version()->GetString()); |
2338 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); | 2359 EXPECT_TRUE(service_->IsIncognitoEnabled(good2->id())); |
2339 EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( | 2360 EXPECT_TRUE(service_->extension_prefs()->DidExtensionEscalatePermissions( |
2340 good2->id())); | 2361 good2->id())); |
2341 } | 2362 } |
2342 | 2363 |
2343 // Tests that updating preserves extension location. | 2364 // Tests that updating preserves extension location. |
2344 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { | 2365 TEST_F(ExtensionServiceTest, UpdateExtensionPreservesLocation) { |
2345 InitializeEmptyExtensionService(); | 2366 InitializeEmptyExtensionService(); |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3361 UninstallExtension(good_crx, true); | 3382 UninstallExtension(good_crx, true); |
3362 } | 3383 } |
3363 | 3384 |
3364 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { | 3385 TEST_F(ExtensionServiceTest, UninstallExtensionHelperTerminated) { |
3365 InitializeEmptyExtensionService(); | 3386 InitializeEmptyExtensionService(); |
3366 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); | 3387 InstallCRX(data_dir_.AppendASCII("good.crx"), INSTALL_NEW); |
3367 TerminateExtension(good_crx); | 3388 TerminateExtension(good_crx); |
3368 UninstallExtension(good_crx, true); | 3389 UninstallExtension(good_crx, true); |
3369 } | 3390 } |
3370 | 3391 |
| 3392 // An extension disabled because of unsupported requirements should re-enabled |
| 3393 // if updated to a version with supported requirements as long as there are no |
| 3394 // other disable reasons. |
| 3395 TEST_F(ExtensionServiceTest, UpgradingRequirementsEnabled) { |
| 3396 InitializeEmptyExtensionService(); |
| 3397 BlackListWebGL(); |
| 3398 |
| 3399 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3400 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3401 .AppendASCII("v1_good.pem"); |
| 3402 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3403 pem_path, |
| 3404 INSTALL_NEW); |
| 3405 std::string id = extension_v1->id(); |
| 3406 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3407 |
| 3408 PackCRX(path.AppendASCII("v2_bad_requirements"), pem_path, |
| 3409 path.AppendASCII("v2_bad_requirements.crx")); |
| 3410 UpdateExtension(id, path.AppendASCII("v2_bad_requirements.crx"), INSTALLED); |
| 3411 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3412 |
| 3413 PackCRX(path.AppendASCII("v3_good"), pem_path, |
| 3414 path.AppendASCII("v3_good.crx")); |
| 3415 UpdateExtension(id, path.AppendASCII("v3_good.crx"), ENABLED); |
| 3416 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3417 } |
| 3418 |
| 3419 // Extensions disabled through user action should stay disabled. |
| 3420 TEST_F(ExtensionServiceTest, UpgradingRequirementsDisabled) { |
| 3421 InitializeEmptyExtensionService(); |
| 3422 BlackListWebGL(); |
| 3423 |
| 3424 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3425 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3426 .AppendASCII("v1_good.pem"); |
| 3427 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3428 pem_path, |
| 3429 INSTALL_NEW); |
| 3430 std::string id = extension_v1->id(); |
| 3431 service_->DisableExtension(id, Extension::DISABLE_USER_ACTION); |
| 3432 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3433 |
| 3434 PackCRX(path.AppendASCII("v2_bad_requirements"), pem_path, |
| 3435 path.AppendASCII("v2_bad_requirements.crx")); |
| 3436 UpdateExtension(id, path.AppendASCII("v2_bad_requirements.crx"), INSTALLED); |
| 3437 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3438 |
| 3439 PackCRX(path.AppendASCII("v3_good"), pem_path, |
| 3440 path.AppendASCII("v3_good.crx")); |
| 3441 UpdateExtension(id, path.AppendASCII("v3_good.crx"), INSTALLED); |
| 3442 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3443 } |
| 3444 |
| 3445 // The extension should not re-enabled because it was disabled from a |
| 3446 // permission increase. |
| 3447 TEST_F(ExtensionServiceTest, UpgradingRequirementsPermissions) { |
| 3448 InitializeEmptyExtensionService(); |
| 3449 BlackListWebGL(); |
| 3450 |
| 3451 FilePath path = data_dir_.AppendASCII("requirements"); |
| 3452 FilePath pem_path = data_dir_.AppendASCII("requirements") |
| 3453 .AppendASCII("v1_good.pem"); |
| 3454 const Extension* extension_v1 = PackAndInstallCRX(path.AppendASCII("v1_good"), |
| 3455 pem_path, |
| 3456 INSTALL_NEW); |
| 3457 std::string id = extension_v1->id(); |
| 3458 EXPECT_TRUE(service_->IsExtensionEnabled(id)); |
| 3459 |
| 3460 PackCRX(path.AppendASCII("v2_bad_requirements_and_permissions"), pem_path, |
| 3461 path.AppendASCII("v2_bad_requirements_and_permissions.crx")); |
| 3462 UpdateExtension( |
| 3463 id, |
| 3464 path.AppendASCII("v2_bad_requirements_and_permissions.crx"), INSTALLED); |
| 3465 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3466 |
| 3467 PackCRX(path.AppendASCII("v3_bad_permissions"), pem_path, |
| 3468 path.AppendASCII("v3_bad_permissions.crx")); |
| 3469 UpdateExtension(id, path.AppendASCII("v3_bad_permissions.crx"), INSTALLED); |
| 3470 EXPECT_FALSE(service_->IsExtensionEnabled(id)); |
| 3471 } |
| 3472 |
| 3473 // Unpacked extensions are not allowed to be installed if they have unsupported |
| 3474 // requirements. |
| 3475 TEST_F(ExtensionServiceTest, UnpackedRequirements) { |
| 3476 InitializeEmptyExtensionService(); |
| 3477 BlackListWebGL(); |
| 3478 |
| 3479 FilePath path = data_dir_.AppendASCII("requirements") |
| 3480 .AppendASCII("v2_bad_requirements"); |
| 3481 extensions::UnpackedInstaller::Create(service_)->Load(path); |
| 3482 loop_.RunAllPending(); |
| 3483 EXPECT_EQ(1u, GetErrors().size()); |
| 3484 EXPECT_EQ(0u, service_->extensions()->size()); |
| 3485 } |
| 3486 |
3371 class ExtensionCookieCallback { | 3487 class ExtensionCookieCallback { |
3372 public: | 3488 public: |
3373 ExtensionCookieCallback() | 3489 ExtensionCookieCallback() |
3374 : result_(false), | 3490 : result_(false), |
3375 weak_factory_(MessageLoop::current()) {} | 3491 weak_factory_(MessageLoop::current()) {} |
3376 | 3492 |
3377 void SetCookieCallback(bool result) { | 3493 void SetCookieCallback(bool result) { |
3378 MessageLoop::current()->PostTask( | 3494 MessageLoop::current()->PostTask( |
3379 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); | 3495 FROM_HERE, base::Bind(&MessageLoop::Quit, weak_factory_.GetWeakPtr())); |
3380 result_ = result; | 3496 result_ = result; |
(...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5352 // This should NOT trigger an alert. | 5468 // This should NOT trigger an alert. |
5353 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", | 5469 provider->UpdateOrAddExtension(hosted_app, "1.0.0.0", |
5354 data_dir_.AppendASCII("hosted_app.crx")); | 5470 data_dir_.AppendASCII("hosted_app.crx")); |
5355 | 5471 |
5356 service_->CheckForExternalUpdates(); | 5472 service_->CheckForExternalUpdates(); |
5357 loop_.RunAllPending(); | 5473 loop_.RunAllPending(); |
5358 | 5474 |
5359 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); | 5475 ASSERT_TRUE(service_->PopulateExtensionErrorUI(extension_error_ui.get())); |
5360 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); | 5476 ASSERT_EQ(1u, extension_error_ui->get_external_extension_ids()->size()); |
5361 } | 5477 } |
OLD | NEW |