| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 18 #include "chrome/browser/content_settings/permission_request_id.h" | 18 #include "chrome/browser/content_settings/permission_request_id.h" |
| 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto
ry.h" | 20 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto
ry.h" |
| 21 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 21 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 22 #include "chrome/browser/infobars/infobar.h" | 22 #include "chrome/browser/infobars/infobar.h" |
| 23 #include "chrome/browser/infobars/infobar_manager.h" |
| 23 #include "chrome/browser/infobars/infobar_service.h" | 24 #include "chrome/browser/infobars/infobar_service.h" |
| 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 26 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 29 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/mock_render_process_host.h" | 32 #include "content/public/test/mock_render_process_host.h" |
| 32 #include "content/public/test/test_renderer_host.h" | 33 #include "content/public/test/test_renderer_host.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 class GeolocationPermissionContextTests | 99 class GeolocationPermissionContextTests |
| 99 : public ChromeRenderViewHostTestHarness { | 100 : public ChromeRenderViewHostTestHarness { |
| 100 protected: | 101 protected: |
| 101 // ChromeRenderViewHostTestHarness: | 102 // ChromeRenderViewHostTestHarness: |
| 102 virtual void SetUp() OVERRIDE; | 103 virtual void SetUp() OVERRIDE; |
| 103 virtual void TearDown() OVERRIDE; | 104 virtual void TearDown() OVERRIDE; |
| 104 | 105 |
| 105 PermissionRequestID RequestID(int bridge_id); | 106 PermissionRequestID RequestID(int bridge_id); |
| 106 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 107 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
| 107 InfoBarService* infobar_service() { | 108 InfoBarManager* infobar_manager() { |
| 108 return InfoBarService::FromWebContents(web_contents()); | 109 return InfoBarService::FromWebContents(web_contents())->infobar_manager(); |
| 109 } | 110 } |
| 110 InfoBarService* infobar_service_for_tab(int tab) { | 111 InfoBarManager* infobar_manager_for_tab(int tab) { |
| 111 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 112 return InfoBarService::FromWebContents(extra_tabs_[tab])->infobar_manager(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void RequestGeolocationPermission(const PermissionRequestID& id, | 115 void RequestGeolocationPermission(const PermissionRequestID& id, |
| 115 const GURL& requesting_frame); | 116 const GURL& requesting_frame); |
| 116 void CancelGeolocationPermissionRequest(const PermissionRequestID& id, | 117 void CancelGeolocationPermissionRequest(const PermissionRequestID& id, |
| 117 const GURL& requesting_frame); | 118 const GURL& requesting_frame); |
| 118 void PermissionResponse(const PermissionRequestID& id, | 119 void PermissionResponse(const PermissionRequestID& id, |
| 119 bool allowed); | 120 bool allowed); |
| 120 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 121 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
| 121 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 122 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 void GeolocationPermissionContextTests::TearDown() { | 255 void GeolocationPermissionContextTests::TearDown() { |
| 255 extra_tabs_.clear(); | 256 extra_tabs_.clear(); |
| 256 ChromeRenderViewHostTestHarness::TearDown(); | 257 ChromeRenderViewHostTestHarness::TearDown(); |
| 257 } | 258 } |
| 258 | 259 |
| 259 // Tests ---------------------------------------------------------------------- | 260 // Tests ---------------------------------------------------------------------- |
| 260 | 261 |
| 261 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
| 262 GURL requesting_frame("http://www.example.com/geolocation"); | 263 GURL requesting_frame("http://www.example.com/geolocation"); |
| 263 NavigateAndCommit(requesting_frame); | 264 NavigateAndCommit(requesting_frame); |
| 264 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 265 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 265 RequestGeolocationPermission(RequestID(0), requesting_frame); | 266 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 266 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 267 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 267 InfoBar* infobar = infobar_service()->infobar_at(0); | 268 InfoBar* infobar = infobar_manager()->infobar_at(0); |
| 268 ConfirmInfoBarDelegate* infobar_delegate = | 269 ConfirmInfoBarDelegate* infobar_delegate = |
| 269 infobar->delegate()->AsConfirmInfoBarDelegate(); | 270 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 270 ASSERT_TRUE(infobar_delegate); | 271 ASSERT_TRUE(infobar_delegate); |
| 271 infobar_delegate->Cancel(); | 272 infobar_delegate->Cancel(); |
| 272 infobar_service()->RemoveInfoBar(infobar); | 273 infobar_manager()->RemoveInfoBar(infobar); |
| 273 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 274 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 275 } | 276 } |
| 276 | 277 |
| 277 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
| 278 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| 279 GURL requesting_frame("http://www.example.com/geolocation"); | 280 GURL requesting_frame("http://www.example.com/geolocation"); |
| 280 NavigateAndCommit(requesting_frame); | 281 NavigateAndCommit(requesting_frame); |
| 281 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
| 282 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 283 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 283 RequestGeolocationPermission(RequestID(0), requesting_frame); | 284 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 284 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 285 EXPECT_EQ(1U, infobar_manager()->infobar_count()); |
| 285 ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_service()-> | 286 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 286 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 287 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 287 ASSERT_TRUE(infobar_delegate_0); | 288 ASSERT_TRUE(infobar_delegate_0); |
| 288 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | 289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
| 289 ConfirmInfoBarDelegate::BUTTON_OK); | 290 ConfirmInfoBarDelegate::BUTTON_OK); |
| 290 | 291 |
| 291 NavigateAndCommit(requesting_frame); | 292 NavigateAndCommit(requesting_frame); |
| 292 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
| 293 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 294 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 294 RequestGeolocationPermission(RequestID(0), requesting_frame); | 295 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 295 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 296 EXPECT_EQ(1U, infobar_manager()->infobar_count()); |
| 296 ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_service()-> | 297 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 297 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 298 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 298 ASSERT_TRUE(infobar_delegate_1); | 299 ASSERT_TRUE(infobar_delegate_1); |
| 299 base::string16 text_1 = infobar_delegate_1->GetButtonLabel( | 300 base::string16 text_1 = infobar_delegate_1->GetButtonLabel( |
| 300 ConfirmInfoBarDelegate::BUTTON_OK); | 301 ConfirmInfoBarDelegate::BUTTON_OK); |
| 301 EXPECT_NE(text_0, text_1); | 302 EXPECT_NE(text_0, text_1); |
| 302 | 303 |
| 303 NavigateAndCommit(requesting_frame); | 304 NavigateAndCommit(requesting_frame); |
| 304 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); | 305 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); |
| 305 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 306 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 306 RequestGeolocationPermission(RequestID(0), requesting_frame); | 307 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 307 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 308 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 308 } | 309 } |
| 309 | 310 |
| 310 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 311 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
| 311 GURL requesting_frame("http://www.example.com/geolocation"); | 312 GURL requesting_frame("http://www.example.com/geolocation"); |
| 312 NavigateAndCommit(requesting_frame); | 313 NavigateAndCommit(requesting_frame); |
| 313 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 314 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
| 314 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 315 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 315 RequestGeolocationPermission(RequestID(0), requesting_frame); | 316 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 316 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 317 EXPECT_EQ(1U, infobar_manager()->infobar_count()); |
| 317 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> | 318 ConfirmInfoBarDelegate* infobar_delegate = |
| 318 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 319 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 319 ASSERT_TRUE(infobar_delegate); | 320 ASSERT_TRUE(infobar_delegate); |
| 320 infobar_delegate->Accept(); | 321 infobar_delegate->Accept(); |
| 321 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 322 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 322 CheckPermissionMessageSent(0, true); | 323 CheckPermissionMessageSent(0, true); |
| 323 } | 324 } |
| 324 | 325 |
| 325 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 326 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
| 326 GURL requesting_frame("http://www.example.com/geolocation"); | 327 GURL requesting_frame("http://www.example.com/geolocation"); |
| 327 NavigateAndCommit(requesting_frame); | 328 NavigateAndCommit(requesting_frame); |
| 328 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 329 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
| 329 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 330 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 330 RequestGeolocationPermission(RequestID(0), requesting_frame); | 331 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 331 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 332 EXPECT_EQ(1U, infobar_manager()->infobar_count()); |
| 332 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> | 333 ConfirmInfoBarDelegate* infobar_delegate = |
| 333 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 334 infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 334 ASSERT_TRUE(infobar_delegate); | 335 ASSERT_TRUE(infobar_delegate); |
| 335 infobar_delegate->Accept(); | 336 infobar_delegate->Accept(); |
| 336 EXPECT_TRUE( | 337 EXPECT_TRUE( |
| 337 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); | 338 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); |
| 338 } | 339 } |
| 339 #endif | 340 #endif |
| 340 | 341 |
| 341 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 342 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| 342 GURL requesting_frame_0("http://www.example.com/geolocation"); | 343 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 343 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 344 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 344 EXPECT_EQ(CONTENT_SETTING_ASK, | 345 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 345 profile()->GetHostContentSettingsMap()->GetContentSetting( | 346 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 346 requesting_frame_0, requesting_frame_0, | 347 requesting_frame_0, requesting_frame_0, |
| 347 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 348 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 348 EXPECT_EQ(CONTENT_SETTING_ASK, | 349 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 349 profile()->GetHostContentSettingsMap()->GetContentSetting( | 350 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 350 requesting_frame_1, requesting_frame_0, | 351 requesting_frame_1, requesting_frame_0, |
| 351 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 352 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 352 | 353 |
| 353 NavigateAndCommit(requesting_frame_0); | 354 NavigateAndCommit(requesting_frame_0); |
| 354 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 355 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 355 // Request permission for two frames. | 356 // Request permission for two frames. |
| 356 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 357 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
| 357 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 358 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
| 358 // Ensure only one infobar is created. | 359 // Ensure only one infobar is created. |
| 359 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 360 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 360 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 361 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); |
| 361 ConfirmInfoBarDelegate* infobar_delegate_0 = | 362 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 362 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 363 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 363 ASSERT_TRUE(infobar_delegate_0); | 364 ASSERT_TRUE(infobar_delegate_0); |
| 364 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 365 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
| 365 | 366 |
| 366 // Accept the first frame. | 367 // Accept the first frame. |
| 367 infobar_delegate_0->Accept(); | 368 infobar_delegate_0->Accept(); |
| 368 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 369 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 369 CheckPermissionMessageSent(0, true); | 370 CheckPermissionMessageSent(0, true); |
| 370 | 371 |
| 371 infobar_service()->RemoveInfoBar(infobar_0); | 372 infobar_manager()->RemoveInfoBar(infobar_0); |
| 372 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 373 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 373 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 374 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| 374 closed_infobar_tracker_.Clear(); | 375 closed_infobar_tracker_.Clear(); |
| 375 // Now we should have a new infobar for the second frame. | 376 // Now we should have a new infobar for the second frame. |
| 376 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 377 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 377 | 378 |
| 378 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 379 InfoBar* infobar_1 = infobar_manager()->infobar_at(0); |
| 379 ConfirmInfoBarDelegate* infobar_delegate_1 = | 380 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 380 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 381 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 381 ASSERT_TRUE(infobar_delegate_1); | 382 ASSERT_TRUE(infobar_delegate_1); |
| 382 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | 383 base::string16 text_1 = infobar_delegate_1->GetMessageText(); |
| 383 EXPECT_NE(text_0, text_1); | 384 EXPECT_NE(text_0, text_1); |
| 384 | 385 |
| 385 // Cancel (block) this frame. | 386 // Cancel (block) this frame. |
| 386 infobar_delegate_1->Cancel(); | 387 infobar_delegate_1->Cancel(); |
| 387 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 388 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 388 CheckPermissionMessageSent(1, false); | 389 CheckPermissionMessageSent(1, false); |
| 389 infobar_service()->RemoveInfoBar(infobar_1); | 390 infobar_manager()->RemoveInfoBar(infobar_1); |
| 390 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 391 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 391 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 392 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 392 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 393 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 393 // Ensure the persisted permissions are ok. | 394 // Ensure the persisted permissions are ok. |
| 394 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 395 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 395 profile()->GetHostContentSettingsMap()->GetContentSetting( | 396 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 396 requesting_frame_0, requesting_frame_0, | 397 requesting_frame_0, requesting_frame_0, |
| 397 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 398 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 398 | 399 |
| 399 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 400 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 400 profile()->GetHostContentSettingsMap()->GetContentSetting( | 401 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 401 requesting_frame_1, requesting_frame_0, | 402 requesting_frame_1, requesting_frame_0, |
| 402 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 403 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 403 } | 404 } |
| 404 | 405 |
| 405 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 406 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
| 406 GURL url_a("http://www.example.com/geolocation#a"); | 407 GURL url_a("http://www.example.com/geolocation#a"); |
| 407 GURL url_b("http://www.example.com/geolocation#b"); | 408 GURL url_b("http://www.example.com/geolocation#b"); |
| 408 | 409 |
| 409 // Navigate to the first url and check permission is requested. | 410 // Navigate to the first url and check permission is requested. |
| 410 NavigateAndCommit(url_a); | 411 NavigateAndCommit(url_a); |
| 411 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 412 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 412 RequestGeolocationPermission(RequestID(0), url_a); | 413 RequestGeolocationPermission(RequestID(0), url_a); |
| 413 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 414 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 414 InfoBar* infobar = infobar_service()->infobar_at(0); | 415 InfoBar* infobar = infobar_manager()->infobar_at(0); |
| 415 ConfirmInfoBarDelegate* infobar_delegate = | 416 ConfirmInfoBarDelegate* infobar_delegate = |
| 416 infobar->delegate()->AsConfirmInfoBarDelegate(); | 417 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 417 ASSERT_TRUE(infobar_delegate); | 418 ASSERT_TRUE(infobar_delegate); |
| 418 | 419 |
| 419 // Change the hash, we'll still be on the same page. | 420 // Change the hash, we'll still be on the same page. |
| 420 NavigateAndCommit(url_b); | 421 NavigateAndCommit(url_b); |
| 421 | 422 |
| 422 // Accept. | 423 // Accept. |
| 423 infobar_delegate->Accept(); | 424 infobar_delegate->Accept(); |
| 424 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 425 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 425 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 426 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 426 CheckPermissionMessageSent(0, true); | 427 CheckPermissionMessageSent(0, true); |
| 427 | 428 |
| 428 // Cleanup. | 429 // Cleanup. |
| 429 infobar_service()->RemoveInfoBar(infobar); | 430 infobar_manager()->RemoveInfoBar(infobar); |
| 430 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 431 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 431 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 432 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 432 } | 433 } |
| 433 | 434 |
| 434 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 435 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { |
| 435 GURL requesting_frame("file://example/geolocation.html"); | 436 GURL requesting_frame("file://example/geolocation.html"); |
| 436 NavigateAndCommit(requesting_frame); | 437 NavigateAndCommit(requesting_frame); |
| 437 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 438 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 438 RequestGeolocationPermission(RequestID(0), requesting_frame); | 439 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 439 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 440 EXPECT_EQ(1U, infobar_manager()->infobar_count()); |
| 440 InfoBar* infobar = infobar_service()->infobar_at(0); | 441 InfoBar* infobar = infobar_manager()->infobar_at(0); |
| 441 ConfirmInfoBarDelegate* infobar_delegate = | 442 ConfirmInfoBarDelegate* infobar_delegate = |
| 442 infobar->delegate()->AsConfirmInfoBarDelegate(); | 443 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 443 ASSERT_TRUE(infobar_delegate); | 444 ASSERT_TRUE(infobar_delegate); |
| 444 // Accept the frame. | 445 // Accept the frame. |
| 445 infobar_delegate->Accept(); | 446 infobar_delegate->Accept(); |
| 446 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 447 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 447 CheckPermissionMessageSent(0, true); | 448 CheckPermissionMessageSent(0, true); |
| 448 infobar_service()->RemoveInfoBar(infobar); | 449 infobar_manager()->RemoveInfoBar(infobar); |
| 449 | 450 |
| 450 // Make sure the setting is not stored. | 451 // Make sure the setting is not stored. |
| 451 EXPECT_EQ(CONTENT_SETTING_ASK, | 452 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 452 profile()->GetHostContentSettingsMap()->GetContentSetting( | 453 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 453 requesting_frame, | 454 requesting_frame, |
| 454 requesting_frame, | 455 requesting_frame, |
| 455 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 456 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 456 std::string())); | 457 std::string())); |
| 457 } | 458 } |
| 458 | 459 |
| 459 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 460 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| 460 GURL requesting_frame_0("http://www.example.com/geolocation"); | 461 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 461 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 462 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 462 EXPECT_EQ(CONTENT_SETTING_ASK, | 463 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 463 profile()->GetHostContentSettingsMap()->GetContentSetting( | 464 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 464 requesting_frame_0, requesting_frame_0, | 465 requesting_frame_0, requesting_frame_0, |
| 465 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 466 | 467 |
| 467 EXPECT_EQ(CONTENT_SETTING_ASK, | 468 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 468 profile()->GetHostContentSettingsMap()->GetContentSetting( | 469 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 469 requesting_frame_1, requesting_frame_0, | 470 requesting_frame_1, requesting_frame_0, |
| 470 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 471 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 471 | 472 |
| 472 NavigateAndCommit(requesting_frame_0); | 473 NavigateAndCommit(requesting_frame_0); |
| 473 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 474 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 474 // Request permission for two frames. | 475 // Request permission for two frames. |
| 475 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 476 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
| 476 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 477 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
| 477 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 478 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 478 | 479 |
| 479 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 480 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); |
| 480 ConfirmInfoBarDelegate* infobar_delegate_0 = | 481 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 481 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 482 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 482 ASSERT_TRUE(infobar_delegate_0); | 483 ASSERT_TRUE(infobar_delegate_0); |
| 483 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 484 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
| 484 | 485 |
| 485 // Simulate the frame going away, ensure the infobar for this frame | 486 // Simulate the frame going away, ensure the infobar for this frame |
| 486 // is removed and the next pending infobar is created. | 487 // is removed and the next pending infobar is created. |
| 487 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); | 488 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); |
| 488 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 489 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 489 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 490 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| 490 closed_infobar_tracker_.Clear(); | 491 closed_infobar_tracker_.Clear(); |
| 491 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 492 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 492 | 493 |
| 493 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 494 InfoBar* infobar_1 = infobar_manager()->infobar_at(0); |
| 494 ConfirmInfoBarDelegate* infobar_delegate_1 = | 495 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 495 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 496 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 496 ASSERT_TRUE(infobar_delegate_1); | 497 ASSERT_TRUE(infobar_delegate_1); |
| 497 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | 498 base::string16 text_1 = infobar_delegate_1->GetMessageText(); |
| 498 EXPECT_NE(text_0, text_1); | 499 EXPECT_NE(text_0, text_1); |
| 499 | 500 |
| 500 // Allow this frame. | 501 // Allow this frame. |
| 501 infobar_delegate_1->Accept(); | 502 infobar_delegate_1->Accept(); |
| 502 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 503 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 503 CheckPermissionMessageSent(1, true); | 504 CheckPermissionMessageSent(1, true); |
| 504 infobar_service()->RemoveInfoBar(infobar_1); | 505 infobar_manager()->RemoveInfoBar(infobar_1); |
| 505 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 506 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 506 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 507 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 507 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 508 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 508 // Ensure the persisted permissions are ok. | 509 // Ensure the persisted permissions are ok. |
| 509 EXPECT_EQ(CONTENT_SETTING_ASK, | 510 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 510 profile()->GetHostContentSettingsMap()->GetContentSetting( | 511 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 511 requesting_frame_0, requesting_frame_0, | 512 requesting_frame_0, requesting_frame_0, |
| 512 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 513 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 513 | 514 |
| 514 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 515 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 515 profile()->GetHostContentSettingsMap()->GetContentSetting( | 516 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 516 requesting_frame_1, requesting_frame_0, | 517 requesting_frame_1, requesting_frame_0, |
| 517 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 518 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 518 } | 519 } |
| 519 | 520 |
| 520 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 521 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| 521 GURL invalid_embedder("about:blank"); | 522 GURL invalid_embedder("about:blank"); |
| 522 GURL requesting_frame; | 523 GURL requesting_frame; |
| 523 NavigateAndCommit(invalid_embedder); | 524 NavigateAndCommit(invalid_embedder); |
| 524 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 525 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 525 RequestGeolocationPermission(RequestID(0), requesting_frame); | 526 RequestGeolocationPermission(RequestID(0), requesting_frame); |
| 526 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 527 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 527 CheckPermissionMessageSent(0, false); | 528 CheckPermissionMessageSent(0, false); |
| 528 } | 529 } |
| 529 | 530 |
| 530 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 531 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| 531 GURL url_a("http://www.example.com/geolocation"); | 532 GURL url_a("http://www.example.com/geolocation"); |
| 532 GURL url_b("http://www.example-2.com/geolocation"); | 533 GURL url_b("http://www.example-2.com/geolocation"); |
| 533 NavigateAndCommit(url_a); | 534 NavigateAndCommit(url_a); |
| 534 AddNewTab(url_b); | 535 AddNewTab(url_b); |
| 535 AddNewTab(url_a); | 536 AddNewTab(url_a); |
| 536 | 537 |
| 537 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 538 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 538 RequestGeolocationPermission(RequestID(0), url_a); | 539 RequestGeolocationPermission(RequestID(0), url_a); |
| 539 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 540 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 540 | 541 |
| 541 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); | 542 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
| 542 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 543 EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); |
| 543 | 544 |
| 544 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); | 545 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
| 545 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 546 ASSERT_EQ(1U, infobar_manager_for_tab(1)->infobar_count()); |
| 546 | 547 |
| 547 InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); | 548 InfoBar* removed_infobar = infobar_manager_for_tab(1)->infobar_at(0); |
| 548 | 549 |
| 549 // Accept the first tab. | 550 // Accept the first tab. |
| 550 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 551 InfoBar* infobar_0 = infobar_manager()->infobar_at(0); |
| 551 ConfirmInfoBarDelegate* infobar_delegate_0 = | 552 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 552 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 553 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 553 ASSERT_TRUE(infobar_delegate_0); | 554 ASSERT_TRUE(infobar_delegate_0); |
| 554 infobar_delegate_0->Accept(); | 555 infobar_delegate_0->Accept(); |
| 555 CheckPermissionMessageSent(0, true); | 556 CheckPermissionMessageSent(0, true); |
| 556 infobar_service()->RemoveInfoBar(infobar_0); | 557 infobar_manager()->RemoveInfoBar(infobar_0); |
| 557 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 558 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| 558 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 559 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| 559 // Now the infobar for the tab with the same origin should have gone. | 560 // Now the infobar for the tab with the same origin should have gone. |
| 560 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 561 EXPECT_EQ(0U, infobar_manager_for_tab(1)->infobar_count()); |
| 561 CheckPermissionMessageSentForTab(1, 0, true); | 562 CheckPermissionMessageSentForTab(1, 0, true); |
| 562 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 563 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
| 563 closed_infobar_tracker_.Clear(); | 564 closed_infobar_tracker_.Clear(); |
| 564 | 565 |
| 565 // But the other tab should still have the info bar... | 566 // But the other tab should still have the info bar... |
| 566 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 567 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); |
| 567 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 568 InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); |
| 568 ConfirmInfoBarDelegate* infobar_delegate_1 = | 569 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 569 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 570 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 570 ASSERT_TRUE(infobar_delegate_1); | 571 ASSERT_TRUE(infobar_delegate_1); |
| 571 infobar_delegate_1->Cancel(); | 572 infobar_delegate_1->Cancel(); |
| 572 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 573 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); |
| 573 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 574 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 574 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 575 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 575 } | 576 } |
| 576 | 577 |
| 577 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 578 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| 578 GURL url_a("http://www.example.com/geolocation"); | 579 GURL url_a("http://www.example.com/geolocation"); |
| 579 GURL url_b("http://www.example-2.com/geolocation"); | 580 GURL url_b("http://www.example-2.com/geolocation"); |
| 580 NavigateAndCommit(url_a); | 581 NavigateAndCommit(url_a); |
| 581 AddNewTab(url_a); | 582 AddNewTab(url_a); |
| 582 | 583 |
| 583 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 584 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 584 RequestGeolocationPermission(RequestID(0), url_a); | 585 RequestGeolocationPermission(RequestID(0), url_a); |
| 585 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 586 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 586 | 587 |
| 587 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); | 588 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
| 588 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 589 EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); |
| 589 | 590 |
| 590 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); | 591 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
| 591 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 592 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); |
| 592 | 593 |
| 593 InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 594 InfoBar* removed_infobar = infobar_manager()->infobar_at(0); |
| 594 | 595 |
| 595 // Accept the second tab. | 596 // Accept the second tab. |
| 596 InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 597 InfoBar* infobar_0 = infobar_manager_for_tab(0)->infobar_at(0); |
| 597 ConfirmInfoBarDelegate* infobar_delegate_0 = | 598 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 598 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 599 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 599 ASSERT_TRUE(infobar_delegate_0); | 600 ASSERT_TRUE(infobar_delegate_0); |
| 600 infobar_delegate_0->Accept(); | 601 infobar_delegate_0->Accept(); |
| 601 CheckPermissionMessageSentForTab(0, 0, true); | 602 CheckPermissionMessageSentForTab(0, 0, true); |
| 602 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 603 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_0); |
| 603 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 604 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| 604 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 605 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| 605 // Now the infobar for the tab with the same origin should have gone. | 606 // Now the infobar for the tab with the same origin should have gone. |
| 606 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 607 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 607 CheckPermissionMessageSent(0, true); | 608 CheckPermissionMessageSent(0, true); |
| 608 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 609 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
| 609 closed_infobar_tracker_.Clear(); | 610 closed_infobar_tracker_.Clear(); |
| 610 | 611 |
| 611 // And we should have the queued infobar displayed now. | 612 // And we should have the queued infobar displayed now. |
| 612 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 613 ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); |
| 613 | 614 |
| 614 // Accept the second infobar. | 615 // Accept the second infobar. |
| 615 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 616 InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); |
| 616 ConfirmInfoBarDelegate* infobar_delegate_1 = | 617 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 617 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 618 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 618 ASSERT_TRUE(infobar_delegate_1); | 619 ASSERT_TRUE(infobar_delegate_1); |
| 619 infobar_delegate_1->Accept(); | 620 infobar_delegate_1->Accept(); |
| 620 CheckPermissionMessageSentForTab(0, 1, true); | 621 CheckPermissionMessageSentForTab(0, 1, true); |
| 621 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 622 infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); |
| 622 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 623 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 623 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 624 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 624 } | 625 } |
| 625 | 626 |
| 626 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 627 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| 627 GURL requesting_frame_0("http://www.example.com/geolocation"); | 628 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 628 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 629 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 629 EXPECT_EQ(CONTENT_SETTING_ASK, | 630 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 630 profile()->GetHostContentSettingsMap()->GetContentSetting( | 631 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 631 requesting_frame_0, requesting_frame_0, | 632 requesting_frame_0, requesting_frame_0, |
| 632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 633 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 633 | 634 |
| 634 EXPECT_EQ(CONTENT_SETTING_ASK, | 635 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 635 profile()->GetHostContentSettingsMap()->GetContentSetting( | 636 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 636 requesting_frame_1, requesting_frame_0, | 637 requesting_frame_1, requesting_frame_0, |
| 637 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 638 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 638 | 639 |
| 639 NavigateAndCommit(requesting_frame_0); | 640 NavigateAndCommit(requesting_frame_0); |
| 640 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 641 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 641 // Request permission for two frames. | 642 // Request permission for two frames. |
| 642 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 643 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
| 643 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 644 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
| 644 // Ensure only one infobar is created. | 645 // Ensure only one infobar is created. |
| 645 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 646 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 646 InfoBar* infobar = infobar_service()->infobar_at(0); | 647 InfoBar* infobar = infobar_manager()->infobar_at(0); |
| 647 | 648 |
| 648 // Delete the tab contents. | 649 // Delete the tab contents. |
| 649 DeleteContents(); | 650 DeleteContents(); |
| 650 | 651 |
| 651 // During contents destruction, the infobar will have been closed, and the | 652 // During contents destruction, the infobar will have been closed, and the |
| 652 // pending request should have been cleared without an infobar being created. | 653 // pending request should have been cleared without an infobar being created. |
| 653 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 654 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
| 654 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 655 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 655 } | 656 } |
| 656 | 657 |
| 657 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 658 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
| 658 GURL requesting_frame_0("http://www.example.com/geolocation"); | 659 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 659 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 660 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 660 NavigateAndCommit(requesting_frame_0); | 661 NavigateAndCommit(requesting_frame_0); |
| 661 NavigateAndCommit(requesting_frame_1); | 662 NavigateAndCommit(requesting_frame_1); |
| 662 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 663 EXPECT_EQ(0U, infobar_manager()->infobar_count()); |
| 663 // Go back: navigate to a pending entry before requesting geolocation | 664 // Go back: navigate to a pending entry before requesting geolocation |
| 664 // permission. | 665 // permission. |
| 665 web_contents()->GetController().GoBack(); | 666 web_contents()->GetController().GoBack(); |
| 666 // Request permission for the committed frame (not the pending one). | 667 // Request permission for the committed frame (not the pending one). |
| 667 RequestGeolocationPermission(RequestID(0), requesting_frame_1); | 668 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
| 668 // Ensure the infobar is created. | 669 // Ensure the infobar is created. |
| 669 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 670 ASSERT_EQ(1U, infobar_manager()->infobar_count()); |
| 670 InfoBarDelegate* infobar_delegate = | 671 InfoBarDelegate* infobar_delegate = |
| 671 infobar_service()->infobar_at(0)->delegate(); | 672 infobar_manager()->infobar_at(0)->delegate(); |
| 672 ASSERT_TRUE(infobar_delegate); | 673 ASSERT_TRUE(infobar_delegate); |
| 673 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 674 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
| 674 content::LoadCommittedDetails details; | 675 content::LoadCommittedDetails details; |
| 675 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 676 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
| 676 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); | 677 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); |
| 677 // Ensure the infobar will expire when we commit the pending navigation. | 678 // Ensure the infobar will expire when we commit the pending navigation. |
| 678 details.entry = web_contents()->GetController().GetActiveEntry(); | 679 details.entry = web_contents()->GetController().GetActiveEntry(); |
| 679 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); | 680 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); |
| 680 | 681 |
| 681 // Delete the tab contents. | 682 // Delete the tab contents. |
| 682 DeleteContents(); | 683 DeleteContents(); |
| 683 } | 684 } |
| OLD | NEW |