Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/content_setting_bubble_model.h" | 5 #include "chrome/browser/content_setting_bubble_model.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "chrome/browser/browser_thread.h" | 9 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 } | 23 } |
| 24 | 24 |
| 25 void CheckGeolocationBubble(size_t expected_domains, | 25 void CheckGeolocationBubble(size_t expected_domains, |
| 26 bool expect_clear_link, | 26 bool expect_clear_link, |
| 27 bool expect_reload_hint) { | 27 bool expect_reload_hint) { |
| 28 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 28 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 29 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 29 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 30 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 30 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 31 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 31 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 32 content_setting_bubble_model->bubble_content(); | 32 content_setting_bubble_model->bubble_content(); |
| 33 EXPECT_EQ(std::string(), bubble_content.title); | |
|
Peter Kasting
2010/12/09 17:56:34
Nit: Use EXPECT_TRUE(bubble_content.title.empty())
| |
| 33 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); | 34 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); |
|
Peter Kasting
2010/12/09 17:56:34
Nit: These can both be changed to EXPECT_TRUE(xxx.
| |
| 34 EXPECT_EQ(0U, bubble_content.popup_items.size()); | 35 EXPECT_EQ(0U, bubble_content.popup_items.size()); |
| 35 // The reload hint is currently implemented as a tacked on domain title, so | |
| 36 // account for this. | |
| 37 if (expect_reload_hint) | |
| 38 ++expected_domains; | |
| 39 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); | 36 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); |
| 40 if (expect_clear_link) | 37 if (expect_clear_link || expect_reload_hint) { |
|
Peter Kasting
2010/12/09 17:56:34
Nit: This conditional can just become:
EXPECT_N
| |
| 41 EXPECT_NE(std::string(), bubble_content.clear_link); | 38 EXPECT_NE(std::string(), bubble_content.custom_link); |
| 42 else | 39 else |
| 43 EXPECT_EQ(std::string(), bubble_content.clear_link); | 40 EXPECT_EQ(std::string(), bubble_content.custom_link); |
| 41 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); | |
| 44 EXPECT_NE(std::string(), bubble_content.manage_link); | 42 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 45 EXPECT_EQ(std::string(), bubble_content.info_link); | |
| 46 EXPECT_EQ(std::string(), bubble_content.title); | |
| 47 EXPECT_EQ(std::string(), bubble_content.load_plugins_link_title); | |
| 48 } | 43 } |
| 49 | 44 |
| 50 BrowserThread ui_thread_; | 45 BrowserThread ui_thread_; |
| 51 }; | 46 }; |
| 52 | 47 |
| 53 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { | 48 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { |
| 54 TabSpecificContentSettings* content_settings = | 49 TabSpecificContentSettings* content_settings = |
| 55 contents()->GetTabSpecificContentSettings(); | 50 contents()->GetTabSpecificContentSettings(); |
| 56 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, | 51 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, |
| 57 std::string()); | 52 std::string()); |
| 58 | 53 |
| 59 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 54 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 60 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 55 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 61 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); | 56 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_IMAGES)); |
| 62 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 57 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 63 content_setting_bubble_model->bubble_content(); | 58 content_setting_bubble_model->bubble_content(); |
| 59 EXPECT_NE(std::string(), bubble_content.title); | |
| 64 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 60 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 65 EXPECT_EQ(0, bubble_content.radio_group.default_item); | 61 EXPECT_EQ(0, bubble_content.radio_group.default_item); |
| 62 EXPECT_EQ(std::string(), bubble_content.custom_link); | |
| 63 EXPECT_FALSE(bubble_content.custom_link_enabled); | |
| 66 EXPECT_NE(std::string(), bubble_content.manage_link); | 64 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 67 EXPECT_EQ(std::string(), bubble_content.info_link); | |
| 68 EXPECT_NE(std::string(), bubble_content.title); | |
| 69 EXPECT_EQ(std::string(), bubble_content.load_plugins_link_title); | |
| 70 } | 65 } |
| 71 | 66 |
| 72 TEST_F(ContentSettingBubbleModelTest, Cookies) { | 67 TEST_F(ContentSettingBubbleModelTest, Cookies) { |
| 73 TabSpecificContentSettings* content_settings = | 68 TabSpecificContentSettings* content_settings = |
| 74 contents()->GetTabSpecificContentSettings(); | 69 contents()->GetTabSpecificContentSettings(); |
| 75 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, | 70 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, |
| 76 std::string()); | 71 std::string()); |
| 77 | 72 |
| 78 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 73 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 79 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 74 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 80 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES)); | 75 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_COOKIES)); |
| 81 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 76 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 82 content_setting_bubble_model->bubble_content(); | 77 content_setting_bubble_model->bubble_content(); |
| 78 EXPECT_NE(std::string(), bubble_content.title); | |
| 83 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); | 79 EXPECT_EQ(0U, bubble_content.radio_group.radio_items.size()); |
| 80 EXPECT_NE(std::string(), bubble_content.custom_link); | |
| 81 EXPECT_TRUE(bubble_content.custom_link_enabled); | |
| 84 EXPECT_NE(std::string(), bubble_content.manage_link); | 82 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 85 EXPECT_NE(std::string(), bubble_content.info_link); | |
| 86 EXPECT_NE(std::string(), bubble_content.title); | |
| 87 EXPECT_EQ(std::string(), bubble_content.load_plugins_link_title); | |
| 88 } | 83 } |
| 89 | 84 |
| 90 TEST_F(ContentSettingBubbleModelTest, Plugins) { | 85 TEST_F(ContentSettingBubbleModelTest, Plugins) { |
| 91 TabSpecificContentSettings* content_settings = | 86 TabSpecificContentSettings* content_settings = |
| 92 contents()->GetTabSpecificContentSettings(); | 87 contents()->GetTabSpecificContentSettings(); |
| 93 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, | 88 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 94 std::string()); | 89 std::string()); |
| 95 | 90 |
| 96 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( | 91 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( |
| 97 ContentSettingBubbleModel::CreateContentSettingBubbleModel( | 92 ContentSettingBubbleModel::CreateContentSettingBubbleModel( |
| 98 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS)); | 93 contents(), profile_.get(), CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 99 const ContentSettingBubbleModel::BubbleContent& bubble_content = | 94 const ContentSettingBubbleModel::BubbleContent& bubble_content = |
| 100 content_setting_bubble_model->bubble_content(); | 95 content_setting_bubble_model->bubble_content(); |
| 96 EXPECT_NE(std::string(), bubble_content.title); | |
| 101 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); | 97 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); |
| 98 EXPECT_EQ(std::string(), bubble_content.custom_link); | |
| 99 EXPECT_FALSE(bubble_content.custom_link_enabled); | |
| 102 EXPECT_NE(std::string(), bubble_content.manage_link); | 100 EXPECT_NE(std::string(), bubble_content.manage_link); |
| 103 EXPECT_EQ(std::string(), bubble_content.info_link); | |
| 104 EXPECT_NE(std::string(), bubble_content.title); | |
| 105 EXPECT_NE(std::string(), bubble_content.load_plugins_link_title); | |
| 106 } | 101 } |
| 107 | 102 |
| 108 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { | 103 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { |
| 109 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 104 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 110 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 105 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 111 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 106 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 112 cmd->AppendSwitch(switches::kEnableClickToPlay); | 107 cmd->AppendSwitch(switches::kEnableClickToPlay); |
| 113 | 108 |
| 114 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); | 109 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); |
| 115 std::string fooPlugin = "foo"; | 110 std::string fooPlugin = "foo"; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 CheckGeolocationBubble(1, false, false); | 181 CheckGeolocationBubble(1, false, false); |
| 187 | 182 |
| 188 // Second frame denied, but not stored in the content map: requires reload. | 183 // Second frame denied, but not stored in the content map: requires reload. |
| 189 content_settings->OnGeolocationPermissionSet(frame2_url, false); | 184 content_settings->OnGeolocationPermissionSet(frame2_url, false); |
| 190 CheckGeolocationBubble(2, false, true); | 185 CheckGeolocationBubble(2, false, true); |
| 191 | 186 |
| 192 // Change the default to block: offer a clear link for the persisted frame 1. | 187 // Change the default to block: offer a clear link for the persisted frame 1. |
| 193 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | 188 setting_map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); |
| 194 CheckGeolocationBubble(2, true, false); | 189 CheckGeolocationBubble(2, true, false); |
| 195 } | 190 } |
| OLD | NEW |