| 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 #ifndef CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ |
| 6 #define CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "content/common/content_notification_types.h" |
| 12 #include "content/common/notification_details.h" | 13 #include "content/common/notification_details.h" |
| 13 #include "content/common/notification_observer.h" | 14 #include "content/common/notification_observer.h" |
| 14 #include "content/common/notification_source.h" | 15 #include "content/common/notification_source.h" |
| 15 #include "content/common/notification_type.h" | |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 17 |
| 18 using testing::Pointee; | 18 using testing::Pointee; |
| 19 using testing::Property; | 19 using testing::Property; |
| 20 using testing::Truly; | 20 using testing::Truly; |
| 21 | 21 |
| 22 // Matcher that checks whether the current value of the preference named | 22 // Matcher that checks whether the current value of the preference named |
| 23 // |pref_name| in |prefs| matches |value|. If |value| is NULL, the matcher | 23 // |pref_name| in |prefs| matches |value|. If |value| is NULL, the matcher |
| 24 // checks that the value is not set. | 24 // checks that the value is not set. |
| 25 MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") { | 25 MATCHER_P3(PrefValueMatches, prefs, pref_name, value, "") { |
| 26 const PrefService::Preference* pref = | 26 const PrefService::Preference* pref = |
| 27 prefs->FindPreference(pref_name.c_str()); | 27 prefs->FindPreference(pref_name.c_str()); |
| 28 if (!pref) | 28 if (!pref) |
| 29 return false; | 29 return false; |
| 30 | 30 |
| 31 const Value* actual_value = pref->GetValue(); | 31 const Value* actual_value = pref->GetValue(); |
| 32 if (!actual_value) | 32 if (!actual_value) |
| 33 return value == NULL; | 33 return value == NULL; |
| 34 if (!value) | 34 if (!value) |
| 35 return actual_value == NULL; | 35 return actual_value == NULL; |
| 36 return value->Equals(actual_value); | 36 return value->Equals(actual_value); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // A mock for testing preference notifications and easy setup of expectations. | 39 // A mock for testing preference notifications and easy setup of expectations. |
| 40 class PrefObserverMock : public NotificationObserver { | 40 class PrefObserverMock : public NotificationObserver { |
| 41 public: | 41 public: |
| 42 PrefObserverMock(); | 42 PrefObserverMock(); |
| 43 virtual ~PrefObserverMock(); | 43 virtual ~PrefObserverMock(); |
| 44 | 44 |
| 45 MOCK_METHOD3(Observe, void(NotificationType type, | 45 MOCK_METHOD3(Observe, void(int type, |
| 46 const NotificationSource& source, | 46 const NotificationSource& source, |
| 47 const NotificationDetails& details)); | 47 const NotificationDetails& details)); |
| 48 | 48 |
| 49 void Expect(const PrefService* prefs, | 49 void Expect(const PrefService* prefs, |
| 50 const std::string& pref_name, | 50 const std::string& pref_name, |
| 51 const Value* value); | 51 const Value* value); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 #endif // CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ | 54 #endif // CHROME_BROWSER_PREFS_PREF_OBSERVER_MOCK_H_ |
| OLD | NEW |