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 "components/content_settings/core/browser/content_settings_pref_provide r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.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/test/simple_test_clock.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 20 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 21 #include "chrome/browser/prefs/browser_prefs.h" | 21 #include "chrome/browser/prefs/browser_prefs.h" |
| 22 #include "chrome/browser/prefs/pref_service_mock_factory.h" | 22 #include "chrome/browser/prefs/pref_service_mock_factory.h" |
| 23 #include "chrome/browser/prefs/pref_service_syncable.h" | 23 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 27 #include "chrome/test/base/testing_pref_service_syncable.h" | 27 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
| 29 #include "components/content_settings/core/browser/content_settings_pref.h" | |
| 29 #include "components/content_settings/core/browser/content_settings_utils.h" | 30 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 30 #include "components/content_settings/core/test/content_settings_test_utils.h" | 31 #include "components/content_settings/core/test/content_settings_test_utils.h" |
| 31 #include "components/pref_registry/pref_registry_syncable.h" | 32 #include "components/pref_registry/pref_registry_syncable.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 35 using ::testing::_; | 36 using ::testing::_; |
| 36 | 37 |
| 37 namespace content_settings { | 38 namespace content_settings { |
| 38 | 39 |
| 39 class DeadlockCheckerThread : public base::PlatformThread::Delegate { | 40 class DeadlockCheckerThread : public base::PlatformThread::Delegate { |
| 40 public: | 41 public: |
| 41 explicit DeadlockCheckerThread(PrefProvider* provider) | 42 explicit DeadlockCheckerThread(PrefProvider* provider) |
| 42 : provider_(provider) {} | 43 : provider_(provider) {} |
| 43 | 44 |
| 44 void ThreadMain() override { | 45 void ThreadMain() override { |
| 45 bool got_lock = provider_->lock_.Try(); | 46 bool got_lock = provider_->content_settings_pref()->lock_.Try(); |
| 46 EXPECT_TRUE(got_lock); | 47 EXPECT_TRUE(got_lock); |
| 47 if (got_lock) | 48 if (got_lock) |
| 48 provider_->lock_.Release(); | 49 provider_->content_settings_pref()->lock_.Release(); |
| 49 } | 50 } |
| 50 private: | 51 private: |
| 51 PrefProvider* provider_; | 52 PrefProvider* provider_; |
| 52 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); | 53 DISALLOW_COPY_AND_ASSIGN(DeadlockCheckerThread); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 // A helper for observing an preference changes and testing whether | 56 // A helper for observing an preference changes and testing whether |
| 56 // |PrefProvider| holds a lock when the preferences change. | 57 // |PrefProvider| holds a lock when the preferences change. |
| 57 class DeadlockCheckerObserver { | 58 class DeadlockCheckerObserver { |
| 58 public: | 59 public: |
| 59 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or | 60 // |DeadlockCheckerObserver| doesn't take the ownership of |prefs| or |
| 60 // ||provider|. | 61 // |provider|. |
| 61 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider) | 62 DeadlockCheckerObserver(PrefService* prefs, PrefProvider* provider) |
| 62 : provider_(provider), | 63 : provider_(provider), |
| 63 notification_received_(false) { | 64 notification_received_(false) { |
| 64 pref_change_registrar_.Init(prefs); | 65 pref_change_registrar_.Init(prefs); |
| 65 pref_change_registrar_.Add( | 66 pref_change_registrar_.Add( |
| 66 prefs::kContentSettingsPatternPairs, | 67 prefs::kContentSettingsPatternPairs, |
|
msramek
2015/03/09 19:02:29
This feels incorrect to me, since in this unittest
raymes
2015/03/09 22:13:52
Hmm I'm not exactly sure what you mean. Could you
msramek
2015/03/10 19:40:36
What I had in mind was - when kContentSettingsPatt
| |
| 67 base::Bind( | 68 base::Bind( |
| 68 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged, | 69 &DeadlockCheckerObserver::OnContentSettingsPatternPairsChanged, |
| 69 base::Unretained(this))); | 70 base::Unretained(this))); |
| 70 } | 71 } |
| 71 virtual ~DeadlockCheckerObserver() {} | 72 virtual ~DeadlockCheckerObserver() {} |
| 72 | 73 |
| 73 bool notification_received() const { | 74 bool notification_received() const { |
| 74 return notification_received_; | 75 return notification_received_; |
| 75 } | 76 } |
| 76 | 77 |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 base::Time second = pref_content_settings_provider.GetLastUsage( | 459 base::Time second = pref_content_settings_provider.GetLastUsage( |
| 459 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 460 pattern, pattern, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 460 | 461 |
| 461 base::TimeDelta delta = second - first; | 462 base::TimeDelta delta = second - first; |
| 462 EXPECT_EQ(delta.InSeconds(), 10); | 463 EXPECT_EQ(delta.InSeconds(), 10); |
| 463 | 464 |
| 464 pref_content_settings_provider.ShutdownOnUIThread(); | 465 pref_content_settings_provider.ShutdownOnUIThread(); |
| 465 } | 466 } |
| 466 | 467 |
| 467 } // namespace content_settings | 468 } // namespace content_settings |
| OLD | NEW |