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

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

Issue 2054773002: Replace the WAS_INSTALLED_BY_CUSTODIAN creation flag with a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to code review by treib@ Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2467 matching lines...) Expand 10 before | Expand all | Expand 10 after
2478 2478
2479 } // namespace 2479 } // namespace
2480 2480
2481 // Test adding a pending extension. 2481 // Test adding a pending extension.
2482 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) { 2482 TEST_F(ExtensionServiceTest, AddPendingExtensionFromSync) {
2483 InitializeEmptyExtensionService(); 2483 InitializeEmptyExtensionService();
2484 2484
2485 const std::string kFakeId(all_zero); 2485 const std::string kFakeId(all_zero);
2486 const GURL kFakeUpdateURL("http:://fake.update/url"); 2486 const GURL kFakeUpdateURL("http:://fake.update/url");
2487 const bool kFakeRemoteInstall(false); 2487 const bool kFakeRemoteInstall(false);
2488 const bool kFakeInstalledByCustodian(false);
2489 2488
2490 EXPECT_TRUE( 2489 EXPECT_TRUE(
2491 service()->pending_extension_manager()->AddFromSync( 2490 service()->pending_extension_manager()->AddFromSync(
2492 kFakeId, 2491 kFakeId,
2493 kFakeUpdateURL, 2492 kFakeUpdateURL,
2494 base::Version(), 2493 base::Version(),
2495 &IsExtension, 2494 &IsExtension,
2496 kFakeRemoteInstall, 2495 kFakeRemoteInstall));
2497 kFakeInstalledByCustodian));
2498 2496
2499 const extensions::PendingExtensionInfo* pending_extension_info; 2497 const extensions::PendingExtensionInfo* pending_extension_info;
2500 ASSERT_TRUE((pending_extension_info = 2498 ASSERT_TRUE((pending_extension_info =
2501 service()->pending_extension_manager()->GetById(kFakeId))); 2499 service()->pending_extension_manager()->GetById(kFakeId)));
2502 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url()); 2500 EXPECT_EQ(kFakeUpdateURL, pending_extension_info->update_url());
2503 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_); 2501 EXPECT_EQ(&IsExtension, pending_extension_info->should_allow_install_);
2504 // Use 2502 // Use
2505 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()) 2503 // EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install())
2506 // instead of 2504 // instead of
2507 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install()) 2505 // EXPECT_EQ(kFakeRemoteInstall, pending_extension_info->remote_install())
2508 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is 2506 // as gcc 4.7 issues the following warning on EXPECT_EQ(false, x), which is
2509 // turned into an error with -Werror=conversion-null: 2507 // turned into an error with -Werror=conversion-null:
2510 // converting 'false' to pointer type for argument 1 of 2508 // converting 'false' to pointer type for argument 1 of
2511 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)' 2509 // 'char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)'
2512 // https://code.google.com/p/googletest/issues/detail?id=458 2510 // https://code.google.com/p/googletest/issues/detail?id=458
2513 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install()); 2511 EXPECT_TRUE(kFakeRemoteInstall == pending_extension_info->remote_install());
2514 } 2512 }
2515 2513
2516 namespace { 2514 namespace {
2517 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 2515 const char kGoodId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
2518 const char kGoodUpdateURL[] = "http://good.update/url"; 2516 const char kGoodUpdateURL[] = "http://good.update/url";
2519 const char kGoodVersion[] = "1"; 2517 const char kGoodVersion[] = "1";
2520 const bool kGoodIsFromSync = true; 2518 const bool kGoodIsFromSync = true;
2521 const bool kGoodRemoteInstall = false; 2519 const bool kGoodRemoteInstall = false;
2522 const bool kGoodInstalledByCustodian = false;
2523 } // namespace 2520 } // namespace
2524 2521
2525 // Test installing a pending extension (this goes through 2522 // Test installing a pending extension (this goes through
2526 // ExtensionService::UpdateExtension). 2523 // ExtensionService::UpdateExtension).
2527 TEST_F(ExtensionServiceTest, UpdatePendingExtension) { 2524 TEST_F(ExtensionServiceTest, UpdatePendingExtension) {
2528 InitializeEmptyExtensionService(); 2525 InitializeEmptyExtensionService();
2529 EXPECT_TRUE( 2526 EXPECT_TRUE(
2530 service()->pending_extension_manager()->AddFromSync( 2527 service()->pending_extension_manager()->AddFromSync(
2531 kGoodId, 2528 kGoodId,
2532 GURL(kGoodUpdateURL), 2529 GURL(kGoodUpdateURL),
2533 base::Version(kGoodVersion), 2530 base::Version(kGoodVersion),
2534 &IsExtension, 2531 &IsExtension,
2535 kGoodRemoteInstall, 2532 kGoodRemoteInstall));
2536 kGoodInstalledByCustodian));
2537 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2533 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2538 2534
2539 base::FilePath path = data_dir().AppendASCII("good.crx"); 2535 base::FilePath path = data_dir().AppendASCII("good.crx");
2540 UpdateExtension(kGoodId, path, ENABLED); 2536 UpdateExtension(kGoodId, path, ENABLED);
2541 2537
2542 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2538 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2543 2539
2544 const Extension* extension = service()->GetExtensionById(kGoodId, true); 2540 const Extension* extension = service()->GetExtensionById(kGoodId, true);
2545 EXPECT_TRUE(extension); 2541 EXPECT_TRUE(extension);
2546 } 2542 }
2547 2543
2548 TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongVersion) { 2544 TEST_F(ExtensionServiceTest, UpdatePendingExtensionWrongVersion) {
2549 InitializeEmptyExtensionService(); 2545 InitializeEmptyExtensionService();
2550 base::Version other_version("0.1"); 2546 base::Version other_version("0.1");
2551 ASSERT_TRUE(other_version.IsValid()); 2547 ASSERT_TRUE(other_version.IsValid());
2552 ASSERT_NE(other_version, base::Version(kGoodVersion)); 2548 ASSERT_NE(other_version, base::Version(kGoodVersion));
2553 EXPECT_TRUE( 2549 EXPECT_TRUE(
2554 service()->pending_extension_manager()->AddFromSync( 2550 service()->pending_extension_manager()->AddFromSync(
2555 kGoodId, 2551 kGoodId,
2556 GURL(kGoodUpdateURL), 2552 GURL(kGoodUpdateURL),
2557 other_version, 2553 other_version,
2558 &IsExtension, 2554 &IsExtension,
2559 kGoodRemoteInstall, 2555 kGoodRemoteInstall));
2560 kGoodInstalledByCustodian));
2561 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2556 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2562 2557
2563 base::FilePath path = data_dir().AppendASCII("good.crx"); 2558 base::FilePath path = data_dir().AppendASCII("good.crx");
2564 // After installation, the extension should be disabled, because it's missing 2559 // After installation, the extension should be disabled, because it's missing
2565 // permissions. 2560 // permissions.
2566 UpdateExtension(kGoodId, path, DISABLED); 2561 UpdateExtension(kGoodId, path, DISABLED);
2567 2562
2568 EXPECT_TRUE( 2563 EXPECT_TRUE(
2569 ExtensionPrefs::Get(profile())->DidExtensionEscalatePermissions(kGoodId)); 2564 ExtensionPrefs::Get(profile())->DidExtensionEscalatePermissions(kGoodId));
2570 2565
(...skipping 10 matching lines...) Expand all
2581 return extension->is_theme(); 2576 return extension->is_theme();
2582 } 2577 }
2583 2578
2584 } // namespace 2579 } // namespace
2585 2580
2586 // Test updating a pending theme. 2581 // Test updating a pending theme.
2587 // Disabled due to ASAN failure. http://crbug.com/108320 2582 // Disabled due to ASAN failure. http://crbug.com/108320
2588 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) { 2583 TEST_F(ExtensionServiceTest, DISABLED_UpdatePendingTheme) {
2589 InitializeEmptyExtensionService(); 2584 InitializeEmptyExtensionService();
2590 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( 2585 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
2591 theme_crx, GURL(), base::Version(), &IsTheme, false, false)); 2586 theme_crx, GURL(), base::Version(), &IsTheme, false));
2592 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2587 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2593 2588
2594 base::FilePath path = data_dir().AppendASCII("theme.crx"); 2589 base::FilePath path = data_dir().AppendASCII("theme.crx");
2595 UpdateExtension(theme_crx, path, ENABLED); 2590 UpdateExtension(theme_crx, path, ENABLED);
2596 2591
2597 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2592 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2598 2593
2599 const Extension* extension = service()->GetExtensionById(theme_crx, true); 2594 const Extension* extension = service()->GetExtensionById(theme_crx, true);
2600 ASSERT_TRUE(extension); 2595 ASSERT_TRUE(extension);
2601 2596
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2646 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) { 2641 TEST_F(ExtensionServiceTest, UpdatePendingExternalCrxWinsOverSync) {
2647 InitializeEmptyExtensionService(); 2642 InitializeEmptyExtensionService();
2648 2643
2649 // Add a crx to be installed from the update mechanism. 2644 // Add a crx to be installed from the update mechanism.
2650 EXPECT_TRUE( 2645 EXPECT_TRUE(
2651 service()->pending_extension_manager()->AddFromSync( 2646 service()->pending_extension_manager()->AddFromSync(
2652 kGoodId, 2647 kGoodId,
2653 GURL(kGoodUpdateURL), 2648 GURL(kGoodUpdateURL),
2654 base::Version(), 2649 base::Version(),
2655 &IsExtension, 2650 &IsExtension,
2656 kGoodRemoteInstall, 2651 kGoodRemoteInstall));
2657 kGoodInstalledByCustodian));
2658 2652
2659 // Check that there is a pending crx, with is_from_sync set to true. 2653 // Check that there is a pending crx, with is_from_sync set to true.
2660 const extensions::PendingExtensionInfo* pending_extension_info; 2654 const extensions::PendingExtensionInfo* pending_extension_info;
2661 ASSERT_TRUE((pending_extension_info = 2655 ASSERT_TRUE((pending_extension_info =
2662 service()->pending_extension_manager()->GetById(kGoodId))); 2656 service()->pending_extension_manager()->GetById(kGoodId)));
2663 EXPECT_TRUE(pending_extension_info->is_from_sync()); 2657 EXPECT_TRUE(pending_extension_info->is_from_sync());
2664 2658
2665 // Add a crx to be updated, with the same ID, from a non-sync source. 2659 // Add a crx to be updated, with the same ID, from a non-sync source.
2666 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl( 2660 EXPECT_TRUE(service()->pending_extension_manager()->AddFromExternalUpdateUrl(
2667 kGoodId, 2661 kGoodId,
(...skipping 10 matching lines...) Expand all
2678 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 2672 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
2679 pending_extension_info->install_source()); 2673 pending_extension_info->install_source());
2680 2674
2681 // Add a crx to be installed from the update mechanism. 2675 // Add a crx to be installed from the update mechanism.
2682 EXPECT_FALSE( 2676 EXPECT_FALSE(
2683 service()->pending_extension_manager()->AddFromSync( 2677 service()->pending_extension_manager()->AddFromSync(
2684 kGoodId, 2678 kGoodId,
2685 GURL(kGoodUpdateURL), 2679 GURL(kGoodUpdateURL),
2686 base::Version(), 2680 base::Version(),
2687 &IsExtension, 2681 &IsExtension,
2688 kGoodRemoteInstall, 2682 kGoodRemoteInstall));
2689 kGoodInstalledByCustodian));
2690 2683
2691 // Check that the external, non-sync update was not overridden. 2684 // Check that the external, non-sync update was not overridden.
2692 ASSERT_TRUE((pending_extension_info = 2685 ASSERT_TRUE((pending_extension_info =
2693 service()->pending_extension_manager()->GetById(kGoodId))); 2686 service()->pending_extension_manager()->GetById(kGoodId)));
2694 EXPECT_FALSE(pending_extension_info->is_from_sync()); 2687 EXPECT_FALSE(pending_extension_info->is_from_sync());
2695 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD, 2688 EXPECT_EQ(Manifest::EXTERNAL_PREF_DOWNLOAD,
2696 pending_extension_info->install_source()); 2689 pending_extension_info->install_source());
2697 } 2690 }
2698 2691
2699 // Updating a theme should fail if the updater is explicitly told that 2692 // Updating a theme should fail if the updater is explicitly told that
2700 // the CRX is not a theme. 2693 // the CRX is not a theme.
2701 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) { 2694 TEST_F(ExtensionServiceTest, UpdatePendingCrxThemeMismatch) {
2702 InitializeEmptyExtensionService(); 2695 InitializeEmptyExtensionService();
2703 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync( 2696 EXPECT_TRUE(service()->pending_extension_manager()->AddFromSync(
2704 theme_crx, GURL(), base::Version(), &IsExtension, false, false)); 2697 theme_crx, GURL(), base::Version(), &IsExtension, false));
2705 2698
2706 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2699 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2707 2700
2708 base::FilePath path = data_dir().AppendASCII("theme.crx"); 2701 base::FilePath path = data_dir().AppendASCII("theme.crx");
2709 UpdateExtension(theme_crx, path, FAILED_SILENTLY); 2702 UpdateExtension(theme_crx, path, FAILED_SILENTLY);
2710 2703
2711 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx)); 2704 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(theme_crx));
2712 2705
2713 const Extension* extension = service()->GetExtensionById(theme_crx, true); 2706 const Extension* extension = service()->GetExtensionById(theme_crx, true);
2714 ASSERT_FALSE(extension); 2707 ASSERT_FALSE(extension);
2715 } 2708 }
2716 2709
2717 // TODO(akalin): Test updating a pending extension non-silently once 2710 // TODO(akalin): Test updating a pending extension non-silently once
2718 // we can mock out ExtensionInstallUI and inject our version into 2711 // we can mock out ExtensionInstallUI and inject our version into
2719 // UpdateExtension(). 2712 // UpdateExtension().
2720 2713
2721 // Test updating a pending extension which fails the should-install test. 2714 // Test updating a pending extension which fails the should-install test.
2722 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) { 2715 TEST_F(ExtensionServiceTest, UpdatePendingExtensionFailedShouldInstallTest) {
2723 InitializeEmptyExtensionService(); 2716 InitializeEmptyExtensionService();
2724 // Add pending extension with a flipped is_theme. 2717 // Add pending extension with a flipped is_theme.
2725 EXPECT_TRUE( 2718 EXPECT_TRUE(
2726 service()->pending_extension_manager()->AddFromSync( 2719 service()->pending_extension_manager()->AddFromSync(
2727 kGoodId, 2720 kGoodId,
2728 GURL(kGoodUpdateURL), 2721 GURL(kGoodUpdateURL),
2729 base::Version(), 2722 base::Version(),
2730 &IsTheme, 2723 &IsTheme,
2731 kGoodRemoteInstall, 2724 kGoodRemoteInstall));
2732 kGoodInstalledByCustodian));
2733 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2725 EXPECT_TRUE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2734 2726
2735 base::FilePath path = data_dir().AppendASCII("good.crx"); 2727 base::FilePath path = data_dir().AppendASCII("good.crx");
2736 UpdateExtension(kGoodId, path, UPDATED); 2728 UpdateExtension(kGoodId, path, UPDATED);
2737 2729
2738 // TODO(akalin): Figure out how to check that the extensions 2730 // TODO(akalin): Figure out how to check that the extensions
2739 // directory is cleaned up properly in OnExtensionInstalled(). 2731 // directory is cleaned up properly in OnExtensionInstalled().
2740 2732
2741 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId)); 2733 EXPECT_FALSE(service()->pending_extension_manager()->IsIdPending(kGoodId));
2742 } 2734 }
(...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after
5762 return service()->OnExternalExtensionFileFound(*info); 5754 return service()->OnExternalExtensionFileFound(*info);
5763 } 5755 }
5764 5756
5765 // Fake a request from sync to install an extension. 5757 // Fake a request from sync to install an extension.
5766 bool AddPendingSyncInstall() { 5758 bool AddPendingSyncInstall() {
5767 return service()->pending_extension_manager()->AddFromSync( 5759 return service()->pending_extension_manager()->AddFromSync(
5768 crx_id_, 5760 crx_id_,
5769 GURL(kGoodUpdateURL), 5761 GURL(kGoodUpdateURL),
5770 base::Version(), 5762 base::Version(),
5771 &IsExtension, 5763 &IsExtension,
5772 kGoodRemoteInstall, 5764 kGoodRemoteInstall);
5773 kGoodInstalledByCustodian);
5774 } 5765 }
5775 5766
5776 // Fake a policy install. 5767 // Fake a policy install.
5777 bool AddPendingPolicyInstall() { 5768 bool AddPendingPolicyInstall() {
5778 // Get path to the CRX with id |kGoodId|. 5769 // Get path to the CRX with id |kGoodId|.
5779 std::unique_ptr<GURL> empty_url(new GURL()); 5770 std::unique_ptr<GURL> empty_url(new GURL());
5780 std::unique_ptr<ExternalInstallInfoUpdateUrl> info( 5771 std::unique_ptr<ExternalInstallInfoUpdateUrl> info(
5781 new ExternalInstallInfoUpdateUrl( 5772 new ExternalInstallInfoUpdateUrl(
5782 crx_id_, std::string(), std::move(empty_url), 5773 crx_id_, std::string(), std::move(empty_url),
5783 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false)); 5774 Manifest::EXTERNAL_POLICY_DOWNLOAD, Extension::NO_FLAGS, false));
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
6523 6514
6524 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED, 6515 service()->Observe(chrome::NOTIFICATION_PROFILE_DESTRUCTION_STARTED,
6525 content::Source<Profile>(profile()), 6516 content::Source<Profile>(profile()),
6526 content::NotificationService::NoDetails()); 6517 content::NotificationService::NoDetails());
6527 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_); 6518 EXPECT_EQ(UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN, unloaded_reason_);
6528 EXPECT_EQ(0u, registry()->enabled_extensions().size()); 6519 EXPECT_EQ(0u, registry()->enabled_extensions().size());
6529 EXPECT_EQ(0u, registry()->disabled_extensions().size()); 6520 EXPECT_EQ(0u, registry()->disabled_extensions().size());
6530 EXPECT_EQ(0u, registry()->terminated_extensions().size()); 6521 EXPECT_EQ(0u, registry()->terminated_extensions().size());
6531 EXPECT_EQ(0u, registry()->blacklisted_extensions().size()); 6522 EXPECT_EQ(0u, registry()->blacklisted_extensions().size());
6532 } 6523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698