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

Side by Side Diff: chrome/browser/permissions/permission_context_base_unittest.cc

Issue 1312453005: Removed Profile::GetHostContentSettingsMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed Notification Subscription from SupervisedProvider Created 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/permissions/permission_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
9 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/permissions/permission_queue_controller.h" 11 #include "chrome/browser/permissions/permission_queue_controller.h"
11 #include "chrome/browser/permissions/permission_request_id.h" 12 #include "chrome/browser/permissions/permission_request_id.h"
12 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 13 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
13 #include "chrome/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
16 #include "components/content_settings/core/browser/host_content_settings_map.h" 17 #include "components/content_settings/core/browser/host_content_settings_map.h"
17 #include "components/content_settings/core/common/content_settings.h" 18 #include "components/content_settings/core/common/content_settings.h"
18 #include "components/content_settings/core/common/content_settings_types.h" 19 #include "components/content_settings/core/common/content_settings_types.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 id, url, true, 110 id, url, true,
110 base::Bind(&TestPermissionContext::TrackPermissionDecision, 111 base::Bind(&TestPermissionContext::TrackPermissionDecision,
111 base::Unretained(&permission_context))); 112 base::Unretained(&permission_context)));
112 113
113 RespondToPermission(&permission_context, id, url, true); 114 RespondToPermission(&permission_context, id, url, true);
114 EXPECT_TRUE(permission_context.permission_set()); 115 EXPECT_TRUE(permission_context.permission_set());
115 EXPECT_TRUE(permission_context.permission_granted()); 116 EXPECT_TRUE(permission_context.permission_granted());
116 EXPECT_TRUE(permission_context.tab_context_updated()); 117 EXPECT_TRUE(permission_context.tab_context_updated());
117 118
118 ContentSetting setting = 119 ContentSetting setting =
119 profile()->GetHostContentSettingsMap()->GetContentSetting( 120 HostContentSettingsMapFactory::GetForProfile(profile())
120 url.GetOrigin(), url.GetOrigin(), 121 ->GetContentSetting(url.GetOrigin(),
121 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); 122 url.GetOrigin(),
123 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
124 std::string());
122 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); 125 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
123 } 126 }
124 127
125 void TestAskAndDismiss_TestContent() { 128 void TestAskAndDismiss_TestContent() {
126 TestPermissionContext permission_context( 129 TestPermissionContext permission_context(
127 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 130 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
128 GURL url("http://www.google.es"); 131 GURL url("http://www.google.es");
129 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 132 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
130 133
131 const PermissionRequestID id( 134 const PermissionRequestID id(
132 web_contents()->GetRenderProcessHost()->GetID(), 135 web_contents()->GetRenderProcessHost()->GetID(),
133 web_contents()->GetMainFrame()->GetRoutingID(), 136 web_contents()->GetMainFrame()->GetRoutingID(),
134 -1, GURL()); 137 -1, GURL());
135 permission_context.RequestPermission( 138 permission_context.RequestPermission(
136 web_contents(), 139 web_contents(),
137 id, url, true, 140 id, url, true,
138 base::Bind(&TestPermissionContext::TrackPermissionDecision, 141 base::Bind(&TestPermissionContext::TrackPermissionDecision,
139 base::Unretained(&permission_context))); 142 base::Unretained(&permission_context)));
140 143
141 RespondToPermission(&permission_context, id, url, false); 144 RespondToPermission(&permission_context, id, url, false);
142 EXPECT_TRUE(permission_context.permission_set()); 145 EXPECT_TRUE(permission_context.permission_set());
143 EXPECT_FALSE(permission_context.permission_granted()); 146 EXPECT_FALSE(permission_context.permission_granted());
144 EXPECT_TRUE(permission_context.tab_context_updated()); 147 EXPECT_TRUE(permission_context.tab_context_updated());
145 148
146 ContentSetting setting = 149 ContentSetting setting =
147 profile()->GetHostContentSettingsMap()->GetContentSetting( 150 HostContentSettingsMapFactory::GetForProfile(profile())
148 url.GetOrigin(), url.GetOrigin(), 151 ->GetContentSetting(url.GetOrigin(),
149 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); 152 url.GetOrigin(),
153 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
154 std::string());
150 EXPECT_EQ(CONTENT_SETTING_ASK, setting); 155 EXPECT_EQ(CONTENT_SETTING_ASK, setting);
151 } 156 }
152 157
153 void TestRequestPermissionInvalidUrl(ContentSettingsType type) { 158 void TestRequestPermissionInvalidUrl(ContentSettingsType type) {
154 TestPermissionContext permission_context(profile(), type); 159 TestPermissionContext permission_context(profile(), type);
155 GURL url; 160 GURL url;
156 ASSERT_FALSE(url.is_valid()); 161 ASSERT_FALSE(url.is_valid());
157 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 162 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
158 163
159 const PermissionRequestID id( 164 const PermissionRequestID id(
160 web_contents()->GetRenderProcessHost()->GetID(), 165 web_contents()->GetRenderProcessHost()->GetID(),
161 web_contents()->GetMainFrame()->GetRoutingID(), 166 web_contents()->GetMainFrame()->GetRoutingID(),
162 -1, GURL()); 167 -1, GURL());
163 permission_context.RequestPermission( 168 permission_context.RequestPermission(
164 web_contents(), 169 web_contents(),
165 id, url, true, 170 id, url, true,
166 base::Bind(&TestPermissionContext::TrackPermissionDecision, 171 base::Bind(&TestPermissionContext::TrackPermissionDecision,
167 base::Unretained(&permission_context))); 172 base::Unretained(&permission_context)));
168 173
169 EXPECT_TRUE(permission_context.permission_set()); 174 EXPECT_TRUE(permission_context.permission_set());
170 EXPECT_FALSE(permission_context.permission_granted()); 175 EXPECT_FALSE(permission_context.permission_granted());
171 EXPECT_TRUE(permission_context.tab_context_updated()); 176 EXPECT_TRUE(permission_context.tab_context_updated());
172 177
173 ContentSetting setting = 178 ContentSetting setting =
174 profile()->GetHostContentSettingsMap()->GetContentSetting( 179 HostContentSettingsMapFactory::GetForProfile(profile())
175 url.GetOrigin(), url.GetOrigin(), type, std::string()); 180 ->GetContentSetting(url.GetOrigin(),
181 url.GetOrigin(),
182 type,
183 std::string());
176 EXPECT_EQ(CONTENT_SETTING_ASK, setting); 184 EXPECT_EQ(CONTENT_SETTING_ASK, setting);
177 } 185 }
178 186
179 void TestGrantAndRevoke_TestContent(ContentSettingsType type, 187 void TestGrantAndRevoke_TestContent(ContentSettingsType type,
180 ContentSetting expected_default) { 188 ContentSetting expected_default) {
181 TestPermissionContext permission_context(profile(), type); 189 TestPermissionContext permission_context(profile(), type);
182 GURL url("https://www.google.com"); 190 GURL url("https://www.google.com");
183 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 191 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
184 192
185 const PermissionRequestID id( 193 const PermissionRequestID id(
186 web_contents()->GetRenderProcessHost()->GetID(), 194 web_contents()->GetRenderProcessHost()->GetID(),
187 web_contents()->GetMainFrame()->GetRoutingID(), 195 web_contents()->GetMainFrame()->GetRoutingID(),
188 -1, GURL()); 196 -1, GURL());
189 permission_context.RequestPermission( 197 permission_context.RequestPermission(
190 web_contents(), 198 web_contents(),
191 id, url, true, 199 id, url, true,
192 base::Bind(&TestPermissionContext::TrackPermissionDecision, 200 base::Bind(&TestPermissionContext::TrackPermissionDecision,
193 base::Unretained(&permission_context))); 201 base::Unretained(&permission_context)));
194 202
195 RespondToPermission(&permission_context, id, url, true); 203 RespondToPermission(&permission_context, id, url, true);
196 EXPECT_TRUE(permission_context.permission_set()); 204 EXPECT_TRUE(permission_context.permission_set());
197 EXPECT_TRUE(permission_context.permission_granted()); 205 EXPECT_TRUE(permission_context.permission_granted());
198 EXPECT_TRUE(permission_context.tab_context_updated()); 206 EXPECT_TRUE(permission_context.tab_context_updated());
199 207
200 ContentSetting setting = 208 ContentSetting setting =
201 profile()->GetHostContentSettingsMap()->GetContentSetting( 209 HostContentSettingsMapFactory::GetForProfile(profile())
202 url.GetOrigin(), url.GetOrigin(), 210 ->GetContentSetting(url.GetOrigin(),
203 type, std::string()); 211 url.GetOrigin(),
212 type,
213 std::string());
204 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting); 214 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
205 215
206 // Try to reset permission. 216 // Try to reset permission.
207 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin()); 217 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin());
208 ContentSetting setting_after_reset = 218 ContentSetting setting_after_reset =
209 profile()->GetHostContentSettingsMap()->GetContentSetting( 219 HostContentSettingsMapFactory::GetForProfile(profile())
210 url.GetOrigin(), url.GetOrigin(), 220 ->GetContentSetting(url.GetOrigin(),
211 type, std::string()); 221 url.GetOrigin(),
222 type,
223 std::string());
212 ContentSetting default_setting = 224 ContentSetting default_setting =
213 profile()->GetHostContentSettingsMap()->GetDefaultContentSetting( 225 HostContentSettingsMapFactory::GetForProfile(profile())
214 type, nullptr); 226 ->GetDefaultContentSetting(type, nullptr);
215 EXPECT_EQ(default_setting, setting_after_reset); 227 EXPECT_EQ(default_setting, setting_after_reset);
216 } 228 }
217 229
218 private: 230 private:
219 // ChromeRenderViewHostTestHarness: 231 // ChromeRenderViewHostTestHarness:
220 void SetUp() override { 232 void SetUp() override {
221 ChromeRenderViewHostTestHarness::SetUp(); 233 ChromeRenderViewHostTestHarness::SetUp();
222 InfoBarService::CreateForWebContents(web_contents()); 234 InfoBarService::CreateForWebContents(web_contents());
223 PermissionBubbleManager::CreateForWebContents(web_contents()); 235 PermissionBubbleManager::CreateForWebContents(web_contents());
224 } 236 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 #if defined(ENABLE_NOTIFICATIONS) 290 #if defined(ENABLE_NOTIFICATIONS)
279 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 291 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
280 CONTENT_SETTING_ASK); 292 CONTENT_SETTING_ASK);
281 #endif 293 #endif
282 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 294 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
283 CONTENT_SETTING_ASK); 295 CONTENT_SETTING_ASK);
284 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 296 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
285 CONTENT_SETTING_ASK); 297 CONTENT_SETTING_ASK);
286 } 298 }
287 #endif 299 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698