Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_unittest.cc

Issue 2742373003: Limit the amount the Location Settings Dialog will be shown to users. (Closed)
Patch Set: Feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void AddNewTab(const GURL& url); 173 void AddNewTab(const GURL& url);
174 void CheckTabContentsState(const GURL& requesting_frame, 174 void CheckTabContentsState(const GURL& requesting_frame,
175 ContentSetting expected_content_setting); 175 ContentSetting expected_content_setting);
176 #if !defined(OS_ANDROID) 176 #if !defined(OS_ANDROID)
177 void SetupRequestManager(content::WebContents* web_contents); 177 void SetupRequestManager(content::WebContents* web_contents);
178 size_t GetBubblesQueueSize(PermissionRequestManager* manager); 178 size_t GetBubblesQueueSize(PermissionRequestManager* manager);
179 void AcceptBubble(PermissionRequestManager* manager); 179 void AcceptBubble(PermissionRequestManager* manager);
180 void DenyBubble(PermissionRequestManager* manager); 180 void DenyBubble(PermissionRequestManager* manager);
181 void CloseBubble(PermissionRequestManager* manager); 181 void CloseBubble(PermissionRequestManager* manager);
182 #endif 182 #endif
183 #if defined(OS_ANDROID)
184 bool RequestPermissionIsLSDShown(const GURL& origin);
185 bool RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin);
186 void AddDayOffsetForTesting(int days);
187 void SetDSEOriginForTesting(const char* dse_origin);
188 #endif
183 void RequestManagerDocumentLoadCompleted(); 189 void RequestManagerDocumentLoadCompleted();
184 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents); 190 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents);
185 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 191 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
186 void SetGeolocationContentSetting(GURL frame_0, 192 void SetGeolocationContentSetting(GURL frame_0,
187 GURL frame_1, 193 GURL frame_1,
188 ContentSetting content_setting); 194 ContentSetting content_setting);
189 size_t GetNumberOfPrompts(); 195 size_t GetNumberOfPrompts();
190 void AcceptPrompt(); 196 void AcceptPrompt();
191 base::string16 GetPromptText(); 197 base::string16 GetPromptText();
192 198
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 CONTENT_SETTINGS_TYPE_GEOLOCATION)); 323 CONTENT_SETTINGS_TYPE_GEOLOCATION));
318 #if defined(OS_ANDROID) 324 #if defined(OS_ANDROID)
319 static_cast<GeolocationPermissionContextAndroid*>( 325 static_cast<GeolocationPermissionContextAndroid*>(
320 geolocation_permission_context_) 326 geolocation_permission_context_)
321 ->SetLocationSettingsForTesting( 327 ->SetLocationSettingsForTesting(
322 std::unique_ptr<LocationSettings>(new MockLocationSettings())); 328 std::unique_ptr<LocationSettings>(new MockLocationSettings()));
323 MockLocationSettings::SetLocationStatus(true, true); 329 MockLocationSettings::SetLocationStatus(true, true);
324 MockLocationSettings::SetCanPromptForAndroidPermission(true); 330 MockLocationSettings::SetCanPromptForAndroidPermission(true);
325 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */, 331 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
326 GRANTED); 332 GRANTED);
333 MockLocationSettings::ClearHasShownLocationSettingsDialog();
327 #else 334 #else
328 SetupRequestManager(web_contents()); 335 SetupRequestManager(web_contents());
329 #endif 336 #endif
330 } 337 }
331 338
332 void GeolocationPermissionContextTests::TearDown() { 339 void GeolocationPermissionContextTests::TearDown() {
333 #if !defined(OS_ANDROID) 340 #if !defined(OS_ANDROID)
334 mock_permission_prompt_factories_.clear(); 341 mock_permission_prompt_factories_.clear();
335 #endif 342 #endif
336 extra_tabs_.clear(); 343 extra_tabs_.clear();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 PermissionRequestManager* manager) { 375 PermissionRequestManager* manager) {
369 manager->Deny(); 376 manager->Deny();
370 } 377 }
371 378
372 void GeolocationPermissionContextTests::CloseBubble( 379 void GeolocationPermissionContextTests::CloseBubble(
373 PermissionRequestManager* manager) { 380 PermissionRequestManager* manager) {
374 manager->Closing(); 381 manager->Closing();
375 } 382 }
376 #endif 383 #endif
377 384
385 #if defined(OS_ANDROID)
386 bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown(
387 const GURL& origin) {
388 NavigateAndCommit(origin);
389 MockLocationSettings::ClearHasShownLocationSettingsDialog();
390 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
391
392 return MockLocationSettings::HasShownLocationSettingsDialog();
393 }
394
395 bool GeolocationPermissionContextTests::
396 RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin) {
397 NavigateAndCommit(origin);
398 MockLocationSettings::ClearHasShownLocationSettingsDialog();
399 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
400
401 EXPECT_EQ(1U, infobar_service()->infobar_count());
402 ConfirmInfoBarDelegate* infobar_delegate =
403 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
404 EXPECT_TRUE(infobar_delegate);
405 infobar_delegate->Accept();
406
407 return MockLocationSettings::HasShownLocationSettingsDialog();
408 }
409
410 void GeolocationPermissionContextTests::AddDayOffsetForTesting(int days) {
411 GeolocationPermissionContextAndroid::AddDayOffsetForTesting(days);
412 }
413
414 void GeolocationPermissionContextTests::SetDSEOriginForTesting(
415 const char* dse_origin) {
416 GeolocationPermissionContextAndroid::SetDSEOriginForTesting(dse_origin);
417 }
418 #endif
419
378 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() { 420 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() {
379 GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( 421 GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
380 web_contents()); 422 web_contents());
381 } 423 }
382 424
383 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( 425 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
384 content::WebContents* web_contents) { 426 content::WebContents* web_contents) {
385 #if !defined(OS_ANDROID) 427 #if !defined(OS_ANDROID)
386 PermissionRequestManager::FromWebContents(web_contents)-> 428 PermissionRequestManager::FromWebContents(web_contents)->
387 DocumentOnLoadCompletedInMainFrame(); 429 DocumentOnLoadCompletedInMainFrame();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 620 }
579 621
580 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { 622 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) {
581 base::test::ScopedFeatureList scoped_feature_list; 623 base::test::ScopedFeatureList scoped_feature_list;
582 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 624 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
583 625
584 GURL requesting_frame("https://www.example.com/geolocation"); 626 GURL requesting_frame("https://www.example.com/geolocation");
585 NavigateAndCommit(requesting_frame); 627 NavigateAndCommit(requesting_frame);
586 MockLocationSettings::SetLocationStatus(true /* android */, 628 MockLocationSettings::SetLocationStatus(true /* android */,
587 false /* system */); 629 false /* system */);
588 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED); 630 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
631 GRANTED);
589 EXPECT_EQ(0U, infobar_service()->infobar_count()); 632 EXPECT_EQ(0U, infobar_service()->infobar_count());
590 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 633 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
591 true); 634 true);
592 EXPECT_EQ(1U, infobar_service()->infobar_count()); 635 EXPECT_EQ(1U, infobar_service()->infobar_count());
593 ConfirmInfoBarDelegate* infobar_delegate = 636 ConfirmInfoBarDelegate* infobar_delegate =
594 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 637 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
595 ASSERT_TRUE(infobar_delegate); 638 ASSERT_TRUE(infobar_delegate);
596 infobar_delegate->Accept(); 639 infobar_delegate->Accept();
597 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 640 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
598 CheckPermissionMessageSent(0, true); 641 CheckPermissionMessageSent(0, true);
599 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); 642 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
600 } 643 }
601 644
602 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { 645 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) {
603 base::test::ScopedFeatureList scoped_feature_list; 646 base::test::ScopedFeatureList scoped_feature_list;
604 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 647 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
605 648
606 GURL requesting_frame("https://www.example.com/geolocation"); 649 GURL requesting_frame("https://www.example.com/geolocation");
607 NavigateAndCommit(requesting_frame); 650 NavigateAndCommit(requesting_frame);
608 MockLocationSettings::SetLocationStatus(true /* android */, 651 MockLocationSettings::SetLocationStatus(true /* android */,
609 false /* system */); 652 false /* system */);
610 MockLocationSettings::SetLocationSettingsDialogStatus(true, DENIED); 653 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
654 DENIED);
611 EXPECT_EQ(0U, infobar_service()->infobar_count()); 655 EXPECT_EQ(0U, infobar_service()->infobar_count());
612 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 656 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
613 true); 657 true);
614 EXPECT_EQ(1U, infobar_service()->infobar_count()); 658 EXPECT_EQ(1U, infobar_service()->infobar_count());
615 ConfirmInfoBarDelegate* infobar_delegate = 659 ConfirmInfoBarDelegate* infobar_delegate =
616 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 660 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
617 ASSERT_TRUE(infobar_delegate); 661 ASSERT_TRUE(infobar_delegate);
618 infobar_delegate->Accept(); 662 infobar_delegate->Accept();
619 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK); 663 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK);
620 CheckPermissionMessageSent(0, false); 664 CheckPermissionMessageSent(0, false);
621 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); 665 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
622 } 666 }
667
668 TEST_F(GeolocationPermissionContextTests, LSDBackOffDifferentSites) {
669 base::test::ScopedFeatureList scoped_feature_list;
670 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
671
672 GURL requesting_frame_1("https://www.example.com/geolocation");
673 GURL requesting_frame_2("https://www.example-2.com/geolocation");
674 const char* requesting_frame_dse_ptr = "https://www.dse.com/geolocation";
675 GURL requesting_frame_dse(requesting_frame_dse_ptr);
676
677 SetDSEOriginForTesting(requesting_frame_dse_ptr);
678
679 // Set all origin geolocation permissions to ALLOW.
680 SetGeolocationContentSetting(requesting_frame_1, requesting_frame_1,
681 CONTENT_SETTING_ALLOW);
682 SetGeolocationContentSetting(requesting_frame_2, requesting_frame_2,
683 CONTENT_SETTING_ALLOW);
684 SetGeolocationContentSetting(requesting_frame_dse, requesting_frame_dse,
685 CONTENT_SETTING_ALLOW);
686
687 // Turn off system location but allow the LSD to be shown, and denied.
688 MockLocationSettings::SetLocationStatus(true /* android */,
689 false /* system */);
690 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
691 DENIED);
692
693 // Now permission requests should trigger the LSD, but the LSD will be denied,
694 // putting the requesting origins into backoff. Check that the two non-DSE
695 // origins share the same backoff, which is distinct to the DSE origin.
696 // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
697 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame_1));
698
699 // Now check that the LSD is prevented on this origin.
700 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_1));
701
702 // Now ask on the other non-DSE origin and check backoff prevented the prompt.
703 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_2));
704
705 // Now request on the DSE and check that the LSD is shown, as the non-DSE
706 // backoff should not apply.
707 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame_dse));
708
709 // Now check that the DSE is in backoff.
710 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_dse));
711 }
712
713 TEST_F(GeolocationPermissionContextTests, LSDBackOffTiming) {
714 base::test::ScopedFeatureList scoped_feature_list;
715 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
716
717 GURL requesting_frame("https://www.example.com/geolocation");
718 SetGeolocationContentSetting(requesting_frame, requesting_frame,
719 CONTENT_SETTING_ALLOW);
720
721 // Turn off system location but allow the LSD to be shown, and denied.
722 MockLocationSettings::SetLocationStatus(true /* android */,
723 false /* system */);
724 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
725 DENIED);
726
727 // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
728 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
729 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
730
731 // Check the LSD is prevented in 6 days time.
732 AddDayOffsetForTesting(6);
733 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
734
735 // Check it is shown in one more days time, but then not straight after..
736 AddDayOffsetForTesting(1);
737 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
738 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
739
740 // Check that it isn't shown 29 days after that.
741 AddDayOffsetForTesting(29);
742 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
743
744 // Check it is shown in one more days time, but then not straight after..
745 AddDayOffsetForTesting(1);
746 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
747 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
748
749 // Check that it isn't shown 89 days after that.
750 AddDayOffsetForTesting(89);
751 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
752
753 // Check it is shown in one more days time, but then not straight after..
754 AddDayOffsetForTesting(1);
755 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
756 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
757
758 // Check that it isn't shown 89 days after that.
759 AddDayOffsetForTesting(89);
760 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
761
762 // Check it is shown in one more days time, but then not straight after..
763 AddDayOffsetForTesting(1);
764 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
765 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
766 }
767
768 TEST_F(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) {
769 base::test::ScopedFeatureList scoped_feature_list;
770 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
771
772 GURL requesting_frame("https://www.example.com/geolocation");
773 SetGeolocationContentSetting(requesting_frame, requesting_frame,
774 CONTENT_SETTING_ALLOW);
775
776 // Turn off system location but allow the LSD to be shown, and denied.
777 MockLocationSettings::SetLocationStatus(true /* android */,
778 false /* system */);
779 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
780 DENIED);
781
782 // The permission status should reflect that the LSD will be shown.
783 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
784 PermissionManager::Get(profile())->GetPermissionStatus(
785 content::PermissionType::GEOLOCATION, requesting_frame,
786 requesting_frame));
787 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
788
789 // Now that the LSD is in backoff, the permission status should reflect it.
790 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
791 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
792 PermissionManager::Get(profile())->GetPermissionStatus(
793 content::PermissionType::GEOLOCATION, requesting_frame,
794 requesting_frame));
795 }
796
797 TEST_F(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) {
798 base::test::ScopedFeatureList scoped_feature_list;
799 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
800
801 GURL requesting_frame("https://www.example.com/geolocation");
802 SetGeolocationContentSetting(requesting_frame, requesting_frame,
803 CONTENT_SETTING_ALLOW);
804
805 // Turn off system location but allow the LSD to be shown, and denied.
806 MockLocationSettings::SetLocationStatus(true /* android */,
807 false /* system */);
808 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
809 DENIED);
810
811 // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
812 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
813 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
814
815 // Set the content setting back to ASK. The permission status should be
816 // prompt, and the LSD prompt should now be shown.
817 SetGeolocationContentSetting(requesting_frame, requesting_frame,
818 CONTENT_SETTING_ASK);
819 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
820 PermissionManager::Get(profile())->GetPermissionStatus(
821 content::PermissionType::GEOLOCATION, requesting_frame,
822 requesting_frame));
823 EXPECT_TRUE(
824 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
825 }
826
827 TEST_F(GeolocationPermissionContextTests,
828 LSDBackOffAcceptPermissionResetsBackOff) {
829 base::test::ScopedFeatureList scoped_feature_list;
830 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
831
832 GURL requesting_frame("https://www.example.com/geolocation");
833 SetGeolocationContentSetting(requesting_frame, requesting_frame,
834 CONTENT_SETTING_ALLOW);
835
836 // Turn off system location but allow the LSD to be shown, and denied.
837 MockLocationSettings::SetLocationStatus(true /* android */,
838 false /* system */);
839 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
840 DENIED);
841
842 // First, get into the highest backoff state.
843 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
844 AddDayOffsetForTesting(7);
845 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
846 AddDayOffsetForTesting(30);
847 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
848 AddDayOffsetForTesting(90);
849 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
850
851 // Now accept a permissions prompt.
852 SetGeolocationContentSetting(requesting_frame, requesting_frame,
853 CONTENT_SETTING_ASK);
854 EXPECT_TRUE(
855 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
856
857 // And check that back in the lowest backoff state.
858 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
859 AddDayOffsetForTesting(7);
860 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
861 }
862
863 TEST_F(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) {
864 base::test::ScopedFeatureList scoped_feature_list;
865 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
866
867 GURL requesting_frame("https://www.example.com/geolocation");
868 SetGeolocationContentSetting(requesting_frame, requesting_frame,
869 CONTENT_SETTING_ALLOW);
870
871 // Turn off system location but allow the LSD to be shown, and denied.
872 MockLocationSettings::SetLocationStatus(true /* android */,
873 false /* system */);
874 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
875 DENIED);
876
877 // First, get into the highest backoff state.
878 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
879 AddDayOffsetForTesting(7);
880 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
881 AddDayOffsetForTesting(30);
882 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
883
884 // Now accept the LSD.
885 AddDayOffsetForTesting(90);
886 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
887 GRANTED);
888 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
889
890 // Check that not in backoff, and that at the lowest backoff state.
891 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
892 DENIED);
893 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
894 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
895 AddDayOffsetForTesting(7);
896 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
897 }
623 #endif 898 #endif
624 899
625 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 900 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
626 GURL requesting_frame_0("https://www.example.com/geolocation"); 901 GURL requesting_frame_0("https://www.example.com/geolocation");
627 GURL requesting_frame_1("https://www.example-2.com/geolocation"); 902 GURL requesting_frame_1("https://www.example-2.com/geolocation");
628 EXPECT_EQ( 903 EXPECT_EQ(
629 CONTENT_SETTING_ASK, 904 CONTENT_SETTING_ASK,
630 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); 905 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1));
631 EXPECT_EQ( 906 EXPECT_EQ(
632 CONTENT_SETTING_ASK, 907 CONTENT_SETTING_ASK,
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 CONTENT_SETTING_ALLOW); 1411 CONTENT_SETTING_ALLOW);
1137 MockLocationSettings::SetLocationStatus(true /* android */, 1412 MockLocationSettings::SetLocationStatus(true /* android */,
1138 false /* system */); 1413 false /* system */);
1139 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 1414 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
1140 DENIED); 1415 DENIED);
1141 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1416 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1142 PermissionManager::Get(profile())->GetPermissionStatus( 1417 PermissionManager::Get(profile())->GetPermissionStatus(
1143 content::PermissionType::GEOLOCATION, requesting_frame, 1418 content::PermissionType::GEOLOCATION, requesting_frame,
1144 requesting_frame)); 1419 requesting_frame));
1145 1420
1146 MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED); 1421 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
1422 GRANTED);
1147 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1423 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1148 PermissionManager::Get(profile())->GetPermissionStatus( 1424 PermissionManager::Get(profile())->GetPermissionStatus(
1149 content::PermissionType::GEOLOCATION, requesting_frame, 1425 content::PermissionType::GEOLOCATION, requesting_frame,
1150 requesting_frame)); 1426 requesting_frame));
1151 1427
1152 // The result should be the same if the location permission is ASK. 1428 // The result should be the same if the location permission is ASK.
1153 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1429 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1154 CONTENT_SETTING_ASK); 1430 CONTENT_SETTING_ASK);
1155 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED); 1431 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
1432 GRANTED);
1156 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1433 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1157 PermissionManager::Get(profile())->GetPermissionStatus( 1434 PermissionManager::Get(profile())->GetPermissionStatus(
1158 content::PermissionType::GEOLOCATION, requesting_frame, 1435 content::PermissionType::GEOLOCATION, requesting_frame,
1159 requesting_frame)); 1436 requesting_frame));
1160 1437
1161 MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED); 1438 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
1439 GRANTED);
1162 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1440 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1163 PermissionManager::Get(profile())->GetPermissionStatus( 1441 PermissionManager::Get(profile())->GetPermissionStatus(
1164 content::PermissionType::GEOLOCATION, requesting_frame, 1442 content::PermissionType::GEOLOCATION, requesting_frame,
1165 requesting_frame)); 1443 requesting_frame));
1166 1444
1167 // With the Android permission off, and location blocked for a domain, the 1445 // With the Android permission off, and location blocked for a domain, the
1168 // permission status should still be BLOCK. 1446 // permission status should still be BLOCK.
1169 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1447 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1170 CONTENT_SETTING_BLOCK); 1448 CONTENT_SETTING_BLOCK);
1171 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED); 1449 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
1450 GRANTED);
1172 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1451 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1173 PermissionManager::Get(profile())->GetPermissionStatus( 1452 PermissionManager::Get(profile())->GetPermissionStatus(
1174 content::PermissionType::GEOLOCATION, requesting_frame, 1453 content::PermissionType::GEOLOCATION, requesting_frame,
1175 requesting_frame)); 1454 requesting_frame));
1176 } 1455 }
1177 #endif // defined(OS_ANDROID) 1456 #endif // defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698