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

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

Issue 2697473002: Remove last usage functions from HostContentSettingsMap and clean up prefs (Closed)
Patch Set: fix up unit test Created 3 years, 10 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 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 #endif 864 #endif
865 865
866 // The content settings should not have changed. 866 // The content settings should not have changed.
867 EXPECT_EQ( 867 EXPECT_EQ(
868 CONTENT_SETTING_ASK, 868 CONTENT_SETTING_ASK,
869 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); 869 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0));
870 EXPECT_EQ( 870 EXPECT_EQ(
871 CONTENT_SETTING_ASK, 871 CONTENT_SETTING_ASK,
872 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); 872 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0));
873 } 873 }
874
875 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
876 GURL requesting_frame("https://www.example.com/geolocation");
877 NavigateAndCommit(requesting_frame);
878 RequestManagerDocumentLoadCompleted();
879
880 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
881 test_clock->SetNow(base::Time::UnixEpoch() +
882 base::TimeDelta::FromSeconds(10));
883
884 HostContentSettingsMap* map =
885 HostContentSettingsMapFactory::GetForProfile(profile());
886 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock));
887
888 // The permission shouldn't have been used yet.
889 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
890 requesting_frame.GetOrigin(),
891 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
892 0);
893 ASSERT_EQ(0U, GetNumberOfPrompts());
894 RequestGeolocationPermission(
895 web_contents(), RequestID(0), requesting_frame, false);
896 ASSERT_EQ(1U, GetNumberOfPrompts());
897
898 AcceptPrompt();
899 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
900 CheckPermissionMessageSent(0, true);
901
902 // Permission has been used at the starting time.
903 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
904 requesting_frame.GetOrigin(),
905 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
906 10);
907
908 test_clock->Advance(base::TimeDelta::FromSeconds(3));
909 RequestGeolocationPermission(
910 web_contents(), RequestID(0), requesting_frame, false);
911
912 // Permission has been used three seconds later.
913 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
914 requesting_frame.GetOrigin(),
915 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
916 13);
917 }
918
919 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
920 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
921 test_clock->SetNow(base::Time::UnixEpoch() +
922 base::TimeDelta::FromSeconds(10));
923
924 HostContentSettingsMap* map =
925 HostContentSettingsMapFactory::GetForProfile(profile());
926 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock));
927
928 GURL requesting_frame_0("https://www.example.com/geolocation");
929 GURL requesting_frame_1("https://www.example-2.com/geolocation");
930
931 // The permission shouldn't have been used yet.
932 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
933 requesting_frame_0.GetOrigin(),
934 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
935 0);
936 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
937 requesting_frame_0.GetOrigin(),
938 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
939 0);
940
941 NavigateAndCommit(requesting_frame_0);
942 RequestManagerDocumentLoadCompleted();
943
944 EXPECT_EQ(0U, GetNumberOfPrompts());
945
946 // Request permission for two frames.
947 RequestGeolocationPermission(
948 web_contents(), RequestID(0), requesting_frame_0, false);
949 RequestGeolocationPermission(
950 web_contents(), RequestID(1), requesting_frame_1, false);
951
952 // Ensure only one infobar is created.
953 ASSERT_EQ(1U, GetNumberOfPrompts());
954
955 // Accept the first frame.
956 AcceptPrompt();
957 #if defined(OS_ANDROID)
958 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
959 #endif
960 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
961 CheckPermissionMessageSent(0, true);
962
963 // Verify that accepting the first didn't accept because it's embedded
964 // in the other.
965 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
966 requesting_frame_0.GetOrigin(),
967 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
968 10);
969 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
970 requesting_frame_0.GetOrigin(),
971 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
972 0);
973
974 ASSERT_EQ(1U, GetNumberOfPrompts());
975
976 test_clock->Advance(base::TimeDelta::FromSeconds(1));
977
978 // Allow the second frame.
979 AcceptPrompt();
980 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
981 CheckPermissionMessageSent(1, true);
982 #if defined(OS_ANDROID)
983 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0));
984 #endif
985
986 // Verify that the times are different.
987 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
988 requesting_frame_0.GetOrigin(),
989 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
990 10);
991 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
992 requesting_frame_0.GetOrigin(),
993 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
994 11);
995
996 test_clock->Advance(base::TimeDelta::FromSeconds(2));
997 RequestGeolocationPermission(
998 web_contents(), RequestID(0), requesting_frame_0, false);
999
1000 // Verify that requesting permission in one frame doesn't update other where
1001 // it is the embedder.
1002 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
1003 requesting_frame_0.GetOrigin(),
1004 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
1005 13);
1006 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
1007 requesting_frame_0.GetOrigin(),
1008 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
1009 11);
1010 }
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/geolocation_browsertest.cc ('k') | chrome/browser/media/webrtc/media_stream_devices_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698