| 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/permissions/permission_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 profile(), content::PermissionType::NOTIFICATIONS, | 145 profile(), content::PermissionType::NOTIFICATIONS, |
| 146 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 146 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 147 GURL url("http://www.google.com"); | 147 GURL url("http://www.google.com"); |
| 148 NavigateAndCommit(url); | 148 NavigateAndCommit(url); |
| 149 | 149 |
| 150 const PermissionRequestID id( | 150 const PermissionRequestID id( |
| 151 web_contents()->GetRenderProcessHost()->GetID(), | 151 web_contents()->GetRenderProcessHost()->GetID(), |
| 152 web_contents()->GetMainFrame()->GetRoutingID(), | 152 web_contents()->GetMainFrame()->GetRoutingID(), |
| 153 -1); | 153 -1); |
| 154 permission_context.RequestPermission( | 154 permission_context.RequestPermission( |
| 155 web_contents(), id, url, | 155 web_contents(), |
| 156 id, url, true /* user_gesture */, |
| 156 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 157 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 157 base::Unretained(&permission_context))); | 158 base::Unretained(&permission_context))); |
| 158 | 159 |
| 159 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ALLOW); | 160 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ALLOW); |
| 160 EXPECT_EQ(1u, permission_context.decisions().size()); | 161 EXPECT_EQ(1u, permission_context.decisions().size()); |
| 161 EXPECT_EQ(CONTENT_SETTING_ALLOW, permission_context.decisions()[0]); | 162 EXPECT_EQ(CONTENT_SETTING_ALLOW, permission_context.decisions()[0]); |
| 162 EXPECT_TRUE(permission_context.tab_context_updated()); | 163 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 163 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 164 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 164 permission_context.GetContentSettingFromMap(url, url)); | 165 permission_context.GetContentSettingFromMap(url, url)); |
| 165 } | 166 } |
| 166 | 167 |
| 167 void TestAskAndDismiss_TestContent() { | 168 void TestAskAndDismiss_TestContent() { |
| 168 TestPermissionContext permission_context( | 169 TestPermissionContext permission_context( |
| 169 profile(), content::PermissionType::MIDI_SYSEX, | 170 profile(), content::PermissionType::MIDI_SYSEX, |
| 170 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); | 171 CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 171 GURL url("http://www.google.es"); | 172 GURL url("http://www.google.es"); |
| 172 NavigateAndCommit(url); | 173 NavigateAndCommit(url); |
| 173 | 174 |
| 174 const PermissionRequestID id( | 175 const PermissionRequestID id( |
| 175 web_contents()->GetRenderProcessHost()->GetID(), | 176 web_contents()->GetRenderProcessHost()->GetID(), |
| 176 web_contents()->GetMainFrame()->GetRoutingID(), | 177 web_contents()->GetMainFrame()->GetRoutingID(), |
| 177 -1); | 178 -1); |
| 178 permission_context.RequestPermission( | 179 permission_context.RequestPermission( |
| 179 web_contents(), id, url, | 180 web_contents(), |
| 181 id, url, true /* user_gesture */, |
| 180 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 182 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 181 base::Unretained(&permission_context))); | 183 base::Unretained(&permission_context))); |
| 182 | 184 |
| 183 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ASK); | 185 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ASK); |
| 184 EXPECT_EQ(1u, permission_context.decisions().size()); | 186 EXPECT_EQ(1u, permission_context.decisions().size()); |
| 185 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.decisions()[0]); | 187 EXPECT_EQ(CONTENT_SETTING_ASK, permission_context.decisions()[0]); |
| 186 EXPECT_TRUE(permission_context.tab_context_updated()); | 188 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 187 EXPECT_EQ(CONTENT_SETTING_ASK, | 189 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 188 permission_context.GetContentSettingFromMap(url, url)); | 190 permission_context.GetContentSettingFromMap(url, url)); |
| 189 } | 191 } |
| 190 | 192 |
| 191 void TestRequestPermissionInvalidUrl( | 193 void TestRequestPermissionInvalidUrl( |
| 192 content::PermissionType permission_type, | 194 content::PermissionType permission_type, |
| 193 ContentSettingsType content_settings_type) { | 195 ContentSettingsType content_settings_type) { |
| 194 TestPermissionContext permission_context(profile(), permission_type, | 196 TestPermissionContext permission_context(profile(), permission_type, |
| 195 content_settings_type); | 197 content_settings_type); |
| 196 GURL url; | 198 GURL url; |
| 197 ASSERT_FALSE(url.is_valid()); | 199 ASSERT_FALSE(url.is_valid()); |
| 198 NavigateAndCommit(url); | 200 NavigateAndCommit(url); |
| 199 | 201 |
| 200 const PermissionRequestID id( | 202 const PermissionRequestID id( |
| 201 web_contents()->GetRenderProcessHost()->GetID(), | 203 web_contents()->GetRenderProcessHost()->GetID(), |
| 202 web_contents()->GetMainFrame()->GetRoutingID(), | 204 web_contents()->GetMainFrame()->GetRoutingID(), |
| 203 -1); | 205 -1); |
| 204 permission_context.RequestPermission( | 206 permission_context.RequestPermission( |
| 205 web_contents(), id, url, | 207 web_contents(), |
| 208 id, url, true /* user_gesture */, |
| 206 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 209 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 207 base::Unretained(&permission_context))); | 210 base::Unretained(&permission_context))); |
| 208 | 211 |
| 209 EXPECT_EQ(1u, permission_context.decisions().size()); | 212 EXPECT_EQ(1u, permission_context.decisions().size()); |
| 210 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); | 213 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); |
| 211 EXPECT_TRUE(permission_context.tab_context_updated()); | 214 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 212 EXPECT_EQ(CONTENT_SETTING_ASK, | 215 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 213 permission_context.GetContentSettingFromMap(url, url)); | 216 permission_context.GetContentSettingFromMap(url, url)); |
| 214 } | 217 } |
| 215 | 218 |
| 216 void TestGrantAndRevoke_TestContent(content::PermissionType permission_type, | 219 void TestGrantAndRevoke_TestContent(content::PermissionType permission_type, |
| 217 ContentSettingsType content_settings_type, | 220 ContentSettingsType content_settings_type, |
| 218 ContentSetting expected_default) { | 221 ContentSetting expected_default) { |
| 219 TestPermissionContext permission_context(profile(), permission_type, | 222 TestPermissionContext permission_context(profile(), permission_type, |
| 220 content_settings_type); | 223 content_settings_type); |
| 221 GURL url("https://www.google.com"); | 224 GURL url("https://www.google.com"); |
| 222 NavigateAndCommit(url); | 225 NavigateAndCommit(url); |
| 223 | 226 |
| 224 const PermissionRequestID id( | 227 const PermissionRequestID id( |
| 225 web_contents()->GetRenderProcessHost()->GetID(), | 228 web_contents()->GetRenderProcessHost()->GetID(), |
| 226 web_contents()->GetMainFrame()->GetRoutingID(), | 229 web_contents()->GetMainFrame()->GetRoutingID(), |
| 227 -1); | 230 -1); |
| 228 permission_context.RequestPermission( | 231 permission_context.RequestPermission( |
| 229 web_contents(), id, url, | 232 web_contents(), |
| 233 id, url, true /* user_gesture */, |
| 230 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 234 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 231 base::Unretained(&permission_context))); | 235 base::Unretained(&permission_context))); |
| 232 | 236 |
| 233 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ALLOW); | 237 RespondToPermission(&permission_context, id, url, CONTENT_SETTING_ALLOW); |
| 234 EXPECT_EQ(1u, permission_context.decisions().size()); | 238 EXPECT_EQ(1u, permission_context.decisions().size()); |
| 235 EXPECT_EQ(CONTENT_SETTING_ALLOW, permission_context.decisions()[0]); | 239 EXPECT_EQ(CONTENT_SETTING_ALLOW, permission_context.decisions()[0]); |
| 236 EXPECT_TRUE(permission_context.tab_context_updated()); | 240 EXPECT_TRUE(permission_context.tab_context_updated()); |
| 237 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 241 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 238 permission_context.GetContentSettingFromMap(url, url)); | 242 permission_context.GetContentSettingFromMap(url, url)); |
| 239 | 243 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 NavigateAndCommit(url); | 280 NavigateAndCommit(url); |
| 277 | 281 |
| 278 const PermissionRequestID id0( | 282 const PermissionRequestID id0( |
| 279 web_contents()->GetRenderProcessHost()->GetID(), | 283 web_contents()->GetRenderProcessHost()->GetID(), |
| 280 web_contents()->GetMainFrame()->GetRoutingID(), 0); | 284 web_contents()->GetMainFrame()->GetRoutingID(), 0); |
| 281 const PermissionRequestID id1( | 285 const PermissionRequestID id1( |
| 282 web_contents()->GetRenderProcessHost()->GetID(), | 286 web_contents()->GetRenderProcessHost()->GetID(), |
| 283 web_contents()->GetMainFrame()->GetRoutingID(), 1); | 287 web_contents()->GetMainFrame()->GetRoutingID(), 1); |
| 284 | 288 |
| 285 permission_context.RequestPermission( | 289 permission_context.RequestPermission( |
| 286 web_contents(), id0, url, | 290 web_contents(), id0, url, true /* user_gesture */, |
| 287 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 291 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 288 base::Unretained(&permission_context))); | 292 base::Unretained(&permission_context))); |
| 289 permission_context.RequestPermission( | 293 permission_context.RequestPermission( |
| 290 web_contents(), id1, url, | 294 web_contents(), id1, url, true /* user_gesture */, |
| 291 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 295 base::Bind(&TestPermissionContext::TrackPermissionDecision, |
| 292 base::Unretained(&permission_context))); | 296 base::Unretained(&permission_context))); |
| 293 | 297 |
| 294 EXPECT_EQ(0u, permission_context.decisions().size()); | 298 EXPECT_EQ(0u, permission_context.decisions().size()); |
| 295 | 299 |
| 296 RespondToPermission(&permission_context, id0, url, response); | 300 RespondToPermission(&permission_context, id0, url, response); |
| 297 | 301 |
| 298 EXPECT_EQ(2u, permission_context.decisions().size()); | 302 EXPECT_EQ(2u, permission_context.decisions().size()); |
| 299 EXPECT_EQ(response, permission_context.decisions()[0]); | 303 EXPECT_EQ(response, permission_context.decisions()[0]); |
| 300 EXPECT_EQ(response, permission_context.decisions()[1]); | 304 EXPECT_EQ(response, permission_context.decisions()[1]); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 TestParallelRequests(CONTENT_SETTING_ALLOW); | 420 TestParallelRequests(CONTENT_SETTING_ALLOW); |
| 417 } | 421 } |
| 418 | 422 |
| 419 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { | 423 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { |
| 420 TestParallelRequests(CONTENT_SETTING_BLOCK); | 424 TestParallelRequests(CONTENT_SETTING_BLOCK); |
| 421 } | 425 } |
| 422 | 426 |
| 423 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { | 427 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { |
| 424 TestParallelRequests(CONTENT_SETTING_ASK); | 428 TestParallelRequests(CONTENT_SETTING_ASK); |
| 425 } | 429 } |
| OLD | NEW |