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

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

Issue 2743603002: Reflect device status in geolocation permissions.request calls. (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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #include "content/public/test/web_contents_tester.h" 51 #include "content/public/test/web_contents_tester.h"
52 #include "extensions/features/features.h" 52 #include "extensions/features/features.h"
53 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
54 54
55 #if defined(OS_ANDROID) 55 #if defined(OS_ANDROID)
56 #include "chrome/browser/android/mock_location_settings.h" 56 #include "chrome/browser/android/mock_location_settings.h"
57 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " 57 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h "
58 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 58 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
59 #include "components/location/android/location_settings_dialog_outcome.h" 59 #include "components/location/android/location_settings_dialog_outcome.h"
60 #include "components/prefs/pref_service.h" 60 #include "components/prefs/pref_service.h"
61 #include "content/public/browser/permission_type.h"
61 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 62 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
62 #else 63 #else
63 #include "chrome/browser/permissions/permission_request_manager.h" 64 #include "chrome/browser/permissions/permission_request_manager.h"
64 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" 65 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
65 #endif 66 #endif
66 67
67 #if BUILDFLAG(ENABLE_EXTENSIONS) 68 #if BUILDFLAG(ENABLE_EXTENSIONS)
68 #include "extensions/browser/view_type_utils.h" 69 #include "extensions/browser/view_type_utils.h"
69 #endif 70 #endif
70 71
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 #if !defined(OS_ANDROID) 176 #if !defined(OS_ANDROID)
176 void SetupRequestManager(content::WebContents* web_contents); 177 void SetupRequestManager(content::WebContents* web_contents);
177 size_t GetBubblesQueueSize(PermissionRequestManager* manager); 178 size_t GetBubblesQueueSize(PermissionRequestManager* manager);
178 void AcceptBubble(PermissionRequestManager* manager); 179 void AcceptBubble(PermissionRequestManager* manager);
179 void DenyBubble(PermissionRequestManager* manager); 180 void DenyBubble(PermissionRequestManager* manager);
180 void CloseBubble(PermissionRequestManager* manager); 181 void CloseBubble(PermissionRequestManager* manager);
181 #endif 182 #endif
182 void RequestManagerDocumentLoadCompleted(); 183 void RequestManagerDocumentLoadCompleted();
183 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents); 184 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents);
184 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 185 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
186 void SetGeolocationContentSetting(GURL frame_0,
187 GURL frame_1,
188 ContentSetting content_setting);
185 size_t GetNumberOfPrompts(); 189 size_t GetNumberOfPrompts();
186 void AcceptPrompt(); 190 void AcceptPrompt();
187 base::string16 GetPromptText(); 191 base::string16 GetPromptText();
188 192
189 // owned by the browser context 193 // owned by the browser context
190 GeolocationPermissionContext* geolocation_permission_context_; 194 GeolocationPermissionContext* geolocation_permission_context_;
191 ClosedInfoBarTracker closed_infobar_tracker_; 195 ClosedInfoBarTracker closed_infobar_tracker_;
192 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_; 196 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_;
193 #if !defined(OS_ANDROID) 197 #if !defined(OS_ANDROID)
194 std::vector<std::unique_ptr<MockPermissionPromptFactory>> 198 std::vector<std::unique_ptr<MockPermissionPromptFactory>>
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 388
385 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( 389 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
386 GURL frame_0, GURL frame_1) { 390 GURL frame_0, GURL frame_1) {
387 return HostContentSettingsMapFactory::GetForProfile(profile()) 391 return HostContentSettingsMapFactory::GetForProfile(profile())
388 ->GetContentSetting(frame_0, 392 ->GetContentSetting(frame_0,
389 frame_1, 393 frame_1,
390 CONTENT_SETTINGS_TYPE_GEOLOCATION, 394 CONTENT_SETTINGS_TYPE_GEOLOCATION,
391 std::string()); 395 std::string());
392 } 396 }
393 397
398 void GeolocationPermissionContextTests::SetGeolocationContentSetting(
399 GURL frame_0,
400 GURL frame_1,
401 ContentSetting content_setting) {
402 return HostContentSettingsMapFactory::GetForProfile(profile())
403 ->SetContentSettingDefaultScope(frame_0, frame_1,
404 CONTENT_SETTINGS_TYPE_GEOLOCATION,
405 std::string(), content_setting);
406 }
407
394 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { 408 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() {
395 #if !defined(OS_ANDROID) 409 #if !defined(OS_ANDROID)
396 PermissionRequestManager* manager = 410 PermissionRequestManager* manager =
397 PermissionRequestManager::FromWebContents(web_contents()); 411 PermissionRequestManager::FromWebContents(web_contents());
398 return GetBubblesQueueSize(manager); 412 return GetBubblesQueueSize(manager);
399 #else 413 #else
400 return infobar_service()->infobar_count(); 414 return infobar_service()->infobar_count();
401 #endif 415 #endif
402 } 416 }
403 417
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 .content_setting); 1018 .content_setting);
1005 1019
1006 // Changing the setting to BLOCK should flow through to incognito. 1020 // Changing the setting to BLOCK should flow through to incognito.
1007 geo_service->SetDSEGeolocationSetting(false); 1021 geo_service->SetDSEGeolocationSetting(false);
1008 ASSERT_EQ(CONTENT_SETTING_BLOCK, 1022 ASSERT_EQ(CONTENT_SETTING_BLOCK,
1009 PermissionManager::Get(otr_profile) 1023 PermissionManager::Get(otr_profile)
1010 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, 1024 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION,
1011 requesting_frame, requesting_frame) 1025 requesting_frame, requesting_frame)
1012 .content_setting); 1026 .content_setting);
1013 } 1027 }
1028
1029 TEST_F(GeolocationPermissionContextTests,
1030 GeolocationStatusAndroidDisabledLegacy) {
1031 GURL requesting_frame("https://www.example.com/geolocation");
1032
1033 // In these tests the Android permission status should not be taken into
1034 // account, only the content setting.
1035 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1036 CONTENT_SETTING_ALLOW);
1037 MockLocationSettings::SetLocationStatus(false /* android */,
1038 true /* system */);
1039 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED,
1040 PermissionManager::Get(profile())->GetPermissionStatus(
1041 content::PermissionType::GEOLOCATION, requesting_frame,
1042 requesting_frame));
1043
1044 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1045 CONTENT_SETTING_ASK);
1046 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1047 PermissionManager::Get(profile())->GetPermissionStatus(
1048 content::PermissionType::GEOLOCATION, requesting_frame,
1049 requesting_frame));
1050
1051 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1052 CONTENT_SETTING_BLOCK);
1053 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1054 PermissionManager::Get(profile())->GetPermissionStatus(
1055 content::PermissionType::GEOLOCATION, requesting_frame,
1056 requesting_frame));
1057 }
1058
1059 TEST_F(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) {
1060 base::test::ScopedFeatureList scoped_feature_list;
1061 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
1062
1063 GURL requesting_frame("https://www.example.com/geolocation");
1064
1065 // With the Android permission off, but location allowed for a domain, the
1066 // permission status should be ASK.
1067 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1068 CONTENT_SETTING_ALLOW);
1069 MockLocationSettings::SetLocationStatus(false /* android */,
1070 true /* system */);
1071 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1072 PermissionManager::Get(profile())->GetPermissionStatus(
1073 content::PermissionType::GEOLOCATION, requesting_frame,
1074 requesting_frame));
1075
1076 // With the Android permission off, and location blocked for a domain, the
1077 // permission status should still be BLOCK.
1078 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1079 CONTENT_SETTING_BLOCK);
1080 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1081 PermissionManager::Get(profile())->GetPermissionStatus(
1082 content::PermissionType::GEOLOCATION, requesting_frame,
1083 requesting_frame));
1084
1085 // With the Android permission off, and location prompt for a domain, the
1086 // permission status should still be ASK.
1087 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1088 CONTENT_SETTING_ASK);
1089 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1090 PermissionManager::Get(profile())->GetPermissionStatus(
1091 content::PermissionType::GEOLOCATION, requesting_frame,
1092 requesting_frame));
1093 }
1094
1095 TEST_F(GeolocationPermissionContextTests,
1096 GeolocationStatusSystemDisabledLegacy) {
1097 GURL requesting_frame("https://www.example.com/geolocation");
1098
1099 // In these tests the system permission status should not be taken into
1100 // account, only the content setting.
1101 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1102 CONTENT_SETTING_ALLOW);
1103 MockLocationSettings::SetLocationStatus(true /* android */,
1104 false /* system */);
1105 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED,
1106 PermissionManager::Get(profile())->GetPermissionStatus(
1107 content::PermissionType::GEOLOCATION, requesting_frame,
1108 requesting_frame));
1109
1110 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1111 CONTENT_SETTING_ASK);
1112 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1113 PermissionManager::Get(profile())->GetPermissionStatus(
1114 content::PermissionType::GEOLOCATION, requesting_frame,
1115 requesting_frame));
1116
1117 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1118 CONTENT_SETTING_BLOCK);
1119 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1120 PermissionManager::Get(profile())->GetPermissionStatus(
1121 content::PermissionType::GEOLOCATION, requesting_frame,
1122 requesting_frame));
1123 }
1124
1125 TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
1126 base::test::ScopedFeatureList scoped_feature_list;
1127 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
1128
1129 GURL requesting_frame("https://www.example.com/geolocation");
1130
1131 // With the system permission off, but location allowed for a domain, the
1132 // permission status should be reflect whether the LSD can be shown.
1133 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1134 CONTENT_SETTING_ALLOW);
1135 MockLocationSettings::SetLocationStatus(true /* android */,
1136 false /* system */);
1137 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1138 PermissionManager::Get(profile())->GetPermissionStatus(
1139 content::PermissionType::GEOLOCATION, requesting_frame,
1140 requesting_frame));
1141
1142 MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED);
1143 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1144 PermissionManager::Get(profile())->GetPermissionStatus(
1145 content::PermissionType::GEOLOCATION, requesting_frame,
1146 requesting_frame));
1147
1148 // The result should be the same if the location permission is ASK.
1149 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1150 CONTENT_SETTING_ASK);
1151 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
1152 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1153 PermissionManager::Get(profile())->GetPermissionStatus(
1154 content::PermissionType::GEOLOCATION, requesting_frame,
1155 requesting_frame));
1156
1157 MockLocationSettings::SetLocationSettingsDialogStatus(false, GRANTED);
1158 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1159 PermissionManager::Get(profile())->GetPermissionStatus(
1160 content::PermissionType::GEOLOCATION, requesting_frame,
1161 requesting_frame));
1162
1163 // With the Android permission off, and location blocked for a domain, the
1164 // permission status should still be BLOCK.
1165 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1166 CONTENT_SETTING_BLOCK);
1167 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
1168 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1169 PermissionManager::Get(profile())->GetPermissionStatus(
1170 content::PermissionType::GEOLOCATION, requesting_frame,
1171 requesting_frame));
1172 }
1014 #endif // defined(OS_ANDROID) 1173 #endif // defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698