| OLD | NEW |
| 1 // Copyright (c) 2010 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 "chrome/browser/geolocation/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include "base/scoped_vector.h" | 7 #include "base/scoped_vector.h" |
| 8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
| 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 10 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 10 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 11 #include "chrome/browser/geolocation/location_arbitrator.h" | 11 #include "chrome/browser/geolocation/location_arbitrator.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 NavigateAndCommit(requesting_frame); | 161 NavigateAndCommit(requesting_frame); |
| 162 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 162 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 163 geolocation_permission_context_->RequestGeolocationPermission( | 163 geolocation_permission_context_->RequestGeolocationPermission( |
| 164 process_id(), render_id(), bridge_id(), requesting_frame); | 164 process_id(), render_id(), bridge_id(), requesting_frame); |
| 165 EXPECT_EQ(1, contents()->infobar_delegate_count()); | 165 EXPECT_EQ(1, contents()->infobar_delegate_count()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 168 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| 169 GURL requesting_frame_0("http://www.example.com/geolocation"); | 169 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 170 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 170 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 171 EXPECT_EQ( | 171 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 172 CONTENT_SETTING_ASK, | |
| 173 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 172 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 174 requesting_frame_0, requesting_frame_0)); | 173 requesting_frame_0, requesting_frame_0)); |
| 175 EXPECT_EQ( | 174 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 176 CONTENT_SETTING_ASK, | |
| 177 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 175 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 178 requesting_frame_1, requesting_frame_0)); | 176 requesting_frame_1, requesting_frame_0)); |
| 179 | 177 |
| 180 NavigateAndCommit(requesting_frame_0); | 178 NavigateAndCommit(requesting_frame_0); |
| 181 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 179 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 182 // Request permission for two frames. | 180 // Request permission for two frames. |
| 183 geolocation_permission_context_->RequestGeolocationPermission( | 181 geolocation_permission_context_->RequestGeolocationPermission( |
| 184 process_id(), render_id(), bridge_id(), requesting_frame_0); | 182 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 185 geolocation_permission_context_->RequestGeolocationPermission( | 183 geolocation_permission_context_->RequestGeolocationPermission( |
| 186 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 184 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 212 // Cancel (block) this frame. | 210 // Cancel (block) this frame. |
| 213 infobar_1->Cancel(); | 211 infobar_1->Cancel(); |
| 214 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 212 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 215 CheckPermissionMessageSent(bridge_id() + 1, false); | 213 CheckPermissionMessageSent(bridge_id() + 1, false); |
| 216 contents()->RemoveInfoBar(infobar_1); | 214 contents()->RemoveInfoBar(infobar_1); |
| 217 EXPECT_EQ(infobar_1, | 215 EXPECT_EQ(infobar_1, |
| 218 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 216 tab_contents_with_pending_infobar_->removed_infobar_delegate_); |
| 219 infobar_1->InfoBarClosed(); | 217 infobar_1->InfoBarClosed(); |
| 220 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 218 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 221 // Ensure the persisted permissions are ok. | 219 // Ensure the persisted permissions are ok. |
| 222 EXPECT_EQ( | 220 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 223 CONTENT_SETTING_ALLOW, | |
| 224 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 221 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 225 requesting_frame_0, requesting_frame_0)); | 222 requesting_frame_0, requesting_frame_0)); |
| 226 EXPECT_EQ( | 223 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 227 CONTENT_SETTING_BLOCK, | |
| 228 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 224 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 229 requesting_frame_1, requesting_frame_0)); | 225 requesting_frame_1, requesting_frame_0)); |
| 230 } | 226 } |
| 231 | 227 |
| 232 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 228 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| 233 GURL requesting_frame_0("http://www.example.com/geolocation"); | 229 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 234 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 230 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 235 EXPECT_EQ( | 231 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 236 CONTENT_SETTING_ASK, | |
| 237 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 232 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 238 requesting_frame_0, requesting_frame_0)); | 233 requesting_frame_0, requesting_frame_0)); |
| 239 EXPECT_EQ( | 234 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 240 CONTENT_SETTING_ASK, | |
| 241 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 235 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 242 requesting_frame_1, requesting_frame_0)); | 236 requesting_frame_1, requesting_frame_0)); |
| 243 | 237 |
| 244 NavigateAndCommit(requesting_frame_0); | 238 NavigateAndCommit(requesting_frame_0); |
| 245 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 239 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 246 // Request permission for two frames. | 240 // Request permission for two frames. |
| 247 geolocation_permission_context_->RequestGeolocationPermission( | 241 geolocation_permission_context_->RequestGeolocationPermission( |
| 248 process_id(), render_id(), bridge_id(), requesting_frame_0); | 242 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 249 geolocation_permission_context_->RequestGeolocationPermission( | 243 geolocation_permission_context_->RequestGeolocationPermission( |
| 250 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 244 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 273 // Allow this frame. | 267 // Allow this frame. |
| 274 infobar_1->Accept(); | 268 infobar_1->Accept(); |
| 275 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 269 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 276 CheckPermissionMessageSent(bridge_id() + 1, true); | 270 CheckPermissionMessageSent(bridge_id() + 1, true); |
| 277 contents()->RemoveInfoBar(infobar_1); | 271 contents()->RemoveInfoBar(infobar_1); |
| 278 EXPECT_EQ(infobar_1, | 272 EXPECT_EQ(infobar_1, |
| 279 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 273 tab_contents_with_pending_infobar_->removed_infobar_delegate_); |
| 280 infobar_1->InfoBarClosed(); | 274 infobar_1->InfoBarClosed(); |
| 281 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 275 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 282 // Ensure the persisted permissions are ok. | 276 // Ensure the persisted permissions are ok. |
| 283 EXPECT_EQ( | 277 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 284 CONTENT_SETTING_ASK, | |
| 285 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 278 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 286 requesting_frame_0, requesting_frame_0)); | 279 requesting_frame_0, requesting_frame_0)); |
| 287 EXPECT_EQ( | 280 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 288 CONTENT_SETTING_ALLOW, | |
| 289 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 281 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 290 requesting_frame_1, requesting_frame_0)); | 282 requesting_frame_1, requesting_frame_0)); |
| 291 } | 283 } |
| 292 | 284 |
| 293 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 285 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| 294 GURL invalid_embedder; | 286 GURL invalid_embedder; |
| 295 GURL requesting_frame("about:blank"); | 287 GURL requesting_frame("about:blank"); |
| 296 NavigateAndCommit(invalid_embedder); | 288 NavigateAndCommit(invalid_embedder); |
| 297 EXPECT_EQ(0, contents()->infobar_delegate_count()); | 289 EXPECT_EQ(0, contents()->infobar_delegate_count()); |
| 298 geolocation_permission_context_->RequestGeolocationPermission( | 290 geolocation_permission_context_->RequestGeolocationPermission( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 // Ensure only one infobar is created. | 414 // Ensure only one infobar is created. |
| 423 EXPECT_EQ(1, contents()->infobar_delegate_count()); | 415 EXPECT_EQ(1, contents()->infobar_delegate_count()); |
| 424 ConfirmInfoBarDelegate* infobar_0 = | 416 ConfirmInfoBarDelegate* infobar_0 = |
| 425 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 417 contents()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 426 ASSERT_TRUE(infobar_0); | 418 ASSERT_TRUE(infobar_0); |
| 427 string16 text_0 = infobar_0->GetMessageText(); | 419 string16 text_0 = infobar_0->GetMessageText(); |
| 428 | 420 |
| 429 // Delete the tab contents. | 421 // Delete the tab contents. |
| 430 DeleteContents(); | 422 DeleteContents(); |
| 431 } | 423 } |
| OLD | NEW |