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 "chrome/browser/content_settings/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/default_pref_store.h" | 11 #include "base/prefs/default_pref_store.h" |
12 #include "base/prefs/overlay_user_pref_store.h" | 12 #include "base/prefs/overlay_user_pref_store.h" |
13 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/scoped_user_pref_update.h" | 15 #include "base/prefs/scoped_user_pref_update.h" |
16 #include "base/prefs/testing_pref_store.h" | 16 #include "base/prefs/testing_pref_store.h" |
17 #include "base/test/simple_test_clock.h" | |
17 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
18 #include "base/values.h" | 19 #include "base/values.h" |
19 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 20 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
20 #include "chrome/browser/content_settings/content_settings_utils.h" | 21 #include "chrome/browser/content_settings/content_settings_utils.h" |
21 #include "chrome/browser/prefs/browser_prefs.h" | 22 #include "chrome/browser/prefs/browser_prefs.h" |
22 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 23 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
23 #include "chrome/browser/prefs/pref_service_syncable.h" | 24 #include "chrome/browser/prefs/pref_service_syncable.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
26 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 prefs::kContentSettingsPatternPairs); | 438 prefs::kContentSettingsPatternPairs); |
438 base::DictionaryValue* mutable_settings = update.Get(); | 439 base::DictionaryValue* mutable_settings = update.Get(); |
439 mutable_settings->SetWithoutPathExpansion("www.example.com,*", | 440 mutable_settings->SetWithoutPathExpansion("www.example.com,*", |
440 new base::DictionaryValue()); | 441 new base::DictionaryValue()); |
441 } | 442 } |
442 EXPECT_TRUE(observer.notification_received()); | 443 EXPECT_TRUE(observer.notification_received()); |
443 | 444 |
444 provider.ShutdownOnUIThread(); | 445 provider.ShutdownOnUIThread(); |
445 } | 446 } |
446 | 447 |
448 TEST_F(PrefProviderTest, LastUsage) { | |
449 TestingProfile testing_profile; | |
450 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), | |
451 false); | |
452 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | |
Bernhard Bauer
2014/07/17 09:11:48
Alternatively, make this a scoped_ptr<base::Simple
Daniel Nishi
2014/07/17 18:01:49
Thanks for the suggestion, but I think I'm going t
| |
453 test_clock->SetNow(base::Time::Now()); | |
454 | |
455 pref_content_settings_provider.SetClockForTesting( | |
456 scoped_ptr<base::Clock>(test_clock)); | |
457 GURL host("http://example.com/"); | |
458 ContentSettingsPattern pattern = | |
459 ContentSettingsPattern::FromString("[*.]example.com"); | |
460 | |
461 base::Time no_usage = pref_content_settings_provider.GetLastUsage( | |
462 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
463 EXPECT_EQ(no_usage.ToDoubleT(), 0); | |
464 | |
465 pref_content_settings_provider.UpdateLastUsage( | |
466 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
467 base::Time first = pref_content_settings_provider.GetLastUsage( | |
468 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
469 | |
470 test_clock->Advance(base::TimeDelta::FromSeconds(10)); | |
471 | |
472 pref_content_settings_provider.UpdateLastUsage( | |
473 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
474 base::Time second = pref_content_settings_provider.GetLastUsage( | |
475 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
476 | |
477 base::TimeDelta delta = second - first; | |
478 EXPECT_EQ(delta.InSeconds(), 10); | |
479 | |
480 pref_content_settings_provider.ShutdownOnUIThread(); | |
481 } | |
482 | |
447 } // namespace content_settings | 483 } // namespace content_settings |
OLD | NEW |