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_mock.h" | 7 #include "chrome/common/notification_observer_mock.h" |
8 #include "chrome/common/notification_source.h" | 8 #include "chrome/common/notification_source.h" |
9 #include "chrome/common/notification_type.h" | 9 #include "chrome/common/notification_type.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
11 #include "chrome/test/testing_pref_service.h" | 11 #include "chrome/test/testing_pref_service.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 using testing::Mock; | 15 using testing::Mock; |
16 using testing::Eq; | 16 using testing::Eq; |
17 | 17 |
18 namespace { | |
19 | |
18 // A mock provider that allows us to capture pref observer changes. | 20 // A mock provider that allows us to capture pref observer changes. |
19 class MockPrefService : public TestingPrefService { | 21 class MockPrefService : public TestingPrefService { |
danno
2010/12/08 13:08:45
Choice of mock name if you clean up the other Mock
Mattias Nissler (ping if slow)
2010/12/09 10:20:20
Doesn't apply any longer.
| |
20 public: | 22 public: |
21 MockPrefService() {} | 23 MockPrefService() {} |
22 virtual ~MockPrefService() {}; | 24 virtual ~MockPrefService() {}; |
23 | 25 |
24 MOCK_METHOD2(AddPrefObserver, void(const char*, NotificationObserver*)); | 26 MOCK_METHOD2(AddPrefObserver, void(const char*, NotificationObserver*)); |
25 MOCK_METHOD2(RemovePrefObserver, void(const char*, NotificationObserver*)); | 27 MOCK_METHOD2(RemovePrefObserver, void(const char*, NotificationObserver*)); |
26 }; | 28 }; |
27 | 29 |
30 } // namespace | |
31 | |
28 class PrefChangeRegistrarTest : public testing::Test { | 32 class PrefChangeRegistrarTest : public testing::Test { |
29 public: | 33 public: |
30 PrefChangeRegistrarTest() {} | 34 PrefChangeRegistrarTest() {} |
31 virtual ~PrefChangeRegistrarTest() {} | 35 virtual ~PrefChangeRegistrarTest() {} |
32 | 36 |
33 protected: | 37 protected: |
34 virtual void SetUp(); | 38 virtual void SetUp(); |
35 | 39 |
36 NotificationObserver* observer() const { return observer_.get(); } | 40 NotificationObserver* observer() const { return observer_.get(); } |
37 MockPrefService* service() const { return service_.get(); } | 41 MockPrefService* service() const { return service_.get(); } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); | 110 RemovePrefObserver(Eq(std::string("test.pref.1")), observer())); |
107 EXPECT_CALL(*service(), | 111 EXPECT_CALL(*service(), |
108 RemovePrefObserver(Eq(std::string("test.pref.2")), observer())); | 112 RemovePrefObserver(Eq(std::string("test.pref.2")), observer())); |
109 registrar.RemoveAll(); | 113 registrar.RemoveAll(); |
110 EXPECT_TRUE(registrar.IsEmpty()); | 114 EXPECT_TRUE(registrar.IsEmpty()); |
111 | 115 |
112 // Explicitly check the expectations now to make sure that the RemoveAll | 116 // Explicitly check the expectations now to make sure that the RemoveAll |
113 // worked (rather than the registrar destructor doing the work). | 117 // worked (rather than the registrar destructor doing the work). |
114 Mock::VerifyAndClearExpectations(service()); | 118 Mock::VerifyAndClearExpectations(service()); |
115 } | 119 } |
OLD | NEW |