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

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

Issue 1312453005: Removed Profile::GetHostContentSettingsMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed redundant functions Created 5 years, 3 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 <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/id_map.h" 14 #include "base/id_map.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/test/simple_test_clock.h" 17 #include "base/test/simple_test_clock.h"
18 #include "base/time/clock.h" 18 #include "base/time/clock.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
22 #include "chrome/browser/infobars/infobar_service.h" 23 #include "chrome/browser/infobars/infobar_service.h"
23 #include "chrome/browser/permissions/permission_request_id.h" 24 #include "chrome/browser/permissions/permission_request_id.h"
24 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" 25 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
25 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
26 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 27 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
27 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 29 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
29 #include "chrome/test/base/testing_profile.h" 30 #include "chrome/test/base/testing_profile.h"
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 324 }
324 325
325 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( 326 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
326 content::WebContents* web_contents) { 327 content::WebContents* web_contents) {
327 PermissionBubbleManager::FromWebContents(web_contents)-> 328 PermissionBubbleManager::FromWebContents(web_contents)->
328 DocumentOnLoadCompletedInMainFrame(); 329 DocumentOnLoadCompletedInMainFrame();
329 } 330 }
330 331
331 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( 332 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
332 GURL frame_0, GURL frame_1) { 333 GURL frame_0, GURL frame_1) {
333 return profile()->GetHostContentSettingsMap()->GetContentSetting( 334 return HostContentSettingsMapFactory::GetForProfile(profile())
334 frame_0, frame_1, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()); 335 ->GetContentSetting(frame_0,
336 frame_1,
337 CONTENT_SETTINGS_TYPE_GEOLOCATION,
338 std::string());
335 } 339 }
336 340
337 bool GeolocationPermissionContextTests::BubbleEnabled() const { 341 bool GeolocationPermissionContextTests::BubbleEnabled() const {
338 return PermissionBubbleManager::Enabled(); 342 return PermissionBubbleManager::Enabled();
339 } 343 }
340 344
341 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { 345 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() {
342 if (BubbleEnabled()) { 346 if (BubbleEnabled()) {
343 PermissionBubbleManager* manager = 347 PermissionBubbleManager* manager =
344 PermissionBubbleManager::FromWebContents(web_contents()); 348 PermissionBubbleManager::FromWebContents(web_contents());
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 830
827 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { 831 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
828 GURL requesting_frame("http://www.example.com/geolocation"); 832 GURL requesting_frame("http://www.example.com/geolocation");
829 NavigateAndCommit(requesting_frame); 833 NavigateAndCommit(requesting_frame);
830 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); 834 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
831 835
832 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 836 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
833 test_clock->SetNow(base::Time::UnixEpoch() + 837 test_clock->SetNow(base::Time::UnixEpoch() +
834 base::TimeDelta::FromSeconds(10)); 838 base::TimeDelta::FromSeconds(10));
835 839
836 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 840 HostContentSettingsMap* map =
841 HostContentSettingsMapFactory::GetForProfile(profile());
837 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 842 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
838 843
839 // The permission shouldn't have been used yet. 844 // The permission shouldn't have been used yet.
840 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 845 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
841 requesting_frame.GetOrigin(), 846 requesting_frame.GetOrigin(),
842 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 847 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
843 0); 848 0);
844 ASSERT_EQ(0U, GetNumberOfPrompts()); 849 ASSERT_EQ(0U, GetNumberOfPrompts());
845 RequestGeolocationPermission( 850 RequestGeolocationPermission(
846 web_contents(), RequestID(0), requesting_frame, false); 851 web_contents(), RequestID(0), requesting_frame, false);
(...skipping 18 matching lines...) Expand all
865 requesting_frame.GetOrigin(), 870 requesting_frame.GetOrigin(),
866 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 871 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
867 13); 872 13);
868 } 873 }
869 874
870 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { 875 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
871 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 876 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
872 test_clock->SetNow(base::Time::UnixEpoch() + 877 test_clock->SetNow(base::Time::UnixEpoch() +
873 base::TimeDelta::FromSeconds(10)); 878 base::TimeDelta::FromSeconds(10));
874 879
875 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 880 HostContentSettingsMap* map =
881 HostContentSettingsMapFactory::GetForProfile(profile());
876 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 882 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
877 883
878 GURL requesting_frame_0("http://www.example.com/geolocation"); 884 GURL requesting_frame_0("http://www.example.com/geolocation");
879 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 885 GURL requesting_frame_1("http://www.example-2.com/geolocation");
880 886
881 // The permission shouldn't have been used yet. 887 // The permission shouldn't have been used yet.
882 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 888 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
883 requesting_frame_0.GetOrigin(), 889 requesting_frame_0.GetOrigin(),
884 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 890 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
885 0); 891 0);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 // it is the embedder. 955 // it is the embedder.
950 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 956 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
951 requesting_frame_0.GetOrigin(), 957 requesting_frame_0.GetOrigin(),
952 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 958 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
953 13); 959 13);
954 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 960 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
955 requesting_frame_0.GetOrigin(), 961 requesting_frame_0.GetOrigin(),
956 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 962 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
957 11); 963 11);
958 } 964 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698