| OLD | NEW |
| 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/content_settings/permission_context_base.h" | 5 #include "chrome/browser/content_settings/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/permission_queue_controller.h" | 9 #include "chrome/browser/content_settings/permission_queue_controller.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 EXPECT_TRUE(permission_context.permission_set()); | 171 EXPECT_TRUE(permission_context.permission_set()); |
| 172 EXPECT_FALSE(permission_context.permission_granted()); | 172 EXPECT_FALSE(permission_context.permission_granted()); |
| 173 EXPECT_TRUE(permission_context.tab_context_updated()); | 173 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 174 | 174 |
| 175 ContentSetting setting = | 175 ContentSetting setting = |
| 176 profile()->GetHostContentSettingsMap()->GetContentSetting( | 176 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 177 url.GetOrigin(), url.GetOrigin(), type, std::string()); | 177 url.GetOrigin(), url.GetOrigin(), type, std::string()); |
| 178 EXPECT_EQ(CONTENT_SETTING_ASK, setting); | 178 EXPECT_EQ(CONTENT_SETTING_ASK, setting); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void TestRequestPermissionNonSecureUrl(ContentSettingsType type) { |
| 182 TestPermissionContext permission_context(profile(), type); |
| 183 GURL url("http://www.google.com"); |
| 184 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
| 185 |
| 186 const PermissionRequestID id( |
| 187 web_contents()->GetRenderProcessHost()->GetID(), |
| 188 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 189 -1, GURL()); |
| 190 permission_context.RequestPermission( |
| 191 web_contents(), |
| 192 id, url, true, |
| 193 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 194 base::Unretained(&permission_context))); |
| 195 |
| 196 EXPECT_TRUE(permission_context.permission_set()); |
| 197 EXPECT_FALSE(permission_context.permission_granted()); |
| 198 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 199 |
| 200 ContentSetting setting = |
| 201 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 202 url.GetOrigin(), url.GetOrigin(), type, std::string()); |
| 203 EXPECT_EQ(CONTENT_SETTING_ASK, setting); |
| 204 } |
| 205 |
| 181 void TestGrantAndRevoke_TestContent(ContentSettingsType type, | 206 void TestGrantAndRevoke_TestContent(ContentSettingsType type, |
| 182 ContentSetting expected_default) { | 207 ContentSetting expected_default) { |
| 183 TestPermissionContext permission_context(profile(), type); | 208 TestPermissionContext permission_context(profile(), type); |
| 184 GURL url("http://www.google.com"); | 209 GURL url("https://www.google.com"); |
| 185 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | 210 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); |
| 186 | 211 |
| 187 const PermissionRequestID id( | 212 const PermissionRequestID id( |
| 188 web_contents()->GetRenderProcessHost()->GetID(), | 213 web_contents()->GetRenderProcessHost()->GetID(), |
| 189 web_contents()->GetRenderViewHost()->GetRoutingID(), | 214 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 190 -1, GURL()); | 215 -1, GURL()); |
| 191 permission_context.RequestPermission( | 216 permission_context.RequestPermission( |
| 192 web_contents(), | 217 web_contents(), |
| 193 id, url, true, | 218 id, url, true, |
| 194 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 219 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 275 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 251 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 276 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 252 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 277 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 253 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 278 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 254 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 279 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 255 TestRequestPermissionInvalidUrl( | 280 TestRequestPermissionInvalidUrl( |
| 256 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 281 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 257 #endif | 282 #endif |
| 258 } | 283 } |
| 259 | 284 |
| 285 // Simulates non-secure requesting URL. |
| 286 // Web MIDI permission should be denied for non-secure origin. |
| 260 // Simulates granting and revoking of permissions. | 287 // Simulates granting and revoking of permissions. |
| 288 TEST_F(PermissionContextBaseTests, TestNonSecureRequestingUrl) { |
| 289 TestRequestPermissionNonSecureUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 290 } |
| 291 |
| 261 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) { | 292 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) { |
| 262 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, | 293 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 263 CONTENT_SETTING_ASK); | 294 CONTENT_SETTING_ASK); |
| 264 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | 295 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 265 CONTENT_SETTING_ASK); | 296 CONTENT_SETTING_ASK); |
| 266 #if defined(OS_ANDROID) | 297 #if defined(OS_ANDROID) |
| 267 TestGrantAndRevoke_TestContent( | 298 TestGrantAndRevoke_TestContent( |
| 268 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); | 299 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); |
| 269 #endif | 300 #endif |
| 270 // TODO(timvolodine): currently no test for | 301 // TODO(timvolodine): currently no test for |
| (...skipping 15 matching lines...) Expand all Loading... |
| 286 #endif | 317 #endif |
| 287 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | 318 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
| 288 CONTENT_SETTING_ASK); | 319 CONTENT_SETTING_ASK); |
| 289 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | 320 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
| 290 CONTENT_SETTING_ASK); | 321 CONTENT_SETTING_ASK); |
| 291 #if defined(OS_ANDROID) | 322 #if defined(OS_ANDROID) |
| 292 TestGrantAndRevoke_TestContent( | 323 TestGrantAndRevoke_TestContent( |
| 293 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); | 324 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); |
| 294 #endif | 325 #endif |
| 295 } | 326 } |
| OLD | NEW |