| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_change_registrar.h" | 5 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 6 #include "chrome/common/notification_details.h" | 6 #include "chrome/common/notification_details.h" |
| 7 #include "chrome/common/notification_observer.h" | 7 #include "chrome/common/notification_observer.h" |
| 8 #include "chrome/common/notification_source.h" | 8 #include "chrome/common/notification_source.h" |
| 9 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/test/testing_pref_service.h" | 10 #include "chrome/test/testing_pref_service.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 PrefChangeRegistrar registrar; | 56 PrefChangeRegistrar registrar; |
| 57 registrar.Init(service()); | 57 registrar.Init(service()); |
| 58 | 58 |
| 59 // Test adding. | 59 // Test adding. |
| 60 EXPECT_CALL(*service(), | 60 EXPECT_CALL(*service(), |
| 61 AddPrefObserver(Eq(std::string("test.pref.1")), observer())); | 61 AddPrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 62 EXPECT_CALL(*service(), | 62 EXPECT_CALL(*service(), |
| 63 AddPrefObserver(Eq(std::string("test.pref.2")), observer())); | 63 AddPrefObserver(Eq(std::string("test.pref.2")), observer())); |
| 64 registrar.Add("test.pref.1", observer()); | 64 registrar.Add("test.pref.1", observer()); |
| 65 registrar.Add("test.pref.2", observer()); | 65 registrar.Add("test.pref.2", observer()); |
| 66 EXPECT_FALSE(registrar.IsEmpty()); |
| 66 | 67 |
| 67 // Test removing. | 68 // Test removing. |
| 68 Mock::VerifyAndClearExpectations(service()); | 69 Mock::VerifyAndClearExpectations(service()); |
| 69 EXPECT_CALL(*service(), | 70 EXPECT_CALL(*service(), |
| 70 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); | 71 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 71 EXPECT_CALL(*service(), | 72 EXPECT_CALL(*service(), |
| 72 RemovePrefObserver(Eq(std::string("test.pref.2")), observer())); | 73 RemovePrefObserver(Eq(std::string("test.pref.2")), observer())); |
| 73 registrar.Remove("test.pref.1", observer()); | 74 registrar.Remove("test.pref.1", observer()); |
| 74 registrar.Remove("test.pref.2", observer()); | 75 registrar.Remove("test.pref.2", observer()); |
| 76 EXPECT_TRUE(registrar.IsEmpty()); |
| 77 |
| 78 // Explicitly check the expectations now to make sure that the Removes |
| 79 // worked (rather than the registrar destructor doing the work). |
| 80 Mock::VerifyAndClearExpectations(service()); |
| 75 } | 81 } |
| 76 | 82 |
| 77 TEST_F(PrefChangeRegistrarTest, AutoRemove) { | 83 TEST_F(PrefChangeRegistrarTest, AutoRemove) { |
| 78 PrefChangeRegistrar registrar; | 84 PrefChangeRegistrar registrar; |
| 79 registrar.Init(service()); | 85 registrar.Init(service()); |
| 80 | 86 |
| 81 // Setup of auto-remove. | 87 // Setup of auto-remove. |
| 82 EXPECT_CALL(*service(), | 88 EXPECT_CALL(*service(), |
| 83 AddPrefObserver(Eq(std::string("test.pref.1")), observer())); | 89 AddPrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 84 registrar.Add("test.pref.1", observer()); | 90 registrar.Add("test.pref.1", observer()); |
| 85 Mock::VerifyAndClearExpectations(service()); | 91 Mock::VerifyAndClearExpectations(service()); |
| 92 EXPECT_FALSE(registrar.IsEmpty()); |
| 86 | 93 |
| 87 // Test auto-removing. | 94 // Test auto-removing. |
| 88 EXPECT_CALL(*service(), | 95 EXPECT_CALL(*service(), |
| 89 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); | 96 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 90 } | 97 } |
| 98 |
| 99 TEST_F(PrefChangeRegistrarTest, RemoveAll) { |
| 100 PrefChangeRegistrar registrar; |
| 101 registrar.Init(service()); |
| 102 |
| 103 EXPECT_CALL(*service(), |
| 104 AddPrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 105 EXPECT_CALL(*service(), |
| 106 AddPrefObserver(Eq(std::string("test.pref.2")), observer())); |
| 107 registrar.Add("test.pref.1", observer()); |
| 108 registrar.Add("test.pref.2", observer()); |
| 109 Mock::VerifyAndClearExpectations(service()); |
| 110 |
| 111 EXPECT_CALL(*service(), |
| 112 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); |
| 113 EXPECT_CALL(*service(), |
| 114 RemovePrefObserver(Eq(std::string("test.pref.2")), observer())); |
| 115 registrar.RemoveAll(); |
| 116 EXPECT_TRUE(registrar.IsEmpty()); |
| 117 |
| 118 // Explicitly check the expectations now to make sure that the RemoveAll |
| 119 // worked (rather than the registrar destructor doing the work). |
| 120 Mock::VerifyAndClearExpectations(service()); |
| 121 } |
| OLD | NEW |