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 "chrome/browser/geolocation/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
825 #endif | 825 #endif |
826 | 826 |
827 // The content settings should not have changed. | 827 // The content settings should not have changed. |
828 EXPECT_EQ( | 828 EXPECT_EQ( |
829 CONTENT_SETTING_ASK, | 829 CONTENT_SETTING_ASK, |
830 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); | 830 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
831 EXPECT_EQ( | 831 EXPECT_EQ( |
832 CONTENT_SETTING_ASK, | 832 CONTENT_SETTING_ASK, |
833 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); | 833 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
834 } | 834 } |
835 | |
836 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { | |
837 GURL requesting_frame("http://www.example.com/geolocation"); | |
838 NavigateAndCommit(requesting_frame); | |
839 BubbleManagerDocumentLoadCompleted(); | |
840 | |
841 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | |
842 test_clock->SetNow(base::Time::UnixEpoch() + | |
843 base::TimeDelta::FromSeconds(10)); | |
844 | |
845 HostContentSettingsMap* map = | |
846 HostContentSettingsMapFactory::GetForProfile(profile()); | |
847 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | |
848 | |
849 // The permission shouldn't have been used yet. | |
850 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | |
851 requesting_frame.GetOrigin(), | |
852 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
853 0); | |
854 ASSERT_EQ(0U, GetNumberOfPrompts()); | |
855 RequestGeolocationPermission( | |
856 web_contents(), RequestID(0), requesting_frame, false); | |
857 ASSERT_EQ(1U, GetNumberOfPrompts()); | |
858 | |
859 AcceptPrompt(); | |
860 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | |
861 CheckPermissionMessageSent(0, true); | |
862 | |
863 // Permission has been used at the starting time. | |
864 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | |
865 requesting_frame.GetOrigin(), | |
866 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
867 10); | |
868 | |
869 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | |
870 RequestGeolocationPermission( | |
871 web_contents(), RequestID(0), requesting_frame, false); | |
872 | |
873 // Permission has been used three seconds later. | |
874 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | |
875 requesting_frame.GetOrigin(), | |
876 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
877 13); | |
878 } | |
879 | |
880 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | |
881 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | |
882 test_clock->SetNow(base::Time::UnixEpoch() + | |
883 base::TimeDelta::FromSeconds(10)); | |
884 | |
885 HostContentSettingsMap* map = | |
886 HostContentSettingsMapFactory::GetForProfile(profile()); | |
887 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | |
888 | |
889 GURL requesting_frame_0("http://www.example.com/geolocation"); | |
890 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | |
891 | |
892 // The permission shouldn't have been used yet. | |
893 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | |
894 requesting_frame_0.GetOrigin(), | |
895 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
896 0); | |
897 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | |
898 requesting_frame_0.GetOrigin(), | |
899 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
900 0); | |
901 | |
902 NavigateAndCommit(requesting_frame_0); | |
903 BubbleManagerDocumentLoadCompleted(); | |
904 | |
905 EXPECT_EQ(0U, GetNumberOfPrompts()); | |
906 | |
907 // Request permission for two frames. | |
908 RequestGeolocationPermission( | |
909 web_contents(), RequestID(0), requesting_frame_0, false); | |
910 RequestGeolocationPermission( | |
911 web_contents(), RequestID(1), requesting_frame_1, false); | |
912 | |
913 // Ensure only one infobar is created. | |
914 ASSERT_EQ(1U, GetNumberOfPrompts()); | |
915 | |
916 // Accept the first frame. | |
917 AcceptPrompt(); | |
918 #if defined(OS_ANDROID) | |
919 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | |
920 #endif | |
921 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | |
922 CheckPermissionMessageSent(0, true); | |
923 | |
924 // Verify that accepting the first didn't accept because it's embedded | |
925 // in the other. | |
926 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | |
927 requesting_frame_0.GetOrigin(), | |
928 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
929 10); | |
930 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | |
931 requesting_frame_0.GetOrigin(), | |
932 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
933 0); | |
934 | |
935 ASSERT_EQ(1U, GetNumberOfPrompts()); | |
936 | |
937 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
938 | |
939 // Allow the second frame. | |
940 AcceptPrompt(); | |
941 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | |
942 CheckPermissionMessageSent(1, true); | |
943 #if defined(OS_ANDROID) | |
944 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | |
945 #endif | |
946 | |
947 // Verify that the times are different. | |
948 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | |
949 requesting_frame_0.GetOrigin(), | |
950 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
951 10); | |
952 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | |
953 requesting_frame_0.GetOrigin(), | |
954 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
955 11); | |
956 | |
957 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | |
958 RequestGeolocationPermission( | |
959 web_contents(), RequestID(0), requesting_frame_0, false); | |
960 | |
961 // Verify that requesting permission in one frame doesn't update other where | |
962 // it is the embedder. | |
963 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | |
964 requesting_frame_0.GetOrigin(), | |
965 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
966 13); | |
967 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | |
968 requesting_frame_0.GetOrigin(), | |
969 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | |
970 11); | |
971 } | |
OLD | NEW |