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 <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void UpdateChromePolicy(const policy::PolicyMap& policies) { | 44 void UpdateChromePolicy(const policy::PolicyMap& policies) { |
45 policy_provider_.UpdateChromePolicy(policies); | 45 policy_provider_.UpdateChromePolicy(policies); |
46 DCHECK(base::MessageLoop::current()); | 46 DCHECK(base::MessageLoop::current()); |
47 base::RunLoop loop; | 47 base::RunLoop loop; |
48 loop.RunUntilIdle(); | 48 loop.RunUntilIdle(); |
49 } | 49 } |
50 | 50 |
51 void SetBooleanPrefValueFromSync(const std::string& name, bool value) { | 51 void SetBooleanPrefValueFromSync(const std::string& name, bool value) { |
52 std::string serialized_value; | 52 std::string serialized_value; |
53 JSONStringValueSerializer json(&serialized_value); | 53 JSONStringValueSerializer json(&serialized_value); |
54 json.Serialize(base::FundamentalValue(value)); | 54 json.Serialize(base::Value(value)); |
55 | 55 |
56 sync_pb::EntitySpecifics specifics; | 56 sync_pb::EntitySpecifics specifics; |
57 sync_pb::PreferenceSpecifics* pref_specifics = | 57 sync_pb::PreferenceSpecifics* pref_specifics = |
58 specifics.mutable_preference(); | 58 specifics.mutable_preference(); |
59 pref_specifics->set_name(name); | 59 pref_specifics->set_name(name); |
60 pref_specifics->set_value(serialized_value); | 60 pref_specifics->set_value(serialized_value); |
61 | 61 |
62 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( | 62 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( |
63 ++next_sync_data_id_, | 63 ++next_sync_data_id_, |
64 specifics, | 64 specifics, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 173 |
174 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, | 174 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, |
175 IgnoreLocalChangesToManagedPrefs) { | 175 IgnoreLocalChangesToManagedPrefs) { |
176 TestSyncedPrefObserver observer = {}; | 176 TestSyncedPrefObserver observer = {}; |
177 registrar()->Add(prefs::kShowHomeButton, | 177 registrar()->Add(prefs::kShowHomeButton, |
178 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); | 178 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); |
179 | 179 |
180 policy::PolicyMap policies; | 180 policy::PolicyMap policies; |
181 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, | 181 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, |
182 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 182 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
183 base::MakeUnique<base::FundamentalValue>(true), nullptr); | 183 base::MakeUnique<base::Value>(true), nullptr); |
184 UpdateChromePolicy(policies); | 184 UpdateChromePolicy(policies); |
185 | 185 |
186 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); | 186 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); |
187 | 187 |
188 SetBooleanPrefValueFromLocal(prefs::kShowHomeButton, false); | 188 SetBooleanPrefValueFromLocal(prefs::kShowHomeButton, false); |
189 EXPECT_FALSE(observer.has_been_notified); | 189 EXPECT_FALSE(observer.has_been_notified); |
190 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); | 190 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); |
191 } | 191 } |
192 | 192 |
193 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, | 193 IN_PROC_BROWSER_TEST_F(SyncedPrefChangeRegistrarTest, |
194 IgnoreSyncChangesToManagedPrefs) { | 194 IgnoreSyncChangesToManagedPrefs) { |
195 TestSyncedPrefObserver observer = {}; | 195 TestSyncedPrefObserver observer = {}; |
196 registrar()->Add(prefs::kShowHomeButton, | 196 registrar()->Add(prefs::kShowHomeButton, |
197 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); | 197 base::Bind(&TestPrefChangeCallback, prefs(), &observer)); |
198 | 198 |
199 policy::PolicyMap policies; | 199 policy::PolicyMap policies; |
200 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, | 200 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, |
201 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, | 201 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, |
202 base::MakeUnique<base::FundamentalValue>(true), nullptr); | 202 base::MakeUnique<base::Value>(true), nullptr); |
203 UpdateChromePolicy(policies); | 203 UpdateChromePolicy(policies); |
204 | 204 |
205 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); | 205 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); |
206 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); | 206 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); |
207 EXPECT_FALSE(observer.has_been_notified); | 207 EXPECT_FALSE(observer.has_been_notified); |
208 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); | 208 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); |
209 } | 209 } |
OLD | NEW |