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

Side by Side Diff: chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc

Issue 7892007: Add ChromeRenderViewHostTestHarness to get rid of the dependency from RVHTH to profile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/host_content_settings_map.h" 7 #include "chrome/browser/content_settings/host_content_settings_map.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" 10 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
15 #include "content/browser/browser_thread.h" 15 #include "content/browser/browser_thread.h"
16 #include "content/browser/tab_contents/test_tab_contents.h" 16 #include "content/browser/tab_contents/test_tab_contents.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 class ContentSettingBubbleModelTest : public TabContentsWrapperTestHarness { 19 class ContentSettingBubbleModelTest : public TabContentsWrapperTestHarness {
20 protected: 20 protected:
21 ContentSettingBubbleModelTest() 21 ContentSettingBubbleModelTest()
22 : ui_thread_(BrowserThread::UI, MessageLoop::current()) { 22 : ui_thread_(BrowserThread::UI, MessageLoop::current()) {
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 NULL, contents_wrapper(), profile_.get(), 30 NULL, contents_wrapper(), profile(),
31 CONTENT_SETTINGS_TYPE_GEOLOCATION)); 31 CONTENT_SETTINGS_TYPE_GEOLOCATION));
32 const ContentSettingBubbleModel::BubbleContent& bubble_content = 32 const ContentSettingBubbleModel::BubbleContent& bubble_content =
33 content_setting_bubble_model->bubble_content(); 33 content_setting_bubble_model->bubble_content();
34 EXPECT_TRUE(bubble_content.title.empty()); 34 EXPECT_TRUE(bubble_content.title.empty());
35 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty()); 35 EXPECT_TRUE(bubble_content.radio_group.radio_items.empty());
36 EXPECT_TRUE(bubble_content.popup_items.empty()); 36 EXPECT_TRUE(bubble_content.popup_items.empty());
37 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size()); 37 EXPECT_EQ(expected_domains, bubble_content.domain_lists.size());
38 EXPECT_NE(expect_clear_link || expect_reload_hint, 38 EXPECT_NE(expect_clear_link || expect_reload_hint,
39 bubble_content.custom_link.empty()); 39 bubble_content.custom_link.empty());
40 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled); 40 EXPECT_EQ(expect_clear_link, bubble_content.custom_link_enabled);
41 EXPECT_FALSE(bubble_content.manage_link.empty()); 41 EXPECT_FALSE(bubble_content.manage_link.empty());
42 } 42 }
43 43
44 BrowserThread ui_thread_; 44 BrowserThread ui_thread_;
45 }; 45 };
46 46
47 TEST_F(ContentSettingBubbleModelTest, ImageRadios) { 47 TEST_F(ContentSettingBubbleModelTest, ImageRadios) {
48 TabSpecificContentSettings* content_settings = 48 TabSpecificContentSettings* content_settings =
49 contents_wrapper()->content_settings(); 49 contents_wrapper()->content_settings();
50 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES, 50 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES,
51 std::string()); 51 std::string());
52 52
53 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 53 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
54 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 54 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
55 NULL, contents_wrapper(), profile_.get(), 55 NULL, contents_wrapper(), profile(),
56 CONTENT_SETTINGS_TYPE_IMAGES)); 56 CONTENT_SETTINGS_TYPE_IMAGES));
57 const ContentSettingBubbleModel::BubbleContent& bubble_content = 57 const ContentSettingBubbleModel::BubbleContent& bubble_content =
58 content_setting_bubble_model->bubble_content(); 58 content_setting_bubble_model->bubble_content();
59 EXPECT_FALSE(bubble_content.title.empty()); 59 EXPECT_FALSE(bubble_content.title.empty());
60 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 60 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
61 EXPECT_EQ(0, bubble_content.radio_group.default_item); 61 EXPECT_EQ(0, bubble_content.radio_group.default_item);
62 EXPECT_TRUE(bubble_content.custom_link.empty()); 62 EXPECT_TRUE(bubble_content.custom_link.empty());
63 EXPECT_FALSE(bubble_content.manage_link.empty()); 63 EXPECT_FALSE(bubble_content.manage_link.empty());
64 } 64 }
65 65
66 TEST_F(ContentSettingBubbleModelTest, Cookies) { 66 TEST_F(ContentSettingBubbleModelTest, Cookies) {
67 TabSpecificContentSettings* content_settings = 67 TabSpecificContentSettings* content_settings =
68 contents_wrapper()->content_settings(); 68 contents_wrapper()->content_settings();
69 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, 69 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES,
70 std::string()); 70 std::string());
71 71
72 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 72 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
73 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 73 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
74 NULL, contents_wrapper(), profile_.get(), 74 NULL, contents_wrapper(), profile(),
75 CONTENT_SETTINGS_TYPE_COOKIES)); 75 CONTENT_SETTINGS_TYPE_COOKIES));
76 const ContentSettingBubbleModel::BubbleContent& bubble_content = 76 const ContentSettingBubbleModel::BubbleContent& bubble_content =
77 content_setting_bubble_model->bubble_content(); 77 content_setting_bubble_model->bubble_content();
78 EXPECT_FALSE(bubble_content.title.empty()); 78 EXPECT_FALSE(bubble_content.title.empty());
79 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty()); 79 EXPECT_FALSE(bubble_content.radio_group.radio_items.empty());
80 EXPECT_FALSE(bubble_content.custom_link.empty()); 80 EXPECT_FALSE(bubble_content.custom_link.empty());
81 EXPECT_TRUE(bubble_content.custom_link_enabled); 81 EXPECT_TRUE(bubble_content.custom_link_enabled);
82 EXPECT_FALSE(bubble_content.manage_link.empty()); 82 EXPECT_FALSE(bubble_content.manage_link.empty());
83 } 83 }
84 84
85 TEST_F(ContentSettingBubbleModelTest, Plugins) { 85 TEST_F(ContentSettingBubbleModelTest, Plugins) {
86 TabSpecificContentSettings* content_settings = 86 TabSpecificContentSettings* content_settings =
87 contents_wrapper()->content_settings(); 87 contents_wrapper()->content_settings();
88 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 88 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
89 std::string()); 89 std::string());
90 90
91 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 91 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
92 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 92 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
93 NULL, contents_wrapper(), profile_.get(), 93 NULL, contents_wrapper(), profile(),
94 CONTENT_SETTINGS_TYPE_PLUGINS)); 94 CONTENT_SETTINGS_TYPE_PLUGINS));
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 EXPECT_FALSE(bubble_content.title.empty()); 97 EXPECT_FALSE(bubble_content.title.empty());
98 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 98 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
99 EXPECT_FALSE(bubble_content.custom_link.empty()); 99 EXPECT_FALSE(bubble_content.custom_link.empty());
100 EXPECT_TRUE(bubble_content.custom_link_enabled); 100 EXPECT_TRUE(bubble_content.custom_link_enabled);
101 EXPECT_FALSE(bubble_content.manage_link.empty()); 101 EXPECT_FALSE(bubble_content.manage_link.empty());
102 } 102 }
103 103
104 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) { 104 TEST_F(ContentSettingBubbleModelTest, MultiplePlugins) {
105 CommandLine* cmd = CommandLine::ForCurrentProcess(); 105 CommandLine* cmd = CommandLine::ForCurrentProcess();
106 AutoReset<CommandLine> auto_reset(cmd, *cmd); 106 AutoReset<CommandLine> auto_reset(cmd, *cmd);
107 cmd->AppendSwitch(switches::kEnableResourceContentSettings); 107 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
108 cmd->AppendSwitch(switches::kEnableClickToPlay); 108 cmd->AppendSwitch(switches::kEnableClickToPlay);
109 109
110 HostContentSettingsMap* map = profile_->GetHostContentSettingsMap(); 110 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap();
111 std::string fooPlugin = "foo"; 111 std::string fooPlugin = "foo";
112 std::string barPlugin = "bar"; 112 std::string barPlugin = "bar";
113 113
114 // Navigating to some sample url prevents the GetURL method from returning an 114 // Navigating to some sample url prevents the GetURL method from returning an
115 // invalid empty URL. 115 // invalid empty URL.
116 contents()->NavigateAndCommit(GURL("http://www.example.com")); 116 contents()->NavigateAndCommit(GURL("http://www.example.com"));
117 GURL url = contents()->GetURL(); 117 GURL url = contents()->GetURL();
118 map->AddExceptionForURL(url, 118 map->AddExceptionForURL(url,
119 url, 119 url,
120 CONTENT_SETTINGS_TYPE_PLUGINS, 120 CONTENT_SETTINGS_TYPE_PLUGINS,
121 fooPlugin, 121 fooPlugin,
122 CONTENT_SETTING_ALLOW); 122 CONTENT_SETTING_ALLOW);
123 map->AddExceptionForURL(url, 123 map->AddExceptionForURL(url,
124 url, 124 url,
125 CONTENT_SETTINGS_TYPE_PLUGINS, 125 CONTENT_SETTINGS_TYPE_PLUGINS,
126 barPlugin, 126 barPlugin,
127 CONTENT_SETTING_ASK); 127 CONTENT_SETTING_ASK);
128 128
129 TabSpecificContentSettings* content_settings = 129 TabSpecificContentSettings* content_settings =
130 contents_wrapper()->content_settings(); 130 contents_wrapper()->content_settings();
131 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 131 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
132 fooPlugin); 132 fooPlugin);
133 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS, 133 content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_PLUGINS,
134 barPlugin); 134 barPlugin);
135 135
136 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 136 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
137 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 137 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
138 NULL, contents_wrapper(), profile_.get(), 138 NULL, contents_wrapper(), profile(),
139 CONTENT_SETTINGS_TYPE_PLUGINS)); 139 CONTENT_SETTINGS_TYPE_PLUGINS));
140 const ContentSettingBubbleModel::BubbleContent& bubble_content = 140 const ContentSettingBubbleModel::BubbleContent& bubble_content =
141 content_setting_bubble_model->bubble_content(); 141 content_setting_bubble_model->bubble_content();
142 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size()); 142 EXPECT_EQ(2U, bubble_content.radio_group.radio_items.size());
143 EXPECT_EQ(1, bubble_content.radio_group.default_item); 143 EXPECT_EQ(1, bubble_content.radio_group.default_item);
144 144
145 content_setting_bubble_model->OnRadioClicked(0); 145 content_setting_bubble_model->OnRadioClicked(0);
146 // Nothing should have changed. 146 // Nothing should have changed.
147 EXPECT_EQ(CONTENT_SETTING_ALLOW, 147 EXPECT_EQ(CONTENT_SETTING_ALLOW,
148 map->GetContentSetting(url, 148 map->GetContentSetting(url,
(...skipping 28 matching lines...) Expand all
177 NavigateAndCommit(page_url); 177 NavigateAndCommit(page_url);
178 TabSpecificContentSettings* content_settings = 178 TabSpecificContentSettings* content_settings =
179 contents_wrapper()->content_settings(); 179 contents_wrapper()->content_settings();
180 180
181 // One permitted frame, but not in the content map: requires reload. 181 // One permitted frame, but not in the content map: requires reload.
182 content_settings->OnGeolocationPermissionSet(frame1_url, true); 182 content_settings->OnGeolocationPermissionSet(frame1_url, true);
183 CheckGeolocationBubble(1, false, true); 183 CheckGeolocationBubble(1, false, true);
184 184
185 // Add it to the content map, should now have a clear link. 185 // Add it to the content map, should now have a clear link.
186 HostContentSettingsMap* setting_map = 186 HostContentSettingsMap* setting_map =
187 profile_->GetHostContentSettingsMap(); 187 profile()->GetHostContentSettingsMap();
188 setting_map->SetContentSetting( 188 setting_map->SetContentSetting(
189 ContentSettingsPattern::FromURLNoWildcard(frame1_url), 189 ContentSettingsPattern::FromURLNoWildcard(frame1_url),
190 ContentSettingsPattern::FromURLNoWildcard(page_url), 190 ContentSettingsPattern::FromURLNoWildcard(page_url),
191 CONTENT_SETTINGS_TYPE_GEOLOCATION, 191 CONTENT_SETTINGS_TYPE_GEOLOCATION,
192 std::string(), 192 std::string(),
193 CONTENT_SETTING_ALLOW); 193 CONTENT_SETTING_ALLOW);
194 CheckGeolocationBubble(1, true, false); 194 CheckGeolocationBubble(1, true, false);
195 195
196 // Change the default to allow: no message needed. 196 // Change the default to allow: no message needed.
197 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 197 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
198 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); 198 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
199 CheckGeolocationBubble(1, false, false); 199 CheckGeolocationBubble(1, false, false);
200 200
201 // Second frame denied, but not stored in the content map: requires reload. 201 // Second frame denied, but not stored in the content map: requires reload.
202 content_settings->OnGeolocationPermissionSet(frame2_url, false); 202 content_settings->OnGeolocationPermissionSet(frame2_url, false);
203 CheckGeolocationBubble(2, false, true); 203 CheckGeolocationBubble(2, false, true);
204 204
205 // Change the default to block: offer a clear link for the persisted frame 1. 205 // Change the default to block: offer a clear link for the persisted frame 1.
206 profile_->GetHostContentSettingsMap()->SetDefaultContentSetting( 206 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting(
207 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK); 207 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
208 CheckGeolocationBubble(2, true, false); 208 CheckGeolocationBubble(2, true, false);
209 } 209 }
210 210
211 TEST_F(ContentSettingBubbleModelTest, FileURL) { 211 TEST_F(ContentSettingBubbleModelTest, FileURL) {
212 std::string file_url("file:///tmp/test.html"); 212 std::string file_url("file:///tmp/test.html");
213 NavigateAndCommit(GURL(file_url)); 213 NavigateAndCommit(GURL(file_url));
214 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model( 214 scoped_ptr<ContentSettingBubbleModel> content_setting_bubble_model(
215 ContentSettingBubbleModel::CreateContentSettingBubbleModel( 215 ContentSettingBubbleModel::CreateContentSettingBubbleModel(
216 NULL, contents_wrapper(), profile_.get(), 216 NULL, contents_wrapper(), profile(),
217 CONTENT_SETTINGS_TYPE_IMAGES)); 217 CONTENT_SETTINGS_TYPE_IMAGES));
218 std::string title = 218 std::string title =
219 content_setting_bubble_model->bubble_content().radio_group.radio_items[0]; 219 content_setting_bubble_model->bubble_content().radio_group.radio_items[0];
220 ASSERT_NE(std::string::npos, title.find(file_url)); 220 ASSERT_NE(std::string::npos, title.find(file_url));
221 } 221 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698