Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Side by Side Diff: chrome/browser/extensions/extension_service_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698