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

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: Fixed patch conflict 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 322 }
322 323
323 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( 324 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted(
324 content::WebContents* web_contents) { 325 content::WebContents* web_contents) {
325 PermissionBubbleManager::FromWebContents(web_contents)-> 326 PermissionBubbleManager::FromWebContents(web_contents)->
326 DocumentOnLoadCompletedInMainFrame(); 327 DocumentOnLoadCompletedInMainFrame();
327 } 328 }
328 329
329 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( 330 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting(
330 GURL frame_0, GURL frame_1) { 331 GURL frame_0, GURL frame_1) {
331 return profile()->GetHostContentSettingsMap()->GetContentSetting( 332 return HostContentSettingsMapFactory::GetForProfile(profile())
332 frame_0, frame_1, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()); 333 ->GetContentSetting(frame_0,
334 frame_1,
335 CONTENT_SETTINGS_TYPE_GEOLOCATION,
336 std::string());
333 } 337 }
334 338
335 bool GeolocationPermissionContextTests::BubbleEnabled() const { 339 bool GeolocationPermissionContextTests::BubbleEnabled() const {
336 return PermissionBubbleManager::Enabled(); 340 return PermissionBubbleManager::Enabled();
337 } 341 }
338 342
339 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { 343 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() {
340 if (BubbleEnabled()) { 344 if (BubbleEnabled()) {
341 PermissionBubbleManager* manager = 345 PermissionBubbleManager* manager =
342 PermissionBubbleManager::FromWebContents(web_contents()); 346 PermissionBubbleManager::FromWebContents(web_contents());
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 828
825 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { 829 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
826 GURL requesting_frame("http://www.example.com/geolocation"); 830 GURL requesting_frame("http://www.example.com/geolocation");
827 NavigateAndCommit(requesting_frame); 831 NavigateAndCommit(requesting_frame);
828 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); 832 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted();
829 833
830 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 834 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
831 test_clock->SetNow(base::Time::UnixEpoch() + 835 test_clock->SetNow(base::Time::UnixEpoch() +
832 base::TimeDelta::FromSeconds(10)); 836 base::TimeDelta::FromSeconds(10));
833 837
834 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 838 HostContentSettingsMap* map =
839 HostContentSettingsMapFactory::GetForProfile(profile());
835 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 840 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
836 841
837 // The permission shouldn't have been used yet. 842 // The permission shouldn't have been used yet.
838 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), 843 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(),
839 requesting_frame.GetOrigin(), 844 requesting_frame.GetOrigin(),
840 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 845 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
841 0); 846 0);
842 ASSERT_EQ(0U, GetNumberOfPrompts()); 847 ASSERT_EQ(0U, GetNumberOfPrompts());
843 RequestGeolocationPermission( 848 RequestGeolocationPermission(
844 web_contents(), RequestID(0), requesting_frame, false); 849 web_contents(), RequestID(0), requesting_frame, false);
(...skipping 18 matching lines...) Expand all
863 requesting_frame.GetOrigin(), 868 requesting_frame.GetOrigin(),
864 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 869 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
865 13); 870 13);
866 } 871 }
867 872
868 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { 873 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) {
869 base::SimpleTestClock* test_clock = new base::SimpleTestClock; 874 base::SimpleTestClock* test_clock = new base::SimpleTestClock;
870 test_clock->SetNow(base::Time::UnixEpoch() + 875 test_clock->SetNow(base::Time::UnixEpoch() +
871 base::TimeDelta::FromSeconds(10)); 876 base::TimeDelta::FromSeconds(10));
872 877
873 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); 878 HostContentSettingsMap* map =
879 HostContentSettingsMapFactory::GetForProfile(profile());
874 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); 880 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock));
875 881
876 GURL requesting_frame_0("http://www.example.com/geolocation"); 882 GURL requesting_frame_0("http://www.example.com/geolocation");
877 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 883 GURL requesting_frame_1("http://www.example-2.com/geolocation");
878 884
879 // The permission shouldn't have been used yet. 885 // The permission shouldn't have been used yet.
880 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 886 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
881 requesting_frame_0.GetOrigin(), 887 requesting_frame_0.GetOrigin(),
882 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 888 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
883 0); 889 0);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 // it is the embedder. 953 // it is the embedder.
948 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), 954 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(),
949 requesting_frame_0.GetOrigin(), 955 requesting_frame_0.GetOrigin(),
950 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 956 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
951 13); 957 13);
952 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 958 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
953 requesting_frame_0.GetOrigin(), 959 requesting_frame_0.GetOrigin(),
954 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 960 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
955 11); 961 11);
956 } 962 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698