Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 12 #include "chrome/browser/infobars/infobar_tab_helper.h" | |
| 12 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 13 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/tab_contents/infobar.h" | 14 #include "chrome/browser/tab_contents/infobar.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 15 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 18 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " | 19 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " |
| 19 #include "content/browser/geolocation/location_arbitrator.h" | 20 #include "content/browser/geolocation/location_arbitrator.h" |
| 20 #include "content/browser/geolocation/location_provider.h" | 21 #include "content/browser/geolocation/location_provider.h" |
| 21 #include "content/browser/geolocation/mock_location_provider.h" | 22 #include "content/browser/geolocation/mock_location_provider.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); | 205 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); |
| 205 TabContentsWrapperTestHarness::TearDown(); | 206 TabContentsWrapperTestHarness::TearDown(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 | 209 |
| 209 // Tests ---------------------------------------------------------------------- | 210 // Tests ---------------------------------------------------------------------- |
| 210 | 211 |
| 211 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 212 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
| 212 GURL requesting_frame("http://www.example.com/geolocation"); | 213 GURL requesting_frame("http://www.example.com/geolocation"); |
| 213 NavigateAndCommit(requesting_frame); | 214 NavigateAndCommit(requesting_frame); |
| 214 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 215 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
|
Peter Kasting
2011/08/31 18:47:32
Nit: Can you factor out infobar_tab_helper() temps
| |
| 215 geolocation_permission_context_->RequestGeolocationPermission( | 216 geolocation_permission_context_->RequestGeolocationPermission( |
| 216 process_id(), render_id(), bridge_id(), requesting_frame); | 217 process_id(), render_id(), bridge_id(), requesting_frame); |
| 217 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 218 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 218 ConfirmInfoBarDelegate* infobar_0 = | 219 ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()-> |
| 219 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 220 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 220 infobar_0->Cancel(); | 221 infobar_0->Cancel(); |
| 221 contents_wrapper()->RemoveInfoBar(infobar_0); | 222 contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0); |
| 222 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 223 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 223 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 224 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
| 224 infobar_0->InfoBarClosed(); | 225 infobar_0->InfoBarClosed(); |
| 225 } | 226 } |
| 226 | 227 |
| 227 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 228 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| 228 GURL requesting_frame_0("http://www.example.com/geolocation"); | 229 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 229 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 230 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 230 EXPECT_EQ(CONTENT_SETTING_ASK, | 231 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 231 profile()->GetHostContentSettingsMap()->GetContentSetting( | 232 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 232 requesting_frame_0, | 233 requesting_frame_0, |
| 233 requesting_frame_0, | 234 requesting_frame_0, |
| 234 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 235 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 235 std::string())); | 236 std::string())); |
| 236 EXPECT_EQ(CONTENT_SETTING_ASK, | 237 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 237 profile()->GetHostContentSettingsMap()->GetContentSetting( | 238 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 238 requesting_frame_1, | 239 requesting_frame_1, |
| 239 requesting_frame_0, | 240 requesting_frame_0, |
| 240 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 241 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 241 std::string())); | 242 std::string())); |
| 242 | 243 |
| 243 | 244 |
| 244 NavigateAndCommit(requesting_frame_0); | 245 NavigateAndCommit(requesting_frame_0); |
| 245 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 246 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 246 // Request permission for two frames. | 247 // Request permission for two frames. |
| 247 geolocation_permission_context_->RequestGeolocationPermission( | 248 geolocation_permission_context_->RequestGeolocationPermission( |
| 248 process_id(), render_id(), bridge_id(), requesting_frame_0); | 249 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 249 geolocation_permission_context_->RequestGeolocationPermission( | 250 geolocation_permission_context_->RequestGeolocationPermission( |
| 250 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 251 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
| 251 // Ensure only one infobar is created. | 252 // Ensure only one infobar is created. |
| 252 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 253 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 253 ConfirmInfoBarDelegate* infobar_0 = | 254 ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()-> |
| 254 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 255 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 255 ASSERT_TRUE(infobar_0); | 256 ASSERT_TRUE(infobar_0); |
| 256 string16 text_0 = infobar_0->GetMessageText(); | 257 string16 text_0 = infobar_0->GetMessageText(); |
| 257 | 258 |
| 258 // Accept the first frame. | 259 // Accept the first frame. |
| 259 infobar_0->Accept(); | 260 infobar_0->Accept(); |
| 260 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 261 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 261 CheckPermissionMessageSent(bridge_id(), true); | 262 CheckPermissionMessageSent(bridge_id(), true); |
| 262 | 263 |
| 263 contents_wrapper()->RemoveInfoBar(infobar_0); | 264 contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0); |
| 264 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 265 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 265 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 266 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
| 266 closed_delegate_tracker_.Clear(); | 267 closed_delegate_tracker_.Clear(); |
| 267 infobar_0->InfoBarClosed(); | 268 infobar_0->InfoBarClosed(); |
| 268 // Now we should have a new infobar for the second frame. | 269 // Now we should have a new infobar for the second frame. |
| 269 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 270 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 270 | 271 |
| 271 ConfirmInfoBarDelegate* infobar_1 = | 272 ConfirmInfoBarDelegate* infobar_1 = contents_wrapper()->infobar_tab_helper()-> |
| 272 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 273 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 273 ASSERT_TRUE(infobar_1); | 274 ASSERT_TRUE(infobar_1); |
| 274 string16 text_1 = infobar_1->GetMessageText(); | 275 string16 text_1 = infobar_1->GetMessageText(); |
| 275 EXPECT_NE(text_0, text_1); | 276 EXPECT_NE(text_0, text_1); |
| 276 | 277 |
| 277 // Cancel (block) this frame. | 278 // Cancel (block) this frame. |
| 278 infobar_1->Cancel(); | 279 infobar_1->Cancel(); |
| 279 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 280 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 280 CheckPermissionMessageSent(bridge_id() + 1, false); | 281 CheckPermissionMessageSent(bridge_id() + 1, false); |
| 281 contents_wrapper()->RemoveInfoBar(infobar_1); | 282 contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
| 282 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 283 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 283 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 284 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
| 284 infobar_1->InfoBarClosed(); | 285 infobar_1->InfoBarClosed(); |
| 285 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 286 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 286 // Ensure the persisted permissions are ok. | 287 // Ensure the persisted permissions are ok. |
| 287 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 288 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 288 profile()->GetHostContentSettingsMap()->GetContentSetting( | 289 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 289 requesting_frame_0, | 290 requesting_frame_0, |
| 290 requesting_frame_0, | 291 requesting_frame_0, |
| 291 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 292 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 292 std::string())); | 293 std::string())); |
| 293 | 294 |
| 294 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 295 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 295 profile()->GetHostContentSettingsMap()->GetContentSetting( | 296 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 311 | 312 |
| 312 EXPECT_EQ(CONTENT_SETTING_ASK, | 313 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 313 profile()->GetHostContentSettingsMap()->GetContentSetting( | 314 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 314 requesting_frame_1, | 315 requesting_frame_1, |
| 315 requesting_frame_0, | 316 requesting_frame_0, |
| 316 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 317 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 317 std::string())); | 318 std::string())); |
| 318 | 319 |
| 319 | 320 |
| 320 NavigateAndCommit(requesting_frame_0); | 321 NavigateAndCommit(requesting_frame_0); |
| 321 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 322 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 322 // Request permission for two frames. | 323 // Request permission for two frames. |
| 323 geolocation_permission_context_->RequestGeolocationPermission( | 324 geolocation_permission_context_->RequestGeolocationPermission( |
| 324 process_id(), render_id(), bridge_id(), requesting_frame_0); | 325 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 325 geolocation_permission_context_->RequestGeolocationPermission( | 326 geolocation_permission_context_->RequestGeolocationPermission( |
| 326 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 327 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
| 327 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 328 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 328 | 329 |
| 329 ConfirmInfoBarDelegate* infobar_0 = | 330 ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()-> |
| 330 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 331 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 331 ASSERT_TRUE(infobar_0); | 332 ASSERT_TRUE(infobar_0); |
| 332 string16 text_0 = infobar_0->GetMessageText(); | 333 string16 text_0 = infobar_0->GetMessageText(); |
| 333 | 334 |
| 334 // Simulate the frame going away, ensure the infobar for this frame | 335 // Simulate the frame going away, ensure the infobar for this frame |
| 335 // is removed and the next pending infobar is created. | 336 // is removed and the next pending infobar is created. |
| 336 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 337 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
| 337 process_id(), render_id(), bridge_id(), requesting_frame_0); | 338 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 338 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 339 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 339 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 340 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
| 340 closed_delegate_tracker_.Clear(); | 341 closed_delegate_tracker_.Clear(); |
| 341 infobar_0->InfoBarClosed(); | 342 infobar_0->InfoBarClosed(); |
| 342 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 343 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 343 | 344 |
| 344 ConfirmInfoBarDelegate* infobar_1 = | 345 ConfirmInfoBarDelegate* infobar_1 = contents_wrapper()->infobar_tab_helper()-> |
| 345 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 346 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 346 ASSERT_TRUE(infobar_1); | 347 ASSERT_TRUE(infobar_1); |
| 347 string16 text_1 = infobar_1->GetMessageText(); | 348 string16 text_1 = infobar_1->GetMessageText(); |
| 348 EXPECT_NE(text_0, text_1); | 349 EXPECT_NE(text_0, text_1); |
| 349 | 350 |
| 350 // Allow this frame. | 351 // Allow this frame. |
| 351 infobar_1->Accept(); | 352 infobar_1->Accept(); |
| 352 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 353 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 353 CheckPermissionMessageSent(bridge_id() + 1, true); | 354 CheckPermissionMessageSent(bridge_id() + 1, true); |
| 354 contents_wrapper()->RemoveInfoBar(infobar_1); | 355 contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
| 355 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 356 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 356 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 357 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
| 357 infobar_1->InfoBarClosed(); | 358 infobar_1->InfoBarClosed(); |
| 358 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 359 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 359 // Ensure the persisted permissions are ok. | 360 // Ensure the persisted permissions are ok. |
| 360 EXPECT_EQ(CONTENT_SETTING_ASK, | 361 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 361 profile()->GetHostContentSettingsMap()->GetContentSetting( | 362 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 362 requesting_frame_0, | 363 requesting_frame_0, |
| 363 requesting_frame_0, | 364 requesting_frame_0, |
| 364 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 365 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 365 std::string())); | 366 std::string())); |
| 366 | 367 |
| 367 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 368 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 368 profile()->GetHostContentSettingsMap()->GetContentSetting( | 369 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 369 requesting_frame_1, | 370 requesting_frame_1, |
| 370 requesting_frame_0, | 371 requesting_frame_0, |
| 371 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 372 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 372 std::string())); | 373 std::string())); |
| 373 } | 374 } |
| 374 | 375 |
| 375 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 376 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| 376 GURL invalid_embedder; | 377 GURL invalid_embedder; |
| 377 GURL requesting_frame("about:blank"); | 378 GURL requesting_frame("about:blank"); |
| 378 NavigateAndCommit(invalid_embedder); | 379 NavigateAndCommit(invalid_embedder); |
| 379 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 380 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 380 geolocation_permission_context_->RequestGeolocationPermission( | 381 geolocation_permission_context_->RequestGeolocationPermission( |
| 381 process_id(), render_id(), bridge_id(), requesting_frame); | 382 process_id(), render_id(), bridge_id(), requesting_frame); |
| 382 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 383 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 383 CheckPermissionMessageSent(bridge_id(), false); | 384 CheckPermissionMessageSent(bridge_id(), false); |
| 384 } | 385 } |
| 385 | 386 |
| 386 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 387 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| 387 GURL url_a("http://www.example.com/geolocation"); | 388 GURL url_a("http://www.example.com/geolocation"); |
| 388 GURL url_b("http://www.example-2.com/geolocation"); | 389 GURL url_b("http://www.example-2.com/geolocation"); |
| 389 NavigateAndCommit(url_a); | 390 NavigateAndCommit(url_a); |
| 390 AddNewTab(url_b); | 391 AddNewTab(url_b); |
| 391 AddNewTab(url_a); | 392 AddNewTab(url_a); |
| 392 | 393 |
| 393 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 394 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 394 geolocation_permission_context_->RequestGeolocationPermission( | 395 geolocation_permission_context_->RequestGeolocationPermission( |
| 395 process_id(), render_id(), bridge_id(), url_a); | 396 process_id(), render_id(), bridge_id(), url_a); |
| 396 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 397 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 397 | 398 |
| 398 geolocation_permission_context_->RequestGeolocationPermission( | 399 geolocation_permission_context_->RequestGeolocationPermission( |
| 399 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); | 400 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); |
| 400 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 401 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
| 401 | 402 |
| 402 geolocation_permission_context_->RequestGeolocationPermission( | 403 geolocation_permission_context_->RequestGeolocationPermission( |
| 403 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); | 404 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); |
| 404 ASSERT_EQ(1U, extra_tabs_[1]->infobar_count()); | 405 ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); |
| 405 | 406 |
| 406 ConfirmInfoBarDelegate* removed_infobar = | 407 ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]-> |
| 407 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 408 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 408 | 409 |
| 409 // Accept the first tab. | 410 // Accept the first tab. |
| 410 ConfirmInfoBarDelegate* infobar_0 = | 411 ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()-> |
| 411 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 412 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 412 ASSERT_TRUE(infobar_0); | 413 ASSERT_TRUE(infobar_0); |
| 413 infobar_0->Accept(); | 414 infobar_0->Accept(); |
| 414 CheckPermissionMessageSent(bridge_id(), true); | 415 CheckPermissionMessageSent(bridge_id(), true); |
| 415 contents_wrapper()->RemoveInfoBar(infobar_0); | 416 contents_wrapper()->infobar_tab_helper()->RemoveInfoBar(infobar_0); |
| 416 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 417 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
| 417 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 418 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
| 418 infobar_0->InfoBarClosed(); | 419 infobar_0->InfoBarClosed(); |
| 419 // Now the infobar for the tab with the same origin should have gone. | 420 // Now the infobar for the tab with the same origin should have gone. |
| 420 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); | 421 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); |
| 421 CheckPermissionMessageSentForTab(1, bridge_id(), true); | 422 CheckPermissionMessageSentForTab(1, bridge_id(), true); |
| 422 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 423 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
| 423 closed_delegate_tracker_.Clear(); | 424 closed_delegate_tracker_.Clear(); |
| 424 // Destroy the infobar that has just been removed. | 425 // Destroy the infobar that has just been removed. |
| 425 removed_infobar->InfoBarClosed(); | 426 removed_infobar->InfoBarClosed(); |
| 426 | 427 |
| 427 // But the other tab should still have the info bar... | 428 // But the other tab should still have the info bar... |
| 428 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 429 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
| 429 ConfirmInfoBarDelegate* infobar_1 = | 430 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
| 430 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 431 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 431 infobar_1->Cancel(); | 432 infobar_1->Cancel(); |
| 432 extra_tabs_[0]->RemoveInfoBar(infobar_1); | 433 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
| 433 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 434 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 434 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 435 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
| 435 infobar_1->InfoBarClosed(); | 436 infobar_1->InfoBarClosed(); |
| 436 | 437 |
| 437 extra_tabs_.reset(); | 438 extra_tabs_.reset(); |
| 438 } | 439 } |
| 439 | 440 |
| 440 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 441 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| 441 GURL url_a("http://www.example.com/geolocation"); | 442 GURL url_a("http://www.example.com/geolocation"); |
| 442 GURL url_b("http://www.example-2.com/geolocation"); | 443 GURL url_b("http://www.example-2.com/geolocation"); |
| 443 NavigateAndCommit(url_a); | 444 NavigateAndCommit(url_a); |
| 444 AddNewTab(url_a); | 445 AddNewTab(url_a); |
| 445 | 446 |
| 446 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 447 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 447 geolocation_permission_context_->RequestGeolocationPermission( | 448 geolocation_permission_context_->RequestGeolocationPermission( |
| 448 process_id(), render_id(), bridge_id(), url_a); | 449 process_id(), render_id(), bridge_id(), url_a); |
| 449 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 450 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 450 | 451 |
| 451 geolocation_permission_context_->RequestGeolocationPermission( | 452 geolocation_permission_context_->RequestGeolocationPermission( |
| 452 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); | 453 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); |
| 453 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 454 EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
| 454 | 455 |
| 455 geolocation_permission_context_->RequestGeolocationPermission( | 456 geolocation_permission_context_->RequestGeolocationPermission( |
| 456 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); | 457 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); |
| 457 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 458 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
| 458 | 459 |
| 459 ConfirmInfoBarDelegate* removed_infobar = | 460 ConfirmInfoBarDelegate* removed_infobar = contents_wrapper()-> |
| 460 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 461 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 461 | 462 |
| 462 // Accept the second tab. | 463 // Accept the second tab. |
| 463 ConfirmInfoBarDelegate* infobar_0 = | 464 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> |
| 464 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 465 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 465 ASSERT_TRUE(infobar_0); | 466 ASSERT_TRUE(infobar_0); |
| 466 infobar_0->Accept(); | 467 infobar_0->Accept(); |
| 467 CheckPermissionMessageSentForTab(0, bridge_id(), true); | 468 CheckPermissionMessageSentForTab(0, bridge_id(), true); |
| 468 extra_tabs_[0]->RemoveInfoBar(infobar_0); | 469 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); |
| 469 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 470 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
| 470 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 471 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
| 471 infobar_0->InfoBarClosed(); | 472 infobar_0->InfoBarClosed(); |
| 472 // Now the infobar for the tab with the same origin should have gone. | 473 // Now the infobar for the tab with the same origin should have gone. |
| 473 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 474 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 474 CheckPermissionMessageSent(bridge_id(), true); | 475 CheckPermissionMessageSent(bridge_id(), true); |
| 475 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 476 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
| 476 closed_delegate_tracker_.Clear(); | 477 closed_delegate_tracker_.Clear(); |
| 477 // Destroy the infobar that has just been removed. | 478 // Destroy the infobar that has just been removed. |
| 478 removed_infobar->InfoBarClosed(); | 479 removed_infobar->InfoBarClosed(); |
| 479 | 480 |
| 480 // And we should have the queued infobar displayed now. | 481 // And we should have the queued infobar displayed now. |
| 481 ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); | 482 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); |
| 482 | 483 |
| 483 // Accept the second infobar. | 484 // Accept the second infobar. |
| 484 ConfirmInfoBarDelegate* infobar_1 = | 485 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> |
| 485 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 486 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 486 ASSERT_TRUE(infobar_1); | 487 ASSERT_TRUE(infobar_1); |
| 487 infobar_1->Accept(); | 488 infobar_1->Accept(); |
| 488 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 489 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); |
| 489 extra_tabs_[0]->RemoveInfoBar(infobar_1); | 490 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); |
| 490 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 491 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
| 491 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 492 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
| 492 infobar_1->InfoBarClosed(); | 493 infobar_1->InfoBarClosed(); |
| 493 | 494 |
| 494 extra_tabs_.reset(); | 495 extra_tabs_.reset(); |
| 495 } | 496 } |
| 496 | 497 |
| 497 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 498 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| 498 GURL requesting_frame_0("http://www.example.com/geolocation"); | 499 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 499 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 500 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 500 EXPECT_EQ( | 501 EXPECT_EQ( |
| 501 CONTENT_SETTING_ASK, | 502 CONTENT_SETTING_ASK, |
| 502 profile()->GetHostContentSettingsMap()->GetContentSetting( | 503 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 503 requesting_frame_0, | 504 requesting_frame_0, |
| 504 requesting_frame_0, | 505 requesting_frame_0, |
| 505 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 506 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 506 std::string())); | 507 std::string())); |
| 507 | 508 |
| 508 EXPECT_EQ( | 509 EXPECT_EQ( |
| 509 CONTENT_SETTING_ASK, | 510 CONTENT_SETTING_ASK, |
| 510 profile()->GetHostContentSettingsMap()->GetContentSetting( | 511 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 511 requesting_frame_1, | 512 requesting_frame_1, |
| 512 requesting_frame_0, | 513 requesting_frame_0, |
| 513 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 514 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 514 std::string())); | 515 std::string())); |
| 515 | 516 |
| 516 NavigateAndCommit(requesting_frame_0); | 517 NavigateAndCommit(requesting_frame_0); |
| 517 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 518 EXPECT_EQ(0U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 518 // Request permission for two frames. | 519 // Request permission for two frames. |
| 519 geolocation_permission_context_->RequestGeolocationPermission( | 520 geolocation_permission_context_->RequestGeolocationPermission( |
| 520 process_id(), render_id(), bridge_id(), requesting_frame_0); | 521 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 521 geolocation_permission_context_->RequestGeolocationPermission( | 522 geolocation_permission_context_->RequestGeolocationPermission( |
| 522 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | 523 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
| 523 // Ensure only one infobar is created. | 524 // Ensure only one infobar is created. |
| 524 ASSERT_EQ(1U, contents_wrapper()->infobar_count()); | 525 ASSERT_EQ(1U, contents_wrapper()->infobar_tab_helper()->infobar_count()); |
| 525 ConfirmInfoBarDelegate* infobar_0 = | 526 ConfirmInfoBarDelegate* infobar_0 = contents_wrapper()->infobar_tab_helper()-> |
| 526 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 527 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 527 ASSERT_TRUE(infobar_0); | 528 ASSERT_TRUE(infobar_0); |
| 528 | 529 |
| 529 // Delete the tab contents. | 530 // Delete the tab contents. |
| 530 DeleteContents(); | 531 DeleteContents(); |
| 531 infobar_0->InfoBarClosed(); | 532 infobar_0->InfoBarClosed(); |
| 532 } | 533 } |
| OLD | NEW |