Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/metrics/field_trial.h" | 18 #include "base/metrics/field_trial.h" |
| 19 #include "base/test/mock_entropy_provider.h" | 19 #include "base/test/mock_entropy_provider.h" |
| 20 #include "base/test/scoped_feature_list.h" | 20 #include "base/test/scoped_feature_list.h" |
| 21 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" | 21 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h" |
| 22 #include "chrome/browser/extensions/chrome_test_extension_loader.h" | |
| 22 #include "chrome/browser/extensions/component_loader.h" | 23 #include "chrome/browser/extensions/component_loader.h" |
| 23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
| 24 #include "chrome/browser/extensions/extension_service_test_with_install.h" | 25 #include "chrome/browser/extensions/extension_service_test_with_install.h" |
| 25 #include "chrome/browser/extensions/extension_sync_data.h" | 26 #include "chrome/browser/extensions/extension_sync_data.h" |
| 26 #include "chrome/browser/extensions/extension_sync_service.h" | 27 #include "chrome/browser/extensions/extension_sync_service.h" |
| 27 #include "chrome/browser/extensions/extension_util.h" | 28 #include "chrome/browser/extensions/extension_util.h" |
| 28 #include "chrome/browser/extensions/scripting_permissions_modifier.h" | 29 #include "chrome/browser/extensions/scripting_permissions_modifier.h" |
| 29 #include "chrome/browser/extensions/updater/extension_updater.h" | 30 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 Extension::DISABLE_USER_ACTION, false, | 331 Extension::DISABLE_USER_ACTION, false, |
| 331 false, ExtensionSyncData::BOOLEAN_UNSET, | 332 false, ExtensionSyncData::BOOLEAN_UNSET, |
| 332 false); | 333 false); |
| 333 SyncChangeList list( | 334 SyncChangeList list( |
| 334 1, disable_good_crx.GetSyncChange(SyncChange::ACTION_UPDATE)); | 335 1, disable_good_crx.GetSyncChange(SyncChange::ACTION_UPDATE)); |
| 335 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 336 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 336 | 337 |
| 337 ASSERT_FALSE(service()->IsExtensionEnabled(good0)); | 338 ASSERT_FALSE(service()->IsExtensionEnabled(good0)); |
| 338 } | 339 } |
| 339 | 340 |
| 341 // Test that sync can enable and disable installed extensions. | |
| 342 TEST_F(ExtensionServiceSyncTest, ReenableDisabledExtensionFromSync) { | |
| 343 InitializeEmptyExtensionService(); | |
| 344 | |
| 345 // Enable sync. | |
| 346 browser_sync::ProfileSyncService* sync_service = | |
| 347 ProfileSyncServiceFactory::GetForProfile(profile()); | |
| 348 sync_service->SetFirstSetupComplete(); | |
| 349 | |
| 350 service()->Init(); | |
| 351 | |
| 352 // Load up a simple extension. | |
| 353 extensions::ChromeTestExtensionLoader extension_loader(profile()); | |
| 354 extension_loader.set_pack_extension(true); | |
| 355 scoped_refptr<const Extension> extension = extension_loader.LoadExtension( | |
| 356 data_dir().AppendASCII("simple_with_file")); | |
| 357 ASSERT_TRUE(extension); | |
| 358 const std::string kExtensionId = extension->id(); | |
| 359 EXPECT_EQ(kExtensionId, extension->id()); | |
|
karandeepb
2017/06/09 22:53:36
This seems redundant. Same below.
Devlin
2017/06/13 16:14:44
Whoops! This expect was from an earlier version.
| |
| 360 ASSERT_TRUE(registry()->enabled_extensions().GetByID(kExtensionId)); | |
| 361 | |
| 362 syncer::FakeSyncChangeProcessor* processor = | |
| 363 new syncer::FakeSyncChangeProcessor; | |
|
karandeepb
2017/06/09 22:53:36
optional nit: Create a unique pointer and then tak
Devlin
2017/06/13 16:14:44
Done.
| |
| 364 extension_sync_service()->MergeDataAndStartSyncing( | |
| 365 syncer::EXTENSIONS, syncer::SyncDataList(), base::WrapUnique(processor), | |
| 366 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
| 367 | |
| 368 processor->changes().clear(); | |
| 369 | |
| 370 // Sync says to disable the extension. | |
| 371 ExtensionSyncData disable_extension( | |
| 372 *extension, false, Extension::DISABLE_USER_ACTION, false, false, | |
| 373 ExtensionSyncData::BOOLEAN_UNSET, false); | |
| 374 SyncChangeList enable_list( | |
| 375 1, disable_extension.GetSyncChange(SyncChange::ACTION_UPDATE)); | |
| 376 extension_sync_service()->ProcessSyncChanges(FROM_HERE, enable_list); | |
| 377 | |
| 378 // The extension should be disabled. | |
| 379 EXPECT_TRUE(registry()->disabled_extensions().GetByID(kExtensionId)); | |
| 380 EXPECT_EQ(Extension::DISABLE_USER_ACTION, | |
| 381 ExtensionPrefs::Get(profile())->GetDisableReasons(kExtensionId)); | |
| 382 EXPECT_TRUE(processor->changes().empty()); | |
| 383 | |
| 384 // Enable the extension. Sync should push the new state. | |
| 385 service()->EnableExtension(kExtensionId); | |
| 386 { | |
| 387 ASSERT_EQ(1u, processor->changes().size()); | |
| 388 const SyncChange& change = processor->changes()[0]; | |
| 389 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); | |
| 390 std::unique_ptr<ExtensionSyncData> data = | |
| 391 ExtensionSyncData::CreateFromSyncData(change.sync_data()); | |
| 392 EXPECT_EQ(kExtensionId, data->id()); | |
| 393 EXPECT_EQ(0, data->disable_reasons()); | |
| 394 EXPECT_TRUE(data->enabled()); | |
| 395 } | |
| 396 | |
| 397 // Disable the extension again. Sync should push the new state. | |
| 398 processor->changes().clear(); | |
| 399 service()->DisableExtension(kExtensionId, Extension::DISABLE_USER_ACTION); | |
| 400 EXPECT_TRUE(registry()->disabled_extensions().GetByID(kExtensionId)); | |
| 401 { | |
| 402 ASSERT_EQ(1u, processor->changes().size()); | |
| 403 const SyncChange& change = processor->changes()[0]; | |
| 404 EXPECT_EQ(SyncChange::ACTION_UPDATE, change.change_type()); | |
| 405 std::unique_ptr<ExtensionSyncData> data = | |
| 406 ExtensionSyncData::CreateFromSyncData(change.sync_data()); | |
| 407 EXPECT_EQ(kExtensionId, data->id()); | |
| 408 EXPECT_EQ(Extension::DISABLE_USER_ACTION, data->disable_reasons()); | |
| 409 EXPECT_FALSE(data->enabled()); | |
| 410 } | |
| 411 processor->changes().clear(); | |
| 412 | |
| 413 // Enable the extension via sync. | |
| 414 ExtensionSyncData enable_extension(*extension, true, 0, false, false, | |
| 415 ExtensionSyncData::BOOLEAN_UNSET, false); | |
| 416 SyncChangeList disable_list( | |
| 417 1, enable_extension.GetSyncChange(SyncChange::ACTION_UPDATE)); | |
| 418 extension_sync_service()->ProcessSyncChanges(FROM_HERE, disable_list); | |
| 419 | |
| 420 // The extension should be enabled. | |
| 421 EXPECT_TRUE(registry()->enabled_extensions().GetByID(kExtensionId)); | |
| 422 EXPECT_TRUE(processor->changes().empty()); | |
| 423 } | |
| 424 | |
| 425 // Tests that default-installed extensions won't be affected by incoming sync | |
| 426 // data. (It's feasible to have a sync entry for an extension that could be | |
| 427 // default installed, since one installation may be default-installed while | |
| 428 // another may not be). | |
| 429 TEST_F(ExtensionServiceSyncTest, | |
| 430 DefaultInstalledExtensionsAreNotReenabledOrDisabledBySync) { | |
| 431 InitializeEmptyExtensionService(); | |
| 432 | |
| 433 // Enable sync. | |
| 434 browser_sync::ProfileSyncService* sync_service = | |
| 435 ProfileSyncServiceFactory::GetForProfile(profile()); | |
| 436 sync_service->SetFirstSetupComplete(); | |
| 437 | |
| 438 service()->Init(); | |
| 439 | |
| 440 // Load up an extension that's considered default installed. | |
| 441 extensions::ChromeTestExtensionLoader extension_loader(profile()); | |
| 442 extension_loader.set_pack_extension(true); | |
| 443 extension_loader.add_creation_flag(Extension::WAS_INSTALLED_BY_DEFAULT); | |
| 444 scoped_refptr<const Extension> extension = extension_loader.LoadExtension( | |
| 445 data_dir().AppendASCII("simple_with_file")); | |
| 446 ASSERT_TRUE(extension); | |
| 447 | |
| 448 // The extension shouldn't sync. | |
| 449 EXPECT_FALSE(extensions::util::ShouldSync(extension.get(), profile())); | |
| 450 const std::string kExtensionId = extension->id(); | |
| 451 EXPECT_EQ(kExtensionId, extension->id()); | |
| 452 ASSERT_TRUE(registry()->enabled_extensions().GetByID(kExtensionId)); | |
| 453 | |
| 454 syncer::FakeSyncChangeProcessor* processor = | |
| 455 new syncer::FakeSyncChangeProcessor; | |
| 456 extension_sync_service()->MergeDataAndStartSyncing( | |
| 457 syncer::EXTENSIONS, syncer::SyncDataList(), base::WrapUnique(processor), | |
| 458 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | |
| 459 processor->changes().clear(); | |
| 460 | |
| 461 // Sync state says the extension is disabled (e.g. on another machine). | |
| 462 ExtensionSyncData disable_extension( | |
| 463 *extension, false, Extension::DISABLE_USER_ACTION, false, false, | |
| 464 ExtensionSyncData::BOOLEAN_UNSET, false); | |
| 465 SyncChangeList disable_list( | |
| 466 1, disable_extension.GetSyncChange(SyncChange::ACTION_UPDATE)); | |
| 467 extension_sync_service()->ProcessSyncChanges(FROM_HERE, disable_list); | |
| 468 | |
| 469 // The extension should still be enabled, since it's default-installed. | |
| 470 EXPECT_TRUE(registry()->enabled_extensions().GetByID(kExtensionId)); | |
| 471 EXPECT_TRUE(processor->changes().empty()); | |
| 472 | |
| 473 // Now disable the extension locally. Sync should *not* push new state. | |
| 474 service()->DisableExtension(kExtensionId, Extension::DISABLE_USER_ACTION); | |
| 475 EXPECT_TRUE(registry()->disabled_extensions().GetByID(kExtensionId)); | |
| 476 EXPECT_TRUE(processor->changes().empty()); | |
| 477 | |
| 478 // Sync state says the extension is enabled. | |
| 479 ExtensionSyncData enable_extension(*extension, true, 0, false, false, | |
| 480 ExtensionSyncData::BOOLEAN_UNSET, false); | |
| 481 SyncChangeList enable_list( | |
| 482 1, enable_extension.GetSyncChange(SyncChange::ACTION_UPDATE)); | |
| 483 extension_sync_service()->ProcessSyncChanges(FROM_HERE, enable_list); | |
| 484 | |
| 485 // As above, the extension should not have been affected by sync. | |
| 486 EXPECT_TRUE(registry()->disabled_extensions().GetByID(kExtensionId)); | |
| 487 EXPECT_TRUE(processor->changes().empty()); | |
| 488 | |
| 489 // And re-enabling the extension should not push new state to sync. | |
| 490 service()->EnableExtension(kExtensionId); | |
| 491 EXPECT_TRUE(registry()->enabled_extensions().GetByID(kExtensionId)); | |
| 492 EXPECT_TRUE(processor->changes().empty()); | |
| 493 } | |
| 494 | |
| 340 TEST_F(ExtensionServiceSyncTest, IgnoreSyncChangesWhenLocalStateIsMoreRecent) { | 495 TEST_F(ExtensionServiceSyncTest, IgnoreSyncChangesWhenLocalStateIsMoreRecent) { |
| 341 // Start the extension service with three extensions already installed. | 496 // Start the extension service with three extensions already installed. |
| 342 base::FilePath source_install_dir = | 497 base::FilePath source_install_dir = |
| 343 data_dir().AppendASCII("good").AppendASCII("Extensions"); | 498 data_dir().AppendASCII("good").AppendASCII("Extensions"); |
| 344 base::FilePath pref_path = | 499 base::FilePath pref_path = |
| 345 source_install_dir.DirName().Append(chrome::kPreferencesFilename); | 500 source_install_dir.DirName().Append(chrome::kPreferencesFilename); |
| 346 | 501 |
| 347 InitializeInstalledExtensionService(pref_path, source_install_dir); | 502 InitializeInstalledExtensionService(pref_path, source_install_dir); |
| 348 | 503 |
| 349 // The user has enabled sync. | 504 // The user has enabled sync. |
| (...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1352 EXPECT_EQ(expect_enabled, service()->IsExtensionEnabled(id)); | 1507 EXPECT_EQ(expect_enabled, service()->IsExtensionEnabled(id)); |
| 1353 EXPECT_EQ(test_case.expect_disable_reasons, prefs->GetDisableReasons(id)); | 1508 EXPECT_EQ(test_case.expect_disable_reasons, prefs->GetDisableReasons(id)); |
| 1354 | 1509 |
| 1355 // Remove the extension again, so we can install it again for the next case. | 1510 // Remove the extension again, so we can install it again for the next case. |
| 1356 UninstallExtension(id, false, expect_enabled ? Extension::ENABLED | 1511 UninstallExtension(id, false, expect_enabled ? Extension::ENABLED |
| 1357 : Extension::DISABLED); | 1512 : Extension::DISABLED); |
| 1358 } | 1513 } |
| 1359 } | 1514 } |
| 1360 | 1515 |
| 1361 TEST_F(ExtensionServiceSyncTest, ProcessSyncDataDeferredEnable) { | 1516 TEST_F(ExtensionServiceSyncTest, ProcessSyncDataDeferredEnable) { |
| 1517 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 1518 switches::kAppsGalleryUpdateURL, | |
| 1519 "http://localhost/autoupdate/updates.xml"); | |
|
karandeepb
2017/06/09 22:53:36
This seems unrelated. I am assuming you also plan
Devlin
2017/06/13 16:14:44
Actually, this one's important. We only sync exte
| |
| 1520 | |
| 1362 InitializeEmptyExtensionService(); | 1521 InitializeEmptyExtensionService(); |
| 1363 extension_sync_service()->MergeDataAndStartSyncing( | 1522 extension_sync_service()->MergeDataAndStartSyncing( |
| 1364 syncer::EXTENSIONS, syncer::SyncDataList(), | 1523 syncer::EXTENSIONS, syncer::SyncDataList(), |
| 1365 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), | 1524 base::MakeUnique<syncer::FakeSyncChangeProcessor>(), |
| 1366 base::MakeUnique<syncer::SyncErrorFactoryMock>()); | 1525 base::MakeUnique<syncer::SyncErrorFactoryMock>()); |
| 1367 | 1526 |
| 1368 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); | 1527 base::FilePath base_path = data_dir().AppendASCII("permissions_increase"); |
| 1369 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); | 1528 base::FilePath pem_path = base_path.AppendASCII("permissions.pem"); |
| 1370 | 1529 |
| 1371 base::FilePath path = base_path.AppendASCII("v1"); | 1530 base::FilePath path = base_path.AppendASCII("v1"); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1384 // Now a sync update comes in, telling us to re-enable a *newer* version. | 1543 // Now a sync update comes in, telling us to re-enable a *newer* version. |
| 1385 sync_pb::EntitySpecifics specifics; | 1544 sync_pb::EntitySpecifics specifics; |
| 1386 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); | 1545 sync_pb::ExtensionSpecifics* ext_specifics = specifics.mutable_extension(); |
| 1387 ext_specifics->set_id(id); | 1546 ext_specifics->set_id(id); |
| 1388 ext_specifics->set_version("3"); | 1547 ext_specifics->set_version("3"); |
| 1389 ext_specifics->set_enabled(true); | 1548 ext_specifics->set_enabled(true); |
| 1390 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); | 1549 ext_specifics->set_disable_reasons(Extension::DISABLE_NONE); |
| 1391 | 1550 |
| 1392 SyncChangeList list = | 1551 SyncChangeList list = |
| 1393 MakeSyncChangeList(good_crx, specifics, SyncChange::ACTION_UPDATE); | 1552 MakeSyncChangeList(good_crx, specifics, SyncChange::ACTION_UPDATE); |
| 1394 | |
|
Devlin
2017/06/09 20:16:35
not sure how these crept in, will remove the chang
| |
| 1395 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); | 1553 extension_sync_service()->ProcessSyncChanges(FROM_HERE, list); |
| 1396 | 1554 |
| 1397 // Since the version didn't match, the extension should still be disabled. | 1555 // Since the version didn't match, the extension should still be disabled. |
| 1398 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); | 1556 EXPECT_TRUE(registry()->disabled_extensions().Contains(id)); |
| 1399 | |
| 1400 // After we update to the matching version, the extension should get enabled. | 1557 // After we update to the matching version, the extension should get enabled. |
| 1401 path = base_path.AppendASCII("v3"); | 1558 path = base_path.AppendASCII("v3"); |
| 1402 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); | 1559 PackCRXAndUpdateExtension(id, path, pem_path, ENABLED); |
| 1403 } | 1560 } |
| 1404 | 1561 |
| 1405 class ExtensionServiceSyncCustomGalleryTest : public ExtensionServiceSyncTest { | 1562 class ExtensionServiceSyncCustomGalleryTest : public ExtensionServiceSyncTest { |
| 1406 public: | 1563 public: |
| 1407 void SetUp() override { | 1564 void SetUp() override { |
| 1408 ExtensionServiceSyncTest::SetUp(); | 1565 ExtensionServiceSyncTest::SetUp(); |
| 1409 | 1566 |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2466 break; | 2623 break; |
| 2467 } | 2624 } |
| 2468 } | 2625 } |
| 2469 } | 2626 } |
| 2470 EXPECT_TRUE(found_delete); | 2627 EXPECT_TRUE(found_delete); |
| 2471 | 2628 |
| 2472 // Make sure there is one extension, and there are no more apps. | 2629 // Make sure there is one extension, and there are no more apps. |
| 2473 EXPECT_EQ(1u, extensions_processor.data().size()); | 2630 EXPECT_EQ(1u, extensions_processor.data().size()); |
| 2474 EXPECT_TRUE(apps_processor.data().empty()); | 2631 EXPECT_TRUE(apps_processor.data().empty()); |
| 2475 } | 2632 } |
| OLD | NEW |