OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 | 434 |
435 void GeolocationBrowserTest::TogglePersist(bool persist) { | 435 void GeolocationBrowserTest::TogglePersist(bool persist) { |
436 content::WebContents* web_contents = | 436 content::WebContents* web_contents = |
437 current_browser()->tab_strip_model()->GetActiveWebContents(); | 437 current_browser()->tab_strip_model()->GetActiveWebContents(); |
438 PermissionRequestManager::FromWebContents(web_contents) | 438 PermissionRequestManager::FromWebContents(web_contents) |
439 ->TogglePersist(persist); | 439 ->TogglePersist(persist); |
440 } | 440 } |
441 | 441 |
442 // Tests ---------------------------------------------------------------------- | 442 // Tests ---------------------------------------------------------------------- |
443 | 443 |
444 #if defined(OS_LINUX) | 444 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPrompt) { |
445 // http://crbug.com/527437 | |
446 #define MAYBE_DisplaysPrompt DISABLED_DisplaysPrompt | |
447 #else | |
448 #define MAYBE_DisplaysPrompt DisplaysPrompt | |
449 #endif | |
450 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_DisplaysPrompt) { | |
451 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 445 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
452 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 446 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
453 | 447 |
454 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 448 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
455 GetHostContentSettingsMap()->GetContentSetting( | 449 GetHostContentSettingsMap()->GetContentSetting( |
456 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 450 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
457 std::string())); | 451 std::string())); |
458 | 452 |
459 // Ensure a second request doesn't create a prompt in this tab. | 453 // Ensure a second request doesn't create a prompt in this tab. |
460 WatchPositionAndObservePermissionRequest(false); | 454 WatchPositionAndObservePermissionRequest(false); |
461 } | 455 } |
462 | 456 |
463 #if defined(OS_LINUX) | 457 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { |
464 // http://crbug.com/527437 | |
465 #define MAYBE_Geoposition DISABLED_Geoposition | |
466 #else | |
467 #define MAYBE_Geoposition Geoposition | |
468 #endif | |
469 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_Geoposition) { | |
470 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 458 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
471 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 459 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
472 ExpectPosition(fake_latitude(), fake_longitude()); | 460 ExpectPosition(fake_latitude(), fake_longitude()); |
473 } | 461 } |
474 | 462 |
475 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { | 463 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, ErrorOnPermissionDenied) { |
476 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 464 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
477 EXPECT_TRUE(WatchPositionAndDenyPermission()); | 465 EXPECT_TRUE(WatchPositionAndDenyPermission()); |
478 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 466 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
479 | 467 |
480 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 468 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
481 GetHostContentSettingsMap()->GetContentSetting( | 469 GetHostContentSettingsMap()->GetContentSetting( |
482 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 470 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
483 std::string())); | 471 std::string())); |
484 | 472 |
485 // Ensure a second request doesn't create a prompt in this tab. | 473 // Ensure a second request doesn't create a prompt in this tab. |
486 WatchPositionAndObservePermissionRequest(false); | 474 WatchPositionAndObservePermissionRequest(false); |
487 } | 475 } |
488 | 476 |
489 #if defined(OS_LINUX) | 477 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForSecondTab) { |
490 // http://crbug.com/527437 | |
491 #define MAYBE_NoPromptForSecondTab DISABLED_NoPromptForSecondTab | |
492 #else | |
493 #define MAYBE_NoPromptForSecondTab NoPromptForSecondTab | |
494 #endif | |
495 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForSecondTab) { | |
496 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 478 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
497 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 479 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
498 | 480 |
499 // Checks request is not needed in a second tab. | 481 // Checks request is not needed in a second tab. |
500 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 482 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
501 WatchPositionAndObservePermissionRequest(false); | 483 WatchPositionAndObservePermissionRequest(false); |
502 ExpectPosition(fake_latitude(), fake_longitude()); | 484 ExpectPosition(fake_latitude(), fake_longitude()); |
503 } | 485 } |
504 | 486 |
505 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { | 487 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
506 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 488 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
507 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 489 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
508 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 490 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
509 std::string(), CONTENT_SETTING_BLOCK); | 491 std::string(), CONTENT_SETTING_BLOCK); |
510 | 492 |
511 // Check that the request wasn't shown but we get an error for this origin. | 493 // Check that the request wasn't shown but we get an error for this origin. |
512 WatchPositionAndObservePermissionRequest(false); | 494 WatchPositionAndObservePermissionRequest(false); |
513 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 495 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
514 | 496 |
515 // Checks prompt will not be created a second tab. | 497 // Checks prompt will not be created a second tab. |
516 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); | 498 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_NEWTAB)); |
517 WatchPositionAndObservePermissionRequest(false); | 499 WatchPositionAndObservePermissionRequest(false); |
518 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); | 500 ExpectValueFromScript(GetErrorCodePermissionDenied(), "geoGetLastError()"); |
519 } | 501 } |
520 | 502 |
521 #if defined(OS_LINUX) | 503 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptForAllowedOrigin) { |
522 // http://crbug.com/527437 | |
523 #define MAYBE_NoPromptForAllowedOrigin DISABLED_NoPromptForAllowedOrigin | |
524 #else | |
525 #define MAYBE_NoPromptForAllowedOrigin NoPromptForAllowedOrigin | |
526 #endif | |
527 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptForAllowedOrigin) { | |
528 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 504 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
529 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 505 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
530 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 506 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
531 std::string(), CONTENT_SETTING_ALLOW); | 507 std::string(), CONTENT_SETTING_ALLOW); |
532 // The request is not shown, there is no error, and the position gets to the | 508 // The request is not shown, there is no error, and the position gets to the |
533 // script. | 509 // script. |
534 WatchPositionAndObservePermissionRequest(false); | 510 WatchPositionAndObservePermissionRequest(false); |
535 ExpectPosition(fake_latitude(), fake_longitude()); | 511 ExpectPosition(fake_latitude(), fake_longitude()); |
536 } | 512 } |
537 | 513 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 | 575 |
600 // Expect the block to be remembered at the blink layer, so a second request | 576 // Expect the block to be remembered at the blink layer, so a second request |
601 // on this page doesn't create a request. | 577 // on this page doesn't create a request. |
602 WatchPositionAndObservePermissionRequest(false); | 578 WatchPositionAndObservePermissionRequest(false); |
603 | 579 |
604 // Navigate and ensure that a prompt is shown when we request again. | 580 // Navigate and ensure that a prompt is shown when we request again. |
605 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 581 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
606 WatchPositionAndObservePermissionRequest(true); | 582 WatchPositionAndObservePermissionRequest(true); |
607 } | 583 } |
608 | 584 |
609 #if defined(OS_LINUX) | 585 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { |
610 // http://crbug.com/527437 | |
611 #define MAYBE_IFramesWithFreshPosition DISABLED_IFramesWithFreshPosition | |
612 #else | |
613 #define MAYBE_IFramesWithFreshPosition IFramesWithFreshPosition | |
614 #endif | |
615 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_IFramesWithFreshPosition) { | |
616 set_html_for_tests("/geolocation/two_iframes.html"); | 586 set_html_for_tests("/geolocation/two_iframes.html"); |
617 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 587 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
618 LoadIFrames(); | 588 LoadIFrames(); |
619 | 589 |
620 // Grant permission in the first frame, the position gets to the script. | 590 // Grant permission in the first frame, the position gets to the script. |
621 SetFrameForScriptExecution("iframe_0"); | 591 SetFrameForScriptExecution("iframe_0"); |
622 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 592 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
623 ExpectPosition(fake_latitude(), fake_longitude()); | 593 ExpectPosition(fake_latitude(), fake_longitude()); |
624 | 594 |
625 // In a second iframe from a different origin with a cached position the user | 595 // In a second iframe from a different origin with a cached position the user |
626 // is prompted. | 596 // is prompted. |
627 SetFrameForScriptExecution("iframe_1"); | 597 SetFrameForScriptExecution("iframe_1"); |
628 WatchPositionAndObservePermissionRequest(true); | 598 WatchPositionAndObservePermissionRequest(true); |
629 | 599 |
630 // Back to the first frame, enable navigation and refresh geoposition. | 600 // Back to the first frame, enable navigation and refresh geoposition. |
631 SetFrameForScriptExecution("iframe_0"); | 601 SetFrameForScriptExecution("iframe_0"); |
632 double fresh_position_latitude = 3.17; | 602 double fresh_position_latitude = 3.17; |
633 double fresh_position_longitude = 4.23; | 603 double fresh_position_longitude = 4.23; |
634 ASSERT_TRUE(SetPositionAndWaitUntilUpdated(fresh_position_latitude, | 604 ASSERT_TRUE(SetPositionAndWaitUntilUpdated(fresh_position_latitude, |
635 fresh_position_longitude)); | 605 fresh_position_longitude)); |
636 ExpectPosition(fresh_position_latitude, fresh_position_longitude); | 606 ExpectPosition(fresh_position_latitude, fresh_position_longitude); |
637 | 607 |
638 // When permission is granted to the second iframe the fresh position gets to | 608 // When permission is granted to the second iframe the fresh position gets to |
639 // the script. | 609 // the script. |
640 SetFrameForScriptExecution("iframe_1"); | 610 SetFrameForScriptExecution("iframe_1"); |
641 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 611 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
642 ExpectPosition(fresh_position_latitude, fresh_position_longitude); | 612 ExpectPosition(fresh_position_latitude, fresh_position_longitude); |
643 } | 613 } |
644 | 614 |
645 #if defined(OS_LINUX) | 615 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithCachedPosition) { |
646 // http://crbug.com/527437 | |
647 #define MAYBE_IFramesWithCachedPosition DISABLED_IFramesWithCachedPosition | |
648 #else | |
649 #define MAYBE_IFramesWithCachedPosition IFramesWithCachedPosition | |
650 #endif | |
651 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, | |
652 MAYBE_IFramesWithCachedPosition) { | |
653 set_html_for_tests("/geolocation/two_iframes.html"); | 616 set_html_for_tests("/geolocation/two_iframes.html"); |
654 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 617 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
655 LoadIFrames(); | 618 LoadIFrames(); |
656 | 619 |
657 // Grant permission in the first frame, the position gets to the script. | 620 // Grant permission in the first frame, the position gets to the script. |
658 SetFrameForScriptExecution("iframe_0"); | 621 SetFrameForScriptExecution("iframe_0"); |
659 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 622 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
660 ExpectPosition(fake_latitude(), fake_longitude()); | 623 ExpectPosition(fake_latitude(), fake_longitude()); |
661 | 624 |
662 // Refresh the position, but let's not yet create the watch on the second | 625 // Refresh the position, but let's not yet create the watch on the second |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 set_html_for_tests("/geolocation/invalid_request_url.html"); | 667 set_html_for_tests("/geolocation/invalid_request_url.html"); |
705 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 668 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
706 | 669 |
707 content::WebContents* original_tab = | 670 content::WebContents* original_tab = |
708 current_browser()->tab_strip_model()->GetActiveWebContents(); | 671 current_browser()->tab_strip_model()->GetActiveWebContents(); |
709 ExpectValueFromScript(GetErrorCodePermissionDenied(), | 672 ExpectValueFromScript(GetErrorCodePermissionDenied(), |
710 "requestGeolocationFromInvalidUrl()"); | 673 "requestGeolocationFromInvalidUrl()"); |
711 ExpectValueFromScriptForFrame("1", "isAlive()", original_tab->GetMainFrame()); | 674 ExpectValueFromScriptForFrame("1", "isAlive()", original_tab->GetMainFrame()); |
712 } | 675 } |
713 | 676 |
714 #if defined(OS_LINUX) | 677 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoPromptBeforeStart) { |
715 // http://crbug.com/527437 | |
716 #define MAYBE_NoPromptBeforeStart DISABLED_NoPromptBeforeStart | |
717 #else | |
718 #define MAYBE_NoPromptBeforeStart NoPromptBeforeStart | |
719 #endif | |
720 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_NoPromptBeforeStart) { | |
721 // See http://crbug.com/42789 | 678 // See http://crbug.com/42789 |
722 set_html_for_tests("/geolocation/two_iframes.html"); | 679 set_html_for_tests("/geolocation/two_iframes.html"); |
723 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 680 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
724 LoadIFrames(); | 681 LoadIFrames(); |
725 | 682 |
726 // In the second iframe, access the navigator.geolocation object, but don't | 683 // In the second iframe, access the navigator.geolocation object, but don't |
727 // call any methods yet so it won't request permission yet. | 684 // call any methods yet so it won't request permission yet. |
728 SetFrameForScriptExecution("iframe_1"); | 685 SetFrameForScriptExecution("iframe_1"); |
729 ExpectValueFromScript("object", "geoAccessNavigatorGeolocation()"); | 686 ExpectValueFromScript("object", "geoAccessNavigatorGeolocation()"); |
730 | 687 |
731 // In the first iframe, call watchPosition, grant permission, and verify that | 688 // In the first iframe, call watchPosition, grant permission, and verify that |
732 // the position gets to the script. | 689 // the position gets to the script. |
733 SetFrameForScriptExecution("iframe_0"); | 690 SetFrameForScriptExecution("iframe_0"); |
734 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 691 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
735 ExpectPosition(fake_latitude(), fake_longitude()); | 692 ExpectPosition(fake_latitude(), fake_longitude()); |
736 | 693 |
737 // Back to the second frame. The user is prompted now (it has a different | 694 // Back to the second frame. The user is prompted now (it has a different |
738 // origin). When permission is granted the position gets to the script. | 695 // origin). When permission is granted the position gets to the script. |
739 SetFrameForScriptExecution("iframe_1"); | 696 SetFrameForScriptExecution("iframe_1"); |
740 ASSERT_TRUE(WatchPositionAndGrantPermission()); | 697 ASSERT_TRUE(WatchPositionAndGrantPermission()); |
741 ExpectPosition(fake_latitude(), fake_longitude()); | 698 ExpectPosition(fake_latitude(), fake_longitude()); |
742 } | 699 } |
743 | 700 |
744 #if defined(OS_LINUX) | 701 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
745 // http://crbug.com/527437 | |
746 #define MAYBE_TwoWatchesInOneFrame DISABLED_TwoWatchesInOneFrame | |
747 #else | |
748 #define MAYBE_TwoWatchesInOneFrame TwoWatchesInOneFrame | |
749 #endif | |
750 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_TwoWatchesInOneFrame) { | |
751 set_html_for_tests("/geolocation/two_watches.html"); | 702 set_html_for_tests("/geolocation/two_watches.html"); |
752 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 703 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
753 | 704 |
754 // Tell the script what to expect as the final coordinates. | 705 // Tell the script what to expect as the final coordinates. |
755 double final_position_latitude = 3.17; | 706 double final_position_latitude = 3.17; |
756 double final_position_longitude = 4.23; | 707 double final_position_longitude = 4.23; |
757 std::string script = | 708 std::string script = |
758 base::StringPrintf("geoSetFinalPosition(%f, %f)", final_position_latitude, | 709 base::StringPrintf("geoSetFinalPosition(%f, %f)", final_position_latitude, |
759 final_position_longitude); | 710 final_position_longitude); |
760 ExpectValueFromScript("ok", script); | 711 ExpectValueFromScript("ok", script); |
(...skipping 27 matching lines...) Expand all Loading... |
788 WatchPositionAndObservePermissionRequest(true); | 739 WatchPositionAndObservePermissionRequest(true); |
789 | 740 |
790 // TODO(mvanouwerkerk): Can't close a window you did not open. Maybe this was | 741 // TODO(mvanouwerkerk): Can't close a window you did not open. Maybe this was |
791 // valid when the test was written, but now it just prints "Scripts may close | 742 // valid when the test was written, but now it just prints "Scripts may close |
792 // only the windows that were opened by it." | 743 // only the windows that were opened by it." |
793 std::string script = "window.domAutomationController.send(window.close())"; | 744 std::string script = "window.domAutomationController.send(window.close())"; |
794 ASSERT_TRUE(content::ExecuteScript( | 745 ASSERT_TRUE(content::ExecuteScript( |
795 current_browser()->tab_strip_model()->GetActiveWebContents(), script)); | 746 current_browser()->tab_strip_model()->GetActiveWebContents(), script)); |
796 } | 747 } |
797 | 748 |
798 #if defined(OS_LINUX) | 749 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) { |
799 // http://crbug.com/527437 | |
800 #define MAYBE_LastUsageUpdated DISABLED_LastUsageUpdated | |
801 #else | |
802 #define MAYBE_LastUsageUpdated LastUsageUpdated | |
803 #endif | |
804 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, MAYBE_LastUsageUpdated) { | |
805 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); | 750 ASSERT_NO_FATAL_FAILURE(Initialize(INITIALIZATION_DEFAULT)); |
806 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); | 751 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); |
807 GetHostContentSettingsMap()->SetPrefClockForTesting( | 752 GetHostContentSettingsMap()->SetPrefClockForTesting( |
808 std::unique_ptr<base::Clock>(clock_)); | 753 std::unique_ptr<base::Clock>(clock_)); |
809 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | 754 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); |
810 | 755 |
811 // Setting the permission should trigger the last usage. | 756 // Setting the permission should trigger the last usage. |
812 GetHostContentSettingsMap()->SetContentSettingDefaultScope( | 757 GetHostContentSettingsMap()->SetContentSettingDefaultScope( |
813 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, | 758 current_url(), current_url(), CONTENT_SETTINGS_TYPE_GEOLOCATION, |
814 std::string(), CONTENT_SETTING_ALLOW); | 759 std::string(), CONTENT_SETTING_ALLOW); |
815 | 760 |
816 // Permission has been used at the starting time. | 761 // Permission has been used at the starting time. |
817 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 762 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
818 current_url().GetOrigin(), | 763 current_url().GetOrigin(), |
819 current_url().GetOrigin(), | 764 current_url().GetOrigin(), |
820 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); | 765 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 10); |
821 | 766 |
822 clock_->Advance(base::TimeDelta::FromSeconds(3)); | 767 clock_->Advance(base::TimeDelta::FromSeconds(3)); |
823 | 768 |
824 // Calling watchPosition should trigger the last usage update. | 769 // Calling watchPosition should trigger the last usage update. |
825 WatchPositionAndObservePermissionRequest(false); | 770 WatchPositionAndObservePermissionRequest(false); |
826 ExpectPosition(fake_latitude(), fake_longitude()); | 771 ExpectPosition(fake_latitude(), fake_longitude()); |
827 | 772 |
828 // Last usage has been updated. | 773 // Last usage has been updated. |
829 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( | 774 EXPECT_EQ(GetHostContentSettingsMap()->GetLastUsage( |
830 current_url().GetOrigin(), | 775 current_url().GetOrigin(), |
831 current_url().GetOrigin(), | 776 current_url().GetOrigin(), |
832 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); | 777 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 13); |
833 } | 778 } |
OLD | NEW |