Chromium Code Reviews| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/simple_test_clock.h" | |
| 12 #include "base/time/clock.h" | |
| 11 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/content_settings/content_settings_usages_state.h" | 14 #include "chrome/browser/content_settings/content_settings_usages_state.h" |
| 13 #include "chrome/browser/content_settings/host_content_settings_map.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 16 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 15 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_commands.h" | 20 #include "chrome/browser/ui/browser_commands.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| (...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 | 764 |
| 763 SetFrameHost("iframe_2"); | 765 SetFrameHost("iframe_2"); |
| 764 AddGeolocationWatch(false); | 766 AddGeolocationWatch(false); |
| 765 | 767 |
| 766 std::string script = | 768 std::string script = |
| 767 "window.domAutomationController.send(window.close());"; | 769 "window.domAutomationController.send(window.close());"; |
| 768 bool result = content::ExecuteScript( | 770 bool result = content::ExecuteScript( |
| 769 current_browser()->tab_strip_model()->GetActiveWebContents(), script); | 771 current_browser()->tab_strip_model()->GetActiveWebContents(), script); |
| 770 EXPECT_EQ(result, true); | 772 EXPECT_EQ(result, true); |
| 771 } | 773 } |
| 774 | |
| 775 IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) { | |
| 776 ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); | |
| 777 base::SimpleTestClock* clock_ = new base::SimpleTestClock(); | |
|
Bernhard Bauer
2014/07/17 09:11:48
Same here.
| |
| 778 current_browser() | |
| 779 ->profile() | |
| 780 ->GetHostContentSettingsMap() | |
| 781 ->SetPrefClockForTesting(scoped_ptr<base::Clock>(clock_)); | |
| 782 clock_->SetNow(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(10)); | |
| 783 | |
| 784 // Setting the permission should trigger the last usage. | |
| 785 current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( | |
| 786 ContentSettingsPattern::FromURLNoWildcard(current_url()), | |
| 787 ContentSettingsPattern::FromURLNoWildcard(current_url()), | |
| 788 CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
| 789 std::string(), | |
| 790 CONTENT_SETTING_ALLOW); | |
| 791 | |
| 792 // Permission has been used at the starting time. | |
| 793 EXPECT_EQ(current_browser() | |
| 794 ->profile() | |
| 795 ->GetHostContentSettingsMap() | |
| 796 ->GetLastUsage(current_url().GetOrigin(), | |
| 797 current_url().GetOrigin(), | |
| 798 CONTENT_SETTINGS_TYPE_GEOLOCATION) | |
| 799 .ToDoubleT(), | |
| 800 10); | |
| 801 | |
| 802 clock_->Advance(base::TimeDelta::FromSeconds(3)); | |
| 803 | |
| 804 // Watching should trigger the last usage update. | |
| 805 SetFrameHost(""); | |
| 806 AddGeolocationWatch(false); | |
| 807 CheckGeoposition(fake_latitude(), fake_longitude()); | |
| 808 | |
| 809 // Last usage has been updated. | |
| 810 EXPECT_EQ(current_browser() | |
| 811 ->profile() | |
| 812 ->GetHostContentSettingsMap() | |
| 813 ->GetLastUsage(current_url().GetOrigin(), | |
| 814 current_url().GetOrigin(), | |
| 815 CONTENT_SETTINGS_TYPE_GEOLOCATION) | |
| 816 .ToDoubleT(), | |
| 817 13); | |
| 818 } | |
| OLD | NEW |