| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/prefs/pref_notifier_impl.h" | 5 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 6 #include "chrome/browser/prefs/pref_observer_mock.h" | 6 #include "chrome/browser/prefs/pref_observer_mock.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" | 7 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/prefs/pref_value_store.h" | 8 #include "chrome/browser/prefs/pref_value_store.h" |
| 9 #include "chrome/common/chrome_notification_types.h" | 9 #include "chrome/common/chrome_notification_types.h" |
| 10 #include "chrome/test/base/testing_browser_process_test.h" | 10 #include "chrome/test/base/testing_browser_process_test.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MockPrefNotifier notifier(&pref_service_); | 98 MockPrefNotifier notifier(&pref_service_); |
| 99 notifier.AddPrefObserver(pref_name, &obs1_); | 99 notifier.AddPrefObserver(pref_name, &obs1_); |
| 100 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); | 100 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); |
| 101 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs1_)); | 101 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs1_)); |
| 102 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); | 102 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); |
| 103 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); | 103 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); |
| 104 | 104 |
| 105 // Re-adding the same observer for the same pref doesn't change anything. | 105 // Re-adding the same observer for the same pref doesn't change anything. |
| 106 // Skip this in debug mode, since it hits a DCHECK and death tests aren't | 106 // Skip this in debug mode, since it hits a DCHECK and death tests aren't |
| 107 // thread-safe. | 107 // thread-safe. |
| 108 #if defined(NDEBUG) | 108 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| 109 notifier.AddPrefObserver(pref_name, &obs1_); | 109 notifier.AddPrefObserver(pref_name, &obs1_); |
| 110 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); | 110 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); |
| 111 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs1_)); | 111 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs1_)); |
| 112 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); | 112 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); |
| 113 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); | 113 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); |
| 114 #endif // NDEBUG | 114 #endif |
| 115 | 115 |
| 116 // Ensure that we can add the same observer to a different pref. | 116 // Ensure that we can add the same observer to a different pref. |
| 117 notifier.AddPrefObserver(pref_name2, &obs1_); | 117 notifier.AddPrefObserver(pref_name2, &obs1_); |
| 118 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); | 118 ASSERT_EQ(1u, notifier.CountObserver(pref_name, &obs1_)); |
| 119 ASSERT_EQ(1u, notifier.CountObserver(pref_name2, &obs1_)); | 119 ASSERT_EQ(1u, notifier.CountObserver(pref_name2, &obs1_)); |
| 120 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); | 120 ASSERT_EQ(0u, notifier.CountObserver(pref_name, &obs2_)); |
| 121 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); | 121 ASSERT_EQ(0u, notifier.CountObserver(pref_name2, &obs2_)); |
| 122 | 122 |
| 123 // Ensure that we can add another observer to the same pref. | 123 // Ensure that we can add another observer to the same pref. |
| 124 notifier.AddPrefObserver(pref_name, &obs2_); | 124 notifier.AddPrefObserver(pref_name, &obs2_); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 obs2_.Expect(&pref_service_, kChangedPref, &value_true); | 191 obs2_.Expect(&pref_service_, kChangedPref, &value_true); |
| 192 notifier.OnPreferenceChanged(kChangedPref); | 192 notifier.OnPreferenceChanged(kChangedPref); |
| 193 Mock::VerifyAndClearExpectations(&obs1_); | 193 Mock::VerifyAndClearExpectations(&obs1_); |
| 194 Mock::VerifyAndClearExpectations(&obs2_); | 194 Mock::VerifyAndClearExpectations(&obs2_); |
| 195 | 195 |
| 196 notifier.RemovePrefObserver(kChangedPref, &obs2_); | 196 notifier.RemovePrefObserver(kChangedPref, &obs2_); |
| 197 notifier.RemovePrefObserver(kUnchangedPref, &obs2_); | 197 notifier.RemovePrefObserver(kUnchangedPref, &obs2_); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace | 200 } // namespace |
| OLD | NEW |