| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/test/base/testing_pref_service.h" | 5 #include "chrome/test/base/testing_pref_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" |
| 8 #include "base/prefs/default_pref_store.h" | 9 #include "base/prefs/default_pref_store.h" |
| 9 #include "chrome/browser/prefs/browser_prefs.h" | 10 #include "chrome/browser/prefs/browser_prefs.h" |
| 10 #include "chrome/browser/prefs/pref_notifier_impl.h" | 11 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 12 #include "chrome/browser/prefs/pref_registrar_simple.h" |
| 11 #include "chrome/browser/prefs/pref_value_store.h" | 13 #include "chrome/browser/prefs/pref_value_store.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // Do-nothing implementation for TestingPrefService. | 19 // Do-nothing implementation for TestingPrefService. |
| 18 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 20 void HandleReadError(PersistentPrefStore::PrefReadError error) { |
| 19 } | 21 } |
| 20 | 22 |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 template<> | 25 template<> |
| 24 TestingPrefServiceBase<PrefServiceSimple>::TestingPrefServiceBase( | 26 TestingPrefServiceBase<PrefService>::TestingPrefServiceBase( |
| 25 TestingPrefStore* managed_prefs, | 27 TestingPrefStore* managed_prefs, |
| 26 TestingPrefStore* user_prefs, | 28 TestingPrefStore* user_prefs, |
| 27 TestingPrefStore* recommended_prefs, | 29 TestingPrefStore* recommended_prefs, |
| 28 DefaultPrefStore* default_store, | 30 DefaultPrefStore* default_store, |
| 29 PrefNotifierImpl* pref_notifier) | 31 PrefNotifierImpl* pref_notifier) |
| 30 : PrefServiceSimple(pref_notifier, | 32 : PrefService(pref_notifier, |
| 31 new PrefValueStore( | 33 new PrefValueStore( |
| 32 managed_prefs, | 34 managed_prefs, |
| 33 NULL, | 35 NULL, |
| 34 NULL, | 36 NULL, |
| 35 user_prefs, | 37 user_prefs, |
| 36 recommended_prefs, | 38 recommended_prefs, |
| 37 default_store, | 39 default_store, |
| 38 pref_notifier), | 40 pref_notifier), |
| 39 user_prefs, | 41 user_prefs, |
| 40 default_store, | 42 default_store, |
| 41 base::Bind(&HandleReadError), | 43 base::Bind(&HandleReadError), |
| 42 false), | 44 false), |
| 43 managed_prefs_(managed_prefs), | 45 managed_prefs_(managed_prefs), |
| 44 user_prefs_(user_prefs), | 46 user_prefs_(user_prefs), |
| 45 recommended_prefs_(recommended_prefs) { | 47 recommended_prefs_(recommended_prefs) { |
| 46 } | 48 } |
| 47 | 49 |
| 48 template<> | 50 template<> |
| 49 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase( | 51 TestingPrefServiceBase<PrefServiceSyncable>::TestingPrefServiceBase( |
| 50 TestingPrefStore* managed_prefs, | 52 TestingPrefStore* managed_prefs, |
| 51 TestingPrefStore* user_prefs, | 53 TestingPrefStore* user_prefs, |
| 52 TestingPrefStore* recommended_prefs, | 54 TestingPrefStore* recommended_prefs, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 user_prefs, | 66 user_prefs, |
| 65 default_store, | 67 default_store, |
| 66 base::Bind(&HandleReadError), | 68 base::Bind(&HandleReadError), |
| 67 false), | 69 false), |
| 68 managed_prefs_(managed_prefs), | 70 managed_prefs_(managed_prefs), |
| 69 user_prefs_(user_prefs), | 71 user_prefs_(user_prefs), |
| 70 recommended_prefs_(recommended_prefs) { | 72 recommended_prefs_(recommended_prefs) { |
| 71 } | 73 } |
| 72 | 74 |
| 73 TestingPrefServiceSimple::TestingPrefServiceSimple() | 75 TestingPrefServiceSimple::TestingPrefServiceSimple() |
| 74 : TestingPrefServiceBase<PrefServiceSimple>(new TestingPrefStore(), | 76 : TestingPrefServiceBase<PrefService>(new TestingPrefStore(), |
| 75 new TestingPrefStore(), | 77 new TestingPrefStore(), |
| 76 new TestingPrefStore(), | 78 new TestingPrefStore(), |
| 77 new DefaultPrefStore(), | 79 new DefaultPrefStore(), |
| 78 new PrefNotifierImpl()) { | 80 new PrefNotifierImpl()), |
| 81 ALLOW_THIS_IN_INITIALIZER_LIST(registrar_(this)) { |
| 79 } | 82 } |
| 80 | 83 |
| 81 TestingPrefServiceSimple::~TestingPrefServiceSimple() { | 84 TestingPrefServiceSimple::~TestingPrefServiceSimple() { |
| 82 } | 85 } |
| 83 | 86 |
| 84 TestingPrefServiceSyncable::TestingPrefServiceSyncable() | 87 TestingPrefServiceSyncable::TestingPrefServiceSyncable() |
| 85 : TestingPrefServiceBase<PrefServiceSyncable>(new TestingPrefStore(), | 88 : TestingPrefServiceBase<PrefServiceSyncable>(new TestingPrefStore(), |
| 86 new TestingPrefStore(), | 89 new TestingPrefStore(), |
| 87 new TestingPrefStore(), | 90 new TestingPrefStore(), |
| 88 new DefaultPrefStore(), | 91 new DefaultPrefStore(), |
| 89 new PrefNotifierImpl()) { | 92 new PrefNotifierImpl()) { |
| 90 } | 93 } |
| 91 | 94 |
| 92 TestingPrefServiceSyncable::~TestingPrefServiceSyncable() { | 95 TestingPrefServiceSyncable::~TestingPrefServiceSyncable() { |
| 93 } | 96 } |
| 94 | 97 |
| 95 ScopedTestingLocalState::ScopedTestingLocalState( | 98 ScopedTestingLocalState::ScopedTestingLocalState( |
| 96 TestingBrowserProcess* browser_process) | 99 TestingBrowserProcess* browser_process) |
| 97 : browser_process_(browser_process) { | 100 : browser_process_(browser_process) { |
| 98 chrome::RegisterLocalState(&local_state_); | 101 chrome::RegisterLocalState(&local_state_); |
| 99 EXPECT_FALSE(browser_process->local_state()); | 102 EXPECT_FALSE(browser_process->local_state()); |
| 100 browser_process->SetLocalState(&local_state_); | 103 browser_process->SetLocalState(&local_state_); |
| 101 } | 104 } |
| 102 | 105 |
| 103 ScopedTestingLocalState::~ScopedTestingLocalState() { | 106 ScopedTestingLocalState::~ScopedTestingLocalState() { |
| 104 EXPECT_EQ(&local_state_, browser_process_->local_state()); | 107 EXPECT_EQ(&local_state_, browser_process_->local_state()); |
| 105 browser_process_->SetLocalState(NULL); | 108 browser_process_->SetLocalState(NULL); |
| 106 } | 109 } |
| OLD | NEW |