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

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

Issue 2721293002: Show the Android Location Settings Dialog when sites want permission. (Closed)
Patch Set: Feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/geolocation/geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/geolocation_permission_context.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 12 matching lines...) Expand all
23 #include "base/test/simple_test_clock.h" 23 #include "base/test/simple_test_clock.h"
24 #include "base/time/clock.h" 24 #include "base/time/clock.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 26 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
27 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 27 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
28 #include "chrome/browser/infobars/infobar_service.h" 28 #include "chrome/browser/infobars/infobar_service.h"
29 #include "chrome/browser/permissions/permission_context_base.h" 29 #include "chrome/browser/permissions/permission_context_base.h"
30 #include "chrome/browser/permissions/permission_manager.h" 30 #include "chrome/browser/permissions/permission_manager.h"
31 #include "chrome/browser/permissions/permission_request.h" 31 #include "chrome/browser/permissions/permission_request.h"
32 #include "chrome/browser/permissions/permission_request_id.h" 32 #include "chrome/browser/permissions/permission_request_id.h"
33 #include "chrome/common/chrome_features.h"
33 #include "chrome/common/chrome_switches.h" 34 #include "chrome/common/chrome_switches.h"
34 #include "chrome/common/features.h"
35 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 35 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
36 #include "chrome/test/base/testing_profile.h" 36 #include "chrome/test/base/testing_profile.h"
37 #include "components/content_settings/core/browser/host_content_settings_map.h" 37 #include "components/content_settings/core/browser/host_content_settings_map.h"
38 #include "components/infobars/core/confirm_infobar_delegate.h" 38 #include "components/infobars/core/confirm_infobar_delegate.h"
39 #include "components/infobars/core/infobar.h" 39 #include "components/infobars/core/infobar.h"
40 #include "content/public/browser/browser_thread.h" 40 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/navigation_details.h" 41 #include "content/public/browser/navigation_details.h"
42 #include "content/public/browser/navigation_entry.h" 42 #include "content/public/browser/navigation_entry.h"
43 #include "content/public/browser/notification_observer.h" 43 #include "content/public/browser/notification_observer.h"
44 #include "content/public/browser/notification_registrar.h" 44 #include "content/public/browser/notification_registrar.h"
45 #include "content/public/browser/notification_service.h" 45 #include "content/public/browser/notification_service.h"
46 #include "content/public/browser/render_frame_host.h" 46 #include "content/public/browser/render_frame_host.h"
47 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
48 #include "content/public/test/mock_render_process_host.h" 48 #include "content/public/test/mock_render_process_host.h"
49 #include "content/public/test/test_renderer_host.h" 49 #include "content/public/test/test_renderer_host.h"
50 #include "content/public/test/test_utils.h" 50 #include "content/public/test/test_utils.h"
51 #include "content/public/test/web_contents_tester.h" 51 #include "content/public/test/web_contents_tester.h"
52 #include "extensions/features/features.h" 52 #include "extensions/features/features.h"
53 #include "testing/gtest/include/gtest/gtest.h" 53 #include "testing/gtest/include/gtest/gtest.h"
54 54
55 #if defined(OS_ANDROID) 55 #if defined(OS_ANDROID)
56 #include "chrome/browser/android/mock_location_settings.h" 56 #include "chrome/browser/android/mock_location_settings.h"
57 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " 57 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h "
58 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 58 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
59 #include "chrome/common/chrome_features.h" 59 #include "components/location/android/location_settings_dialog_outcome.h"
60 #include "components/prefs/pref_service.h" 60 #include "components/prefs/pref_service.h"
61 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h" 61 #include "third_party/WebKit/public/platform/modules/permissions/permission_stat us.mojom.h"
62 #else 62 #else
63 #include "chrome/browser/permissions/permission_request_manager.h" 63 #include "chrome/browser/permissions/permission_request_manager.h"
64 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h" 64 #include "chrome/browser/ui/website_settings/mock_permission_prompt_factory.h"
65 #endif 65 #endif
66 66
67 #if BUILDFLAG(ENABLE_EXTENSIONS) 67 #if BUILDFLAG(ENABLE_EXTENSIONS)
68 #include "extensions/browser/view_type_utils.h" 68 #include "extensions/browser/view_type_utils.h"
69 #endif 69 #endif
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 TabSpecificContentSettings::CreateForWebContents(web_contents()); 310 TabSpecificContentSettings::CreateForWebContents(web_contents());
311 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( 311 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>(
312 PermissionManager::Get(profile())->GetPermissionContext( 312 PermissionManager::Get(profile())->GetPermissionContext(
313 CONTENT_SETTINGS_TYPE_GEOLOCATION)); 313 CONTENT_SETTINGS_TYPE_GEOLOCATION));
314 #if defined(OS_ANDROID) 314 #if defined(OS_ANDROID)
315 static_cast<GeolocationPermissionContextAndroid*>( 315 static_cast<GeolocationPermissionContextAndroid*>(
316 geolocation_permission_context_) 316 geolocation_permission_context_)
317 ->SetLocationSettingsForTesting( 317 ->SetLocationSettingsForTesting(
318 std::unique_ptr<LocationSettings>(new MockLocationSettings())); 318 std::unique_ptr<LocationSettings>(new MockLocationSettings()));
319 MockLocationSettings::SetLocationStatus(true, true); 319 MockLocationSettings::SetLocationStatus(true, true);
320 MockLocationSettings::SetCanPromptForAndroidPermission(true);
320 #else 321 #else
321 SetupRequestManager(web_contents()); 322 SetupRequestManager(web_contents());
322 #endif 323 #endif
323 } 324 }
324 325
325 void GeolocationPermissionContextTests::TearDown() { 326 void GeolocationPermissionContextTests::TearDown() {
326 #if !defined(OS_ANDROID) 327 #if !defined(OS_ANDROID)
327 mock_permission_prompt_factories_.clear(); 328 mock_permission_prompt_factories_.clear();
328 #endif 329 #endif
329 extra_tabs_.clear(); 330 extra_tabs_.clear();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 infobar_delegate->Cancel(); 469 infobar_delegate->Cancel();
469 infobar_service()->RemoveInfoBar(infobar); 470 infobar_service()->RemoveInfoBar(infobar);
470 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 471 EXPECT_EQ(1U, closed_infobar_tracker_.size());
471 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 472 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
472 } 473 }
473 474
474 // Infobar-only tests; Android doesn't support permission bubbles. 475 // Infobar-only tests; Android doesn't support permission bubbles.
475 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 476 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
476 GURL requesting_frame("https://www.example.com/geolocation"); 477 GURL requesting_frame("https://www.example.com/geolocation");
477 NavigateAndCommit(requesting_frame); 478 NavigateAndCommit(requesting_frame);
478 MockLocationSettings::SetLocationStatus(true, true); 479 MockLocationSettings::SetLocationStatus(true /* android */,
480 true /* system */);
479 EXPECT_EQ(0U, infobar_service()->infobar_count()); 481 EXPECT_EQ(0U, infobar_service()->infobar_count());
480 RequestGeolocationPermission( 482 RequestGeolocationPermission(
481 web_contents(), RequestID(0), requesting_frame, true); 483 web_contents(), RequestID(0), requesting_frame, true);
482 EXPECT_EQ(1U, infobar_service()->infobar_count()); 484 EXPECT_EQ(1U, infobar_service()->infobar_count());
483 ConfirmInfoBarDelegate* infobar_delegate_0 = 485 ConfirmInfoBarDelegate* infobar_delegate_0 =
484 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 486 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
485 ASSERT_TRUE(infobar_delegate_0); 487 ASSERT_TRUE(infobar_delegate_0);
486 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 488 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
487 ConfirmInfoBarDelegate::BUTTON_OK); 489 ConfirmInfoBarDelegate::BUTTON_OK);
488 490
489 Reload(); 491 Reload();
490 MockLocationSettings::SetLocationStatus(true, false); 492 MockLocationSettings::SetLocationStatus(false /* android */,
493 true /* system */);
494 MockLocationSettings::SetCanPromptForAndroidPermission(false);
491 EXPECT_EQ(0U, infobar_service()->infobar_count()); 495 EXPECT_EQ(0U, infobar_service()->infobar_count());
492 RequestGeolocationPermission( 496 RequestGeolocationPermission(
493 web_contents(), RequestID(0), requesting_frame, true); 497 web_contents(), RequestID(0), requesting_frame, true);
494 EXPECT_EQ(0U, infobar_service()->infobar_count()); 498 EXPECT_EQ(0U, infobar_service()->infobar_count());
495 } 499 }
496 500
497 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 501 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) {
498 GURL requesting_frame("https://www.example.com/geolocation"); 502 GURL requesting_frame("https://www.example.com/geolocation");
499 NavigateAndCommit(requesting_frame); 503 NavigateAndCommit(requesting_frame);
500 MockLocationSettings::SetLocationStatus(true, true); 504 MockLocationSettings::SetLocationStatus(false /* android */,
505 true /* system */);
501 EXPECT_EQ(0U, infobar_service()->infobar_count()); 506 EXPECT_EQ(0U, infobar_service()->infobar_count());
502 RequestGeolocationPermission( 507 RequestGeolocationPermission(
503 web_contents(), RequestID(0), requesting_frame, true); 508 web_contents(), RequestID(0), requesting_frame, true);
504 EXPECT_EQ(1U, infobar_service()->infobar_count()); 509 EXPECT_EQ(1U, infobar_service()->infobar_count());
505 ConfirmInfoBarDelegate* infobar_delegate = 510 ConfirmInfoBarDelegate* infobar_delegate =
506 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 511 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
507 ASSERT_TRUE(infobar_delegate); 512 ASSERT_TRUE(infobar_delegate);
508 infobar_delegate->Accept(); 513 infobar_delegate->Accept();
509 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 514 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
510 CheckPermissionMessageSent(0, true); 515 CheckPermissionMessageSent(0, true);
511 } 516 }
512 517
513 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 518 TEST_F(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) {
514 GURL requesting_frame("https://www.example.com/geolocation"); 519 GURL requesting_frame("https://www.example.com/geolocation");
515 NavigateAndCommit(requesting_frame); 520 NavigateAndCommit(requesting_frame);
516 MockLocationSettings::SetLocationStatus(true, false); 521 MockLocationSettings::SetLocationStatus(false /* android */,
522 true /* system */);
523 MockLocationSettings::SetCanPromptForAndroidPermission(false);
524 EXPECT_EQ(0U, infobar_service()->infobar_count());
525 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
526 true);
527 EXPECT_EQ(0U, infobar_service()->infobar_count());
528 }
529
530 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) {
531 base::test::ScopedFeatureList scoped_feature_list;
532 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
533
534 GURL requesting_frame("https://www.example.com/geolocation");
535 NavigateAndCommit(requesting_frame);
536 MockLocationSettings::SetLocationStatus(true /* android */,
537 false /* system */);
517 EXPECT_EQ(0U, infobar_service()->infobar_count()); 538 EXPECT_EQ(0U, infobar_service()->infobar_count());
518 RequestGeolocationPermission( 539 RequestGeolocationPermission(
519 web_contents(), RequestID(0), requesting_frame, true); 540 web_contents(), RequestID(0), requesting_frame, true);
520 EXPECT_EQ(0U, infobar_service()->infobar_count()); 541 EXPECT_EQ(0U, infobar_service()->infobar_count());
542 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog());
543 }
544
545 TEST_F(GeolocationPermissionContextTests, SystemLocationOnNoLSD) {
546 base::test::ScopedFeatureList scoped_feature_list;
547 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
548
549 GURL requesting_frame("https://www.example.com/geolocation");
550 NavigateAndCommit(requesting_frame);
551 EXPECT_EQ(0U, infobar_service()->infobar_count());
552 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
553 true);
554 EXPECT_EQ(1U, infobar_service()->infobar_count());
555 ConfirmInfoBarDelegate* infobar_delegate =
556 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
557 ASSERT_TRUE(infobar_delegate);
558 infobar_delegate->Accept();
559 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
560 CheckPermissionMessageSent(0, true);
561 EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog());
562 }
563
564 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) {
565 base::test::ScopedFeatureList scoped_feature_list;
566 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
567
568 GURL requesting_frame("https://www.example.com/geolocation");
569 NavigateAndCommit(requesting_frame);
570 MockLocationSettings::SetLocationStatus(true /* android */,
571 false /* system */);
572 MockLocationSettings::SetLocationSettingsDialogStatus(true, GRANTED);
573 EXPECT_EQ(0U, infobar_service()->infobar_count());
574 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
575 true);
576 EXPECT_EQ(1U, infobar_service()->infobar_count());
577 ConfirmInfoBarDelegate* infobar_delegate =
578 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
579 ASSERT_TRUE(infobar_delegate);
580 infobar_delegate->Accept();
581 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
582 CheckPermissionMessageSent(0, true);
583 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
584 }
585
586 TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) {
587 base::test::ScopedFeatureList scoped_feature_list;
588 scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt);
589
590 GURL requesting_frame("https://www.example.com/geolocation");
591 NavigateAndCommit(requesting_frame);
592 MockLocationSettings::SetLocationStatus(true /* android */,
593 false /* system */);
594 MockLocationSettings::SetLocationSettingsDialogStatus(true, DENIED);
595 EXPECT_EQ(0U, infobar_service()->infobar_count());
596 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
597 true);
598 EXPECT_EQ(1U, infobar_service()->infobar_count());
599 ConfirmInfoBarDelegate* infobar_delegate =
600 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
601 ASSERT_TRUE(infobar_delegate);
602 infobar_delegate->Accept();
603 CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK);
604 CheckPermissionMessageSent(0, false);
605 EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog());
521 } 606 }
522 #endif 607 #endif
523 608
524 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 609 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
525 GURL requesting_frame_0("https://www.example.com/geolocation"); 610 GURL requesting_frame_0("https://www.example.com/geolocation");
526 GURL requesting_frame_1("https://www.example-2.com/geolocation"); 611 GURL requesting_frame_1("https://www.example-2.com/geolocation");
527 EXPECT_EQ( 612 EXPECT_EQ(
528 CONTENT_SETTING_ASK, 613 CONTENT_SETTING_ASK,
529 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); 614 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1));
530 EXPECT_EQ( 615 EXPECT_EQ(
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 1005
921 // Changing the setting to BLOCK should flow through to incognito. 1006 // Changing the setting to BLOCK should flow through to incognito.
922 geo_service->SetDSEGeolocationSetting(false); 1007 geo_service->SetDSEGeolocationSetting(false);
923 ASSERT_EQ(CONTENT_SETTING_BLOCK, 1008 ASSERT_EQ(CONTENT_SETTING_BLOCK,
924 PermissionManager::Get(otr_profile) 1009 PermissionManager::Get(otr_profile)
925 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, 1010 ->GetPermissionStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION,
926 requesting_frame, requesting_frame) 1011 requesting_frame, requesting_frame)
927 .content_setting); 1012 .content_setting);
928 } 1013 }
929 #endif // defined(OS_ANDROID) 1014 #endif // defined(OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698