| 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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 310 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 311 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( | 311 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( |
| 312 PermissionManager::Get(profile())->GetPermissionContext( | 312 PermissionManager::Get(profile())->GetPermissionContext( |
| 313 CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 313 CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 314 #if defined(OS_ANDROID) | 314 #if defined(OS_ANDROID) |
| 315 static_cast<GeolocationPermissionContextAndroid*>( | 315 static_cast<GeolocationPermissionContextAndroid*>( |
| 316 geolocation_permission_context_) | 316 geolocation_permission_context_) |
| 317 ->SetLocationSettingsForTesting( | 317 ->SetLocationSettingsForTesting( |
| 318 std::unique_ptr<LocationSettings>(new MockLocationSettings())); | 318 std::unique_ptr<LocationSettings>(new MockLocationSettings())); |
| 319 MockLocationSettings::SetLocationStatus(true, true); | 319 MockLocationSettings::SetLocationStatus(true, true); |
| 320 MockLocationSettings::SetCanPromptForAndroidPermission(true); |
| 320 #else | 321 #else |
| 321 SetupRequestManager(web_contents()); | 322 SetupRequestManager(web_contents()); |
| 322 #endif | 323 #endif |
| 323 } | 324 } |
| 324 | 325 |
| 325 void GeolocationPermissionContextTests::TearDown() { | 326 void GeolocationPermissionContextTests::TearDown() { |
| 326 #if !defined(OS_ANDROID) | 327 #if !defined(OS_ANDROID) |
| 327 mock_permission_prompt_factories_.clear(); | 328 mock_permission_prompt_factories_.clear(); |
| 328 #endif | 329 #endif |
| 329 extra_tabs_.clear(); | 330 extra_tabs_.clear(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 infobar_delegate->Cancel(); | 469 infobar_delegate->Cancel(); |
| 469 infobar_service()->RemoveInfoBar(infobar); | 470 infobar_service()->RemoveInfoBar(infobar); |
| 470 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 471 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 471 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 472 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 472 } | 473 } |
| 473 | 474 |
| 474 // Infobar-only tests; Android doesn't support permission bubbles. | 475 // Infobar-only tests; Android doesn't support permission bubbles. |
| 475 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 476 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| 476 GURL requesting_frame("https://www.example.com/geolocation"); | 477 GURL requesting_frame("https://www.example.com/geolocation"); |
| 477 NavigateAndCommit(requesting_frame); | 478 NavigateAndCommit(requesting_frame); |
| 478 MockLocationSettings::SetLocationStatus(true, true); | 479 MockLocationSettings::SetLocationStatus(true /* android */, |
| 480 true /* system */); |
| 479 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 481 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 480 RequestGeolocationPermission( | 482 RequestGeolocationPermission( |
| 481 web_contents(), RequestID(0), requesting_frame, true); | 483 web_contents(), RequestID(0), requesting_frame, true); |
| 482 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 484 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 483 ConfirmInfoBarDelegate* infobar_delegate_0 = | 485 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 484 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 486 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 485 ASSERT_TRUE(infobar_delegate_0); | 487 ASSERT_TRUE(infobar_delegate_0); |
| 486 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | 488 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
| 487 ConfirmInfoBarDelegate::BUTTON_OK); | 489 ConfirmInfoBarDelegate::BUTTON_OK); |
| 488 | 490 |
| 489 Reload(); | 491 Reload(); |
| 490 MockLocationSettings::SetLocationStatus(true, false); | 492 MockLocationSettings::SetLocationStatus(false /* android */, |
| 493 true /* system */); |
| 494 MockLocationSettings::SetCanPromptForAndroidPermission(false); |
| 491 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 495 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 492 RequestGeolocationPermission( | 496 RequestGeolocationPermission( |
| 493 web_contents(), RequestID(0), requesting_frame, true); | 497 web_contents(), RequestID(0), requesting_frame, true); |
| 494 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 498 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 495 } | 499 } |
| 496 | 500 |
| 497 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 501 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) { |
| 498 GURL requesting_frame("https://www.example.com/geolocation"); | 502 GURL requesting_frame("https://www.example.com/geolocation"); |
| 499 NavigateAndCommit(requesting_frame); | 503 NavigateAndCommit(requesting_frame); |
| 500 MockLocationSettings::SetLocationStatus(true, true); | 504 MockLocationSettings::SetLocationStatus(false /* android */, |
| 505 true /* system */); |
| 501 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 506 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 502 RequestGeolocationPermission( | 507 RequestGeolocationPermission( |
| 503 web_contents(), RequestID(0), requesting_frame, true); | 508 web_contents(), RequestID(0), requesting_frame, true); |
| 504 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 509 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 505 ConfirmInfoBarDelegate* infobar_delegate = | 510 ConfirmInfoBarDelegate* infobar_delegate = |
| 506 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 511 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 507 ASSERT_TRUE(infobar_delegate); | 512 ASSERT_TRUE(infobar_delegate); |
| 508 infobar_delegate->Accept(); | 513 infobar_delegate->Accept(); |
| 509 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 514 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 510 CheckPermissionMessageSent(0, true); | 515 CheckPermissionMessageSent(0, true); |
| 511 } | 516 } |
| 512 | 517 |
| 513 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 518 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) { |
| 514 GURL requesting_frame("https://www.example.com/geolocation"); | 519 GURL requesting_frame("https://www.example.com/geolocation"); |
| 515 NavigateAndCommit(requesting_frame); | 520 NavigateAndCommit(requesting_frame); |
| 516 MockLocationSettings::SetLocationStatus(true, false); | 521 MockLocationSettings::SetLocationStatus(false /* android */, |
| 522 true /* system */); |
| 523 MockLocationSettings::SetCanPromptForAndroidPermission(false); |
| 524 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 525 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| 526 true); |
| 527 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 528 } |
| 529 |
| 530 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) { |
| 531 base::test::ScopedFeatureList scoped_feature_list; |
| 532 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| 533 |
| 534 GURL requesting_frame("https://www.example.com/geolocation"); |
| 535 NavigateAndCommit(requesting_frame); |
| 536 MockLocationSettings::SetLocationStatus(true /* android */, |
| 537 false /* system */); |
| 517 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 538 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 518 RequestGeolocationPermission( | 539 RequestGeolocationPermission( |
| 519 web_contents(), RequestID(0), requesting_frame, true); | 540 web_contents(), RequestID(0), requesting_frame, true); |
| 520 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 541 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 521 } | 542 } |
| 543 |
| 544 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { |
| 545 base::test::ScopedFeatureList scoped_feature_list; |
| 546 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| 547 |
| 548 GURL requesting_frame("https://www.example.com/geolocation"); |
| 549 NavigateAndCommit(requesting_frame); |
| 550 MockLocationSettings::SetLocationStatus(true /* android */, |
| 551 false /* system */); |
| 552 MockLocationSettings::SetLocationSettingsDialogStatus( |
| 553 true, LocationSettings::GRANTED); |
| 554 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 555 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| 556 true); |
| 557 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 558 ConfirmInfoBarDelegate* infobar_delegate = |
| 559 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 560 ASSERT_TRUE(infobar_delegate); |
| 561 infobar_delegate->Accept(); |
| 562 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 563 CheckPermissionMessageSent(0, true); |
| 564 } |
| 565 |
| 566 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { |
| 567 base::test::ScopedFeatureList scoped_feature_list; |
| 568 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| 569 |
| 570 GURL requesting_frame("https://www.example.com/geolocation"); |
| 571 NavigateAndCommit(requesting_frame); |
| 572 MockLocationSettings::SetLocationStatus(true /* android */, |
| 573 false /* system */); |
| 574 MockLocationSettings::SetLocationSettingsDialogStatus( |
| 575 true, LocationSettings::DENIED); |
| 576 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 577 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| 578 true); |
| 579 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 580 ConfirmInfoBarDelegate* infobar_delegate = |
| 581 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 582 ASSERT_TRUE(infobar_delegate); |
| 583 infobar_delegate->Accept(); |
| 584 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK); |
| 585 CheckPermissionMessageSent(0, false); |
| 586 } |
| 522 #endif | 587 #endif |
| 523 | 588 |
| 524 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 589 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| 525 GURL requesting_frame_0("https://www.example.com/geolocation"); | 590 GURL requesting_frame_0("https://www.example.com/geolocation"); |
| 526 GURL requesting_frame_1("https://www.example-2.com/geolocation"); | 591 GURL requesting_frame_1("https://www.example-2.com/geolocation"); |
| 527 EXPECT_EQ( | 592 EXPECT_EQ( |
| 528 CONTENT_SETTING_ASK, | 593 CONTENT_SETTING_ASK, |
| 529 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); | 594 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); |
| 530 EXPECT_EQ( | 595 EXPECT_EQ( |
| 531 CONTENT_SETTING_ASK, | 596 CONTENT_SETTING_ASK, |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 920 | 985 |
| 921 // Changing the setting to BLOCK should flow through to incognito. | 986 // Changing the setting to BLOCK should flow through to incognito. |
| 922 geo_service->SetDSEGeolocationSetting(false); | 987 geo_service->SetDSEGeolocationSetting(false); |
| 923 ASSERT_EQ(CONTENT_SETTING_BLOCK, | 988 ASSERT_EQ(CONTENT_SETTING_BLOCK, |
| 924 PermissionManager::Get(otr_profile) | 989 PermissionManager::Get(otr_profile) |
| 925 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, | 990 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 926 requesting_frame, requesting_frame) | 991 requesting_frame, requesting_frame) |
| 927 .content_setting); | 992 .content_setting); |
| 928 } | 993 } |
| 929 #endif // defined(OS_ANDROID) | 994 #endif // defined(OS_ANDROID) |
| OLD | NEW |