OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/json/json_string_value_serializer.h" | 7 #include "base/json/json_string_value_serializer.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/prefs/synced_pref_change_registrar.h" | 11 #include "chrome/browser/prefs/synced_pref_change_registrar.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "chrome/test/base/testing_pref_service_syncable.h" | 15 #include "chrome/test/base/testing_pref_service_syncable.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 18 #include "sync/api/fake_sync_change_processor.h" |
18 #include "sync/api/sync_change.h" | 19 #include "sync/api/sync_change.h" |
19 #include "sync/api/sync_error_factory.h" | 20 #include "sync/api/sync_error_factory.h" |
20 #include "sync/api/sync_error_factory_mock.h" | 21 #include "sync/api/sync_error_factory_mock.h" |
21 #include "sync/api/syncable_service.h" | 22 #include "sync/api/syncable_service.h" |
22 #include "sync/protocol/sync.pb.h" | 23 #include "sync/protocol/sync.pb.h" |
23 | 24 |
24 #if defined(ENABLE_CONFIGURATION_POLICY) | 25 #if defined(ENABLE_CONFIGURATION_POLICY) |
25 #include "components/policy/core/browser/browser_policy_connector.h" | 26 #include "components/policy/core/browser/browser_policy_connector.h" |
26 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 27 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
27 #include "components/policy/core/common/policy_map.h" | 28 #include "components/policy/core/common/policy_map.h" |
28 #include "policy/policy_constants.h" | 29 #include "policy/policy_constants.h" |
29 #endif | 30 #endif |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 using testing::Return; | 34 using testing::Return; |
34 using testing::_; | 35 using testing::_; |
35 | 36 |
36 class TestSyncProcessorStub : public syncer::SyncChangeProcessor { | |
37 virtual syncer::SyncError ProcessSyncChanges( | |
38 const tracked_objects::Location& from_here, | |
39 const syncer::SyncChangeList& change_list) OVERRIDE { | |
40 return syncer::SyncError(); | |
41 } | |
42 | |
43 virtual syncer::SyncDataList GetAllSyncData(syncer::ModelType type) const | |
44 OVERRIDE { | |
45 return syncer::SyncDataList(); | |
46 } | |
47 }; | |
48 | |
49 class SyncedPrefChangeRegistrarTest : public InProcessBrowserTest { | 37 class SyncedPrefChangeRegistrarTest : public InProcessBrowserTest { |
50 public: | 38 public: |
51 SyncedPrefChangeRegistrarTest() : next_sync_data_id_(0) {} | 39 SyncedPrefChangeRegistrarTest() : next_sync_data_id_(0) {} |
52 virtual ~SyncedPrefChangeRegistrarTest() {} | 40 virtual ~SyncedPrefChangeRegistrarTest() {} |
53 | 41 |
54 #if defined(ENABLE_CONFIGURATION_POLICY) | 42 #if defined(ENABLE_CONFIGURATION_POLICY) |
55 void UpdateChromePolicy(const policy::PolicyMap& policies) { | 43 void UpdateChromePolicy(const policy::PolicyMap& policies) { |
56 policy_provider_.UpdateChromePolicy(policies); | 44 policy_provider_.UpdateChromePolicy(policies); |
57 DCHECK(base::MessageLoop::current()); | 45 DCHECK(base::MessageLoop::current()); |
58 base::RunLoop loop; | 46 base::RunLoop loop; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 &policy_provider_); | 95 &policy_provider_); |
108 } | 96 } |
109 #endif | 97 #endif |
110 | 98 |
111 virtual void SetUpOnMainThread() OVERRIDE { | 99 virtual void SetUpOnMainThread() OVERRIDE { |
112 prefs_ = PrefServiceSyncable::FromProfile(browser()->profile()); | 100 prefs_ = PrefServiceSyncable::FromProfile(browser()->profile()); |
113 syncer_ = prefs_->GetSyncableService(syncer::PREFERENCES); | 101 syncer_ = prefs_->GetSyncableService(syncer::PREFERENCES); |
114 syncer_->MergeDataAndStartSyncing( | 102 syncer_->MergeDataAndStartSyncing( |
115 syncer::PREFERENCES, | 103 syncer::PREFERENCES, |
116 syncer::SyncDataList(), | 104 syncer::SyncDataList(), |
117 scoped_ptr<syncer::SyncChangeProcessor>(new TestSyncProcessorStub), | 105 scoped_ptr<syncer::SyncChangeProcessor>( |
| 106 new syncer::FakeSyncChangeProcessor), |
118 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); | 107 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); |
119 registrar_.reset(new SyncedPrefChangeRegistrar(prefs_)); | 108 registrar_.reset(new SyncedPrefChangeRegistrar(prefs_)); |
120 } | 109 } |
121 | 110 |
122 virtual void CleanUpOnMainThread() OVERRIDE { | 111 virtual void CleanUpOnMainThread() OVERRIDE { |
123 registrar_.reset(); | 112 registrar_.reset(); |
124 } | 113 } |
125 | 114 |
126 PrefServiceSyncable* prefs_; | 115 PrefServiceSyncable* prefs_; |
127 syncer::SyncableService* syncer_; | 116 syncer::SyncableService* syncer_; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::Value::CreateBooleanValue(true), | 210 base::Value::CreateBooleanValue(true), |
222 NULL); | 211 NULL); |
223 UpdateChromePolicy(policies); | 212 UpdateChromePolicy(policies); |
224 | 213 |
225 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); | 214 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); |
226 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); | 215 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); |
227 EXPECT_FALSE(observer.has_been_notified); | 216 EXPECT_FALSE(observer.has_been_notified); |
228 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); | 217 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); |
229 } | 218 } |
230 #endif | 219 #endif |
OLD | NEW |