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

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

Issue 356543003: Audit the last usage of Geolocation and Notification permissions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add auditing for actual usage, too. Created 6 years, 5 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/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/test/simple_test_clock.h"
17 #include "base/time/clock.h"
16 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h" 19 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/content_settings/permission_request_id.h" 20 #include "chrome/browser/content_settings/permission_request_id.h"
19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
20 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
21 #include "chrome/browser/infobars/infobar_service.h" 23 #include "chrome/browser/infobars/infobar_service.h"
22 #include "chrome/browser/infobars/infobar_service.h" 24 #include "chrome/browser/infobars/infobar_service.h"
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
24 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
25 #include "components/infobars/core/confirm_infobar_delegate.h" 27 #include "components/infobars/core/confirm_infobar_delegate.h"
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 EXPECT_FALSE(infobar_delegate->ShouldExpire( 691 EXPECT_FALSE(infobar_delegate->ShouldExpire(
690 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 692 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
691 // Ensure the infobar will expire when we commit the pending navigation. 693 // Ensure the infobar will expire when we commit the pending navigation.
692 details.entry = web_contents()->GetController().GetActiveEntry(); 694 details.entry = web_contents()->GetController().GetActiveEntry();
693 EXPECT_TRUE(infobar_delegate->ShouldExpire( 695 EXPECT_TRUE(infobar_delegate->ShouldExpire(
694 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); 696 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details)));
695 697
696 // Delete the tab contents. 698 // Delete the tab contents.
697 DeleteContents(); 699 DeleteContents();
698 } 700 }
701
702 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) {
703 GURL requesting_frame("http://www.example.com/geolocation");
704 NavigateAndCommit(requesting_frame);
705
706 base::SimpleTestClock test_clock_;
707 test_clock_.SetNow(base::Time::UnixEpoch() +
708 base::TimeDelta::FromSeconds(10));
709 profile()->GetHostContentSettingsMap()->SetPrefClockForTesting(&test_clock_);
710
711 // The permission shouldn't have been used yet.
712 EXPECT_EQ(profile()
713 ->GetHostContentSettingsMap()
714 ->GetLastUsage(requesting_frame.GetOrigin(),
715 requesting_frame.GetOrigin(),
716 CONTENT_SETTINGS_TYPE_GEOLOCATION)
717 .ToDoubleT(),
718 0);
719
720 EXPECT_EQ(0U, infobar_service()->infobar_count());
721 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
722 ASSERT_EQ(1U, infobar_service()->infobar_count());
723 infobars::InfoBar* infobar = infobar_service()->infobar_at(0);
724 ConfirmInfoBarDelegate* infobar_delegate =
725 infobar->delegate()->AsConfirmInfoBarDelegate();
726 ASSERT_TRUE(infobar_delegate);
727 infobar_delegate->Accept();
728 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW);
729 CheckPermissionMessageSent(0, true);
730
731 // Permission has been used at the starting time.
732 EXPECT_EQ(profile()
733 ->GetHostContentSettingsMap()
734 ->GetLastUsage(requesting_frame.GetOrigin(),
735 requesting_frame.GetOrigin(),
736 CONTENT_SETTINGS_TYPE_GEOLOCATION)
737 .ToDoubleT(),
738 10);
739
740 test_clock_.Advance(base::TimeDelta::FromSeconds(3));
741 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame);
742
743 // Permission has been used three seconds later.
744 EXPECT_EQ(profile()
745 ->GetHostContentSettingsMap()
746 ->GetLastUsage(requesting_frame.GetOrigin(),
747 requesting_frame.GetOrigin(),
748 CONTENT_SETTINGS_TYPE_GEOLOCATION)
749 .ToDoubleT(),
750 13);
751 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698