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 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/extensions/extension_updater.h" | 33 #include "chrome/browser/extensions/extension_updater.h" |
34 #include "chrome/browser/extensions/external_extension_provider_impl.h" | 34 #include "chrome/browser/extensions/external_extension_provider_impl.h" |
35 #include "chrome/browser/extensions/external_extension_provider_interface.h" | 35 #include "chrome/browser/extensions/external_extension_provider_interface.h" |
36 #include "chrome/browser/extensions/external_pref_extension_loader.h" | 36 #include "chrome/browser/extensions/external_pref_extension_loader.h" |
37 #include "chrome/browser/extensions/pack_extension_job.cc" | 37 #include "chrome/browser/extensions/pack_extension_job.cc" |
38 #include "chrome/browser/extensions/pending_extension_info.h" | 38 #include "chrome/browser/extensions/pending_extension_info.h" |
39 #include "chrome/browser/extensions/pending_extension_manager.h" | 39 #include "chrome/browser/extensions/pending_extension_manager.h" |
40 #include "chrome/browser/prefs/browser_prefs.h" | 40 #include "chrome/browser/prefs/browser_prefs.h" |
41 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 41 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
42 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 42 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
43 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | |
44 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
45 #include "chrome/common/chrome_paths.h" | 44 #include "chrome/common/chrome_paths.h" |
46 #include "chrome/common/chrome_switches.h" | 45 #include "chrome/common/chrome_switches.h" |
47 #include "chrome/common/extensions/extension.h" | 46 #include "chrome/common/extensions/extension.h" |
48 #include "chrome/common/extensions/extension_constants.h" | 47 #include "chrome/common/extensions/extension_constants.h" |
49 #include "chrome/common/extensions/extension_resource.h" | 48 #include "chrome/common/extensions/extension_resource.h" |
50 #include "chrome/common/extensions/url_pattern.h" | 49 #include "chrome/common/extensions/url_pattern.h" |
51 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
52 #include "chrome/common/url_constants.h" | 51 #include "chrome/common/url_constants.h" |
53 #include "chrome/test/base/testing_profile.h" | 52 #include "chrome/test/base/testing_profile.h" |
(...skipping 3386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3440 | 3439 |
3441 // Reload all extensions, and make sure it comes back. | 3440 // Reload all extensions, and make sure it comes back. |
3442 std::string extension_id = service_->extensions()->at(0)->id(); | 3441 std::string extension_id = service_->extensions()->at(0)->id(); |
3443 loaded_.clear(); | 3442 loaded_.clear(); |
3444 service_->ReloadExtensions(); | 3443 service_->ReloadExtensions(); |
3445 ASSERT_EQ(1u, service_->extensions()->size()); | 3444 ASSERT_EQ(1u, service_->extensions()->size()); |
3446 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); | 3445 EXPECT_EQ(extension_id, service_->extensions()->at(0)->id()); |
3447 } | 3446 } |
3448 | 3447 |
3449 namespace { | 3448 namespace { |
3450 class TestSyncProcessorStub : public SyncChangeProcessor { | 3449 |
3451 virtual SyncError ProcessSyncChanges( | 3450 bool AllExtensions(const Extension& extension) { |
3452 const tracked_objects::Location& from_here, | 3451 return true; |
3453 const SyncChangeList& change_list) OVERRIDE { | |
3454 return SyncError(); | |
3455 } | |
3456 }; | |
3457 } | 3452 } |
3458 | 3453 |
| 3454 bool NoExtensions(const Extension& extension) { |
| 3455 return false; |
| 3456 } |
| 3457 |
| 3458 bool ExtensionsOnly(const Extension& extension) { |
| 3459 return extension.GetType() == Extension::TYPE_EXTENSION; |
| 3460 } |
| 3461 |
| 3462 bool ThemesOnly(const Extension& extension) { |
| 3463 return extension.is_theme(); |
| 3464 } |
| 3465 |
| 3466 bool GoodOnly(const Extension& extension) { |
| 3467 return extension.id() == good_crx; |
| 3468 } |
| 3469 |
| 3470 } // namespace |
| 3471 |
3459 TEST_F(ExtensionServiceTest, GetSyncData) { | 3472 TEST_F(ExtensionServiceTest, GetSyncData) { |
3460 InitializeEmptyExtensionService(); | 3473 InitializeEmptyExtensionService(); |
3461 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3474 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3462 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3475 const Extension* extension = service_->GetInstalledExtension(good_crx); |
3463 ASSERT_TRUE(extension); | 3476 ASSERT_TRUE(extension); |
3464 | 3477 |
3465 TestSyncProcessorStub processor; | 3478 ExtensionSyncData data; |
3466 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | 3479 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3467 &processor); | 3480 EXPECT_EQ(extension->id(), data.id); |
3468 | 3481 EXPECT_FALSE(data.uninstalled); |
3469 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3482 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled); |
3470 ASSERT_EQ(list.size(), 1U); | 3483 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled); |
3471 ExtensionSyncData data(list[0]); | 3484 EXPECT_TRUE(data.version.Equals(*extension->version())); |
3472 EXPECT_EQ(extension->id(), data.id()); | 3485 EXPECT_EQ(extension->update_url(), data.update_url); |
3473 EXPECT_FALSE(data.uninstalled()); | 3486 EXPECT_EQ(extension->name(), data.name); |
3474 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); | |
3475 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); | |
3476 EXPECT_TRUE(data.version().Equals(*extension->version())); | |
3477 EXPECT_EQ(extension->update_url(), data.update_url()); | |
3478 EXPECT_EQ(extension->name(), data.name()); | |
3479 } | 3487 } |
3480 | 3488 |
3481 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { | 3489 TEST_F(ExtensionServiceTest, GetSyncDataTerminated) { |
3482 InitializeEmptyExtensionService(); | 3490 InitializeEmptyExtensionService(); |
3483 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3491 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3484 TerminateExtension(good_crx); | 3492 TerminateExtension(good_crx); |
3485 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3493 const Extension* extension = service_->GetInstalledExtension(good_crx); |
3486 ASSERT_TRUE(extension); | 3494 ASSERT_TRUE(extension); |
3487 | 3495 ExtensionSyncData data; |
3488 TestSyncProcessorStub processor; | 3496 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3489 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3490 &processor); | |
3491 | |
3492 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | |
3493 ASSERT_EQ(list.size(), 1U); | |
3494 ExtensionSyncData data(list[0]); | |
3495 EXPECT_EQ(extension->id(), data.id()); | |
3496 EXPECT_FALSE(data.uninstalled()); | |
3497 EXPECT_EQ(service_->IsExtensionEnabled(good_crx), data.enabled()); | |
3498 EXPECT_EQ(service_->IsIncognitoEnabled(good_crx), data.incognito_enabled()); | |
3499 EXPECT_TRUE(data.version().Equals(*extension->version())); | |
3500 EXPECT_EQ(extension->update_url(), data.update_url()); | |
3501 EXPECT_EQ(extension->name(), data.name()); | |
3502 } | 3497 } |
3503 | 3498 |
3504 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { | 3499 TEST_F(ExtensionServiceTest, GetSyncDataFilter) { |
3505 InitializeEmptyExtensionService(); | 3500 InitializeEmptyExtensionService(); |
3506 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3501 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3507 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3502 const Extension* extension = service_->GetInstalledExtension(good_crx); |
3508 ASSERT_TRUE(extension); | 3503 ASSERT_TRUE(extension); |
3509 | 3504 ExtensionSyncData data; |
3510 TestSyncProcessorStub processor; | 3505 EXPECT_FALSE(service_->GetSyncData(*extension, &ThemesOnly, &data)); |
3511 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), | |
3512 &processor); | |
3513 | |
3514 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | |
3515 ASSERT_EQ(list.size(), 0U); | |
3516 } | 3506 } |
3517 | 3507 |
3518 TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { | 3508 TEST_F(ExtensionServiceTest, GetSyncDataUserSettings) { |
3519 InitializeEmptyExtensionService(); | 3509 InitializeEmptyExtensionService(); |
3520 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3510 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3521 const Extension* extension = service_->GetInstalledExtension(good_crx); | 3511 const Extension* extension = service_->GetInstalledExtension(good_crx); |
3522 ASSERT_TRUE(extension); | 3512 ASSERT_TRUE(extension); |
3523 | 3513 |
3524 TestSyncProcessorStub processor; | |
3525 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3526 &processor); | |
3527 | |
3528 { | 3514 { |
3529 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3515 ExtensionSyncData data; |
3530 ASSERT_EQ(list.size(), 1U); | 3516 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3531 ExtensionSyncData data(list[0]); | 3517 EXPECT_TRUE(data.enabled); |
3532 EXPECT_TRUE(data.enabled()); | 3518 EXPECT_FALSE(data.incognito_enabled); |
3533 EXPECT_FALSE(data.incognito_enabled()); | |
3534 } | 3519 } |
3535 | 3520 |
3536 service_->DisableExtension(good_crx); | 3521 service_->DisableExtension(good_crx); |
3537 { | 3522 { |
3538 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3523 ExtensionSyncData data; |
3539 ASSERT_EQ(list.size(), 1U); | 3524 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3540 ExtensionSyncData data(list[0]); | 3525 EXPECT_FALSE(data.enabled); |
3541 EXPECT_FALSE(data.enabled()); | 3526 EXPECT_FALSE(data.incognito_enabled); |
3542 EXPECT_FALSE(data.incognito_enabled()); | |
3543 } | 3527 } |
3544 | 3528 |
3545 service_->SetIsIncognitoEnabled(good_crx, true); | 3529 service_->SetIsIncognitoEnabled(good_crx, true); |
3546 { | 3530 { |
3547 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3531 ExtensionSyncData data; |
3548 ASSERT_EQ(list.size(), 1U); | 3532 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3549 ExtensionSyncData data(list[0]); | 3533 EXPECT_FALSE(data.enabled); |
3550 EXPECT_FALSE(data.enabled()); | 3534 EXPECT_TRUE(data.incognito_enabled); |
3551 EXPECT_TRUE(data.incognito_enabled()); | |
3552 } | 3535 } |
3553 | 3536 |
3554 service_->EnableExtension(good_crx); | 3537 service_->EnableExtension(good_crx); |
3555 { | 3538 { |
3556 SyncDataList list = service_->GetAllSyncData(syncable::EXTENSIONS); | 3539 ExtensionSyncData data; |
3557 ASSERT_EQ(list.size(), 1U); | 3540 EXPECT_TRUE(service_->GetSyncData(*extension, &AllExtensions, &data)); |
3558 ExtensionSyncData data(list[0]); | 3541 EXPECT_TRUE(data.enabled); |
3559 EXPECT_TRUE(data.enabled()); | 3542 EXPECT_TRUE(data.incognito_enabled); |
3560 EXPECT_TRUE(data.incognito_enabled()); | |
3561 } | 3543 } |
3562 } | 3544 } |
3563 | 3545 |
3564 TEST_F(ExtensionServiceTest, GetSyncDataList) { | 3546 TEST_F(ExtensionServiceTest, GetSyncDataList) { |
3565 InitializeEmptyExtensionService(); | 3547 InitializeEmptyExtensionService(); |
3566 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3548 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3567 InstallCrx(data_dir_.AppendASCII("page_action.crx"), true); | 3549 InstallCrx(data_dir_.AppendASCII("page_action.crx"), true); |
3568 InstallCrx(data_dir_.AppendASCII("theme.crx"), true); | 3550 InstallCrx(data_dir_.AppendASCII("theme.crx"), true); |
3569 InstallCrx(data_dir_.AppendASCII("theme2.crx"), true); | 3551 InstallCrx(data_dir_.AppendASCII("theme2.crx"), true); |
3570 | 3552 |
3571 TestSyncProcessorStub processor; | |
3572 service_->MergeDataAndStartSyncing(syncable::APPS, SyncDataList(), | |
3573 &processor); | |
3574 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3575 &processor); | |
3576 | |
3577 service_->DisableExtension(page_action); | 3553 service_->DisableExtension(page_action); |
3578 TerminateExtension(theme2_crx); | 3554 TerminateExtension(theme2_crx); |
3579 | 3555 |
3580 EXPECT_EQ(0u, service_->GetAllSyncData(syncable::APPS).size()); | 3556 EXPECT_EQ(4u, service_->GetSyncDataList(&AllExtensions).size()); |
3581 EXPECT_EQ(2u, service_->GetAllSyncData(syncable::EXTENSIONS).size()); | 3557 EXPECT_EQ(0u, service_->GetSyncDataList(&NoExtensions).size()); |
| 3558 EXPECT_EQ(2u, service_->GetSyncDataList(&ExtensionsOnly).size()); |
| 3559 EXPECT_EQ(2u, service_->GetSyncDataList(&ThemesOnly).size()); |
| 3560 EXPECT_EQ(1u, service_->GetSyncDataList(&GoodOnly).size()); |
3582 } | 3561 } |
3583 | 3562 |
3584 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { | 3563 TEST_F(ExtensionServiceTest, ProcessSyncDataUninstall) { |
3585 InitializeEmptyExtensionService(); | 3564 InitializeEmptyExtensionService(); |
3586 TestSyncProcessorStub processor; | |
3587 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3588 &processor); | |
3589 | 3565 |
3590 sync_pb::EntitySpecifics specifics; | 3566 ExtensionSyncData extension_sync_data; |
3591 sync_pb::ExtensionSpecifics* ext_specifics = | 3567 extension_sync_data.id = good_crx; |
3592 specifics.MutableExtension(sync_pb::extension); | 3568 extension_sync_data.uninstalled = true; |
3593 ext_specifics->set_id(good_crx); | |
3594 ext_specifics->set_version("1.0"); | |
3595 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | |
3596 SyncChange sync_change(SyncChange::ACTION_DELETE, sync_data); | |
3597 SyncChangeList list(1); | |
3598 list[0] = sync_change; | |
3599 | 3569 |
3600 // Should do nothing. | 3570 // Should do nothing. |
3601 service_->ProcessSyncChanges(FROM_HERE, list); | 3571 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3602 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | |
3603 | 3572 |
3604 // Install the extension. | 3573 // Install the extension. |
3605 FilePath extension_path = data_dir_.AppendASCII("good.crx"); | 3574 FilePath extension_path = data_dir_.AppendASCII("good.crx"); |
3606 InstallCrx(extension_path, true); | 3575 InstallCrx(extension_path, true); |
3607 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); | 3576 EXPECT_TRUE(service_->GetExtensionById(good_crx, true)); |
3608 | 3577 |
3609 // Should uninstall the extension. | 3578 // Should uninstall the extension. |
3610 service_->ProcessSyncChanges(FROM_HERE, list); | 3579 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3611 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | 3580 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); |
3612 | 3581 |
3613 // Should again do nothing. | 3582 // Should again do nothing. |
3614 service_->ProcessSyncChanges(FROM_HERE, list); | 3583 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3615 EXPECT_FALSE(service_->GetExtensionById(good_crx, true)); | |
3616 } | 3584 } |
3617 | 3585 |
| 3586 |
3618 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { | 3587 TEST_F(ExtensionServiceTest, ProcessSyncDataSettings) { |
3619 InitializeEmptyExtensionService(); | 3588 InitializeEmptyExtensionService(); |
3620 TestSyncProcessorStub processor; | |
3621 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3622 &processor); | |
3623 | 3589 |
3624 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3590 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3625 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 3591 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
3626 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 3592 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
3627 | 3593 |
3628 sync_pb::EntitySpecifics specifics; | 3594 ExtensionSyncData extension_sync_data; |
3629 sync_pb::ExtensionSpecifics* ext_specifics = | 3595 extension_sync_data.id = good_crx; |
3630 specifics.MutableExtension(sync_pb::extension); | 3596 extension_sync_data.version = |
3631 ext_specifics->set_id(good_crx); | 3597 *(service_->GetInstalledExtension(good_crx)->version()); |
3632 ext_specifics->set_version( | |
3633 service_->GetInstalledExtension(good_crx)->version()->GetString()); | |
3634 ext_specifics->set_enabled(false); | |
3635 | 3598 |
3636 { | 3599 extension_sync_data.enabled = false; |
3637 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3600 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3638 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 3601 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
3639 SyncChangeList list(1); | 3602 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
3640 list[0] = sync_change; | |
3641 service_->ProcessSyncChanges(FROM_HERE, list); | |
3642 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | |
3643 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | |
3644 } | |
3645 | 3603 |
3646 { | 3604 extension_sync_data.enabled = true; |
3647 ext_specifics->set_enabled(true); | 3605 extension_sync_data.incognito_enabled = true; |
3648 ext_specifics->set_incognito_enabled(true); | 3606 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3649 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3607 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
3650 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 3608 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
3651 SyncChangeList list(1); | |
3652 list[0] = sync_change; | |
3653 service_->ProcessSyncChanges(FROM_HERE, list); | |
3654 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | |
3655 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | |
3656 } | |
3657 | 3609 |
3658 { | 3610 extension_sync_data.enabled = false; |
3659 ext_specifics->set_enabled(false); | 3611 extension_sync_data.incognito_enabled = true; |
3660 ext_specifics->set_incognito_enabled(true); | 3612 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3661 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3613 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
3662 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 3614 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
3663 SyncChangeList list(1); | |
3664 list[0] = sync_change; | |
3665 service_->ProcessSyncChanges(FROM_HERE, list); | |
3666 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | |
3667 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | |
3668 } | |
3669 | 3615 |
3670 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 3616 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
3671 } | 3617 } |
3672 | 3618 |
3673 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { | 3619 TEST_F(ExtensionServiceTest, ProcessSyncDataTerminatedExtension) { |
3674 InitializeExtensionServiceWithUpdater(); | 3620 InitializeExtensionServiceWithUpdater(); |
3675 TestSyncProcessorStub processor; | |
3676 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3677 &processor); | |
3678 | 3621 |
3679 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3622 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3680 TerminateExtension(good_crx); | 3623 TerminateExtension(good_crx); |
3681 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 3624 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
3682 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 3625 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
3683 | 3626 |
3684 sync_pb::EntitySpecifics specifics; | 3627 ExtensionSyncData extension_sync_data; |
3685 sync_pb::ExtensionSpecifics* ext_specifics = | 3628 extension_sync_data.id = good_crx; |
3686 specifics.MutableExtension(sync_pb::extension); | 3629 extension_sync_data.version = |
3687 ext_specifics->set_id(good_crx); | 3630 *(service_->GetInstalledExtension(good_crx)->version()); |
3688 ext_specifics->set_version( | 3631 extension_sync_data.enabled = false; |
3689 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 3632 extension_sync_data.incognito_enabled = true; |
3690 ext_specifics->set_enabled(false); | 3633 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3691 ext_specifics->set_incognito_enabled(true); | |
3692 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | |
3693 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | |
3694 SyncChangeList list(1); | |
3695 list[0] = sync_change; | |
3696 | |
3697 service_->ProcessSyncChanges(FROM_HERE, list); | |
3698 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 3634 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
3699 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 3635 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
3700 | 3636 |
3701 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 3637 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
3702 } | 3638 } |
3703 | 3639 |
3704 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { | 3640 TEST_F(ExtensionServiceTest, ProcessSyncDataVersionCheck) { |
3705 InitializeExtensionServiceWithUpdater(); | 3641 InitializeExtensionServiceWithUpdater(); |
3706 TestSyncProcessorStub processor; | |
3707 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3708 &processor); | |
3709 | 3642 |
3710 InstallCrx(data_dir_.AppendASCII("good.crx"), true); | 3643 InstallCrx(data_dir_.AppendASCII("good.crx"), true); |
3711 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 3644 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
3712 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 3645 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
3713 | 3646 |
3714 sync_pb::EntitySpecifics specifics; | 3647 ExtensionSyncData extension_sync_data; |
3715 sync_pb::ExtensionSpecifics* ext_specifics = | 3648 extension_sync_data.id = good_crx; |
3716 specifics.MutableExtension(sync_pb::extension); | 3649 extension_sync_data.enabled = true; |
3717 ext_specifics->set_id(good_crx); | 3650 extension_sync_data.version = |
3718 ext_specifics->set_enabled(true); | 3651 *(service_->GetInstalledExtension(good_crx)->version()); |
3719 | 3652 |
3720 { | 3653 // Should do nothing if extension version == sync version. |
3721 ext_specifics->set_version( | 3654 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3722 service_->GetInstalledExtension(good_crx)->version()->GetString()); | 3655 EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
3723 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | |
3724 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | |
3725 SyncChangeList list(1); | |
3726 list[0] = sync_change; | |
3727 | |
3728 // Should do nothing if extension version == sync version. | |
3729 service_->ProcessSyncChanges(FROM_HERE, list); | |
3730 EXPECT_FALSE(service_->updater()->WillCheckSoon()); | |
3731 } | |
3732 | 3656 |
3733 // Should do nothing if extension version > sync version (but see | 3657 // Should do nothing if extension version > sync version (but see |
3734 // the TODO in ProcessExtensionSyncData). | 3658 // the TODO in ProcessSyncData). |
3735 { | 3659 { |
3736 ext_specifics->set_version("0.0.0.0"); | 3660 scoped_ptr<Version> version(Version::GetVersionFromString("0.0.0.0")); |
3737 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3661 extension_sync_data.version = *version; |
3738 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 3662 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3739 SyncChangeList list(1); | |
3740 list[0] = sync_change; | |
3741 | |
3742 service_->ProcessSyncChanges(FROM_HERE, list); | |
3743 EXPECT_FALSE(service_->updater()->WillCheckSoon()); | 3663 EXPECT_FALSE(service_->updater()->WillCheckSoon()); |
3744 } | 3664 } |
3745 | 3665 |
3746 // Should kick off an update if extension version < sync version. | 3666 // Should kick off an update if extension version < sync version. |
3747 { | 3667 { |
3748 ext_specifics->set_version("9.9.9.9"); | 3668 scoped_ptr<Version> version(Version::GetVersionFromString("9.9.9.9")); |
3749 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3669 extension_sync_data.version = *version; |
3750 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | 3670 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3751 SyncChangeList list(1); | |
3752 list[0] = sync_change; | |
3753 | |
3754 service_->ProcessSyncChanges(FROM_HERE, list); | |
3755 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 3671 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
3756 } | 3672 } |
3757 | 3673 |
3758 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); | 3674 EXPECT_FALSE(service_->pending_extension_manager()->IsIdPending(good_crx)); |
3759 } | 3675 } |
3760 | 3676 |
3761 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { | 3677 TEST_F(ExtensionServiceTest, ProcessSyncDataNotInstalled) { |
3762 InitializeExtensionServiceWithUpdater(); | 3678 InitializeExtensionServiceWithUpdater(); |
3763 TestSyncProcessorStub processor; | |
3764 service_->MergeDataAndStartSyncing(syncable::EXTENSIONS, SyncDataList(), | |
3765 &processor); | |
3766 | 3679 |
3767 sync_pb::EntitySpecifics specifics; | 3680 ExtensionSyncData extension_sync_data; |
3768 sync_pb::ExtensionSpecifics* ext_specifics = | 3681 extension_sync_data.id = good_crx; |
3769 specifics.MutableExtension(sync_pb::extension); | 3682 extension_sync_data.update_url = GURL("http://www.google.com"); |
3770 ext_specifics->set_id(good_crx); | 3683 extension_sync_data.enabled = false; |
3771 ext_specifics->set_enabled(false); | 3684 extension_sync_data.incognito_enabled = true; |
3772 ext_specifics->set_incognito_enabled(true); | 3685 { |
3773 ext_specifics->set_update_url("http://www.google.com/"); | 3686 scoped_ptr<Version> version(Version::GetVersionFromString("1.2.3.4")); |
3774 ext_specifics->set_version("1.2.3.4"); | 3687 extension_sync_data.version = *version; |
3775 SyncData sync_data = SyncData::CreateLocalData(good_crx, "Name", specifics); | 3688 } |
3776 SyncChange sync_change(SyncChange::ACTION_UPDATE, sync_data); | |
3777 SyncChangeList list(1); | |
3778 list[0] = sync_change; | |
3779 | |
3780 | 3689 |
3781 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); | 3690 EXPECT_TRUE(service_->IsExtensionEnabled(good_crx)); |
3782 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); | 3691 EXPECT_FALSE(service_->IsIncognitoEnabled(good_crx)); |
3783 service_->ProcessSyncChanges(FROM_HERE, list); | 3692 service_->ProcessSyncData(extension_sync_data, &AllExtensions); |
3784 EXPECT_TRUE(service_->updater()->WillCheckSoon()); | 3693 EXPECT_TRUE(service_->updater()->WillCheckSoon()); |
3785 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); | 3694 EXPECT_FALSE(service_->IsExtensionEnabled(good_crx)); |
3786 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); | 3695 EXPECT_TRUE(service_->IsIncognitoEnabled(good_crx)); |
3787 | 3696 |
3788 PendingExtensionInfo info; | 3697 PendingExtensionInfo info; |
3789 EXPECT_TRUE( | 3698 EXPECT_TRUE( |
3790 service_->pending_extension_manager()->GetById(good_crx, &info)); | 3699 service_->pending_extension_manager()->GetById(good_crx, &info)); |
3791 EXPECT_EQ(ext_specifics->update_url(), info.update_url().spec()); | 3700 EXPECT_EQ(extension_sync_data.update_url, info.update_url()); |
3792 EXPECT_TRUE(info.is_from_sync()); | 3701 EXPECT_TRUE(info.is_from_sync()); |
3793 EXPECT_TRUE(info.install_silently()); | 3702 EXPECT_TRUE(info.install_silently()); |
3794 EXPECT_EQ(Extension::INTERNAL, info.install_source()); | 3703 EXPECT_EQ(Extension::INTERNAL, info.install_source()); |
3795 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. | 3704 // TODO(akalin): Figure out a way to test |info.ShouldAllowInstall()|. |
3796 } | 3705 } |
3797 | 3706 |
3798 TEST_F(ExtensionServiceTest, HigherPriorityInstall) { | 3707 TEST_F(ExtensionServiceTest, HigherPriorityInstall) { |
3799 InitializeEmptyExtensionService(); | 3708 InitializeEmptyExtensionService(); |
3800 | 3709 |
3801 FilePath path = data_dir_.AppendASCII("good.crx"); | 3710 FilePath path = data_dir_.AppendASCII("good.crx"); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3966 ASSERT_FALSE(AddPendingSyncInstall()); | 3875 ASSERT_FALSE(AddPendingSyncInstall()); |
3967 | 3876 |
3968 // Wait for the external source to install. | 3877 // Wait for the external source to install. |
3969 WaitForCrxInstall(crx_path_, true); | 3878 WaitForCrxInstall(crx_path_, true); |
3970 ASSERT_TRUE(IsCrxInstalled()); | 3879 ASSERT_TRUE(IsCrxInstalled()); |
3971 | 3880 |
3972 // Now that the extension is installed, sync request should fail | 3881 // Now that the extension is installed, sync request should fail |
3973 // because the extension is already installed. | 3882 // because the extension is already installed. |
3974 ASSERT_FALSE(AddPendingSyncInstall()); | 3883 ASSERT_FALSE(AddPendingSyncInstall()); |
3975 } | 3884 } |
OLD | NEW |