Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(673)

Side by Side Diff: chrome/browser/prefs/synced_pref_change_registrar_browsertest.cc

Issue 2459823002: [Sync] Rename syncable_prefs to sync_preferences. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/prefs/pref_service_syncable_util.h" 12 #include "chrome/browser/prefs/pref_service_syncable_util.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "components/policy/core/browser/browser_policy_connector.h" 17 #include "components/policy/core/browser/browser_policy_connector.h"
18 #include "components/policy/core/common/mock_configuration_policy_provider.h" 18 #include "components/policy/core/common/mock_configuration_policy_provider.h"
19 #include "components/policy/core/common/policy_map.h" 19 #include "components/policy/core/common/policy_map.h"
20 #include "components/policy/core/common/policy_types.h" 20 #include "components/policy/core/common/policy_types.h"
21 #include "components/policy/policy_constants.h" 21 #include "components/policy/policy_constants.h"
22 #include "components/sync/model/attachments/attachment_id.h" 22 #include "components/sync/model/attachments/attachment_id.h"
23 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" 23 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h"
24 #include "components/sync/model/fake_sync_change_processor.h" 24 #include "components/sync/model/fake_sync_change_processor.h"
25 #include "components/sync/model/sync_change.h" 25 #include "components/sync/model/sync_change.h"
26 #include "components/sync/model/sync_error_factory.h" 26 #include "components/sync/model/sync_error_factory.h"
27 #include "components/sync/model/sync_error_factory_mock.h" 27 #include "components/sync/model/sync_error_factory_mock.h"
28 #include "components/sync/model/syncable_service.h" 28 #include "components/sync/model/syncable_service.h"
29 #include "components/sync/protocol/sync.pb.h" 29 #include "components/sync/protocol/sync.pb.h"
30 #include "components/syncable_prefs/synced_pref_change_registrar.h" 30 #include "components/sync_preferences/synced_pref_change_registrar.h"
31 #include "components/syncable_prefs/testing_pref_service_syncable.h" 31 #include "components/sync_preferences/testing_pref_service_syncable.h"
32 #include "content/public/test/test_utils.h" 32 #include "content/public/test/test_utils.h"
33 33
34 namespace { 34 namespace {
35 35
36 using testing::Return; 36 using testing::Return;
37 using testing::_; 37 using testing::_;
38 38
39 class SyncedPrefChangeRegistrarTest : public InProcessBrowserTest { 39 class SyncedPrefChangeRegistrarTest : public InProcessBrowserTest {
40 public: 40 public:
41 SyncedPrefChangeRegistrarTest() : next_sync_data_id_(0) {} 41 SyncedPrefChangeRegistrarTest() : next_sync_data_id_(0) {}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 void SetBooleanPrefValueFromLocal(const std::string& name, bool value) { 77 void SetBooleanPrefValueFromLocal(const std::string& name, bool value) {
78 prefs_->SetBoolean(name.c_str(), value); 78 prefs_->SetBoolean(name.c_str(), value);
79 } 79 }
80 80
81 bool GetBooleanPrefValue(const std::string& name) { 81 bool GetBooleanPrefValue(const std::string& name) {
82 return prefs_->GetBoolean(name.c_str()); 82 return prefs_->GetBoolean(name.c_str());
83 } 83 }
84 84
85 syncable_prefs::PrefServiceSyncable* prefs() const { 85 sync_preferences::PrefServiceSyncable* prefs() const { return prefs_; }
86 return prefs_;
87 }
88 86
89 syncable_prefs::SyncedPrefChangeRegistrar* registrar() const { 87 sync_preferences::SyncedPrefChangeRegistrar* registrar() const {
90 return registrar_.get(); 88 return registrar_.get();
91 } 89 }
92 90
93 private: 91 private:
94 void SetUpInProcessBrowserTestFixture() override { 92 void SetUpInProcessBrowserTestFixture() override {
95 EXPECT_CALL(policy_provider_, IsInitializationComplete(_)) 93 EXPECT_CALL(policy_provider_, IsInitializationComplete(_))
96 .WillRepeatedly(Return(true)); 94 .WillRepeatedly(Return(true));
97 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( 95 policy::BrowserPolicyConnector::SetPolicyProviderForTesting(
98 &policy_provider_); 96 &policy_provider_);
99 } 97 }
100 98
101 void SetUpOnMainThread() override { 99 void SetUpOnMainThread() override {
102 prefs_ = PrefServiceSyncableFromProfile(browser()->profile()); 100 prefs_ = PrefServiceSyncableFromProfile(browser()->profile());
103 syncer_ = prefs_->GetSyncableService(syncer::PREFERENCES); 101 syncer_ = prefs_->GetSyncableService(syncer::PREFERENCES);
104 syncer_->MergeDataAndStartSyncing( 102 syncer_->MergeDataAndStartSyncing(
105 syncer::PREFERENCES, syncer::SyncDataList(), 103 syncer::PREFERENCES, syncer::SyncDataList(),
106 std::unique_ptr<syncer::SyncChangeProcessor>( 104 std::unique_ptr<syncer::SyncChangeProcessor>(
107 new syncer::FakeSyncChangeProcessor), 105 new syncer::FakeSyncChangeProcessor),
108 std::unique_ptr<syncer::SyncErrorFactory>( 106 std::unique_ptr<syncer::SyncErrorFactory>(
109 new syncer::SyncErrorFactoryMock)); 107 new syncer::SyncErrorFactoryMock));
110 registrar_.reset(new syncable_prefs::SyncedPrefChangeRegistrar(prefs_)); 108 registrar_.reset(new sync_preferences::SyncedPrefChangeRegistrar(prefs_));
111 } 109 }
112 110
113 void TearDownOnMainThread() override { registrar_.reset(); } 111 void TearDownOnMainThread() override { registrar_.reset(); }
114 112
115 syncable_prefs::PrefServiceSyncable* prefs_; 113 sync_preferences::PrefServiceSyncable* prefs_;
116 syncer::SyncableService* syncer_; 114 syncer::SyncableService* syncer_;
117 int next_sync_data_id_; 115 int next_sync_data_id_;
118 116
119 std::unique_ptr<syncable_prefs::SyncedPrefChangeRegistrar> registrar_; 117 std::unique_ptr<sync_preferences::SyncedPrefChangeRegistrar> registrar_;
120 policy::MockConfigurationPolicyProvider policy_provider_; 118 policy::MockConfigurationPolicyProvider policy_provider_;
121 }; 119 };
122 120
123 struct TestSyncedPrefObserver { 121 struct TestSyncedPrefObserver {
124 bool last_seen_value; 122 bool last_seen_value;
125 bool last_update_is_from_sync; 123 bool last_update_is_from_sync;
126 bool has_been_notified; 124 bool has_been_notified;
127 }; 125 };
128 126
129 void TestPrefChangeCallback(PrefService* prefs, 127 void TestPrefChangeCallback(PrefService* prefs,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY, 200 policies.Set(policy::key::kShowHomeButton, policy::POLICY_LEVEL_MANDATORY,
203 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD, 201 policy::POLICY_SCOPE_USER, policy::POLICY_SOURCE_CLOUD,
204 base::MakeUnique<base::FundamentalValue>(true), nullptr); 202 base::MakeUnique<base::FundamentalValue>(true), nullptr);
205 UpdateChromePolicy(policies); 203 UpdateChromePolicy(policies);
206 204
207 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton)); 205 EXPECT_TRUE(prefs()->IsManagedPreference(prefs::kShowHomeButton));
208 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false); 206 SetBooleanPrefValueFromSync(prefs::kShowHomeButton, false);
209 EXPECT_FALSE(observer.has_been_notified); 207 EXPECT_FALSE(observer.has_been_notified);
210 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton)); 208 EXPECT_TRUE(GetBooleanPrefValue(prefs::kShowHomeButton));
211 } 209 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698