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

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

Issue 2876993003: Test PermissionRequestManager in GeolocationPermissionContext unit tests (Closed)
Patch Set: :d Created 3 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 #include "base/test/simple_test_clock.h" 24 #include "base/test/simple_test_clock.h"
25 #include "base/time/clock.h" 25 #include "base/time/clock.h"
26 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 27 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
28 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 28 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
29 #include "chrome/browser/infobars/infobar_service.h" 29 #include "chrome/browser/infobars/infobar_service.h"
30 #include "chrome/browser/permissions/permission_context_base.h" 30 #include "chrome/browser/permissions/permission_context_base.h"
31 #include "chrome/browser/permissions/permission_manager.h" 31 #include "chrome/browser/permissions/permission_manager.h"
32 #include "chrome/browser/permissions/permission_request.h" 32 #include "chrome/browser/permissions/permission_request.h"
33 #include "chrome/browser/permissions/permission_request_id.h" 33 #include "chrome/browser/permissions/permission_request_id.h"
34 #include "chrome/browser/permissions/permission_request_manager.h"
35 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h"
34 #include "chrome/common/chrome_features.h" 36 #include "chrome/common/chrome_features.h"
35 #include "chrome/common/chrome_switches.h" 37 #include "chrome/common/chrome_switches.h"
36 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 38 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
37 #include "chrome/test/base/testing_profile.h" 39 #include "chrome/test/base/testing_profile.h"
38 #include "components/content_settings/core/browser/host_content_settings_map.h" 40 #include "components/content_settings/core/browser/host_content_settings_map.h"
39 #include "components/infobars/core/confirm_infobar_delegate.h" 41 #include "components/infobars/core/confirm_infobar_delegate.h"
40 #include "components/infobars/core/infobar.h" 42 #include "components/infobars/core/infobar.h"
41 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
42 #include "content/public/browser/navigation_details.h" 44 #include "content/public/browser/navigation_details.h"
43 #include "content/public/browser/navigation_entry.h" 45 #include "content/public/browser/navigation_entry.h"
(...skipping 10 matching lines...) Expand all
54 #include "testing/gtest/include/gtest/gtest.h" 56 #include "testing/gtest/include/gtest/gtest.h"
55 57
56 #if defined(OS_ANDROID) 58 #if defined(OS_ANDROID)
57 #include "chrome/browser/android/mock_location_settings.h" 59 #include "chrome/browser/android/mock_location_settings.h"
58 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " 60 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h "
59 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 61 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
60 #include "components/location/android/location_settings_dialog_outcome.h" 62 #include "components/location/android/location_settings_dialog_outcome.h"
61 #include "components/prefs/pref_service.h" 63 #include "components/prefs/pref_service.h"
62 #include "content/public/browser/permission_type.h" 64 #include "content/public/browser/permission_type.h"
63 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 65 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
64 #else
65 #include "chrome/browser/permissions/permission_request_manager.h"
66 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h"
67 #endif 66 #endif
68 67
69 #if BUILDFLAG(ENABLE_EXTENSIONS) 68 #if BUILDFLAG(ENABLE_EXTENSIONS)
70 #include "extensions/browser/view_type_utils.h" 69 #include "extensions/browser/view_type_utils.h"
71 #endif 70 #endif
72 71
73 using content::MockRenderProcessHost; 72 using content::MockRenderProcessHost;
74 73
75 74
76 // ClosedInfoBarTracker ------------------------------------------------------- 75 // ClosedInfoBarTracker -------------------------------------------------------
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 void SetDSEChangedCallback(const base::Closure& callback) override {} 135 void SetDSEChangedCallback(const base::Closure& callback) override {}
137 136
138 static const char kDSETestUrl[]; 137 static const char kDSETestUrl[];
139 }; 138 };
140 139
141 const char TestSearchEngineDelegate::kDSETestUrl[] = "https://www.dsetest.com"; 140 const char TestSearchEngineDelegate::kDSETestUrl[] = "https://www.dsetest.com";
142 #endif // defined(OS_ANDROID) 141 #endif // defined(OS_ANDROID)
143 142
144 // GeolocationPermissionContextTests ------------------------------------------ 143 // GeolocationPermissionContextTests ------------------------------------------
145 144
145 enum class TestType {
146 PERMISSION_REQUEST_MANAGER,
147 PERMISSION_QUEUE_CONTROLLER,
148 };
149
146 class GeolocationPermissionContextTests 150 class GeolocationPermissionContextTests
147 : public ChromeRenderViewHostTestHarness { 151 : public ChromeRenderViewHostTestHarness,
152 public ::testing::WithParamInterface<TestType> {
148 protected: 153 protected:
149 // ChromeRenderViewHostTestHarness: 154 // ChromeRenderViewHostTestHarness:
150 void SetUp() override; 155 void SetUp() override;
151 void TearDown() override; 156 void TearDown() override;
152 157
153 PermissionRequestID RequestID(int request_id); 158 PermissionRequestID RequestID(int request_id);
154 PermissionRequestID RequestIDForTab(int tab, int request_id); 159 PermissionRequestID RequestIDForTab(int tab, int request_id);
155 InfoBarService* infobar_service() { 160 InfoBarService* infobar_service() {
156 return InfoBarService::FromWebContents(web_contents()); 161 return InfoBarService::FromWebContents(web_contents());
157 } 162 }
158 InfoBarService* infobar_service_for_tab(int tab) { 163 InfoBarService* infobar_service_for_tab(int tab) {
159 return InfoBarService::FromWebContents(extra_tabs_[tab].get()); 164 return InfoBarService::FromWebContents(extra_tabs_[tab].get());
160 } 165 }
161 166
162 void RequestGeolocationPermission(content::WebContents* web_contents, 167 void RequestGeolocationPermission(content::WebContents* web_contents,
163 const PermissionRequestID& id, 168 const PermissionRequestID& id,
164 const GURL& requesting_frame, 169 const GURL& requesting_frame,
165 bool user_gesture); 170 bool user_gesture);
166 171
167 void PermissionResponse(const PermissionRequestID& id, 172 void PermissionResponse(const PermissionRequestID& id,
168 ContentSetting content_setting); 173 ContentSetting content_setting);
169 void CheckPermissionMessageSent(int request_id, bool allowed); 174 void CheckPermissionMessageSent(int request_id, bool allowed);
170 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); 175 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed);
171 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 176 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
172 int request_id, 177 int request_id,
173 bool allowed); 178 bool allowed);
174 void AddNewTab(const GURL& url); 179 void AddNewTab(const GURL& url);
175 void CheckTabContentsState(const GURL& requesting_frame, 180 void CheckTabContentsState(const GURL& requesting_frame,
176 ContentSetting expected_content_setting); 181 ContentSetting expected_content_setting);
177 #if !defined(OS_ANDROID)
178 void SetupRequestManager(content::WebContents* web_contents); 182 void SetupRequestManager(content::WebContents* web_contents);
179 size_t GetBubblesQueueSize(PermissionRequestManager* manager);
180 void AcceptBubble(PermissionRequestManager* manager);
181 void DenyBubble(PermissionRequestManager* manager);
182 void CloseBubble(PermissionRequestManager* manager);
183 #endif
184 #if defined(OS_ANDROID) 183 #if defined(OS_ANDROID)
185 bool RequestPermissionIsLSDShown(const GURL& origin); 184 bool RequestPermissionIsLSDShown(const GURL& origin);
186 bool RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin); 185 bool RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin);
187 void AddDayOffsetForTesting(int days); 186 void AddDayOffsetForTesting(int days);
188 void SetDSEOriginForTesting(const char* dse_origin); 187 void SetDSEOriginForTesting(const char* dse_origin);
189 #endif 188 #endif
190 void RequestManagerDocumentLoadCompleted(); 189 void RequestManagerDocumentLoadCompleted();
191 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents); 190 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents);
192 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 191 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
193 void SetGeolocationContentSetting(GURL frame_0, 192 void SetGeolocationContentSetting(GURL frame_0,
194 GURL frame_1, 193 GURL frame_1,
195 ContentSetting content_setting); 194 ContentSetting content_setting);
196 size_t GetNumberOfPrompts(); 195 size_t GetNumberOfPrompts();
196 size_t GetNumberOfPrompts(content::WebContents* web_contents);
197 void AcceptPrompt(); 197 void AcceptPrompt();
198 void AcceptPrompt(content::WebContents* web_contents);
199 void DenyPrompt();
200 void ClosePrompt();
198 base::string16 GetPromptText(); 201 base::string16 GetPromptText();
199 202
203 void EnableFeature(base::test::ScopedFeatureList& scoped_feature_list,
raymes 2017/05/17 04:24:49 in Chrome we never pass arguments by non-const ref
Timothy Loh 2017/05/19 01:43:01 Done.
204 const base::Feature& feature);
205
200 // owned by the browser context 206 // owned by the browser context
201 GeolocationPermissionContext* geolocation_permission_context_; 207 GeolocationPermissionContext* geolocation_permission_context_;
202 ClosedInfoBarTracker closed_infobar_tracker_; 208 ClosedInfoBarTracker closed_infobar_tracker_;
203 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_; 209 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_;
204 #if !defined(OS_ANDROID)
205 std::vector<std::unique_ptr<MockPermissionPromptFactory>> 210 std::vector<std::unique_ptr<MockPermissionPromptFactory>>
206 mock_permission_prompt_factories_; 211 mock_permission_prompt_factories_;
207 #endif
208 212
209 // A map between renderer child id and a pair represending the bridge id and 213 // A map between renderer child id and a pair represending the bridge id and
210 // whether the requested permission was allowed. 214 // whether the requested permission was allowed.
211 base::hash_map<int, std::pair<int, bool> > responses_; 215 base::hash_map<int, std::pair<int, bool> > responses_;
216
217 // For testing the PermissionRequestManager on Android
218 base::test::ScopedFeatureList scoped_feature_list_;
212 }; 219 };
213 220
214 PermissionRequestID GeolocationPermissionContextTests::RequestID( 221 PermissionRequestID GeolocationPermissionContextTests::RequestID(
215 int request_id) { 222 int request_id) {
216 return PermissionRequestID( 223 return PermissionRequestID(
217 web_contents()->GetRenderProcessHost()->GetID(), 224 web_contents()->GetRenderProcessHost()->GetID(),
218 web_contents()->GetMainFrame()->GetRoutingID(), 225 web_contents()->GetMainFrame()->GetRoutingID(),
219 request_id); 226 request_id);
220 } 227 }
221 228
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 285 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
279 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); 286 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry();
280 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) 287 content::RenderFrameHostTester::For(new_tab->GetMainFrame())
281 ->SendNavigate(entry->GetUniqueID(), true, url); 288 ->SendNavigate(entry->GetUniqueID(), true, url);
282 289
283 // Set up required helpers, and make this be as "tabby" as the code requires. 290 // Set up required helpers, and make this be as "tabby" as the code requires.
284 #if BUILDFLAG(ENABLE_EXTENSIONS) 291 #if BUILDFLAG(ENABLE_EXTENSIONS)
285 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); 292 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS);
286 #endif 293 #endif
287 294
288 #if defined(OS_ANDROID) 295 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER)
289 InfoBarService::CreateForWebContents(new_tab); 296 SetupRequestManager(new_tab);
290 #else 297 else
291 SetupRequestManager(new_tab); 298 InfoBarService::CreateForWebContents(new_tab);
292 #endif
293 299
294 extra_tabs_.push_back(base::WrapUnique(new_tab)); 300 extra_tabs_.push_back(base::WrapUnique(new_tab));
295 } 301 }
296 302
297 void GeolocationPermissionContextTests::CheckTabContentsState( 303 void GeolocationPermissionContextTests::CheckTabContentsState(
298 const GURL& requesting_frame, 304 const GURL& requesting_frame,
299 ContentSetting expected_content_setting) { 305 ContentSetting expected_content_setting) {
300 TabSpecificContentSettings* content_settings = 306 TabSpecificContentSettings* content_settings =
301 TabSpecificContentSettings::FromWebContents(web_contents()); 307 TabSpecificContentSettings::FromWebContents(web_contents());
302 const ContentSettingsUsagesState::StateMap& state_map = 308 const ContentSettingsUsagesState::StateMap& state_map =
(...skipping 12 matching lines...) Expand all
315 321
316 // Set up required helpers, and make this be as "tabby" as the code requires. 322 // Set up required helpers, and make this be as "tabby" as the code requires.
317 #if BUILDFLAG(ENABLE_EXTENSIONS) 323 #if BUILDFLAG(ENABLE_EXTENSIONS)
318 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 324 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
319 #endif 325 #endif
320 InfoBarService::CreateForWebContents(web_contents()); 326 InfoBarService::CreateForWebContents(web_contents());
321 TabSpecificContentSettings::CreateForWebContents(web_contents()); 327 TabSpecificContentSettings::CreateForWebContents(web_contents());
322 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( 328 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>(
323 PermissionManager::Get(profile())->GetPermissionContext( 329 PermissionManager::Get(profile())->GetPermissionContext(
324 CONTENT_SETTINGS_TYPE_GEOLOCATION)); 330 CONTENT_SETTINGS_TYPE_GEOLOCATION));
331
332 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
333 // This feature enables the PRM for Android and no-ops on desktop.
334 scoped_feature_list_.InitAndEnableFeature(
335 features::kUseGroupedPermissionInfobars);
336 SetupRequestManager(web_contents());
337 }
338
325 #if defined(OS_ANDROID) 339 #if defined(OS_ANDROID)
326 static_cast<GeolocationPermissionContextAndroid*>( 340 static_cast<GeolocationPermissionContextAndroid*>(
327 geolocation_permission_context_) 341 geolocation_permission_context_)
328 ->SetLocationSettingsForTesting( 342 ->SetLocationSettingsForTesting(
329 std::unique_ptr<LocationSettings>(new MockLocationSettings())); 343 std::unique_ptr<LocationSettings>(new MockLocationSettings()));
330 MockLocationSettings::SetLocationStatus(true, true); 344 MockLocationSettings::SetLocationStatus(true, true);
331 MockLocationSettings::SetCanPromptForAndroidPermission(true); 345 MockLocationSettings::SetCanPromptForAndroidPermission(true);
332 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */, 346 MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */,
333 GRANTED); 347 GRANTED);
334 MockLocationSettings::ClearHasShownLocationSettingsDialog(); 348 MockLocationSettings::ClearHasShownLocationSettingsDialog();
335 #else
336 SetupRequestManager(web_contents());
337 #endif 349 #endif
338 } 350 }
339 351
340 void GeolocationPermissionContextTests::TearDown() { 352 void GeolocationPermissionContextTests::TearDown() {
341 #if !defined(OS_ANDROID)
342 mock_permission_prompt_factories_.clear(); 353 mock_permission_prompt_factories_.clear();
343 #endif
344 extra_tabs_.clear(); 354 extra_tabs_.clear();
345 ChromeRenderViewHostTestHarness::TearDown(); 355 ChromeRenderViewHostTestHarness::TearDown();
346 } 356 }
347 357
348 #if !defined(OS_ANDROID)
349 void GeolocationPermissionContextTests::SetupRequestManager( 358 void GeolocationPermissionContextTests::SetupRequestManager(
350 content::WebContents* web_contents) { 359 content::WebContents* web_contents) {
351 // Create PermissionRequestManager. 360 // Create PermissionRequestManager.
352 PermissionRequestManager::CreateForWebContents(web_contents); 361 PermissionRequestManager::CreateForWebContents(web_contents);
353 PermissionRequestManager* permission_request_manager = 362 PermissionRequestManager* permission_request_manager =
354 PermissionRequestManager::FromWebContents(web_contents); 363 PermissionRequestManager::FromWebContents(web_contents);
355 364
356 // Create a MockPermissionPromptFactory for the PermissionRequestManager. 365 // Create a MockPermissionPromptFactory for the PermissionRequestManager.
357 mock_permission_prompt_factories_.push_back( 366 mock_permission_prompt_factories_.push_back(
358 base::MakeUnique<MockPermissionPromptFactory>( 367 base::MakeUnique<MockPermissionPromptFactory>(
359 permission_request_manager)); 368 permission_request_manager));
360 369
361 // Prepare the PermissionRequestManager to display a mock bubble. 370 // Prepare the PermissionRequestManager to display a mock bubble.
362 permission_request_manager->DisplayPendingRequests(); 371 permission_request_manager->DisplayPendingRequests();
363 } 372 }
364 373
365 size_t GeolocationPermissionContextTests::GetBubblesQueueSize( 374 #if defined(OS_ANDROID)
366 PermissionRequestManager* manager) {
367 return manager->requests_.size();
368 }
369 375
370 void GeolocationPermissionContextTests::AcceptBubble(
371 PermissionRequestManager* manager) {
372 manager->Accept();
373 }
374
375 void GeolocationPermissionContextTests::DenyBubble(
376 PermissionRequestManager* manager) {
377 manager->Deny();
378 }
379
380 void GeolocationPermissionContextTests::CloseBubble(
381 PermissionRequestManager* manager) {
382 manager->Closing();
383 }
384 #endif
385
386 #if defined(OS_ANDROID)
387 bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown( 376 bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown(
388 const GURL& origin) { 377 const GURL& origin) {
389 NavigateAndCommit(origin); 378 NavigateAndCommit(origin);
379 RequestManagerDocumentLoadCompleted();
390 MockLocationSettings::ClearHasShownLocationSettingsDialog(); 380 MockLocationSettings::ClearHasShownLocationSettingsDialog();
391 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true); 381 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
392 382
393 return MockLocationSettings::HasShownLocationSettingsDialog(); 383 return MockLocationSettings::HasShownLocationSettingsDialog();
394 } 384 }
395 385
396 bool GeolocationPermissionContextTests:: 386 bool GeolocationPermissionContextTests::
397 RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin) { 387 RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin) {
398 NavigateAndCommit(origin); 388 NavigateAndCommit(origin);
389 RequestManagerDocumentLoadCompleted();
399 MockLocationSettings::ClearHasShownLocationSettingsDialog(); 390 MockLocationSettings::ClearHasShownLocationSettingsDialog();
400 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true); 391 RequestGeolocationPermission(web_contents(), RequestID(0), origin, true);
401 392
402 EXPECT_EQ(1U, infobar_service()->infobar_count()); 393 EXPECT_EQ(1U, GetNumberOfPrompts());
403 ConfirmInfoBarDelegate* infobar_delegate = 394 AcceptPrompt();
404 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
405 EXPECT_TRUE(infobar_delegate);
406 infobar_delegate->Accept();
407 395
408 return MockLocationSettings::HasShownLocationSettingsDialog(); 396 return MockLocationSettings::HasShownLocationSettingsDialog();
409 } 397 }
410 398
411 void GeolocationPermissionContextTests::AddDayOffsetForTesting(int days) { 399 void GeolocationPermissionContextTests::AddDayOffsetForTesting(int days) {
412 GeolocationPermissionContextAndroid::AddDayOffsetForTesting(days); 400 GeolocationPermissionContextAndroid::AddDayOffsetForTesting(days);
413 } 401 }
414 402
415 void GeolocationPermissionContextTests::SetDSEOriginForTesting( 403 void GeolocationPermissionContextTests::SetDSEOriginForTesting(
416 const char* dse_origin) { 404 const char* dse_origin) {
417 GeolocationPermissionContextAndroid::SetDSEOriginForTesting(dse_origin); 405 GeolocationPermissionContextAndroid::SetDSEOriginForTesting(dse_origin);
418 } 406 }
419 #endif 407 #endif
420 408
421 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() { 409 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() {
422 GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( 410 GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
423 web_contents()); 411 web_contents());
424 } 412 }
425 413
426 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( 414 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted(
427 content::WebContents* web_contents) { 415 content::WebContents* web_contents) {
428 #if !defined(OS_ANDROID) 416 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
429 PermissionRequestManager::FromWebContents(web_contents)-> 417 PermissionRequestManager::FromWebContents(web_contents)
430 DocumentOnLoadCompletedInMainFrame(); 418 ->DocumentOnLoadCompletedInMainFrame();
431 #endif 419 }
432 } 420 }
433 421
434 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( 422 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
435 GURL frame_0, GURL frame_1) { 423 GURL frame_0, GURL frame_1) {
436 return HostContentSettingsMapFactory::GetForProfile(profile()) 424 return HostContentSettingsMapFactory::GetForProfile(profile())
437 ->GetContentSetting(frame_0, 425 ->GetContentSetting(frame_0,
438 frame_1, 426 frame_1,
439 CONTENT_SETTINGS_TYPE_GEOLOCATION, 427 CONTENT_SETTINGS_TYPE_GEOLOCATION,
440 std::string()); 428 std::string());
441 } 429 }
442 430
443 void GeolocationPermissionContextTests::SetGeolocationContentSetting( 431 void GeolocationPermissionContextTests::SetGeolocationContentSetting(
444 GURL frame_0, 432 GURL frame_0,
445 GURL frame_1, 433 GURL frame_1,
446 ContentSetting content_setting) { 434 ContentSetting content_setting) {
447 return HostContentSettingsMapFactory::GetForProfile(profile()) 435 return HostContentSettingsMapFactory::GetForProfile(profile())
448 ->SetContentSettingDefaultScope(frame_0, frame_1, 436 ->SetContentSettingDefaultScope(frame_0, frame_1,
449 CONTENT_SETTINGS_TYPE_GEOLOCATION, 437 CONTENT_SETTINGS_TYPE_GEOLOCATION,
450 std::string(), content_setting); 438 std::string(), content_setting);
451 } 439 }
452 440
453 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { 441 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() {
454 #if !defined(OS_ANDROID) 442 return GetNumberOfPrompts(web_contents());
455 PermissionRequestManager* manager = 443 }
456 PermissionRequestManager::FromWebContents(web_contents()); 444
457 return GetBubblesQueueSize(manager); 445 size_t GeolocationPermissionContextTests::GetNumberOfPrompts(
458 #else 446 content::WebContents* web_contents) {
459 return infobar_service()->infobar_count(); 447 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
460 #endif 448 PermissionRequestManager* manager =
449 PermissionRequestManager::FromWebContents(web_contents);
450 return manager->requests_.size();
451 }
452
453 return InfoBarService::FromWebContents(web_contents)->infobar_count();
461 } 454 }
462 455
463 void GeolocationPermissionContextTests::AcceptPrompt() { 456 void GeolocationPermissionContextTests::AcceptPrompt() {
464 #if !defined(OS_ANDROID) 457 return AcceptPrompt(web_contents());
465 PermissionRequestManager* manager = 458 }
466 PermissionRequestManager::FromWebContents(web_contents()); 459
467 AcceptBubble(manager); 460 void GeolocationPermissionContextTests::AcceptPrompt(
468 #else 461 content::WebContents* web_contents) {
469 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 462 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
470 ConfirmInfoBarDelegate* infobar_delegate = 463 PermissionRequestManager* manager =
471 infobar->delegate()->AsConfirmInfoBarDelegate(); 464 PermissionRequestManager::FromWebContents(web_contents);
472 infobar_delegate->Accept(); 465 manager->Accept();
473 #endif 466 } else {
467 InfoBarService* infobar_service =
468 InfoBarService::FromWebContents(web_contents);
469 infobars::InfoBar* infobar = infobar_service->infobar_at(0);
470 ConfirmInfoBarDelegate* infobar_delegate =
471 infobar->delegate()->AsConfirmInfoBarDelegate();
472 ASSERT_TRUE(infobar_delegate);
473 infobar_delegate->Accept();
474 infobar_service->RemoveInfoBar(infobar);
raymes 2017/05/17 04:24:49 Question: do you know why all this removing happen
Timothy Loh 2017/05/19 01:43:01 Yeah, clean-up for a couple of tests which queue m
475 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
476 }
477 }
478
479 void GeolocationPermissionContextTests::DenyPrompt() {
480 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
481 PermissionRequestManager* manager =
482 PermissionRequestManager::FromWebContents(web_contents());
483 manager->Deny();
484 } else {
485 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
raymes 2017/05/17 04:24:49 nit: why infobar_1?
Timothy Loh 2017/05/19 01:43:01 Bad copy-paste... fixed!
486 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel();
487 }
488 }
489
490 void GeolocationPermissionContextTests::ClosePrompt() {
491 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
492 PermissionRequestManager* manager =
493 PermissionRequestManager::FromWebContents(web_contents());
494 manager->Closing();
495 } else {
496 geolocation_permission_context_->CancelPermissionRequest(web_contents(),
497 RequestID(0));
498 }
474 } 499 }
475 500
476 base::string16 GeolocationPermissionContextTests::GetPromptText() { 501 base::string16 GeolocationPermissionContextTests::GetPromptText() {
477 #if !defined(OS_ANDROID) 502 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
478 PermissionRequestManager* manager = 503 PermissionRequestManager* manager =
479 PermissionRequestManager::FromWebContents(web_contents()); 504 PermissionRequestManager::FromWebContents(web_contents());
480 PermissionRequest* request = manager->requests_.front(); 505 PermissionRequest* request = manager->requests_.front();
481 return base::ASCIIToUTF16(request->GetOrigin().spec()) + 506 return base::ASCIIToUTF16(request->GetOrigin().spec()) +
482 request->GetMessageTextFragment(); 507 request->GetMessageTextFragment();
483 #else 508 }
509
484 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 510 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
485 ConfirmInfoBarDelegate* infobar_delegate = 511 ConfirmInfoBarDelegate* infobar_delegate =
486 infobar->delegate()->AsConfirmInfoBarDelegate(); 512 infobar->delegate()->AsConfirmInfoBarDelegate();
487 return infobar_delegate->GetMessageText(); 513 return infobar_delegate->GetMessageText();
488 #endif 514 }
515
516 void GeolocationPermissionContextTests::EnableFeature(
517 base::test::ScopedFeatureList& scoped_feature_list,
518 const base::Feature& feature) {
519 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
520 scoped_feature_list.InitWithFeatures(
521 {features::kUseGroupedPermissionInfobars, feature}, {});
522 } else {
523 scoped_feature_list.InitAndEnableFeature(feature);
524 }
489 } 525 }
490 526
491 // Tests ---------------------------------------------------------------------- 527 // Tests ----------------------------------------------------------------------
492 528
493 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { 529 TEST_P(GeolocationPermissionContextTests, SinglePermissionPrompt) {
494 GURL requesting_frame("https://www.example.com/geolocation"); 530 GURL requesting_frame("https://www.example.com/geolocation");
495 NavigateAndCommit(requesting_frame); 531 NavigateAndCommit(requesting_frame);
496 RequestManagerDocumentLoadCompleted(); 532 RequestManagerDocumentLoadCompleted();
497 533
498 EXPECT_EQ(0U, GetNumberOfPrompts()); 534 EXPECT_EQ(0U, GetNumberOfPrompts());
499 RequestGeolocationPermission( 535 RequestGeolocationPermission(
500 web_contents(), RequestID(0), requesting_frame, true); 536 web_contents(), RequestID(0), requesting_frame, true);
501 ASSERT_EQ(1U, GetNumberOfPrompts()); 537 ASSERT_EQ(1U, GetNumberOfPrompts());
502 } 538 }
503 539
504 TEST_F(GeolocationPermissionContextTests, 540 TEST_P(GeolocationPermissionContextTests,
505 SinglePermissionBubbleFailsOnInsecureOrigin) { 541 SinglePermissionPromptFailsOnInsecureOrigin) {
506 GURL requesting_frame("http://www.example.com/geolocation"); 542 GURL requesting_frame("http://www.example.com/geolocation");
507 NavigateAndCommit(requesting_frame); 543 NavigateAndCommit(requesting_frame);
508 RequestManagerDocumentLoadCompleted(); 544 RequestManagerDocumentLoadCompleted();
509 545
510 EXPECT_EQ(0U, GetNumberOfPrompts()); 546 EXPECT_EQ(0U, GetNumberOfPrompts());
511 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 547 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
512 true); 548 true);
513 ASSERT_EQ(0U, GetNumberOfPrompts()); 549 ASSERT_EQ(0U, GetNumberOfPrompts());
514 } 550 }
515 551
516 #if defined(OS_ANDROID) 552 #if defined(OS_ANDROID)
517 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { 553 // Tests concerning Android location settings permission
554 TEST_P(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
518 GURL requesting_frame("https://www.example.com/geolocation"); 555 GURL requesting_frame("https://www.example.com/geolocation");
519 NavigateAndCommit(requesting_frame); 556 NavigateAndCommit(requesting_frame);
520 EXPECT_EQ(0U, infobar_service()->infobar_count()); 557 RequestManagerDocumentLoadCompleted();
558 MockLocationSettings::SetLocationStatus(true /* android */,
559 true /* system */);
560 EXPECT_EQ(0U, GetNumberOfPrompts());
521 RequestGeolocationPermission( 561 RequestGeolocationPermission(
522 web_contents(), RequestID(0), requesting_frame, true); 562 web_contents(), RequestID(0), requesting_frame, true);
523 ASSERT_EQ(1U, infobar_service()->infobar_count()); 563 EXPECT_EQ(1U, GetNumberOfPrompts());
524 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
525 ConfirmInfoBarDelegate* infobar_delegate =
526 infobar->delegate()->AsConfirmInfoBarDelegate();
527 ASSERT_TRUE(infobar_delegate);
528 infobar_delegate->Cancel();
529 infobar_service()->RemoveInfoBar(infobar);
530 EXPECT_EQ(1U, closed_infobar_tracker_.size());
531 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
raymes 2017/05/17 04:24:49 Is this now covered somewhere else?
Timothy Loh 2017/05/19 01:43:01 This test and SinglePermissionBubble (renamed bubb
532 }
533
534 // Infobar-only tests; Android doesn't support permission bubbles.
535 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
536 GURL requesting_frame("https://www.example.com/geolocation");
537 NavigateAndCommit(requesting_frame);
538 MockLocationSettings::SetLocationStatus(true /* android */,
539 true /* system */);
540 EXPECT_EQ(0U, infobar_service()->infobar_count());
541 RequestGeolocationPermission(
542 web_contents(), RequestID(0), requesting_frame, true);
543 EXPECT_EQ(1U, infobar_service()->infobar_count());
544 ConfirmInfoBarDelegate* infobar_delegate_0 =
545 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
546 ASSERT_TRUE(infobar_delegate_0);
547 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
548 ConfirmInfoBarDelegate::BUTTON_OK);
549 564
550 Reload(); 565 Reload();
551 MockLocationSettings::SetLocationStatus(false /* android */, 566 MockLocationSettings::SetLocationStatus(false /* android */,
552 true /* system */); 567 true /* system */);
553 MockLocationSettings::SetCanPromptForAndroidPermission(false); 568 MockLocationSettings::SetCanPromptForAndroidPermission(false);
554 EXPECT_EQ(0U, infobar_service()->infobar_count()); 569 EXPECT_EQ(0U, GetNumberOfPrompts());
555 RequestGeolocationPermission( 570 RequestGeolocationPermission(
556 web_contents(), RequestID(0), requesting_frame, true); 571 web_contents(), RequestID(0), requesting_frame, true);
557 EXPECT_EQ(0U, infobar_service()->infobar_count()); 572 EXPECT_EQ(0U, GetNumberOfPrompts());
558 } 573 }
559 574
560 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) { 575 TEST_P(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) {
561 GURL requesting_frame("https://www.example.com/geolocation"); 576 GURL requesting_frame("https://www.example.com/geolocation");
562 NavigateAndCommit(requesting_frame); 577 NavigateAndCommit(requesting_frame);
578 RequestManagerDocumentLoadCompleted();
563 MockLocationSettings::SetLocationStatus(false /* android */, 579 MockLocationSettings::SetLocationStatus(false /* android */,
564 true /* system */); 580 true /* system */);
565 EXPECT_EQ(0U, infobar_service()->infobar_count()); 581 EXPECT_EQ(0U, GetNumberOfPrompts());
566 RequestGeolocationPermission( 582 RequestGeolocationPermission(
567 web_contents(), RequestID(0), requesting_frame, true); 583 web_contents(), RequestID(0), requesting_frame, true);
568 EXPECT_EQ(1U, infobar_service()->infobar_count()); 584 ASSERT_EQ(1U, GetNumberOfPrompts());
569 ConfirmInfoBarDelegate* infobar_delegate = 585 AcceptPrompt();
570 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
571 ASSERT_TRUE(infobar_delegate);
572 infobar_delegate->Accept();
573 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 586 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
574 CheckPermissionMessageSent(0, true); 587 CheckPermissionMessageSent(0, true);
575 } 588 }
576 589
577 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) { 590 TEST_P(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) {
578 GURL requesting_frame("https://www.example.com/geolocation"); 591 GURL requesting_frame("https://www.example.com/geolocation");
579 NavigateAndCommit(requesting_frame); 592 NavigateAndCommit(requesting_frame);
593 RequestManagerDocumentLoadCompleted();
580 MockLocationSettings::SetLocationStatus(false /* android */, 594 MockLocationSettings::SetLocationStatus(false /* android */,
581 true /* system */); 595 true /* system */);
582 MockLocationSettings::SetCanPromptForAndroidPermission(false); 596 MockLocationSettings::SetCanPromptForAndroidPermission(false);
583 EXPECT_EQ(0U, infobar_service()->infobar_count()); 597 EXPECT_EQ(0U, GetNumberOfPrompts());
584 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 598 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
585 true); 599 true);
586 EXPECT_EQ(0U, infobar_service()->infobar_count()); 600 EXPECT_EQ(0U, GetNumberOfPrompts());
587 } 601 }
588 602
589 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) { 603 TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) {
590 base::test::ScopedFeatureList scoped_feature_list; 604 base::test::ScopedFeatureList scoped_feature_list;
591 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 605 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
592 606
593 GURL requesting_frame("https://www.example.com/geolocation"); 607 GURL requesting_frame("https://www.example.com/geolocation");
594 NavigateAndCommit(requesting_frame); 608 NavigateAndCommit(requesting_frame);
609 RequestManagerDocumentLoadCompleted();
595 MockLocationSettings::SetLocationStatus(true /* android */, 610 MockLocationSettings::SetLocationStatus(true /* android */,
596 false /* system */); 611 false /* system */);
597 EXPECT_EQ(0U, infobar_service()->infobar_count()); 612 EXPECT_EQ(0U, GetNumberOfPrompts());
598 RequestGeolocationPermission( 613 RequestGeolocationPermission(
599 web_contents(), RequestID(0), requesting_frame, true); 614 web_contents(), RequestID(0), requesting_frame, true);
600 EXPECT_EQ(0U, infobar_service()->infobar_count()); 615 EXPECT_EQ(0U, GetNumberOfPrompts());
601 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog()); 616 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog());
602 } 617 }
603 618
604 TEST_F(GeolocationPermissionContextTests, SystemLocationOnNoLSD) { 619 TEST_P(GeolocationPermissionContextTests, SystemLocationOnNoLSD) {
605 base::test::ScopedFeatureList scoped_feature_list; 620 base::test::ScopedFeatureList scoped_feature_list;
606 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 621 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
607 622
608 GURL requesting_frame("https://www.example.com/geolocation"); 623 GURL requesting_frame("https://www.example.com/geolocation");
609 NavigateAndCommit(requesting_frame); 624 NavigateAndCommit(requesting_frame);
610 EXPECT_EQ(0U, infobar_service()->infobar_count()); 625 RequestManagerDocumentLoadCompleted();
626 EXPECT_EQ(0U, GetNumberOfPrompts());
611 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 627 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
612 true); 628 true);
613 EXPECT_EQ(1U, infobar_service()->infobar_count()); 629 ASSERT_EQ(1U, GetNumberOfPrompts());
614 ConfirmInfoBarDelegate* infobar_delegate = 630 AcceptPrompt();
615 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
616 ASSERT_TRUE(infobar_delegate);
617 infobar_delegate->Accept();
618 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 631 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
619 CheckPermissionMessageSent(0, true); 632 CheckPermissionMessageSent(0, true);
620 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog()); 633 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog());
621 } 634 }
622 635
623 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { 636 TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) {
624 base::HistogramTester tester; 637 base::HistogramTester tester;
625 base::test::ScopedFeatureList scoped_feature_list; 638 base::test::ScopedFeatureList scoped_feature_list;
626 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 639 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
627 640
628 GURL requesting_frame("https://www.example.com/geolocation"); 641 GURL requesting_frame("https://www.example.com/geolocation");
629 NavigateAndCommit(requesting_frame); 642 NavigateAndCommit(requesting_frame);
643 RequestManagerDocumentLoadCompleted();
630 MockLocationSettings::SetLocationStatus(true /* android */, 644 MockLocationSettings::SetLocationStatus(true /* android */,
631 false /* system */); 645 false /* system */);
632 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 646 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
633 GRANTED); 647 GRANTED);
634 EXPECT_EQ(0U, infobar_service()->infobar_count()); 648 EXPECT_EQ(0U, GetNumberOfPrompts());
635 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 649 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
636 true); 650 true);
637 EXPECT_EQ(1U, infobar_service()->infobar_count()); 651 ASSERT_EQ(1U, GetNumberOfPrompts());
638 ConfirmInfoBarDelegate* infobar_delegate = 652 AcceptPrompt();
639 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
640 ASSERT_TRUE(infobar_delegate);
641 infobar_delegate->Accept();
642 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 653 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
643 CheckPermissionMessageSent(0, true); 654 CheckPermissionMessageSent(0, true);
644 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); 655 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
645 656
646 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1); 657 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1);
647 tester.ExpectTotalCount("Geolocation.SettingsDialog.AcceptEvent.NonDSE", 1); 658 tester.ExpectTotalCount("Geolocation.SettingsDialog.AcceptEvent.NonDSE", 1);
648 tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 0); 659 tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 0);
649 } 660 }
650 661
651 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { 662 TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDReject) {
652 base::HistogramTester tester; 663 base::HistogramTester tester;
653 base::test::ScopedFeatureList scoped_feature_list; 664 base::test::ScopedFeatureList scoped_feature_list;
654 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 665 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
655 666
656 GURL requesting_frame("https://www.example.com/geolocation"); 667 GURL requesting_frame("https://www.example.com/geolocation");
657 NavigateAndCommit(requesting_frame); 668 NavigateAndCommit(requesting_frame);
669 RequestManagerDocumentLoadCompleted();
658 MockLocationSettings::SetLocationStatus(true /* android */, 670 MockLocationSettings::SetLocationStatus(true /* android */,
659 false /* system */); 671 false /* system */);
660 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 672 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
661 DENIED); 673 DENIED);
662 EXPECT_EQ(0U, infobar_service()->infobar_count()); 674 EXPECT_EQ(0U, GetNumberOfPrompts());
663 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, 675 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
664 true); 676 true);
665 EXPECT_EQ(1U, infobar_service()->infobar_count()); 677 ASSERT_EQ(1U, GetNumberOfPrompts());
666 ConfirmInfoBarDelegate* infobar_delegate = 678 AcceptPrompt();
667 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
668 ASSERT_TRUE(infobar_delegate);
669 infobar_delegate->Accept();
670 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK); 679 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK);
671 CheckPermissionMessageSent(0, false); 680 CheckPermissionMessageSent(0, false);
672 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); 681 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
673 682
674 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1); 683 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1);
675 tester.ExpectTotalCount("Geolocation.SettingsDialog.AcceptEvent.NonDSE", 0); 684 tester.ExpectTotalCount("Geolocation.SettingsDialog.AcceptEvent.NonDSE", 0);
676 tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 1); 685 tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 1);
677 } 686 }
678 687
679 TEST_F(GeolocationPermissionContextTests, LSDBackOffDifferentSites) { 688 TEST_P(GeolocationPermissionContextTests, LSDBackOffDifferentSites) {
680 base::HistogramTester tester; 689 base::HistogramTester tester;
681 base::test::ScopedFeatureList scoped_feature_list; 690 base::test::ScopedFeatureList scoped_feature_list;
682 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 691 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
683 692
684 GURL requesting_frame_1("https://www.example.com/geolocation"); 693 GURL requesting_frame_1("https://www.example.com/geolocation");
685 GURL requesting_frame_2("https://www.example-2.com/geolocation"); 694 GURL requesting_frame_2("https://www.example-2.com/geolocation");
686 const char* requesting_frame_dse_ptr = "https://www.dse.com/geolocation"; 695 const char* requesting_frame_dse_ptr = "https://www.dse.com/geolocation";
687 GURL requesting_frame_dse(requesting_frame_dse_ptr); 696 GURL requesting_frame_dse(requesting_frame_dse_ptr);
688 697
689 SetDSEOriginForTesting(requesting_frame_dse_ptr); 698 SetDSEOriginForTesting(requesting_frame_dse_ptr);
690 699
691 // Set all origin geolocation permissions to ALLOW. 700 // Set all origin geolocation permissions to ALLOW.
692 SetGeolocationContentSetting(requesting_frame_1, requesting_frame_1, 701 SetGeolocationContentSetting(requesting_frame_1, requesting_frame_1,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 // Now check that the DSE is in backoff. 736 // Now check that the DSE is in backoff.
728 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_dse)); 737 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame_dse));
729 738
730 // Test that the right histograms are updated. 739 // Test that the right histograms are updated.
731 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1); 740 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 1);
732 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.DSE", 1); 741 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.DSE", 1);
733 tester.ExpectTotalCount("Geolocation.SettingsDialog.SuppressEvent.NonDSE", 2); 742 tester.ExpectTotalCount("Geolocation.SettingsDialog.SuppressEvent.NonDSE", 2);
734 tester.ExpectTotalCount("Geolocation.SettingsDialog.SuppressEvent.DSE", 1); 743 tester.ExpectTotalCount("Geolocation.SettingsDialog.SuppressEvent.DSE", 1);
735 } 744 }
736 745
737 TEST_F(GeolocationPermissionContextTests, LSDBackOffTiming) { 746 TEST_P(GeolocationPermissionContextTests, LSDBackOffTiming) {
738 base::HistogramTester tester; 747 base::HistogramTester tester;
739 base::test::ScopedFeatureList scoped_feature_list; 748 base::test::ScopedFeatureList scoped_feature_list;
740 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 749 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
741 750
742 GURL requesting_frame("https://www.example.com/geolocation"); 751 GURL requesting_frame("https://www.example.com/geolocation");
743 SetGeolocationContentSetting(requesting_frame, requesting_frame, 752 SetGeolocationContentSetting(requesting_frame, requesting_frame,
744 CONTENT_SETTING_ALLOW); 753 CONTENT_SETTING_ALLOW);
745 754
746 // Turn off system location but allow the LSD to be shown, and denied. 755 // Turn off system location but allow the LSD to be shown, and denied.
747 MockLocationSettings::SetLocationStatus(true /* android */, 756 MockLocationSettings::SetLocationStatus(true /* android */,
748 false /* system */); 757 false /* system */);
749 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 758 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
750 DENIED); 759 DENIED);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 824
816 // Check histograms so far. 825 // Check histograms so far.
817 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 5); 826 tester.ExpectTotalCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 5);
818 tester.ExpectBucketCount("Geolocation.SettingsDialog.ShowEvent.NonDSE", 827 tester.ExpectBucketCount("Geolocation.SettingsDialog.ShowEvent.NonDSE",
819 static_cast<base::HistogramBase::Sample>( 828 static_cast<base::HistogramBase::Sample>(
820 GeolocationPermissionContextAndroid:: 829 GeolocationPermissionContextAndroid::
821 LocationSettingsDialogBackOff::kThreeMonths), 830 LocationSettingsDialogBackOff::kThreeMonths),
822 2); 831 2);
823 } 832 }
824 833
825 TEST_F(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) { 834 TEST_P(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) {
826 base::test::ScopedFeatureList scoped_feature_list; 835 base::test::ScopedFeatureList scoped_feature_list;
827 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 836 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
828 837
829 GURL requesting_frame("https://www.example.com/geolocation"); 838 GURL requesting_frame("https://www.example.com/geolocation");
830 SetGeolocationContentSetting(requesting_frame, requesting_frame, 839 SetGeolocationContentSetting(requesting_frame, requesting_frame,
831 CONTENT_SETTING_ALLOW); 840 CONTENT_SETTING_ALLOW);
832 841
833 // Turn off system location but allow the LSD to be shown, and denied. 842 // Turn off system location but allow the LSD to be shown, and denied.
834 MockLocationSettings::SetLocationStatus(true /* android */, 843 MockLocationSettings::SetLocationStatus(true /* android */,
835 false /* system */); 844 false /* system */);
836 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 845 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
837 DENIED); 846 DENIED);
838 847
839 // The permission status should reflect that the LSD will be shown. 848 // The permission status should reflect that the LSD will be shown.
840 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 849 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
841 PermissionManager::Get(profile())->GetPermissionStatus( 850 PermissionManager::Get(profile())->GetPermissionStatus(
842 content::PermissionType::GEOLOCATION, requesting_frame, 851 content::PermissionType::GEOLOCATION, requesting_frame,
843 requesting_frame)); 852 requesting_frame));
844 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 853 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
845 854
846 // Now that the LSD is in backoff, the permission status should reflect it. 855 // Now that the LSD is in backoff, the permission status should reflect it.
847 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame)); 856 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
848 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 857 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
849 PermissionManager::Get(profile())->GetPermissionStatus( 858 PermissionManager::Get(profile())->GetPermissionStatus(
850 content::PermissionType::GEOLOCATION, requesting_frame, 859 content::PermissionType::GEOLOCATION, requesting_frame,
851 requesting_frame)); 860 requesting_frame));
852 } 861 }
853 862
854 TEST_F(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) { 863 TEST_P(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) {
855 base::test::ScopedFeatureList scoped_feature_list; 864 base::test::ScopedFeatureList scoped_feature_list;
856 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 865 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
857 866
858 GURL requesting_frame("https://www.example.com/geolocation"); 867 GURL requesting_frame("https://www.example.com/geolocation");
859 SetGeolocationContentSetting(requesting_frame, requesting_frame, 868 SetGeolocationContentSetting(requesting_frame, requesting_frame,
860 CONTENT_SETTING_ALLOW); 869 CONTENT_SETTING_ALLOW);
861 870
862 // Turn off system location but allow the LSD to be shown, and denied. 871 // Turn off system location but allow the LSD to be shown, and denied.
863 MockLocationSettings::SetLocationStatus(true /* android */, 872 MockLocationSettings::SetLocationStatus(true /* android */,
864 false /* system */); 873 false /* system */);
865 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 874 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
866 DENIED); 875 DENIED);
867 876
868 // First, cancel a LSD prompt on the first non-DSE origin to go into backoff. 877 // First, cancel a LSD prompt on the first non-DSE origin to go into backoff.
869 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 878 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
870 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame)); 879 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
871 880
872 // Set the content setting back to ASK. The permission status should be 881 // Set the content setting back to ASK. The permission status should be
873 // prompt, and the LSD prompt should now be shown. 882 // prompt, and the LSD prompt should now be shown.
874 SetGeolocationContentSetting(requesting_frame, requesting_frame, 883 SetGeolocationContentSetting(requesting_frame, requesting_frame,
875 CONTENT_SETTING_ASK); 884 CONTENT_SETTING_ASK);
876 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 885 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
877 PermissionManager::Get(profile())->GetPermissionStatus( 886 PermissionManager::Get(profile())->GetPermissionStatus(
878 content::PermissionType::GEOLOCATION, requesting_frame, 887 content::PermissionType::GEOLOCATION, requesting_frame,
879 requesting_frame)); 888 requesting_frame));
880 EXPECT_TRUE( 889 EXPECT_TRUE(
881 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame)); 890 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
882 } 891 }
883 892
884 TEST_F(GeolocationPermissionContextTests, 893 TEST_P(GeolocationPermissionContextTests,
885 LSDBackOffAcceptPermissionResetsBackOff) { 894 LSDBackOffAcceptPermissionResetsBackOff) {
886 base::test::ScopedFeatureList scoped_feature_list; 895 base::test::ScopedFeatureList scoped_feature_list;
887 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 896 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
888 897
889 GURL requesting_frame("https://www.example.com/geolocation"); 898 GURL requesting_frame("https://www.example.com/geolocation");
890 SetGeolocationContentSetting(requesting_frame, requesting_frame, 899 SetGeolocationContentSetting(requesting_frame, requesting_frame,
891 CONTENT_SETTING_ALLOW); 900 CONTENT_SETTING_ALLOW);
892 901
893 // Turn off system location but allow the LSD to be shown, and denied. 902 // Turn off system location but allow the LSD to be shown, and denied.
894 MockLocationSettings::SetLocationStatus(true /* android */, 903 MockLocationSettings::SetLocationStatus(true /* android */,
895 false /* system */); 904 false /* system */);
896 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 905 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
897 DENIED); 906 DENIED);
898 907
899 // First, get into the highest backoff state. 908 // First, get into the highest backoff state.
900 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 909 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
901 AddDayOffsetForTesting(7); 910 AddDayOffsetForTesting(7);
902 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 911 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
903 AddDayOffsetForTesting(30); 912 AddDayOffsetForTesting(30);
904 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 913 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
905 AddDayOffsetForTesting(90); 914 AddDayOffsetForTesting(90);
906 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 915 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
907 916
908 // Now accept a permissions prompt. 917 // Now accept a permissions prompt.
909 SetGeolocationContentSetting(requesting_frame, requesting_frame, 918 SetGeolocationContentSetting(requesting_frame, requesting_frame,
910 CONTENT_SETTING_ASK); 919 CONTENT_SETTING_ASK);
911 EXPECT_TRUE( 920 EXPECT_TRUE(
912 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame)); 921 RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame));
913 922
923 // Denying the LSD stops the content setting from being stored, so explicitly
924 // set it to ALLOW.
925 SetGeolocationContentSetting(requesting_frame, requesting_frame,
926 CONTENT_SETTING_ALLOW);
927
914 // And check that back in the lowest backoff state. 928 // And check that back in the lowest backoff state.
915 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame)); 929 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
916 AddDayOffsetForTesting(7); 930 AddDayOffsetForTesting(7);
917 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 931 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
918 } 932 }
919 933
920 TEST_F(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) { 934 TEST_P(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) {
921 base::test::ScopedFeatureList scoped_feature_list; 935 base::test::ScopedFeatureList scoped_feature_list;
922 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 936 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
923 937
924 GURL requesting_frame("https://www.example.com/geolocation"); 938 GURL requesting_frame("https://www.example.com/geolocation");
925 SetGeolocationContentSetting(requesting_frame, requesting_frame, 939 SetGeolocationContentSetting(requesting_frame, requesting_frame,
926 CONTENT_SETTING_ALLOW); 940 CONTENT_SETTING_ALLOW);
927 941
928 // Turn off system location but allow the LSD to be shown, and denied. 942 // Turn off system location but allow the LSD to be shown, and denied.
929 MockLocationSettings::SetLocationStatus(true /* android */, 943 MockLocationSettings::SetLocationStatus(true /* android */,
930 false /* system */); 944 false /* system */);
931 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 945 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
932 DENIED); 946 DENIED);
(...skipping 14 matching lines...) Expand all
947 // Check that not in backoff, and that at the lowest backoff state. 961 // Check that not in backoff, and that at the lowest backoff state.
948 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 962 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
949 DENIED); 963 DENIED);
950 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 964 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
951 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame)); 965 EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame));
952 AddDayOffsetForTesting(7); 966 AddDayOffsetForTesting(7);
953 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); 967 EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame));
954 } 968 }
955 #endif 969 #endif
956 970
957 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 971 TEST_P(GeolocationPermissionContextTests, QueuedPermission) {
958 GURL requesting_frame_0("https://www.example.com/geolocation"); 972 GURL requesting_frame_0("https://www.example.com/geolocation");
959 GURL requesting_frame_1("https://www.example-2.com/geolocation"); 973 GURL requesting_frame_1("https://www.example-2.com/geolocation");
960 EXPECT_EQ( 974 EXPECT_EQ(
961 CONTENT_SETTING_ASK, 975 CONTENT_SETTING_ASK,
962 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); 976 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1));
963 EXPECT_EQ( 977 EXPECT_EQ(
964 CONTENT_SETTING_ASK, 978 CONTENT_SETTING_ASK,
965 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1)); 979 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1));
966 980
967 NavigateAndCommit(requesting_frame_0); 981 NavigateAndCommit(requesting_frame_0);
968 RequestManagerDocumentLoadCompleted(); 982 RequestManagerDocumentLoadCompleted();
969 983
970 // Check that no permission requests have happened yet. 984 // Check that no permission requests have happened yet.
971 EXPECT_EQ(0U, GetNumberOfPrompts()); 985 EXPECT_EQ(0U, GetNumberOfPrompts());
972 986
973 // Request permission for two frames. 987 // Request permission for two frames.
974 RequestGeolocationPermission( 988 RequestGeolocationPermission(
975 web_contents(), RequestID(0), requesting_frame_0, true); 989 web_contents(), RequestID(0), requesting_frame_0, true);
976 RequestGeolocationPermission( 990 RequestGeolocationPermission(
977 web_contents(), RequestID(1), requesting_frame_1, true); 991 web_contents(), RequestID(1), requesting_frame_1, true);
978 // Ensure only one infobar is created. 992 // Ensure only one infobar is created.
979 ASSERT_EQ(1U, GetNumberOfPrompts()); 993 ASSERT_EQ(1U, GetNumberOfPrompts());
980 base::string16 text_0 = GetPromptText(); 994 base::string16 text_0 = GetPromptText();
981 995
982 // Accept the first frame. 996 // Accept the first frame.
983 AcceptPrompt(); 997 AcceptPrompt();
984 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 998 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
985 CheckPermissionMessageSent(0, true); 999 CheckPermissionMessageSent(0, true);
986 1000
987 #if defined(OS_ANDROID)
988 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0);
989 infobar_service()->RemoveInfoBar(infobar_0);
990 EXPECT_EQ(1U, closed_infobar_tracker_.size());
991 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0));
992 closed_infobar_tracker_.Clear();
993 #endif
994
995 // Now we should have a new infobar for the second frame. 1001 // Now we should have a new infobar for the second frame.
996 ASSERT_EQ(1U, GetNumberOfPrompts()); 1002 ASSERT_EQ(1U, GetNumberOfPrompts());
997 base::string16 text_1 = GetPromptText(); 1003 base::string16 text_1 = GetPromptText();
998 1004
999 // Check that the messages differ. 1005 // Check that the messages differ.
1000 EXPECT_NE(text_0, text_1); 1006 EXPECT_NE(text_0, text_1);
1001 1007
1002 // Cancel (block) this frame. 1008 // Cancel (block) this frame.
1003 #if !defined(OS_ANDROID) 1009 DenyPrompt();
1004 PermissionRequestManager* manager =
1005 PermissionRequestManager::FromWebContents(web_contents());
1006 DenyBubble(manager);
1007 #else
1008 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0);
1009 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel();
1010 #endif
1011 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 1010 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
1012 CheckPermissionMessageSent(1, false); 1011 CheckPermissionMessageSent(1, false);
1013 1012
1014 // Ensure the persisted permissions are ok. 1013 // Ensure the persisted permissions are ok.
1015 EXPECT_EQ( 1014 EXPECT_EQ(
1016 CONTENT_SETTING_ALLOW, 1015 CONTENT_SETTING_ALLOW,
1017 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 1016 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
1018 EXPECT_EQ( 1017 EXPECT_EQ(
1019 CONTENT_SETTING_BLOCK, 1018 CONTENT_SETTING_BLOCK,
1020 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 1019 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
1021 } 1020 }
1022 1021
1023 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 1022 TEST_P(GeolocationPermissionContextTests, HashIsIgnored) {
1024 GURL url_a("https://www.example.com/geolocation#a"); 1023 GURL url_a("https://www.example.com/geolocation#a");
1025 GURL url_b("https://www.example.com/geolocation#b"); 1024 GURL url_b("https://www.example.com/geolocation#b");
1026 1025
1027 // Navigate to the first url. 1026 // Navigate to the first url.
1028 NavigateAndCommit(url_a); 1027 NavigateAndCommit(url_a);
1029 RequestManagerDocumentLoadCompleted(); 1028 RequestManagerDocumentLoadCompleted();
1030 1029
1031 // Check permission is requested. 1030 // Check permission is requested.
1032 ASSERT_EQ(0U, GetNumberOfPrompts()); 1031 ASSERT_EQ(0U, GetNumberOfPrompts());
1033 #if defined(OS_ANDROID)
1034 const bool user_gesture = false;
1035 #else
1036 const bool user_gesture = true; 1032 const bool user_gesture = true;
1037 #endif
1038 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, 1033 RequestGeolocationPermission(web_contents(), RequestID(0), url_a,
1039 user_gesture); 1034 user_gesture);
1040 ASSERT_EQ(1U, GetNumberOfPrompts()); 1035 ASSERT_EQ(1U, GetNumberOfPrompts());
1041 1036
1042 // Change the hash, we'll still be on the same page. 1037 // Change the hash, we'll still be on the same page.
1043 NavigateAndCommit(url_b); 1038 NavigateAndCommit(url_b);
1044 RequestManagerDocumentLoadCompleted(); 1039 RequestManagerDocumentLoadCompleted();
1045 1040
1046 // Accept. 1041 // Accept.
1047 AcceptPrompt(); 1042 AcceptPrompt();
1048 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 1043 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
1049 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 1044 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
1050 CheckPermissionMessageSent(0, true); 1045 CheckPermissionMessageSent(0, true);
1051
1052 // Cleanup.
1053 #if defined(OS_ANDROID)
1054 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
1055 infobar_service()->RemoveInfoBar(infobar);
1056 EXPECT_EQ(1U, closed_infobar_tracker_.size());
1057 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
1058 #endif
1059 } 1046 }
1060 1047
1061 // TODO(felt): The bubble is rejecting file:// permission requests. 1048 // TODO(felt): The bubble is rejecting file:// permission requests.
1062 // Fix and enable this test. crbug.com/444047 1049 // Fix and enable this test. crbug.com/444047
1063 #if defined(OS_ANDROID) 1050 #if defined(OS_ANDROID)
1064 #define MAYBE_PermissionForFileScheme PermissionForFileScheme 1051 TEST_P(GeolocationPermissionContextTests, PermissionForFileScheme) {
1065 #else 1052 #else
1066 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme 1053 TEST_P(GeolocationPermissionContextTests, DISABLED_PermissionForFileScheme) {
1067 #endif 1054 #endif
1068 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { 1055 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER)
1056 return;
raymes 2017/05/17 04:24:49 Maybe remove the #ifdef above and just rely on thi
Timothy Loh 2017/05/19 01:43:01 Done.
1057
1069 GURL requesting_frame("file://example/geolocation.html"); 1058 GURL requesting_frame("file://example/geolocation.html");
1070 NavigateAndCommit(requesting_frame); 1059 NavigateAndCommit(requesting_frame);
1071 RequestManagerDocumentLoadCompleted(); 1060 RequestManagerDocumentLoadCompleted();
1072 1061
1073 // Check permission is requested. 1062 // Check permission is requested.
1074 ASSERT_EQ(0U, GetNumberOfPrompts()); 1063 ASSERT_EQ(0U, GetNumberOfPrompts());
1075 RequestGeolocationPermission( 1064 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
1076 web_contents(), RequestID(0), requesting_frame, true); 1065 true);
1077 EXPECT_EQ(1U, GetNumberOfPrompts()); 1066 EXPECT_EQ(1U, GetNumberOfPrompts());
1078 1067
1079 // Accept the frame. 1068 // Accept the frame.
1080 AcceptPrompt(); 1069 AcceptPrompt();
1081 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 1070 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
1082 CheckPermissionMessageSent(0, true); 1071 CheckPermissionMessageSent(0, true);
1083 1072
1084 // Make sure the setting is not stored. 1073 // Make sure the setting is not stored.
1085 EXPECT_EQ( 1074 EXPECT_EQ(CONTENT_SETTING_ASK,
1086 CONTENT_SETTING_ASK, 1075 GetGeolocationContentSetting(requesting_frame, requesting_frame));
1087 GetGeolocationContentSetting(requesting_frame, requesting_frame));
1088 } 1076 }
1089 1077
1090 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 1078 TEST_P(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
1091 GURL frame_0("https://www.example.com/geolocation"); 1079 GURL frame_0("https://www.example.com/geolocation");
1092 GURL frame_1("https://www.example-2.com/geolocation"); 1080 GURL frame_1("https://www.example-2.com/geolocation");
1093 EXPECT_EQ( 1081 EXPECT_EQ(
1094 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); 1082 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0));
1095 EXPECT_EQ( 1083 EXPECT_EQ(
1096 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0)); 1084 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0));
1097 1085
1098 NavigateAndCommit(frame_0); 1086 NavigateAndCommit(frame_0);
1099 RequestManagerDocumentLoadCompleted(); 1087 RequestManagerDocumentLoadCompleted();
1100 1088
1101 ASSERT_EQ(0U, GetNumberOfPrompts()); 1089 ASSERT_EQ(0U, GetNumberOfPrompts());
1102 1090
1103 // Request permission for two frames. 1091 // Request permission for two frames.
1104 RequestGeolocationPermission( 1092 RequestGeolocationPermission(
1105 web_contents(), RequestID(0), frame_0, true); 1093 web_contents(), RequestID(0), frame_0, true);
1106 RequestGeolocationPermission( 1094 RequestGeolocationPermission(
1107 web_contents(), RequestID(1), frame_1, true); 1095 web_contents(), RequestID(1), frame_1, true);
1108 1096
1109 // Get the first permission request text. 1097 // Get the first permission request text.
1110 ASSERT_EQ(1U, GetNumberOfPrompts()); 1098 ASSERT_EQ(1U, GetNumberOfPrompts());
1111 base::string16 text_0 = GetPromptText(); 1099 base::string16 text_0 = GetPromptText();
1112 ASSERT_FALSE(text_0.empty()); 1100 ASSERT_FALSE(text_0.empty());
1113 1101
1114 // Simulate the frame going away; the request should be removed. 1102 // Simulate the frame going away; the request should be removed.
1115 #if !defined(OS_ANDROID) 1103 ClosePrompt();
1116 PermissionRequestManager* manager =
1117 PermissionRequestManager::FromWebContents(web_contents());
1118 CloseBubble(manager);
1119 #else
1120 geolocation_permission_context_->CancelPermissionRequest(web_contents(),
1121 RequestID(0));
1122 #endif
1123 1104
1124 // Check that the next pending request is created correctly. 1105 // Check that the next pending request is created correctly.
1125 base::string16 text_1 = GetPromptText(); 1106 base::string16 text_1 = GetPromptText();
1126 EXPECT_NE(text_0, text_1); 1107 EXPECT_NE(text_0, text_1);
1127 1108
1128 // Allow this frame and check that it worked. 1109 // Allow this frame and check that it worked.
1129 AcceptPrompt(); 1110 AcceptPrompt();
1130 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); 1111 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW);
1131 CheckPermissionMessageSent(1, true); 1112 CheckPermissionMessageSent(1, true);
1132 1113
1133 // Ensure the persisted permissions are ok. 1114 // Ensure the persisted permissions are ok.
1134 EXPECT_EQ( 1115 EXPECT_EQ(
1135 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); 1116 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0));
1136 EXPECT_EQ( 1117 EXPECT_EQ(
1137 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0)); 1118 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0));
1138 } 1119 }
1139 1120
1140 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 1121 TEST_P(GeolocationPermissionContextTests, InvalidURL) {
1141 // Navigate to the first url. 1122 // Navigate to the first url.
1142 GURL invalid_embedder("about:blank"); 1123 GURL invalid_embedder("about:blank");
1143 GURL requesting_frame; 1124 GURL requesting_frame;
1144 NavigateAndCommit(invalid_embedder); 1125 NavigateAndCommit(invalid_embedder);
1145 RequestManagerDocumentLoadCompleted(); 1126 RequestManagerDocumentLoadCompleted();
1146 1127
1147 // Nothing should be displayed. 1128 // Nothing should be displayed.
1148 EXPECT_EQ(0U, GetNumberOfPrompts()); 1129 EXPECT_EQ(0U, GetNumberOfPrompts());
1149 RequestGeolocationPermission( 1130 RequestGeolocationPermission(
1150 web_contents(), RequestID(0), requesting_frame, true); 1131 web_contents(), RequestID(0), requesting_frame, true);
1151 EXPECT_EQ(0U, GetNumberOfPrompts()); 1132 EXPECT_EQ(0U, GetNumberOfPrompts());
1152 CheckPermissionMessageSent(0, false); 1133 CheckPermissionMessageSent(0, false);
1153 } 1134 }
1154 1135
1155 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 1136 TEST_P(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
1156 GURL url_a("https://www.example.com/geolocation"); 1137 GURL url_a("https://www.example.com/geolocation");
1157 GURL url_b("https://www.example-2.com/geolocation"); 1138 GURL url_b("https://www.example-2.com/geolocation");
1158 NavigateAndCommit(url_a); // Tab A0 1139 NavigateAndCommit(url_a); // Tab A0
1159 AddNewTab(url_b); // Tab B (extra_tabs_[0]) 1140 AddNewTab(url_b); // Tab B (extra_tabs_[0])
1160 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) 1141 AddNewTab(url_a); // Tab A1 (extra_tabs_[1])
1161 RequestManagerDocumentLoadCompleted(); 1142 RequestManagerDocumentLoadCompleted();
1162 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); 1143 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get());
1163 RequestManagerDocumentLoadCompleted(extra_tabs_[1].get()); 1144 RequestManagerDocumentLoadCompleted(extra_tabs_[1].get());
1164 #if !defined(OS_ANDROID)
1165 PermissionRequestManager* manager_a0 =
1166 PermissionRequestManager::FromWebContents(web_contents());
1167 PermissionRequestManager* manager_b =
1168 PermissionRequestManager::FromWebContents(extra_tabs_[0].get());
1169 PermissionRequestManager* manager_a1 =
1170 PermissionRequestManager::FromWebContents(extra_tabs_[1].get());
1171 #endif
1172 1145
1173 // Request permission in all three tabs. 1146 // Request permission in all three tabs.
1174 RequestGeolocationPermission( 1147 RequestGeolocationPermission(
1175 web_contents(), RequestID(0), url_a, true); 1148 web_contents(), RequestID(0), url_a, true);
1176 RequestGeolocationPermission( 1149 RequestGeolocationPermission(
1177 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true); 1150 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true);
1178 RequestGeolocationPermission( 1151 RequestGeolocationPermission(
1179 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true); 1152 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true);
1180 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. 1153 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0.
1181 #if !defined(OS_ANDROID) 1154 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get()));
1182 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 1155 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[1].get()));
1183 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
1184 #else
1185 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
1186 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
1187 #endif
1188 1156
1189 // Accept the permission in tab A0. 1157 // Accept the permission in tab A0.
1190 #if !defined(OS_ANDROID) 1158 AcceptPrompt();
1191 AcceptBubble(manager_a0); 1159 if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) {
1192 #else 1160 EXPECT_EQ(2U, closed_infobar_tracker_.size());
1193 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); 1161 }
1194 ConfirmInfoBarDelegate* infobar_delegate_a0 =
1195 infobar_a0->delegate()->AsConfirmInfoBarDelegate();
1196 ASSERT_TRUE(infobar_delegate_a0);
1197 infobar_delegate_a0->Accept();
1198 infobar_service()->RemoveInfoBar(infobar_a0);
1199 EXPECT_EQ(2U, closed_infobar_tracker_.size());
1200 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0));
1201 #endif
1202 CheckPermissionMessageSent(0, true); 1162 CheckPermissionMessageSent(0, true);
1203 // Because they're the same origin, this will cause tab A1's infobar to 1163 // Because they're the same origin, this will cause tab A1's infobar to
1204 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 1164 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
1205 // TODO(felt): Update this test when the bubble's behavior is changed. 1165 // TODO(felt): Update this test when the bubble's behavior is changed.
1206 // Either way, tab B should still have a pending permission request. 1166 // Either way, tab B should still have a pending permission request.
1207 #if !defined(OS_ANDROID) 1167 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get()));
1208 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 1168 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
1209 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 1169 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[1].get()));
1210 #else 1170 } else {
1211 CheckPermissionMessageSentForTab(1, 0, true); 1171 CheckPermissionMessageSentForTab(1, 0, true);
1212 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 1172 }
1213 #endif
1214 } 1173 }
1215 1174
1216 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 1175 TEST_P(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
1217 GURL url_a("https://www.example.com/geolocation"); 1176 GURL url_a("https://www.example.com/geolocation");
1218 GURL url_b("https://www.example-2.com/geolocation"); 1177 GURL url_b("https://www.example-2.com/geolocation");
1219 NavigateAndCommit(url_a); // Tab A0. 1178 NavigateAndCommit(url_a); // Tab A0.
1220 AddNewTab(url_a); // Tab A1. 1179 AddNewTab(url_a); // Tab A1.
1221 #if !defined(OS_ANDROID)
1222 RequestManagerDocumentLoadCompleted(); 1180 RequestManagerDocumentLoadCompleted();
1223 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); 1181 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get());
1224 PermissionRequestManager* manager_a0 =
1225 PermissionRequestManager::FromWebContents(web_contents());
1226 PermissionRequestManager* manager_a1 =
1227 PermissionRequestManager::FromWebContents(extra_tabs_[0].get());
1228 #endif
1229 1182
1230 // Request permission in both tabs; the extra tab will have two permission 1183 // Request permission in both tabs; the extra tab will have two permission
1231 // requests from two origins. 1184 // requests from two origins.
1232 RequestGeolocationPermission( 1185 RequestGeolocationPermission(
1233 web_contents(), RequestID(0), url_a, true); 1186 web_contents(), RequestID(0), url_a, true);
1234 RequestGeolocationPermission( 1187 RequestGeolocationPermission(
1235 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true); 1188 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true);
1236 RequestGeolocationPermission( 1189 RequestGeolocationPermission(
1237 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true); 1190 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true);
1238 #if !defined(OS_ANDROID) 1191
1239 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0)); 1192 ASSERT_EQ(1U, GetNumberOfPrompts());
1240 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 1193 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get()));
1241 #else
1242 ASSERT_EQ(1U, infobar_service()->infobar_count());
1243 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
1244 #endif
1245 1194
1246 // Accept the first request in tab A1. 1195 // Accept the first request in tab A1.
1247 #if !defined(OS_ANDROID) 1196 AcceptPrompt(extra_tabs_[0].get());
1248 AcceptBubble(manager_a1); 1197 if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) {
1249 #else 1198 EXPECT_EQ(2U, closed_infobar_tracker_.size());
1250 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); 1199 }
1251 ConfirmInfoBarDelegate* infobar_delegate_a1 =
1252 infobar_a1->delegate()->AsConfirmInfoBarDelegate();
1253 ASSERT_TRUE(infobar_delegate_a1);
1254 infobar_delegate_a1->Accept();
1255 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1);
1256 EXPECT_EQ(2U, closed_infobar_tracker_.size());
1257 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1));
1258 #endif
1259 CheckPermissionMessageSentForTab(0, 0, true); 1200 CheckPermissionMessageSentForTab(0, 0, true);
1260 1201
1261 // Because they're the same origin, this will cause tab A0's infobar to 1202 // Because they're the same origin, this will cause tab A0's infobar to
1262 // disappear. It does not cause the bubble to disappear: crbug.com/443013. 1203 // disappear. It does not cause the bubble to disappear: crbug.com/443013.
1263 // TODO(felt): Update this test when the bubble's behavior is changed. 1204 // TODO(felt): Update this test when the bubble's behavior is changed.
1264 #if !defined(OS_ANDROID) 1205 if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) {
1265 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); 1206 EXPECT_EQ(1U, GetNumberOfPrompts());
1266 #else 1207 } else {
1267 EXPECT_EQ(0U, infobar_service()->infobar_count()); 1208 EXPECT_EQ(0U, GetNumberOfPrompts());
1268 CheckPermissionMessageSent(0, true); 1209 CheckPermissionMessageSent(0, true);
1269 #endif 1210 }
1270 1211
1271 // The second request should now be visible in tab A1. 1212 // The second request should now be visible in tab A1.
1272 #if !defined(OS_ANDROID) 1213 ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get()));
1273 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
1274 #else
1275 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
1276 #endif
1277 1214
1278 // Accept the second request and check that it's gone. 1215 // Accept the second request and check that it's gone.
1279 #if !defined(OS_ANDROID) 1216 AcceptPrompt(extra_tabs_[0].get());
1280 AcceptBubble(manager_a1); 1217 EXPECT_EQ(0U, GetNumberOfPrompts(extra_tabs_[0].get()));
1281 EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1));
1282 #else
1283 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0);
1284 ConfirmInfoBarDelegate* infobar_delegate_1 =
1285 infobar_1->delegate()->AsConfirmInfoBarDelegate();
1286 ASSERT_TRUE(infobar_delegate_1);
1287 infobar_delegate_1->Accept();
1288 #endif
1289 } 1218 }
1290 1219
1291 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 1220 TEST_P(GeolocationPermissionContextTests, TabDestroyed) {
1292 GURL requesting_frame_0("https://www.example.com/geolocation"); 1221 GURL requesting_frame_0("https://www.example.com/geolocation");
1293 GURL requesting_frame_1("https://www.example-2.com/geolocation"); 1222 GURL requesting_frame_1("https://www.example-2.com/geolocation");
1294 EXPECT_EQ( 1223 EXPECT_EQ(
1295 CONTENT_SETTING_ASK, 1224 CONTENT_SETTING_ASK,
1296 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 1225 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
1297 EXPECT_EQ( 1226 EXPECT_EQ(
1298 CONTENT_SETTING_ASK, 1227 CONTENT_SETTING_ASK,
1299 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 1228 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
1300 1229
1301 NavigateAndCommit(requesting_frame_0); 1230 NavigateAndCommit(requesting_frame_0);
1302 RequestManagerDocumentLoadCompleted(); 1231 RequestManagerDocumentLoadCompleted();
1303 1232
1304 // Request permission for two frames. 1233 // Request permission for two frames.
1305 RequestGeolocationPermission( 1234 RequestGeolocationPermission(
1306 web_contents(), RequestID(0), requesting_frame_0, false); 1235 web_contents(), RequestID(0), requesting_frame_0, false);
1307 RequestGeolocationPermission( 1236 RequestGeolocationPermission(
1308 web_contents(), RequestID(1), requesting_frame_1, false); 1237 web_contents(), RequestID(1), requesting_frame_1, false);
1309 1238
1310 // Ensure only one prompt is created. 1239 // Ensure only one prompt is created.
1311 ASSERT_EQ(1U, GetNumberOfPrompts()); 1240 ASSERT_EQ(1U, GetNumberOfPrompts());
1312 1241
1313 // Delete the tab contents. 1242 // Delete the tab contents.
1314 #if defined(OS_ANDROID) 1243 if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) {
1315 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 1244 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
1316 DeleteContents(); 1245 DeleteContents();
1317 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 1246 ASSERT_EQ(1U, closed_infobar_tracker_.size());
1318 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 1247 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
1319 #endif 1248 }
1320 1249
1321 // The content settings should not have changed. 1250 // The content settings should not have changed.
1322 EXPECT_EQ( 1251 EXPECT_EQ(
1323 CONTENT_SETTING_ASK, 1252 CONTENT_SETTING_ASK,
1324 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 1253 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
1325 EXPECT_EQ( 1254 EXPECT_EQ(
1326 CONTENT_SETTING_ASK, 1255 CONTENT_SETTING_ASK,
1327 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 1256 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
1328 } 1257 }
1329 1258
1330 #if defined(OS_ANDROID) 1259 #if defined(OS_ANDROID)
1331 TEST_F(GeolocationPermissionContextTests, SearchGeolocationInIncognito) { 1260 TEST_P(GeolocationPermissionContextTests, SearchGeolocationInIncognito) {
1332 base::test::ScopedFeatureList scoped_feature_list; 1261 base::test::ScopedFeatureList scoped_feature_list;
1333 scoped_feature_list.InitAndEnableFeature( 1262 EnableFeature(scoped_feature_list, features::kConsistentOmniboxGeolocation);
1334 features::kConsistentOmniboxGeolocation);
1335 1263
1336 GURL requesting_frame(TestSearchEngineDelegate::kDSETestUrl); 1264 GURL requesting_frame(TestSearchEngineDelegate::kDSETestUrl);
1337 // The DSE Geolocation setting should be used in incognito if it is BLOCK, 1265 // The DSE Geolocation setting should be used in incognito if it is BLOCK,
1338 // but not if it is ALLOW. 1266 // but not if it is ALLOW.
1339 SearchGeolocationService* geo_service = 1267 SearchGeolocationService* geo_service =
1340 SearchGeolocationService::Factory::GetForBrowserContext(profile()); 1268 SearchGeolocationService::Factory::GetForBrowserContext(profile());
1341 geo_service->SetSearchEngineDelegateForTest( 1269 geo_service->SetSearchEngineDelegateForTest(
1342 base::MakeUnique<TestSearchEngineDelegate>()); 1270 base::MakeUnique<TestSearchEngineDelegate>());
1343 1271
1344 Profile* otr_profile = profile()->GetOffTheRecordProfile(); 1272 Profile* otr_profile = profile()->GetOffTheRecordProfile();
1345 1273
1346 // A DSE setting of ALLOW should not flow through to incognito. 1274 // A DSE setting of ALLOW should not flow through to incognito.
1347 geo_service->SetDSEGeolocationSetting(true); 1275 geo_service->SetDSEGeolocationSetting(true);
1348 ASSERT_EQ(CONTENT_SETTING_ASK, 1276 ASSERT_EQ(CONTENT_SETTING_ASK,
1349 PermissionManager::Get(otr_profile) 1277 PermissionManager::Get(otr_profile)
1350 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, 1278 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION,
1351 requesting_frame, requesting_frame) 1279 requesting_frame, requesting_frame)
1352 .content_setting); 1280 .content_setting);
1353 1281
1354 // Changing the setting to BLOCK should flow through to incognito. 1282 // Changing the setting to BLOCK should flow through to incognito.
1355 geo_service->SetDSEGeolocationSetting(false); 1283 geo_service->SetDSEGeolocationSetting(false);
1356 ASSERT_EQ(CONTENT_SETTING_BLOCK, 1284 ASSERT_EQ(CONTENT_SETTING_BLOCK,
1357 PermissionManager::Get(otr_profile) 1285 PermissionManager::Get(otr_profile)
1358 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, 1286 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION,
1359 requesting_frame, requesting_frame) 1287 requesting_frame, requesting_frame)
1360 .content_setting); 1288 .content_setting);
1361 } 1289 }
1362 1290
1363 TEST_F(GeolocationPermissionContextTests, 1291 TEST_P(GeolocationPermissionContextTests,
1364 GeolocationStatusAndroidDisabledLegacy) { 1292 GeolocationStatusAndroidDisabledLegacy) {
1365 GURL requesting_frame("https://www.example.com/geolocation"); 1293 GURL requesting_frame("https://www.example.com/geolocation");
1366 1294
1367 // In these tests the Android permission status should not be taken into 1295 // In these tests the Android permission status should not be taken into
1368 // account, only the content setting. 1296 // account, only the content setting.
1369 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1297 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1370 CONTENT_SETTING_ALLOW); 1298 CONTENT_SETTING_ALLOW);
1371 MockLocationSettings::SetLocationStatus(false /* android */, 1299 MockLocationSettings::SetLocationStatus(false /* android */,
1372 true /* system */); 1300 true /* system */);
1373 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED, 1301 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED,
1374 PermissionManager::Get(profile())->GetPermissionStatus( 1302 PermissionManager::Get(profile())->GetPermissionStatus(
1375 content::PermissionType::GEOLOCATION, requesting_frame, 1303 content::PermissionType::GEOLOCATION, requesting_frame,
1376 requesting_frame)); 1304 requesting_frame));
1377 1305
1378 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1306 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1379 CONTENT_SETTING_ASK); 1307 CONTENT_SETTING_ASK);
1380 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1308 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1381 PermissionManager::Get(profile())->GetPermissionStatus( 1309 PermissionManager::Get(profile())->GetPermissionStatus(
1382 content::PermissionType::GEOLOCATION, requesting_frame, 1310 content::PermissionType::GEOLOCATION, requesting_frame,
1383 requesting_frame)); 1311 requesting_frame));
1384 1312
1385 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1313 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1386 CONTENT_SETTING_BLOCK); 1314 CONTENT_SETTING_BLOCK);
1387 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1315 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1388 PermissionManager::Get(profile())->GetPermissionStatus( 1316 PermissionManager::Get(profile())->GetPermissionStatus(
1389 content::PermissionType::GEOLOCATION, requesting_frame, 1317 content::PermissionType::GEOLOCATION, requesting_frame,
1390 requesting_frame)); 1318 requesting_frame));
1391 } 1319 }
1392 1320
1393 TEST_F(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) { 1321 TEST_P(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) {
1394 base::test::ScopedFeatureList scoped_feature_list; 1322 base::test::ScopedFeatureList scoped_feature_list;
1395 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 1323 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
1396 1324
1397 GURL requesting_frame("https://www.example.com/geolocation"); 1325 GURL requesting_frame("https://www.example.com/geolocation");
1398 1326
1399 // With the Android permission off, but location allowed for a domain, the 1327 // With the Android permission off, but location allowed for a domain, the
1400 // permission status should be ASK. 1328 // permission status should be ASK.
1401 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1329 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1402 CONTENT_SETTING_ALLOW); 1330 CONTENT_SETTING_ALLOW);
1403 MockLocationSettings::SetLocationStatus(false /* android */, 1331 MockLocationSettings::SetLocationStatus(false /* android */,
1404 true /* system */); 1332 true /* system */);
1405 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1333 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
(...skipping 13 matching lines...) Expand all
1419 // With the Android permission off, and location prompt for a domain, the 1347 // With the Android permission off, and location prompt for a domain, the
1420 // permission status should still be ASK. 1348 // permission status should still be ASK.
1421 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1349 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1422 CONTENT_SETTING_ASK); 1350 CONTENT_SETTING_ASK);
1423 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1351 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1424 PermissionManager::Get(profile())->GetPermissionStatus( 1352 PermissionManager::Get(profile())->GetPermissionStatus(
1425 content::PermissionType::GEOLOCATION, requesting_frame, 1353 content::PermissionType::GEOLOCATION, requesting_frame,
1426 requesting_frame)); 1354 requesting_frame));
1427 } 1355 }
1428 1356
1429 TEST_F(GeolocationPermissionContextTests, 1357 TEST_P(GeolocationPermissionContextTests,
1430 GeolocationStatusSystemDisabledLegacy) { 1358 GeolocationStatusSystemDisabledLegacy) {
1431 GURL requesting_frame("https://www.example.com/geolocation"); 1359 GURL requesting_frame("https://www.example.com/geolocation");
1432 1360
1433 // In these tests the system permission status should not be taken into 1361 // In these tests the system permission status should not be taken into
1434 // account, only the content setting. 1362 // account, only the content setting.
1435 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1363 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1436 CONTENT_SETTING_ALLOW); 1364 CONTENT_SETTING_ALLOW);
1437 MockLocationSettings::SetLocationStatus(true /* android */, 1365 MockLocationSettings::SetLocationStatus(true /* android */,
1438 false /* system */); 1366 false /* system */);
1439 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED, 1367 ASSERT_EQ(blink::mojom::PermissionStatus::GRANTED,
1440 PermissionManager::Get(profile())->GetPermissionStatus( 1368 PermissionManager::Get(profile())->GetPermissionStatus(
1441 content::PermissionType::GEOLOCATION, requesting_frame, 1369 content::PermissionType::GEOLOCATION, requesting_frame,
1442 requesting_frame)); 1370 requesting_frame));
1443 1371
1444 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1372 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1445 CONTENT_SETTING_ASK); 1373 CONTENT_SETTING_ASK);
1446 ASSERT_EQ(blink::mojom::PermissionStatus::ASK, 1374 ASSERT_EQ(blink::mojom::PermissionStatus::ASK,
1447 PermissionManager::Get(profile())->GetPermissionStatus( 1375 PermissionManager::Get(profile())->GetPermissionStatus(
1448 content::PermissionType::GEOLOCATION, requesting_frame, 1376 content::PermissionType::GEOLOCATION, requesting_frame,
1449 requesting_frame)); 1377 requesting_frame));
1450 1378
1451 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1379 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1452 CONTENT_SETTING_BLOCK); 1380 CONTENT_SETTING_BLOCK);
1453 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1381 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1454 PermissionManager::Get(profile())->GetPermissionStatus( 1382 PermissionManager::Get(profile())->GetPermissionStatus(
1455 content::PermissionType::GEOLOCATION, requesting_frame, 1383 content::PermissionType::GEOLOCATION, requesting_frame,
1456 requesting_frame)); 1384 requesting_frame));
1457 } 1385 }
1458 1386
1459 TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) { 1387 TEST_P(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) {
1460 base::test::ScopedFeatureList scoped_feature_list; 1388 base::test::ScopedFeatureList scoped_feature_list;
1461 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); 1389 EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt);
1462 1390
1463 GURL requesting_frame("https://www.example.com/geolocation"); 1391 GURL requesting_frame("https://www.example.com/geolocation");
1464 1392
1465 // With the system permission off, but location allowed for a domain, the 1393 // With the system permission off, but location allowed for a domain, the
1466 // permission status should be reflect whether the LSD can be shown. 1394 // permission status should be reflect whether the LSD can be shown.
1467 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1395 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1468 CONTENT_SETTING_ALLOW); 1396 CONTENT_SETTING_ALLOW);
1469 MockLocationSettings::SetLocationStatus(true /* android */, 1397 MockLocationSettings::SetLocationStatus(true /* android */,
1470 false /* system */); 1398 false /* system */);
1471 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 1399 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 SetGeolocationContentSetting(requesting_frame, requesting_frame, 1432 SetGeolocationContentSetting(requesting_frame, requesting_frame,
1505 CONTENT_SETTING_BLOCK); 1433 CONTENT_SETTING_BLOCK);
1506 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, 1434 MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */,
1507 GRANTED); 1435 GRANTED);
1508 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED, 1436 ASSERT_EQ(blink::mojom::PermissionStatus::DENIED,
1509 PermissionManager::Get(profile())->GetPermissionStatus( 1437 PermissionManager::Get(profile())->GetPermissionStatus(
1510 content::PermissionType::GEOLOCATION, requesting_frame, 1438 content::PermissionType::GEOLOCATION, requesting_frame,
1511 requesting_frame)); 1439 requesting_frame));
1512 } 1440 }
1513 #endif // defined(OS_ANDROID) 1441 #endif // defined(OS_ANDROID)
1442
1443 #if defined(OS_ANDROID)
1444 INSTANTIATE_TEST_CASE_P(
1445 GeolocationPermissionContextTestsInstance,
1446 GeolocationPermissionContextTests,
1447 ::testing::Values(TestType::PERMISSION_REQUEST_MANAGER,
1448 TestType::PERMISSION_QUEUE_CONTROLLER));
1449 #else
1450 INSTANTIATE_TEST_CASE_P(
1451 GeolocationPermissionContextTestsInstance,
1452 GeolocationPermissionContextTests,
1453 ::testing::Values(TestType::PERMISSION_REQUEST_MANAGER));
1454 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698