OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 9 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" | 10 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 bool expect_clear_link, | 40 bool expect_clear_link, |
41 bool expect_reload_hint) { | 41 bool expect_reload_hint) { |
42 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 42 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
43 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 43 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
44 NULL, web_contents(), profile(), | 44 NULL, web_contents(), profile(), |
45 CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 45 CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
46 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 46 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
47 content_setting_bubble_model->bubble_content(); | 47 content_setting_bubble_model->bubble_content(); |
48 EXPECT_TRUE(bubble_content.title.empty()); | 48 EXPECT_TRUE(bubble_content.title.empty()); |
49 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); | 49 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); |
50 EXPECT_TRUE(bubble_content.popup_items.empty()); | 50 EXPECT_TRUE(bubble_content.list_items.empty()); |
51 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); | 51 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); |
52 EXPECT_NE(expect_clear_link || expect_reload_hint, | 52 EXPECT_NE(expect_clear_link || expect_reload_hint, |
53 bubble_content.custom_link.empty()); | 53 bubble_content.custom_link.empty()); |
54 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); | 54 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); |
55 EXPECT_FALSE(bubble_content.manage_link.empty()); | 55 EXPECT_FALSE(bubble_content.manage_link.empty()); |
56 } | 56 } |
57 | 57 |
58 std::string GetDefaultAudioDevice() { | 58 std::string GetDefaultAudioDevice() { |
59 PrefService* prefs = profile()->GetPrefs(); | 59 PrefService* prefs = profile()->GetPrefs(); |
60 return prefs->GetString(prefs::kDefaultAudioCaptureDevice); | 60 return prefs->GetString(prefs::kDefaultAudioCaptureDevice); |
(...skipping 28 matching lines...) Expand all Loading... |
89 TabSpecificContentSettings::FromWebContents(web_contents()); | 89 TabSpecificContentSettings::FromWebContents(web_contents()); |
90 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); | 90 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES); |
91 | 91 |
92 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 92 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
93 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 93 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
94 NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES)); | 94 NULL, web_contents(), profile(), CONTENT_SETTINGS_TYPE_COOKIES)); |
95 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 95 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
96 content_setting_bubble_model->bubble_content(); | 96 content_setting_bubble_model->bubble_content(); |
97 std::string title = bubble_content.title; | 97 std::string title = bubble_content.title; |
98 EXPECT_FALSE(title.empty()); | 98 EXPECT_FALSE(title.empty()); |
99 EXPECT_TRUE(bubble_content.plugin_names.empty()); | |
100 ASSERT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 99 ASSERT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
101 std::string radio1 = bubble_content.radio_group.radio_items[0]; | 100 std::string radio1 = bubble_content.radio_group.radio_items[0]; |
102 std::string radio2 = bubble_content.radio_group.radio_items[1]; | 101 std::string radio2 = bubble_content.radio_group.radio_items[1]; |
103 EXPECT_FALSE(bubble_content.custom_link.empty()); | 102 EXPECT_FALSE(bubble_content.custom_link.empty()); |
104 EXPECT_TRUE(bubble_content.custom_link_enabled); | 103 EXPECT_TRUE(bubble_content.custom_link_enabled); |
105 EXPECT_FALSE(bubble_content.manage_link.empty()); | 104 EXPECT_FALSE(bubble_content.manage_link.empty()); |
106 | 105 |
107 content_settings->ClearCookieSpecificContentSettings(); | 106 content_settings->ClearCookieSpecificContentSettings(); |
108 content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); | 107 content_settings->OnContentAllowed(CONTENT_SETTINGS_TYPE_COOKIES); |
109 content_setting_bubble_model.reset( | 108 content_setting_bubble_model.reset( |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 content_settings->OnContentBlockedWithDetail(CONTENT_SETTINGS_TYPE_PLUGINS, | 734 content_settings->OnContentBlockedWithDetail(CONTENT_SETTINGS_TYPE_PLUGINS, |
736 plugin_name); | 735 plugin_name); |
737 | 736 |
738 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 737 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
739 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 738 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
740 NULL, web_contents(), profile(), | 739 NULL, web_contents(), profile(), |
741 CONTENT_SETTINGS_TYPE_PLUGINS)); | 740 CONTENT_SETTINGS_TYPE_PLUGINS)); |
742 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 741 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
743 content_setting_bubble_model->bubble_content(); | 742 content_setting_bubble_model->bubble_content(); |
744 EXPECT_FALSE(bubble_content.title.empty()); | 743 EXPECT_FALSE(bubble_content.title.empty()); |
745 EXPECT_FALSE(bubble_content.plugin_names.empty()); | 744 ASSERT_EQ(1U, bubble_content.list_items.size()); |
746 EXPECT_NE(base::string16::npos, | 745 EXPECT_EQ(plugin_name, |
747 bubble_content.plugin_names.find(plugin_name)); | 746 base::ASCIIToUTF16(bubble_content.list_items[0].title)); |
748 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 747 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
749 EXPECT_FALSE(bubble_content.custom_link.empty()); | 748 EXPECT_FALSE(bubble_content.custom_link.empty()); |
750 EXPECT_TRUE(bubble_content.custom_link_enabled); | 749 EXPECT_TRUE(bubble_content.custom_link_enabled); |
751 EXPECT_FALSE(bubble_content.manage_link.empty()); | 750 EXPECT_FALSE(bubble_content.manage_link.empty()); |
752 EXPECT_FALSE(bubble_content.learn_more_link.empty()); | 751 EXPECT_FALSE(bubble_content.learn_more_link.empty()); |
753 } | 752 } |
754 | 753 |
755 TEST_F(ContentSettingBubbleModelTest, PepperBroker) { | 754 TEST_F(ContentSettingBubbleModelTest, PepperBroker) { |
756 TabSpecificContentSettings* content_settings = | 755 TabSpecificContentSettings* content_settings = |
757 TabSpecificContentSettings::FromWebContents(web_contents()); | 756 TabSpecificContentSettings::FromWebContents(web_contents()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { | 845 TEST_F(ContentSettingBubbleModelTest, RegisterProtocolHandler) { |
847 const GURL page_url("http://toplevel.example/"); | 846 const GURL page_url("http://toplevel.example/"); |
848 NavigateAndCommit(page_url); | 847 NavigateAndCommit(page_url); |
849 TabSpecificContentSettings* content_settings = | 848 TabSpecificContentSettings* content_settings = |
850 TabSpecificContentSettings::FromWebContents(web_contents()); | 849 TabSpecificContentSettings::FromWebContents(web_contents()); |
851 content_settings->set_pending_protocol_handler( | 850 content_settings->set_pending_protocol_handler( |
852 ProtocolHandler::CreateProtocolHandler( | 851 ProtocolHandler::CreateProtocolHandler( |
853 "mailto", GURL("http://www.toplevel.example/"))); | 852 "mailto", GURL("http://www.toplevel.example/"))); |
854 | 853 |
855 ContentSettingRPHBubbleModel content_setting_bubble_model( | 854 ContentSettingRPHBubbleModel content_setting_bubble_model( |
856 NULL, web_contents(), profile(), NULL, | 855 NULL, web_contents(), profile(), NULL); |
857 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | |
858 | 856 |
859 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 857 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
860 content_setting_bubble_model.bubble_content(); | 858 content_setting_bubble_model.bubble_content(); |
861 EXPECT_FALSE(bubble_content.title.empty()); | 859 EXPECT_FALSE(bubble_content.title.empty()); |
862 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); | 860 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); |
863 EXPECT_TRUE(bubble_content.popup_items.empty()); | 861 EXPECT_TRUE(bubble_content.list_items.empty()); |
864 EXPECT_TRUE(bubble_content.domain_lists.empty()); | 862 EXPECT_TRUE(bubble_content.domain_lists.empty()); |
865 EXPECT_TRUE(bubble_content.custom_link.empty()); | 863 EXPECT_TRUE(bubble_content.custom_link.empty()); |
866 EXPECT_FALSE(bubble_content.custom_link_enabled); | 864 EXPECT_FALSE(bubble_content.custom_link_enabled); |
867 EXPECT_FALSE(bubble_content.manage_link.empty()); | 865 EXPECT_FALSE(bubble_content.manage_link.empty()); |
868 } | 866 } |
869 | 867 |
870 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { | 868 class FakeDelegate : public ProtocolHandlerRegistry::Delegate { |
871 public: | 869 public: |
872 void RegisterExternalHandler(const std::string& protocol) override { | 870 void RegisterExternalHandler(const std::string& protocol) override { |
873 // Overrides in order to not register the handler with the | 871 // Overrides in order to not register the handler with the |
(...skipping 26 matching lines...) Expand all Loading... |
900 | 898 |
901 const GURL page_url("http://toplevel.example/"); | 899 const GURL page_url("http://toplevel.example/"); |
902 NavigateAndCommit(page_url); | 900 NavigateAndCommit(page_url); |
903 TabSpecificContentSettings* content_settings = | 901 TabSpecificContentSettings* content_settings = |
904 TabSpecificContentSettings::FromWebContents(web_contents()); | 902 TabSpecificContentSettings::FromWebContents(web_contents()); |
905 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( | 903 ProtocolHandler test_handler = ProtocolHandler::CreateProtocolHandler( |
906 "mailto", GURL("http://www.toplevel.example/")); | 904 "mailto", GURL("http://www.toplevel.example/")); |
907 content_settings->set_pending_protocol_handler(test_handler); | 905 content_settings->set_pending_protocol_handler(test_handler); |
908 | 906 |
909 ContentSettingRPHBubbleModel content_setting_bubble_model( | 907 ContentSettingRPHBubbleModel content_setting_bubble_model( |
910 NULL, web_contents(), profile(), ®istry, | 908 NULL, web_contents(), profile(), ®istry); |
911 CONTENT_SETTINGS_TYPE_PROTOCOL_HANDLERS); | |
912 | 909 |
913 { | 910 { |
914 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 911 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
915 EXPECT_TRUE(handler.IsEmpty()); | 912 EXPECT_TRUE(handler.IsEmpty()); |
916 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 913 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
917 content_settings->pending_protocol_handler_setting()); | 914 content_settings->pending_protocol_handler_setting()); |
918 } | 915 } |
919 | 916 |
920 // "0" is the "Allow" radio button. | 917 // "0" is the "Allow" radio button. |
921 content_setting_bubble_model.OnRadioClicked(0); | 918 content_setting_bubble_model.OnRadioClicked(0); |
(...skipping 28 matching lines...) Expand all Loading... |
950 { | 947 { |
951 ProtocolHandler handler = registry.GetHandlerFor("mailto"); | 948 ProtocolHandler handler = registry.GetHandlerFor("mailto"); |
952 ASSERT_FALSE(handler.IsEmpty()); | 949 ASSERT_FALSE(handler.IsEmpty()); |
953 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 950 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
954 content_settings->pending_protocol_handler_setting()); | 951 content_settings->pending_protocol_handler_setting()); |
955 EXPECT_FALSE(registry.IsIgnored(test_handler)); | 952 EXPECT_FALSE(registry.IsIgnored(test_handler)); |
956 } | 953 } |
957 | 954 |
958 registry.Shutdown(); | 955 registry.Shutdown(); |
959 } | 956 } |
OLD | NEW |