Chromium Code Reviews| 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 TestGrantAndRevoke_TestContent(ContentSettingsType type, | |
| 182 ContentSetting expected_default) { | |
| 183 TestPermissionContext permission_context(profile(), type); | |
| 184 GURL url("http://www.google.com"); | |
| 185 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); | |
| 186 | |
| 187 const PermissionRequestID id( | |
| 188 web_contents()->GetRenderProcessHost()->GetID(), | |
| 189 web_contents()->GetRenderViewHost()->GetRoutingID(), | |
| 190 -1, GURL()); | |
| 191 permission_context.RequestPermission( | |
| 192 web_contents(), | |
| 193 id, url, true, | |
| 194 base::Bind(&TestPermissionContext::TrackPermissionDecision, | |
| 195 base::Unretained(&permission_context))); | |
| 196 | |
| 197 RespondToPermission(&permission_context, id, url, true); | |
| 198 EXPECT_TRUE(permission_context.permission_set()); | |
| 199 EXPECT_TRUE(permission_context.permission_granted()); | |
| 200 EXPECT_TRUE(permission_context.tab_context_updated()); | |
| 201 | |
| 202 ContentSetting setting = | |
| 203 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 204 url.GetOrigin(), url.GetOrigin(), | |
| 205 type, std::string()); | |
| 206 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); | |
| 207 | |
| 208 // Try to reset permission. | |
| 209 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin()); | |
| 210 ContentSetting setting_after_reset = | |
| 211 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 212 url.GetOrigin(), url.GetOrigin(), | |
| 213 type, std::string()); | |
| 214 EXPECT_EQ(expected_default, setting_after_reset); | |
| 215 } | |
| 216 | |
| 181 private: | 217 private: |
| 182 // ChromeRenderViewHostTestHarness: | 218 // ChromeRenderViewHostTestHarness: |
| 183 void SetUp() override { | 219 void SetUp() override { |
| 184 ChromeRenderViewHostTestHarness::SetUp(); | 220 ChromeRenderViewHostTestHarness::SetUp(); |
| 185 InfoBarService::CreateForWebContents(web_contents()); | 221 InfoBarService::CreateForWebContents(web_contents()); |
| 186 PermissionBubbleManager::CreateForWebContents(web_contents()); | 222 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 187 } | 223 } |
| 188 | 224 |
| 189 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 225 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); |
| 190 }; | 226 }; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 210 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) { | 246 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) { |
| 211 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 247 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 212 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 248 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 213 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 249 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 214 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); | 250 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); |
| 215 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | 251 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) |
| 216 TestRequestPermissionInvalidUrl( | 252 TestRequestPermissionInvalidUrl( |
| 217 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); | 253 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); |
| 218 #endif | 254 #endif |
| 219 } | 255 } |
| 256 | |
| 257 // Simulates granting and revoking of permissions. | |
| 258 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) { | |
| 259 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 260 CONTENT_SETTING_ASK); | |
| 261 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
| 262 CONTENT_SETTING_ASK); | |
| 263 } | |
| 264 | |
| 265 // Simulates granting and revoking of permissions using permission bubbles. | |
| 266 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithBubbles) { | |
| 267 StartUsingPermissionBubble(); | |
| 268 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 269 CONTENT_SETTING_ASK); | |
| 270 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
| 271 CONTENT_SETTING_ASK); | |
| 272 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, | |
| 273 CONTENT_SETTING_ASK); | |
| 274 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, | |
| 275 CONTENT_SETTING_ASK); | |
|
mlamouri (slow - plz ping)
2015/01/26 10:38:17
Is there a reason why we run more tests with bubbl
timvolodine
2015/01/30 14:07:47
I've added protected media permission, but there a
| |
| 276 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) | |
| 277 TestGrantAndRevoke_TestContent( | |
| 278 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); | |
| 279 #endif | |
| 280 } | |
| OLD | NEW |