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