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

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

Issue 2110343002: Reintroduce plumbing for user gesture into permission system. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nits Created 4 years, 5 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 PermissionRequestID RequestIDForTab(int tab, int request_id); 129 PermissionRequestID RequestIDForTab(int tab, int request_id);
130 InfoBarService* infobar_service() { 130 InfoBarService* infobar_service() {
131 return InfoBarService::FromWebContents(web_contents()); 131 return InfoBarService::FromWebContents(web_contents());
132 } 132 }
133 InfoBarService* infobar_service_for_tab(int tab) { 133 InfoBarService* infobar_service_for_tab(int tab) {
134 return InfoBarService::FromWebContents(extra_tabs_[tab].get()); 134 return InfoBarService::FromWebContents(extra_tabs_[tab].get());
135 } 135 }
136 136
137 void RequestGeolocationPermission(content::WebContents* web_contents, 137 void RequestGeolocationPermission(content::WebContents* web_contents,
138 const PermissionRequestID& id, 138 const PermissionRequestID& id,
139 const GURL& requesting_frame); 139 const GURL& requesting_frame,
140 bool user_gesture);
140 141
141 void PermissionResponse(const PermissionRequestID& id, 142 void PermissionResponse(const PermissionRequestID& id,
142 ContentSetting content_setting); 143 ContentSetting content_setting);
143 void CheckPermissionMessageSent(int request_id, bool allowed); 144 void CheckPermissionMessageSent(int request_id, bool allowed);
144 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); 145 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed);
145 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 146 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
146 int request_id, 147 int request_id,
147 bool allowed); 148 bool allowed);
148 void AddNewTab(const GURL& url); 149 void AddNewTab(const GURL& url);
149 void CheckTabContentsState(const GURL& requesting_frame, 150 void CheckTabContentsState(const GURL& requesting_frame,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int request_id) { 190 int request_id) {
190 return PermissionRequestID( 191 return PermissionRequestID(
191 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), 192 extra_tabs_[tab]->GetRenderProcessHost()->GetID(),
192 extra_tabs_[tab]->GetMainFrame()->GetRoutingID(), 193 extra_tabs_[tab]->GetMainFrame()->GetRoutingID(),
193 request_id); 194 request_id);
194 } 195 }
195 196
196 void GeolocationPermissionContextTests::RequestGeolocationPermission( 197 void GeolocationPermissionContextTests::RequestGeolocationPermission(
197 content::WebContents* web_contents, 198 content::WebContents* web_contents,
198 const PermissionRequestID& id, 199 const PermissionRequestID& id,
199 const GURL& requesting_frame) { 200 const GURL& requesting_frame,
201 bool user_gesture) {
200 geolocation_permission_context_->RequestPermission( 202 geolocation_permission_context_->RequestPermission(
201 web_contents, id, requesting_frame, 203 web_contents, id, requesting_frame, user_gesture,
202 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, 204 base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
203 base::Unretained(this), id)); 205 base::Unretained(this), id));
204 content::RunAllBlockingPoolTasksUntilIdle(); 206 content::RunAllBlockingPoolTasksUntilIdle();
205 } 207 }
206 208
207 void GeolocationPermissionContextTests::PermissionResponse( 209 void GeolocationPermissionContextTests::PermissionResponse(
208 const PermissionRequestID& id, 210 const PermissionRequestID& id,
209 ContentSetting content_setting) { 211 ContentSetting content_setting) {
210 responses_[id.render_process_id()] = 212 responses_[id.render_process_id()] =
211 std::make_pair(id.request_id(), content_setting == CONTENT_SETTING_ALLOW); 213 std::make_pair(id.request_id(), content_setting == CONTENT_SETTING_ALLOW);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 405 }
404 406
405 // Tests ---------------------------------------------------------------------- 407 // Tests ----------------------------------------------------------------------
406 408
407 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { 409 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) {
408 GURL requesting_frame("https://www.example.com/geolocation"); 410 GURL requesting_frame("https://www.example.com/geolocation");
409 NavigateAndCommit(requesting_frame); 411 NavigateAndCommit(requesting_frame);
410 BubbleManagerDocumentLoadCompleted(); 412 BubbleManagerDocumentLoadCompleted();
411 413
412 EXPECT_EQ(0U, GetNumberOfPrompts()); 414 EXPECT_EQ(0U, GetNumberOfPrompts());
413 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 415 RequestGeolocationPermission(
416 web_contents(), RequestID(0), requesting_frame, true);
414 ASSERT_EQ(1U, GetNumberOfPrompts()); 417 ASSERT_EQ(1U, GetNumberOfPrompts());
415 } 418 }
416 419
417 TEST_F(GeolocationPermissionContextTests, 420 TEST_F(GeolocationPermissionContextTests,
418 SinglePermissionBubbleFailsOnInsecureOrigin) { 421 SinglePermissionBubbleFailsOnInsecureOrigin) {
419 GURL requesting_frame("http://www.example.com/geolocation"); 422 GURL requesting_frame("http://www.example.com/geolocation");
420 NavigateAndCommit(requesting_frame); 423 NavigateAndCommit(requesting_frame);
421 BubbleManagerDocumentLoadCompleted(); 424 BubbleManagerDocumentLoadCompleted();
422 425
423 EXPECT_EQ(0U, GetNumberOfPrompts()); 426 EXPECT_EQ(0U, GetNumberOfPrompts());
424 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 427 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame,
428 true);
425 ASSERT_EQ(0U, GetNumberOfPrompts()); 429 ASSERT_EQ(0U, GetNumberOfPrompts());
426 } 430 }
427 431
428 #if BUILDFLAG(ANDROID_JAVA_UI) 432 #if BUILDFLAG(ANDROID_JAVA_UI)
429 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { 433 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) {
430 GURL requesting_frame("https://www.example.com/geolocation"); 434 GURL requesting_frame("https://www.example.com/geolocation");
431 NavigateAndCommit(requesting_frame); 435 NavigateAndCommit(requesting_frame);
432 EXPECT_EQ(0U, infobar_service()->infobar_count()); 436 EXPECT_EQ(0U, infobar_service()->infobar_count());
433 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 437 RequestGeolocationPermission(
438 web_contents(), RequestID(0), requesting_frame, true);
434 ASSERT_EQ(1U, infobar_service()->infobar_count()); 439 ASSERT_EQ(1U, infobar_service()->infobar_count());
435 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 440 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
436 ConfirmInfoBarDelegate* infobar_delegate = 441 ConfirmInfoBarDelegate* infobar_delegate =
437 infobar->delegate()->AsConfirmInfoBarDelegate(); 442 infobar->delegate()->AsConfirmInfoBarDelegate();
438 ASSERT_TRUE(infobar_delegate); 443 ASSERT_TRUE(infobar_delegate);
439 infobar_delegate->Cancel(); 444 infobar_delegate->Cancel();
440 infobar_service()->RemoveInfoBar(infobar); 445 infobar_service()->RemoveInfoBar(infobar);
441 EXPECT_EQ(1U, closed_infobar_tracker_.size()); 446 EXPECT_EQ(1U, closed_infobar_tracker_.size());
442 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); 447 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar));
443 } 448 }
444 449
445 // Infobar-only tests; Android doesn't support permission bubbles. 450 // Infobar-only tests; Android doesn't support permission bubbles.
446 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { 451 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) {
447 GURL requesting_frame("https://www.example.com/geolocation"); 452 GURL requesting_frame("https://www.example.com/geolocation");
448 NavigateAndCommit(requesting_frame); 453 NavigateAndCommit(requesting_frame);
449 MockLocationSettings::SetLocationStatus(true, true); 454 MockLocationSettings::SetLocationStatus(true, true);
450 EXPECT_EQ(0U, infobar_service()->infobar_count()); 455 EXPECT_EQ(0U, infobar_service()->infobar_count());
451 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 456 RequestGeolocationPermission(
457 web_contents(), RequestID(0), requesting_frame, true);
452 EXPECT_EQ(1U, infobar_service()->infobar_count()); 458 EXPECT_EQ(1U, infobar_service()->infobar_count());
453 ConfirmInfoBarDelegate* infobar_delegate_0 = 459 ConfirmInfoBarDelegate* infobar_delegate_0 =
454 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 460 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
455 ASSERT_TRUE(infobar_delegate_0); 461 ASSERT_TRUE(infobar_delegate_0);
456 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( 462 base::string16 text_0 = infobar_delegate_0->GetButtonLabel(
457 ConfirmInfoBarDelegate::BUTTON_OK); 463 ConfirmInfoBarDelegate::BUTTON_OK);
458 464
459 Reload(); 465 Reload();
460 MockLocationSettings::SetLocationStatus(true, false); 466 MockLocationSettings::SetLocationStatus(true, false);
461 EXPECT_EQ(0U, infobar_service()->infobar_count()); 467 EXPECT_EQ(0U, infobar_service()->infobar_count());
462 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 468 RequestGeolocationPermission(
469 web_contents(), RequestID(0), requesting_frame, true);
463 EXPECT_EQ(0U, infobar_service()->infobar_count()); 470 EXPECT_EQ(0U, infobar_service()->infobar_count());
464 } 471 }
465 472
466 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { 473 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) {
467 GURL requesting_frame("https://www.example.com/geolocation"); 474 GURL requesting_frame("https://www.example.com/geolocation");
468 NavigateAndCommit(requesting_frame); 475 NavigateAndCommit(requesting_frame);
469 MockLocationSettings::SetLocationStatus(true, true); 476 MockLocationSettings::SetLocationStatus(true, true);
470 EXPECT_EQ(0U, infobar_service()->infobar_count()); 477 EXPECT_EQ(0U, infobar_service()->infobar_count());
471 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 478 RequestGeolocationPermission(
479 web_contents(), RequestID(0), requesting_frame, true);
472 EXPECT_EQ(1U, infobar_service()->infobar_count()); 480 EXPECT_EQ(1U, infobar_service()->infobar_count());
473 ConfirmInfoBarDelegate* infobar_delegate = 481 ConfirmInfoBarDelegate* infobar_delegate =
474 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 482 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate();
475 ASSERT_TRUE(infobar_delegate); 483 ASSERT_TRUE(infobar_delegate);
476 infobar_delegate->Accept(); 484 infobar_delegate->Accept();
477 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 485 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
478 CheckPermissionMessageSent(0, true); 486 CheckPermissionMessageSent(0, true);
479 } 487 }
480 488
481 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { 489 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) {
482 GURL requesting_frame("https://www.example.com/geolocation"); 490 GURL requesting_frame("https://www.example.com/geolocation");
483 NavigateAndCommit(requesting_frame); 491 NavigateAndCommit(requesting_frame);
484 MockLocationSettings::SetLocationStatus(true, false); 492 MockLocationSettings::SetLocationStatus(true, false);
485 EXPECT_EQ(0U, infobar_service()->infobar_count()); 493 EXPECT_EQ(0U, infobar_service()->infobar_count());
486 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 494 RequestGeolocationPermission(
495 web_contents(), RequestID(0), requesting_frame, true);
487 EXPECT_EQ(0U, infobar_service()->infobar_count()); 496 EXPECT_EQ(0U, infobar_service()->infobar_count());
488 } 497 }
489 #endif 498 #endif
490 499
491 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 500 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
492 GURL requesting_frame_0("https://www.example.com/geolocation"); 501 GURL requesting_frame_0("https://www.example.com/geolocation");
493 GURL requesting_frame_1("https://www.example-2.com/geolocation"); 502 GURL requesting_frame_1("https://www.example-2.com/geolocation");
494 EXPECT_EQ( 503 EXPECT_EQ(
495 CONTENT_SETTING_ASK, 504 CONTENT_SETTING_ASK,
496 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); 505 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1));
497 EXPECT_EQ( 506 EXPECT_EQ(
498 CONTENT_SETTING_ASK, 507 CONTENT_SETTING_ASK,
499 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1)); 508 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1));
500 509
501 NavigateAndCommit(requesting_frame_0); 510 NavigateAndCommit(requesting_frame_0);
502 BubbleManagerDocumentLoadCompleted(); 511 BubbleManagerDocumentLoadCompleted();
503 512
504 // Check that no permission requests have happened yet. 513 // Check that no permission requests have happened yet.
505 EXPECT_EQ(0U, GetNumberOfPrompts()); 514 EXPECT_EQ(0U, GetNumberOfPrompts());
506 515
507 // Request permission for two frames. 516 // Request permission for two frames.
508 RequestGeolocationPermission( 517 RequestGeolocationPermission(
509 web_contents(), RequestID(0), requesting_frame_0); 518 web_contents(), RequestID(0), requesting_frame_0, true);
510 RequestGeolocationPermission( 519 RequestGeolocationPermission(
511 web_contents(), RequestID(1), requesting_frame_1); 520 web_contents(), RequestID(1), requesting_frame_1, true);
512 // Ensure only one infobar is created. 521 // Ensure only one infobar is created.
513 ASSERT_EQ(1U, GetNumberOfPrompts()); 522 ASSERT_EQ(1U, GetNumberOfPrompts());
514 base::string16 text_0 = GetPromptText(); 523 base::string16 text_0 = GetPromptText();
515 524
516 // Accept the first frame. 525 // Accept the first frame.
517 AcceptPrompt(); 526 AcceptPrompt();
518 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 527 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
519 CheckPermissionMessageSent(0, true); 528 CheckPermissionMessageSent(0, true);
520 529
521 #if BUILDFLAG(ANDROID_JAVA_UI) 530 #if BUILDFLAG(ANDROID_JAVA_UI)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { 566 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) {
558 GURL url_a("https://www.example.com/geolocation#a"); 567 GURL url_a("https://www.example.com/geolocation#a");
559 GURL url_b("https://www.example.com/geolocation#b"); 568 GURL url_b("https://www.example.com/geolocation#b");
560 569
561 // Navigate to the first url. 570 // Navigate to the first url.
562 NavigateAndCommit(url_a); 571 NavigateAndCommit(url_a);
563 BubbleManagerDocumentLoadCompleted(); 572 BubbleManagerDocumentLoadCompleted();
564 573
565 // Check permission is requested. 574 // Check permission is requested.
566 ASSERT_EQ(0U, GetNumberOfPrompts()); 575 ASSERT_EQ(0U, GetNumberOfPrompts());
567 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); 576 #if BUILDFLAG(ANDROID_JAVA_UI)
577 const bool user_gesture = false;
578 #else
579 const bool user_gesture = true;
580 #endif
581 RequestGeolocationPermission(web_contents(), RequestID(0), url_a,
582 user_gesture);
568 ASSERT_EQ(1U, GetNumberOfPrompts()); 583 ASSERT_EQ(1U, GetNumberOfPrompts());
569 584
570 // Change the hash, we'll still be on the same page. 585 // Change the hash, we'll still be on the same page.
571 NavigateAndCommit(url_b); 586 NavigateAndCommit(url_b);
572 BubbleManagerDocumentLoadCompleted(); 587 BubbleManagerDocumentLoadCompleted();
573 588
574 // Accept. 589 // Accept.
575 AcceptPrompt(); 590 AcceptPrompt();
576 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); 591 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW);
577 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); 592 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW);
(...skipping 15 matching lines...) Expand all
593 #else 608 #else
594 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme 609 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme
595 #endif 610 #endif
596 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { 611 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) {
597 GURL requesting_frame("file://example/geolocation.html"); 612 GURL requesting_frame("file://example/geolocation.html");
598 NavigateAndCommit(requesting_frame); 613 NavigateAndCommit(requesting_frame);
599 BubbleManagerDocumentLoadCompleted(); 614 BubbleManagerDocumentLoadCompleted();
600 615
601 // Check permission is requested. 616 // Check permission is requested.
602 ASSERT_EQ(0U, GetNumberOfPrompts()); 617 ASSERT_EQ(0U, GetNumberOfPrompts());
603 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 618 RequestGeolocationPermission(
619 web_contents(), RequestID(0), requesting_frame, true);
604 EXPECT_EQ(1U, GetNumberOfPrompts()); 620 EXPECT_EQ(1U, GetNumberOfPrompts());
605 621
606 // Accept the frame. 622 // Accept the frame.
607 AcceptPrompt(); 623 AcceptPrompt();
608 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 624 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
609 CheckPermissionMessageSent(0, true); 625 CheckPermissionMessageSent(0, true);
610 626
611 // Make sure the setting is not stored. 627 // Make sure the setting is not stored.
612 EXPECT_EQ( 628 EXPECT_EQ(
613 CONTENT_SETTING_ASK, 629 CONTENT_SETTING_ASK,
614 GetGeolocationContentSetting(requesting_frame, requesting_frame)); 630 GetGeolocationContentSetting(requesting_frame, requesting_frame));
615 } 631 }
616 632
617 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { 633 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) {
618 GURL frame_0("https://www.example.com/geolocation"); 634 GURL frame_0("https://www.example.com/geolocation");
619 GURL frame_1("https://www.example-2.com/geolocation"); 635 GURL frame_1("https://www.example-2.com/geolocation");
620 EXPECT_EQ( 636 EXPECT_EQ(
621 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); 637 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0));
622 EXPECT_EQ( 638 EXPECT_EQ(
623 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0)); 639 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0));
624 640
625 NavigateAndCommit(frame_0); 641 NavigateAndCommit(frame_0);
626 BubbleManagerDocumentLoadCompleted(); 642 BubbleManagerDocumentLoadCompleted();
627 643
628 ASSERT_EQ(0U, GetNumberOfPrompts()); 644 ASSERT_EQ(0U, GetNumberOfPrompts());
629 645
630 // Request permission for two frames. 646 // Request permission for two frames.
631 RequestGeolocationPermission(web_contents(), RequestID(0), frame_0); 647 RequestGeolocationPermission(
632 RequestGeolocationPermission(web_contents(), RequestID(1), frame_1); 648 web_contents(), RequestID(0), frame_0, true);
649 RequestGeolocationPermission(
650 web_contents(), RequestID(1), frame_1, true);
633 651
634 // Get the first permission request text. 652 // Get the first permission request text.
635 ASSERT_EQ(1U, GetNumberOfPrompts()); 653 ASSERT_EQ(1U, GetNumberOfPrompts());
636 base::string16 text_0 = GetPromptText(); 654 base::string16 text_0 = GetPromptText();
637 ASSERT_FALSE(text_0.empty()); 655 ASSERT_FALSE(text_0.empty());
638 656
639 // Simulate the frame going away; the request should be removed. 657 // Simulate the frame going away; the request should be removed.
640 #if !BUILDFLAG(ANDROID_JAVA_UI) 658 #if !BUILDFLAG(ANDROID_JAVA_UI)
641 PermissionBubbleManager* manager = 659 PermissionBubbleManager* manager =
642 PermissionBubbleManager::FromWebContents(web_contents()); 660 PermissionBubbleManager::FromWebContents(web_contents());
(...skipping 21 matching lines...) Expand all
664 682
665 TEST_F(GeolocationPermissionContextTests, InvalidURL) { 683 TEST_F(GeolocationPermissionContextTests, InvalidURL) {
666 // Navigate to the first url. 684 // Navigate to the first url.
667 GURL invalid_embedder("about:blank"); 685 GURL invalid_embedder("about:blank");
668 GURL requesting_frame; 686 GURL requesting_frame;
669 NavigateAndCommit(invalid_embedder); 687 NavigateAndCommit(invalid_embedder);
670 BubbleManagerDocumentLoadCompleted(); 688 BubbleManagerDocumentLoadCompleted();
671 689
672 // Nothing should be displayed. 690 // Nothing should be displayed.
673 EXPECT_EQ(0U, GetNumberOfPrompts()); 691 EXPECT_EQ(0U, GetNumberOfPrompts());
674 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 692 RequestGeolocationPermission(
693 web_contents(), RequestID(0), requesting_frame, true);
675 EXPECT_EQ(0U, GetNumberOfPrompts()); 694 EXPECT_EQ(0U, GetNumberOfPrompts());
676 CheckPermissionMessageSent(0, false); 695 CheckPermissionMessageSent(0, false);
677 } 696 }
678 697
679 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { 698 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) {
680 GURL url_a("https://www.example.com/geolocation"); 699 GURL url_a("https://www.example.com/geolocation");
681 GURL url_b("https://www.example-2.com/geolocation"); 700 GURL url_b("https://www.example-2.com/geolocation");
682 NavigateAndCommit(url_a); // Tab A0 701 NavigateAndCommit(url_a); // Tab A0
683 AddNewTab(url_b); // Tab B (extra_tabs_[0]) 702 AddNewTab(url_b); // Tab B (extra_tabs_[0])
684 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) 703 AddNewTab(url_a); // Tab A1 (extra_tabs_[1])
685 BubbleManagerDocumentLoadCompleted(); 704 BubbleManagerDocumentLoadCompleted();
686 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get()); 705 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get());
687 BubbleManagerDocumentLoadCompleted(extra_tabs_[1].get()); 706 BubbleManagerDocumentLoadCompleted(extra_tabs_[1].get());
688 #if !BUILDFLAG(ANDROID_JAVA_UI) 707 #if !BUILDFLAG(ANDROID_JAVA_UI)
689 PermissionBubbleManager* manager_a0 = 708 PermissionBubbleManager* manager_a0 =
690 PermissionBubbleManager::FromWebContents(web_contents()); 709 PermissionBubbleManager::FromWebContents(web_contents());
691 PermissionBubbleManager* manager_b = 710 PermissionBubbleManager* manager_b =
692 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get()); 711 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get());
693 PermissionBubbleManager* manager_a1 = 712 PermissionBubbleManager* manager_a1 =
694 PermissionBubbleManager::FromWebContents(extra_tabs_[1].get()); 713 PermissionBubbleManager::FromWebContents(extra_tabs_[1].get());
695 #endif 714 #endif
696 715
697 // Request permission in all three tabs. 716 // Request permission in all three tabs.
698 RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
699 RequestGeolocationPermission( 717 RequestGeolocationPermission(
700 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b); 718 web_contents(), RequestID(0), url_a, true);
701 RequestGeolocationPermission( 719 RequestGeolocationPermission(
702 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a); 720 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true);
721 RequestGeolocationPermission(
722 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true);
703 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. 723 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0.
704 #if !BUILDFLAG(ANDROID_JAVA_UI) 724 #if !BUILDFLAG(ANDROID_JAVA_UI)
705 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); 725 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b));
706 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 726 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
707 #else 727 #else
708 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 728 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
709 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); 729 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count());
710 #endif 730 #endif
711 731
712 // Accept the permission in tab A0. 732 // Accept the permission in tab A0.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 BubbleManagerDocumentLoadCompleted(); 765 BubbleManagerDocumentLoadCompleted();
746 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get()); 766 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get());
747 PermissionBubbleManager* manager_a0 = 767 PermissionBubbleManager* manager_a0 =
748 PermissionBubbleManager::FromWebContents(web_contents()); 768 PermissionBubbleManager::FromWebContents(web_contents());
749 PermissionBubbleManager* manager_a1 = 769 PermissionBubbleManager* manager_a1 =
750 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get()); 770 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get());
751 #endif 771 #endif
752 772
753 // Request permission in both tabs; the extra tab will have two permission 773 // Request permission in both tabs; the extra tab will have two permission
754 // requests from two origins. 774 // requests from two origins.
755 RequestGeolocationPermission(web_contents(), RequestID(0), url_a);
756 RequestGeolocationPermission( 775 RequestGeolocationPermission(
757 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a); 776 web_contents(), RequestID(0), url_a, true);
758 RequestGeolocationPermission( 777 RequestGeolocationPermission(
759 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b); 778 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true);
779 RequestGeolocationPermission(
780 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true);
760 #if !BUILDFLAG(ANDROID_JAVA_UI) 781 #if !BUILDFLAG(ANDROID_JAVA_UI)
761 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0)); 782 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0));
762 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); 783 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1));
763 #else 784 #else
764 ASSERT_EQ(1U, infobar_service()->infobar_count()); 785 ASSERT_EQ(1U, infobar_service()->infobar_count());
765 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); 786 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count());
766 #endif 787 #endif
767 788
768 // Accept the first request in tab A1. 789 // Accept the first request in tab A1.
769 #if !BUILDFLAG(ANDROID_JAVA_UI) 790 #if !BUILDFLAG(ANDROID_JAVA_UI)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 839 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
819 EXPECT_EQ( 840 EXPECT_EQ(
820 CONTENT_SETTING_ASK, 841 CONTENT_SETTING_ASK,
821 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 842 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
822 843
823 NavigateAndCommit(requesting_frame_0); 844 NavigateAndCommit(requesting_frame_0);
824 BubbleManagerDocumentLoadCompleted(); 845 BubbleManagerDocumentLoadCompleted();
825 846
826 // Request permission for two frames. 847 // Request permission for two frames.
827 RequestGeolocationPermission( 848 RequestGeolocationPermission(
828 web_contents(), RequestID(0), requesting_frame_0); 849 web_contents(), RequestID(0), requesting_frame_0, false);
829 RequestGeolocationPermission( 850 RequestGeolocationPermission(
830 web_contents(), RequestID(1), requesting_frame_1); 851 web_contents(), RequestID(1), requesting_frame_1, false);
831 852
832 // Ensure only one prompt is created. 853 // Ensure only one prompt is created.
833 ASSERT_EQ(1U, GetNumberOfPrompts()); 854 ASSERT_EQ(1U, GetNumberOfPrompts());
834 855
835 // Delete the tab contents. 856 // Delete the tab contents.
836 #if BUILDFLAG(ANDROID_JAVA_UI) 857 #if BUILDFLAG(ANDROID_JAVA_UI)
837 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); 858 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
838 DeleteContents(); 859 DeleteContents();
839 ASSERT_EQ(1U, closed_infobar_tracker_.size()); 860 ASSERT_EQ(1U, closed_infobar_tracker_.size());
840 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); 861 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar));
(...skipping 20 matching lines...) Expand all
861 HostContentSettingsMap* map = 882 HostContentSettingsMap* map =
862 HostContentSettingsMapFactory::GetForProfile(profile()); 883 HostContentSettingsMapFactory::GetForProfile(profile());
863 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock)); 884 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock));
864 885
865 // The permission shouldn't have been used yet. 886 // The permission shouldn't have been used yet.
866 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 887 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
867 requesting_frame.GetOrigin(), 888 requesting_frame.GetOrigin(),
868 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 889 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
869 0); 890 0);
870 ASSERT_EQ(0U, GetNumberOfPrompts()); 891 ASSERT_EQ(0U, GetNumberOfPrompts());
871 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 892 RequestGeolocationPermission(
893 web_contents(), RequestID(0), requesting_frame, false);
872 ASSERT_EQ(1U, GetNumberOfPrompts()); 894 ASSERT_EQ(1U, GetNumberOfPrompts());
873 895
874 AcceptPrompt(); 896 AcceptPrompt();
875 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); 897 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
876 CheckPermissionMessageSent(0, true); 898 CheckPermissionMessageSent(0, true);
877 899
878 // Permission has been used at the starting time. 900 // Permission has been used at the starting time.
879 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 901 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
880 requesting_frame.GetOrigin(), 902 requesting_frame.GetOrigin(),
881 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 903 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
882 10); 904 10);
883 905
884 test_clock->Advance(base::TimeDelta::FromSeconds(3)); 906 test_clock->Advance(base::TimeDelta::FromSeconds(3));
885 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); 907 RequestGeolocationPermission(
908 web_contents(), RequestID(0), requesting_frame, false);
886 909
887 // Permission has been used three seconds later. 910 // Permission has been used three seconds later.
888 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 911 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
889 requesting_frame.GetOrigin(), 912 requesting_frame.GetOrigin(),
890 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 913 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
891 13); 914 13);
892 } 915 }
893 916
894 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { 917 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
895 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 918 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
(...skipping 17 matching lines...) Expand all
913 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 936 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
914 0); 937 0);
915 938
916 NavigateAndCommit(requesting_frame_0); 939 NavigateAndCommit(requesting_frame_0);
917 BubbleManagerDocumentLoadCompleted(); 940 BubbleManagerDocumentLoadCompleted();
918 941
919 EXPECT_EQ(0U, GetNumberOfPrompts()); 942 EXPECT_EQ(0U, GetNumberOfPrompts());
920 943
921 // Request permission for two frames. 944 // Request permission for two frames.
922 RequestGeolocationPermission( 945 RequestGeolocationPermission(
923 web_contents(), RequestID(0), requesting_frame_0); 946 web_contents(), RequestID(0), requesting_frame_0, false);
924 RequestGeolocationPermission( 947 RequestGeolocationPermission(
925 web_contents(), RequestID(1), requesting_frame_1); 948 web_contents(), RequestID(1), requesting_frame_1, false);
926 949
927 // Ensure only one infobar is created. 950 // Ensure only one infobar is created.
928 ASSERT_EQ(1U, GetNumberOfPrompts()); 951 ASSERT_EQ(1U, GetNumberOfPrompts());
929 952
930 // Accept the first frame. 953 // Accept the first frame.
931 AcceptPrompt(); 954 AcceptPrompt();
932 #if BUILDFLAG(ANDROID_JAVA_UI) 955 #if BUILDFLAG(ANDROID_JAVA_UI)
933 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); 956 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
934 #endif 957 #endif
935 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 958 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
(...skipping 27 matching lines...) Expand all
963 requesting_frame_0.GetOrigin(), 986 requesting_frame_0.GetOrigin(),
964 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 987 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
965 10); 988 10);
966 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 989 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
967 requesting_frame_0.GetOrigin(), 990 requesting_frame_0.GetOrigin(),
968 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 991 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
969 11); 992 11);
970 993
971 test_clock->Advance(base::TimeDelta::FromSeconds(2)); 994 test_clock->Advance(base::TimeDelta::FromSeconds(2));
972 RequestGeolocationPermission( 995 RequestGeolocationPermission(
973 web_contents(), RequestID(0), requesting_frame_0); 996 web_contents(), RequestID(0), requesting_frame_0, false);
974 997
975 // Verify that requesting permission in one frame doesn't update other where 998 // Verify that requesting permission in one frame doesn't update other where
976 // it is the embedder. 999 // it is the embedder.
977 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 1000 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
978 requesting_frame_0.GetOrigin(), 1001 requesting_frame_0.GetOrigin(),
979 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 1002 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
980 13); 1003 13);
981 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 1004 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
982 requesting_frame_0.GetOrigin(), 1005 requesting_frame_0.GetOrigin(),
983 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 1006 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
984 11); 1007 11);
985 } 1008 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698