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 "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/scoped_path_override.h" | 10 #include "base/test/scoped_path_override.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/browser/webdata/web_data_service_factory.h" | 23 #include "chrome/browser/webdata/web_data_service_factory.h" |
24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
25 #include "chrome/test/base/browser_with_test_window_test.h" | 25 #include "chrome/test/base/browser_with_test_window_test.h" |
26 #include "components/content_settings/core/browser/host_content_settings_map.h" | 26 #include "components/content_settings/core/browser/host_content_settings_map.h" |
27 #include "components/google/core/browser/google_pref_names.h" | 27 #include "components/google/core/browser/google_pref_names.h" |
28 #include "components/search_engines/template_url_service.h" | 28 #include "components/search_engines/template_url_service.h" |
29 #include "components/search_engines/template_url_service_client.h" | 29 #include "components/search_engines/template_url_service_client.h" |
30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
31 #include "content/public/test/test_browser_thread.h" | 31 #include "content/public/test/test_browser_thread.h" |
| 32 #include "extensions/browser/extension_registry.h" |
32 #include "extensions/common/extension.h" | 33 #include "extensions/common/extension.h" |
33 #include "extensions/common/manifest_constants.h" | 34 #include "extensions/common/manifest_constants.h" |
34 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
35 #include "net/http/http_status_code.h" | 36 #include "net/http/http_status_code.h" |
36 #include "net/url_request/test_url_fetcher_factory.h" | 37 #include "net/url_request/test_url_fetcher_factory.h" |
37 #include "net/url_request/url_request_status.h" | 38 #include "net/url_request/url_request_status.h" |
38 #include "url/gurl.h" | 39 #include "url/gurl.h" |
39 | 40 |
40 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
41 #include "base/files/file_util.h" | 42 #include "base/files/file_util.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 extensions::Manifest::TYPE_EXTENSION, | 622 extensions::Manifest::TYPE_EXTENSION, |
622 false); | 623 false); |
623 service_->AddExtension(ext5.get()); | 624 service_->AddExtension(ext5.get()); |
624 scoped_refptr<Extension> ext6 = CreateExtension( | 625 scoped_refptr<Extension> ext6 = CreateExtension( |
625 base::ASCIIToUTF16("example6"), | 626 base::ASCIIToUTF16("example6"), |
626 base::FilePath(FILE_PATH_LITERAL("//nonexistent5")), | 627 base::FilePath(FILE_PATH_LITERAL("//nonexistent5")), |
627 Manifest::EXTERNAL_POLICY, | 628 Manifest::EXTERNAL_POLICY, |
628 extensions::Manifest::TYPE_EXTENSION, | 629 extensions::Manifest::TYPE_EXTENSION, |
629 false); | 630 false); |
630 service_->AddExtension(ext6.get()); | 631 service_->AddExtension(ext6.get()); |
631 EXPECT_EQ(6u, service_->extensions()->size()); | 632 EXPECT_EQ(6u, registry()->enabled_extensions().size()); |
632 | 633 |
633 ResetAndWait(ProfileResetter::EXTENSIONS); | 634 ResetAndWait(ProfileResetter::EXTENSIONS); |
634 EXPECT_EQ(4u, service_->extensions()->size()); | 635 EXPECT_EQ(4u, registry()->enabled_extensions().size()); |
635 EXPECT_FALSE(service_->extensions()->Contains(theme->id())); | 636 EXPECT_FALSE(registry()->enabled_extensions().Contains(theme->id())); |
636 EXPECT_FALSE(service_->extensions()->Contains(ext2->id())); | 637 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext2->id())); |
637 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); | 638 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
638 EXPECT_TRUE(service_->extensions()->Contains(ext4->id())); | 639 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext4->id())); |
639 EXPECT_TRUE(service_->extensions()->Contains(ext5->id())); | 640 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext5->id())); |
640 EXPECT_TRUE(service_->extensions()->Contains(ext6->id())); | 641 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext6->id())); |
641 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 642 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
642 } | 643 } |
643 | 644 |
644 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { | 645 TEST_F(ProfileResetterTest, ResetExtensionsByDisablingNonOrganic) { |
645 scoped_refptr<Extension> ext2 = CreateExtension( | 646 scoped_refptr<Extension> ext2 = CreateExtension( |
646 base::ASCIIToUTF16("example2"), | 647 base::ASCIIToUTF16("example2"), |
647 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 648 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
648 Manifest::INVALID_LOCATION, | 649 Manifest::INVALID_LOCATION, |
649 extensions::Manifest::TYPE_EXTENSION, | 650 extensions::Manifest::TYPE_EXTENSION, |
650 false); | 651 false); |
651 service_->AddExtension(ext2.get()); | 652 service_->AddExtension(ext2.get()); |
652 // Components and external policy extensions shouldn't be deleted. | 653 // Components and external policy extensions shouldn't be deleted. |
653 scoped_refptr<Extension> ext3 = CreateExtension( | 654 scoped_refptr<Extension> ext3 = CreateExtension( |
654 base::ASCIIToUTF16("example3"), | 655 base::ASCIIToUTF16("example3"), |
655 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), | 656 base::FilePath(FILE_PATH_LITERAL("//nonexistent2")), |
656 Manifest::INVALID_LOCATION, | 657 Manifest::INVALID_LOCATION, |
657 extensions::Manifest::TYPE_EXTENSION, | 658 extensions::Manifest::TYPE_EXTENSION, |
658 false); | 659 false); |
659 service_->AddExtension(ext3.get()); | 660 service_->AddExtension(ext3.get()); |
660 EXPECT_EQ(2u, service_->extensions()->size()); | 661 EXPECT_EQ(2u, registry()->enabled_extensions().size()); |
661 | 662 |
662 std::string master_prefs(kDistributionConfig); | 663 std::string master_prefs(kDistributionConfig); |
663 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); | 664 ReplaceString(&master_prefs, "placeholder_for_id", ext3->id()); |
664 | 665 |
665 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); | 666 ResetAndWait(ProfileResetter::EXTENSIONS, master_prefs); |
666 | 667 |
667 EXPECT_EQ(1u, service_->extensions()->size()); | 668 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
668 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); | 669 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
669 } | 670 } |
670 | 671 |
671 TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) { | 672 TEST_F(ProfileResetterTest, ResetExtensionsAndDefaultApps) { |
672 service_->Init(); | 673 service_->Init(); |
673 | 674 |
674 base::ScopedTempDir temp_dir; | 675 base::ScopedTempDir temp_dir; |
675 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 676 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
676 | 677 |
677 scoped_refptr<Extension> ext1 = | 678 scoped_refptr<Extension> ext1 = |
678 CreateExtension(base::ASCIIToUTF16("example1"), | 679 CreateExtension(base::ASCIIToUTF16("example1"), |
(...skipping 17 matching lines...) Expand all Loading... |
696 false); | 697 false); |
697 service_->AddExtension(ext2.get()); | 698 service_->AddExtension(ext2.get()); |
698 | 699 |
699 scoped_refptr<Extension> ext3 = | 700 scoped_refptr<Extension> ext3 = |
700 CreateExtension(base::ASCIIToUTF16("example2"), | 701 CreateExtension(base::ASCIIToUTF16("example2"), |
701 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), | 702 base::FilePath(FILE_PATH_LITERAL("//nonexistent3")), |
702 Manifest::INVALID_LOCATION, | 703 Manifest::INVALID_LOCATION, |
703 extensions::Manifest::TYPE_HOSTED_APP, | 704 extensions::Manifest::TYPE_HOSTED_APP, |
704 true); | 705 true); |
705 service_->AddExtension(ext3.get()); | 706 service_->AddExtension(ext3.get()); |
706 EXPECT_EQ(3u, service_->extensions()->size()); | 707 EXPECT_EQ(3u, registry()->enabled_extensions().size()); |
707 | 708 |
708 ResetAndWait(ProfileResetter::EXTENSIONS); | 709 ResetAndWait(ProfileResetter::EXTENSIONS); |
709 | 710 |
710 EXPECT_EQ(1u, service_->extensions()->size()); | 711 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
711 EXPECT_FALSE(service_->extensions()->Contains(ext1->id())); | 712 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext1->id())); |
712 EXPECT_FALSE(service_->extensions()->Contains(ext2->id())); | 713 EXPECT_FALSE(registry()->enabled_extensions().Contains(ext2->id())); |
713 EXPECT_TRUE(service_->extensions()->Contains(ext3->id())); | 714 EXPECT_TRUE(registry()->enabled_extensions().Contains(ext3->id())); |
714 EXPECT_TRUE(theme_service->UsingDefaultTheme()); | 715 EXPECT_TRUE(theme_service->UsingDefaultTheme()); |
715 } | 716 } |
716 | 717 |
717 TEST_F(ProfileResetterTest, ResetStartPageNonOrganic) { | 718 TEST_F(ProfileResetterTest, ResetStartPageNonOrganic) { |
718 PrefService* prefs = profile()->GetPrefs(); | 719 PrefService* prefs = profile()->GetPrefs(); |
719 DCHECK(prefs); | 720 DCHECK(prefs); |
720 | 721 |
721 SessionStartupPref startup_pref(SessionStartupPref::LAST); | 722 SessionStartupPref startup_pref(SessionStartupPref::LAST); |
722 SessionStartupPref::SetStartupPref(prefs, startup_pref); | 723 SessionStartupPref::SetStartupPref(prefs, startup_pref); |
723 | 724 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 new ResettableSettingsSnapshot(profile())); | 1097 new ResettableSettingsSnapshot(profile())); |
1097 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, | 1098 deleted_snapshot->RequestShortcuts(base::Bind(&FeedbackCapture::Fail, |
1098 base::Unretained(&capture))); | 1099 base::Unretained(&capture))); |
1099 deleted_snapshot.reset(); | 1100 deleted_snapshot.reset(); |
1100 // Running remaining tasks shouldn't trigger the callback to be called as | 1101 // Running remaining tasks shouldn't trigger the callback to be called as |
1101 // |deleted_snapshot| was deleted before it could run. | 1102 // |deleted_snapshot| was deleted before it could run. |
1102 base::MessageLoop::current()->RunUntilIdle(); | 1103 base::MessageLoop::current()->RunUntilIdle(); |
1103 } | 1104 } |
1104 | 1105 |
1105 } // namespace | 1106 } // namespace |
OLD | NEW |