| OLD | NEW |
| 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/profile_resetter/profile_resetter.h" | 5 #include "chrome/browser/profile_resetter/profile_resetter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 } | 553 } |
| 554 } | 554 } |
| 555 | 555 |
| 556 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { | 556 TEST_F(ProfileResetterTest, ResetExtensionsByDisabling) { |
| 557 service_->Init(); | 557 service_->Init(); |
| 558 | 558 |
| 559 base::ScopedTempDir temp_dir; | 559 base::ScopedTempDir temp_dir; |
| 560 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 560 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 561 | 561 |
| 562 scoped_refptr<Extension> theme = CreateExtension( | 562 scoped_refptr<Extension> theme = CreateExtension( |
| 563 base::ASCIIToUTF16("example1"), temp_dir.GetPath(), | 563 base::ASCIIToUTF16("example1"), temp_dir.GetPath(), Manifest::UNPACKED, |
| 564 Manifest::INVALID_LOCATION, extensions::Manifest::TYPE_THEME, false); | 564 extensions::Manifest::TYPE_THEME, false); |
| 565 service_->FinishInstallationForTest(theme.get()); | 565 service_->FinishInstallationForTest(theme.get()); |
| 566 // Let ThemeService finish creating the theme pack. | 566 // Let ThemeService finish creating the theme pack. |
| 567 base::RunLoop().RunUntilIdle(); | 567 base::RunLoop().RunUntilIdle(); |
| 568 | 568 |
| 569 ThemeService* theme_service = | 569 ThemeService* theme_service = |
| 570 ThemeServiceFactory::GetForProfile(profile()); | 570 ThemeServiceFactory::GetForProfile(profile()); |
| 571 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | 571 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| 572 | 572 |
| 573 scoped_refptr<Extension> ext2 = CreateExtension( | 573 scoped_refptr<Extension> ext2 = CreateExtension( |
| 574 base::ASCIIToUTF16("example2"), | 574 base::ASCIIToUTF16("example2"), |
| 575 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 575 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), Manifest::UNPACKED, |
| 576 Manifest::INVALID_LOCATION, | 576 extensions::Manifest::TYPE_EXTENSION, false); |
| 577 extensions::Manifest::TYPE_EXTENSION, | |
| 578 false); | |
| 579 service_->AddExtension(ext2.get()); | 577 service_->AddExtension(ext2.get()); |
| 580 // Component extensions and policy-managed extensions shouldn't be disabled. | 578 // Component extensions and policy-managed extensions shouldn't be disabled. |
| 581 scoped_refptr<Extension> ext3 = CreateExtension( | 579 scoped_refptr<Extension> ext3 = CreateExtension( |
| 582 base::ASCIIToUTF16("example3"), | 580 base::ASCIIToUTF16("example3"), |
| 583 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 581 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), |
| 584 Manifest::COMPONENT, | 582 Manifest::COMPONENT, |
| 585 extensions::Manifest::TYPE_EXTENSION, | 583 extensions::Manifest::TYPE_EXTENSION, |
| 586 false); | 584 false); |
| 587 service_->AddExtension(ext3.get()); | 585 service_->AddExtension(ext3.get()); |
| 588 scoped_refptr<Extension> ext4 = | 586 scoped_refptr<Extension> ext4 = |
| (...skipping 26 matching lines...) Expand all Loading... |
| 615 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); | 613 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
| 616 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext4->id())); | 614 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext4->id())); |
| 617 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext5->id())); | 615 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext5->id())); |
| 618 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext6->id())); | 616 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext6->id())); |
| 619 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 617 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
| 620 } | 618 } |
| 621 | 619 |
| 622 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { | 620 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { |
| 623 scoped_refptr<Extension> ext2 = CreateExtension( | 621 scoped_refptr<Extension> ext2 = CreateExtension( |
| 624 base::ASCIIToUTF16("example2"), | 622 base::ASCIIToUTF16("example2"), |
| 625 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 623 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), Manifest::UNPACKED, |
| 626 Manifest::INVALID_LOCATION, | 624 extensions::Manifest::TYPE_EXTENSION, false); |
| 627 extensions::Manifest::TYPE_EXTENSION, | |
| 628 false); | |
| 629 service_->AddExtension(ext2.get()); | 625 service_->AddExtension(ext2.get()); |
| 630 // Components and external policy extensions shouldn't be deleted. | 626 // Components and external policy extensions shouldn't be deleted. |
| 631 scoped_refptr<Extension> ext3 = CreateExtension( | 627 scoped_refptr<Extension> ext3 = CreateExtension( |
| 632 base::ASCIIToUTF16("example3"), | 628 base::ASCIIToUTF16("example3"), |
| 633 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 629 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), Manifest::UNPACKED, |
| 634 Manifest::INVALID_LOCATION, | 630 extensions::Manifest::TYPE_EXTENSION, false); |
| 635 extensions::Manifest::TYPE_EXTENSION, | |
| 636 false); | |
| 637 service_->AddExtension(ext3.get()); | 631 service_->AddExtension(ext3.get()); |
| 638 EXPECT_EQ(2u, registry()->enabled_extensions().size()); | 632 EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
| 639 | 633 |
| 640 std::string master_prefs(kDistributionConfig); | 634 std::string master_prefs(kDistributionConfig); |
| 641 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); | 635 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); |
| 642 | 636 |
| 643 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); | 637 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); |
| 644 | 638 |
| 645 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 639 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 646 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); | 640 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
| 647 } | 641 } |
| 648 | 642 |
| 649 TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) { | 643 TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) { |
| 650 service_->Init(); | 644 service_->Init(); |
| 651 | 645 |
| 652 base::ScopedTempDir temp_dir; | 646 base::ScopedTempDir temp_dir; |
| 653 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 647 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 654 | 648 |
| 655 scoped_refptr<Extension> ext1 = CreateExtension( | 649 scoped_refptr<Extension> ext1 = CreateExtension( |
| 656 base::ASCIIToUTF16("example1"), temp_dir.GetPath(), | 650 base::ASCIIToUTF16("example1"), temp_dir.GetPath(), Manifest::UNPACKED, |
| 657 Manifest::INVALID_LOCATION, extensions::Manifest::TYPE_THEME, false); | 651 extensions::Manifest::TYPE_THEME, false); |
| 658 service_->FinishInstallationForTest(ext1.get()); | 652 service_->FinishInstallationForTest(ext1.get()); |
| 659 // Let ThemeService finish creating the theme pack. | 653 // Let ThemeService finish creating the theme pack. |
| 660 base::RunLoop().RunUntilIdle(); | 654 base::RunLoop().RunUntilIdle(); |
| 661 | 655 |
| 662 ThemeService* theme_service = | 656 ThemeService* theme_service = |
| 663 ThemeServiceFactory::GetForProfile(profile()); | 657 ThemeServiceFactory::GetForProfile(profile()); |
| 664 EXPECT_FALSE(theme_service->UsingDefaultTheme()); | 658 EXPECT_FALSE(theme_service->UsingDefaultTheme()); |
| 665 | 659 |
| 666 scoped_refptr<Extension> ext2 = | 660 scoped_refptr<Extension> ext2 = CreateExtension( |
| 667 CreateExtension(base::ASCIIToUTF16("example2"), | 661 base::ASCIIToUTF16("example2"), |
| 668 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 662 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), Manifest::UNPACKED, |
| 669 Manifest::INVALID_LOCATION, | 663 extensions::Manifest::TYPE_EXTENSION, false); |
| 670 extensions::Manifest::TYPE_EXTENSION, | |
| 671 false); | |
| 672 service_->AddExtension(ext2.get()); | 664 service_->AddExtension(ext2.get()); |
| 673 | 665 |
| 674 scoped_refptr<Extension> ext3 = | 666 scoped_refptr<Extension> ext3 = CreateExtension( |
| 675 CreateExtension(base::ASCIIToUTF16("example2"), | 667 base::ASCIIToUTF16("example2"), |
| 676 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), | 668 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), Manifest::UNPACKED, |
| 677 Manifest::INVALID_LOCATION, | 669 extensions::Manifest::TYPE_HOSTED_APP, true); |
| 678 extensions::Manifest::TYPE_HOSTED_APP, | |
| 679 true); | |
| 680 service_->AddExtension(ext3.get()); | 670 service_->AddExtension(ext3.get()); |
| 681 EXPECT_EQ(3u, registry()->enabled_extensions().size()); | 671 EXPECT_EQ(3u, registry()->enabled_extensions().size()); |
| 682 | 672 |
| 683 ResetAndWait(ProfileResetter::EXTENSIONS); | 673 ResetAndWait(ProfileResetter::EXTENSIONS); |
| 684 | 674 |
| 685 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 675 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
| 686 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext1->id())); | 676 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext1->id())); |
| 687 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext2->id())); | 677 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext2->id())); |
| 688 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); | 678 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
| 689 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 679 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 EXPECT_EQ("http://goo.gl", startup_pages[0]); | 832 EXPECT_EQ("http://goo.gl", startup_pages[0]); |
| 843 EXPECT_EQ("http://foo.de", startup_pages[1]); | 833 EXPECT_EQ("http://foo.de", startup_pages[1]); |
| 844 } | 834 } |
| 845 | 835 |
| 846 TEST_F(ProfileResetterTest, CheckSnapshots) { | 836 TEST_F(ProfileResetterTest, CheckSnapshots) { |
| 847 ResettableSettingsSnapshot empty_snap(profile()); | 837 ResettableSettingsSnapshot empty_snap(profile()); |
| 848 EXPECT_EQ(0, empty_snap.FindDifferentFields(empty_snap)); | 838 EXPECT_EQ(0, empty_snap.FindDifferentFields(empty_snap)); |
| 849 | 839 |
| 850 scoped_refptr<Extension> ext = CreateExtension( | 840 scoped_refptr<Extension> ext = CreateExtension( |
| 851 base::ASCIIToUTF16("example"), | 841 base::ASCIIToUTF16("example"), |
| 852 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 842 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), Manifest::UNPACKED, |
| 853 Manifest::INVALID_LOCATION, | 843 extensions::Manifest::TYPE_EXTENSION, false); |
| 854 extensions::Manifest::TYPE_EXTENSION, | |
| 855 false); | |
| 856 ASSERT_TRUE(ext.get()); | 844 ASSERT_TRUE(ext.get()); |
| 857 service_->AddExtension(ext.get()); | 845 service_->AddExtension(ext.get()); |
| 858 | 846 |
| 859 std::string master_prefs(kDistributionConfig); | 847 std::string master_prefs(kDistributionConfig); |
| 860 std::string ext_id = ext->id(); | 848 std::string ext_id = ext->id(); |
| 861 ReplaceString(&master_prefs, "placeholder_for_id", ext_id); | 849 ReplaceString(&master_prefs, "placeholder_for_id", ext_id); |
| 862 | 850 |
| 863 // Reset to non organic defaults. | 851 // Reset to non organic defaults. |
| 864 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | | 852 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | |
| 865 ProfileResetter::HOMEPAGE | | 853 ProfileResetter::HOMEPAGE | |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 | 919 |
| 932 TEST_F(ProfileResetterTest, FeedbackSerializationAsProtoTest) { | 920 TEST_F(ProfileResetterTest, FeedbackSerializationAsProtoTest) { |
| 933 // Reset to non organic defaults. | 921 // Reset to non organic defaults. |
| 934 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | | 922 ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE | |
| 935 ProfileResetter::HOMEPAGE | | 923 ProfileResetter::HOMEPAGE | |
| 936 ProfileResetter::STARTUP_PAGES, | 924 ProfileResetter::STARTUP_PAGES, |
| 937 kDistributionConfig); | 925 kDistributionConfig); |
| 938 | 926 |
| 939 scoped_refptr<Extension> ext = CreateExtension( | 927 scoped_refptr<Extension> ext = CreateExtension( |
| 940 base::ASCIIToUTF16("example"), | 928 base::ASCIIToUTF16("example"), |
| 941 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 929 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), Manifest::UNPACKED, |
| 942 Manifest::INVALID_LOCATION, | 930 extensions::Manifest::TYPE_EXTENSION, false); |
| 943 extensions::Manifest::TYPE_EXTENSION, | |
| 944 false); | |
| 945 ASSERT_TRUE(ext.get()); | 931 ASSERT_TRUE(ext.get()); |
| 946 service_->AddExtension(ext.get()); | 932 service_->AddExtension(ext.get()); |
| 947 | 933 |
| 948 ShortcutHandler shortcut; | 934 ShortcutHandler shortcut; |
| 949 ShortcutCommand command_line = shortcut.CreateWithArguments( | 935 ShortcutCommand command_line = shortcut.CreateWithArguments( |
| 950 base::ASCIIToUTF16("chrome.lnk"), | 936 base::ASCIIToUTF16("chrome.lnk"), |
| 951 base::ASCIIToUTF16("--profile-directory=Default foo.com")); | 937 base::ASCIIToUTF16("--profile-directory=Default foo.com")); |
| 952 | 938 |
| 953 ResettableSettingsSnapshot nonorganic_snap(profile()); | 939 ResettableSettingsSnapshot nonorganic_snap(profile()); |
| 954 nonorganic_snap.RequestShortcuts(base::Closure()); | 940 nonorganic_snap.RequestShortcuts(base::Closure()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 981 |
| 996 MOCK_METHOD0(OnUpdatedList, void(void)); | 982 MOCK_METHOD0(OnUpdatedList, void(void)); |
| 997 | 983 |
| 998 std::unique_ptr<base::ListValue> list_; | 984 std::unique_ptr<base::ListValue> list_; |
| 999 }; | 985 }; |
| 1000 | 986 |
| 1001 // Make sure GetReadableFeedback handles non-ascii letters. | 987 // Make sure GetReadableFeedback handles non-ascii letters. |
| 1002 TEST_F(ProfileResetterTest, GetReadableFeedback) { | 988 TEST_F(ProfileResetterTest, GetReadableFeedback) { |
| 1003 scoped_refptr<Extension> ext = CreateExtension( | 989 scoped_refptr<Extension> ext = CreateExtension( |
| 1004 base::WideToUTF16(L"Tiësto"), | 990 base::WideToUTF16(L"Tiësto"), |
| 1005 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 991 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), Manifest::UNPACKED, |
| 1006 Manifest::INVALID_LOCATION, | 992 extensions::Manifest::TYPE_EXTENSION, false); |
| 1007 extensions::Manifest::TYPE_EXTENSION, | |
| 1008 false); | |
| 1009 ASSERT_TRUE(ext.get()); | 993 ASSERT_TRUE(ext.get()); |
| 1010 service_->AddExtension(ext.get()); | 994 service_->AddExtension(ext.get()); |
| 1011 | 995 |
| 1012 PrefService* prefs = profile()->GetPrefs(); | 996 PrefService* prefs = profile()->GetPrefs(); |
| 1013 DCHECK(prefs); | 997 DCHECK(prefs); |
| 1014 // The URL is "http://россия.рф". | 998 // The URL is "http://россия.рф". |
| 1015 std::wstring url(L"http://" | 999 std::wstring url(L"http://" |
| 1016 L"\u0440\u043e\u0441\u0441\u0438\u044f.\u0440\u0444"); | 1000 L"\u0440\u043e\u0441\u0441\u0438\u044f.\u0440\u0444"); |
| 1017 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); | 1001 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); |
| 1018 prefs->SetString(prefs::kHomePage, base::WideToUTF8(url)); | 1002 prefs->SetString(prefs::kHomePage, base::WideToUTF8(url)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 new ResettableSettingsSnapshot(profile())); | 1054 new ResettableSettingsSnapshot(profile())); |
| 1071 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, | 1055 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, |
| 1072 base::Unretained(&capture))); | 1056 base::Unretained(&capture))); |
| 1073 deleted_snapshot.reset(); | 1057 deleted_snapshot.reset(); |
| 1074 // Running remaining tasks shouldn't trigger the callback to be called as | 1058 // Running remaining tasks shouldn't trigger the callback to be called as |
| 1075 // |deleted_snapshot| was deleted before it could run. | 1059 // |deleted_snapshot| was deleted before it could run. |
| 1076 base::RunLoop().RunUntilIdle(); | 1060 base::RunLoop().RunUntilIdle(); |
| 1077 } | 1061 } |
| 1078 | 1062 |
| 1079 } // namespace | 1063 } // namespace |
| OLD | NEW |