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

Side by Side Diff: chrome/browser/sync/profile_sync_service_preference_unittest.cc

Issue 9395058: [Sync] Remove SyncableServiceAdapter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 months 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 | Annotate | Revision Log
OLDNEW
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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_string_value_serializer.h" 12 #include "base/json/json_string_value_serializer.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/string_piece.h" 15 #include "base/string_piece.h"
16 #include "chrome/browser/prefs/pref_model_associator.h" 16 #include "chrome/browser/prefs/pref_model_associator.h"
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" 17 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/signin/signin_manager.h" 18 #include "chrome/browser/signin/signin_manager.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 19 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/signin/token_service.h" 20 #include "chrome/browser/signin/token_service.h"
21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
22 #include "chrome/browser/sync/api/sync_data.h" 22 #include "chrome/browser/sync/api/sync_data.h"
23 #include "chrome/browser/sync/glue/generic_change_processor.h" 23 #include "chrome/browser/sync/glue/generic_change_processor.h"
24 #include "chrome/browser/sync/glue/preference_data_type_controller.h" 24 #include "chrome/browser/sync/glue/ui_data_type_controller.h"
25 #include "chrome/browser/sync/glue/syncable_service_adapter.h"
26 #include "chrome/browser/sync/glue/sync_backend_host.h" 25 #include "chrome/browser/sync/glue/sync_backend_host.h"
27 #include "chrome/browser/sync/internal_api/change_record.h" 26 #include "chrome/browser/sync/internal_api/change_record.h"
28 #include "chrome/browser/sync/internal_api/read_node.h" 27 #include "chrome/browser/sync/internal_api/read_node.h"
29 #include "chrome/browser/sync/internal_api/read_transaction.h" 28 #include "chrome/browser/sync/internal_api/read_transaction.h"
30 #include "chrome/browser/sync/internal_api/write_node.h" 29 #include "chrome/browser/sync/internal_api/write_node.h"
31 #include "chrome/browser/sync/internal_api/write_transaction.h" 30 #include "chrome/browser/sync/internal_api/write_transaction.h"
32 #include "chrome/browser/sync/profile_sync_test_util.h" 31 #include "chrome/browser/sync/profile_sync_test_util.h"
33 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" 32 #include "chrome/browser/sync/protocol/preference_specifics.pb.h"
34 #include "chrome/browser/sync/syncable/model_type.h" 33 #include "chrome/browser/sync/syncable/model_type.h"
35 #include "chrome/browser/sync/test_profile_sync_service.h" 34 #include "chrome/browser/sync/test_profile_sync_service.h"
36 #include "chrome/common/net/gaia/gaia_constants.h" 35 #include "chrome/common/net/gaia/gaia_constants.h"
37 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
38 #include "chrome/test/base/testing_pref_service.h" 37 #include "chrome/test/base/testing_pref_service.h"
39 #include "chrome/test/base/testing_profile.h" 38 #include "chrome/test/base/testing_profile.h"
40 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
42 41
43 using base::JSONReader; 42 using base::JSONReader;
44 using browser_sync::GenericChangeProcessor; 43 using browser_sync::GenericChangeProcessor;
45 using browser_sync::PreferenceDataTypeController; 44 using browser_sync::UIDataTypeController;
46 using browser_sync::SyncBackendHost; 45 using browser_sync::SyncBackendHost;
47 using browser_sync::SyncableServiceAdapter;
48 using sync_api::ChangeRecord; 46 using sync_api::ChangeRecord;
49 using testing::_; 47 using testing::_;
50 using testing::Invoke; 48 using testing::Invoke;
51 using testing::Return; 49 using testing::Return;
52 50
53 typedef std::map<const std::string, const Value*> PreferenceValues; 51 typedef std::map<const std::string, const Value*> PreferenceValues;
54 52
55 ACTION_P5(BuildPrefSyncComponents, profile_sync_service, pref_sync_service, 53 ACTION_P(CreateAndSaveChangeProcessor, change_processor) {
56 data_type_controller, model_associator_ptr, change_processor_ptr) { 54 sync_api::UserShare* user_share = arg0->GetUserShare();
57 sync_api::UserShare* user_share = profile_sync_service->GetUserShare(); 55 *change_processor = new GenericChangeProcessor(arg1, arg2, user_share);
58 *change_processor_ptr = new GenericChangeProcessor( 56 return *change_processor;
59 data_type_controller,
60 pref_sync_service->AsWeakPtr(),
61 user_share);
62 *model_associator_ptr = new browser_sync::SyncableServiceAdapter(
63 syncable::PREFERENCES,
64 pref_sync_service,
65 *change_processor_ptr);
66 return ProfileSyncComponentsFactory::SyncComponents(*model_associator_ptr,
67 *change_processor_ptr);
68 } 57 }
69 58
70 // TODO(zea): Refactor to remove the ProfileSyncService usage. 59 // TODO(zea): Refactor to remove the ProfileSyncService usage.
71 class ProfileSyncServicePreferenceTest 60 class ProfileSyncServicePreferenceTest
72 : public AbstractProfileSyncServiceTest { 61 : public AbstractProfileSyncServiceTest {
73 public: 62 public:
74 int64 SetSyncedValue(const std::string& name, const Value& value) { 63 int64 SetSyncedValue(const std::string& name, const Value& value) {
75 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare()); 64 sync_api::WriteTransaction trans(FROM_HERE, service_->GetUserShare());
76 sync_api::ReadNode root(&trans); 65 sync_api::ReadNode root(&trans);
77 if (!root.InitByTagLookup( 66 if (!root.InitByTagLookup(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 factory, 118 factory,
130 profile_.get(), 119 profile_.get(),
131 signin, 120 signin,
132 ProfileSyncService::AUTO_START, 121 ProfileSyncService::AUTO_START,
133 false, 122 false,
134 callback)); 123 callback));
135 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>( 124 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>(
136 prefs_->GetSyncableService()); 125 prefs_->GetSyncableService());
137 if (!pref_sync_service_) 126 if (!pref_sync_service_)
138 return false; 127 return false;
139 128 EXPECT_CALL(*factory, GetSyncableServiceForType(syncable::PREFERENCES)).
140 dtc_ = new PreferenceDataTypeController(factory, 129 WillOnce(Return(pref_sync_service_->AsWeakPtr()));
141 profile_.get(),
142 service_.get());
143
144 EXPECT_CALL(*factory, CreatePreferenceSyncComponents(_, _)).
145 WillOnce(BuildPrefSyncComponents(service_.get(),
146 pref_sync_service_,
147 dtc_,
148 &model_associator_,
149 &change_processor_));
150 130
151 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)). 131 EXPECT_CALL(*factory, CreateDataTypeManager(_, _)).
152 WillOnce(ReturnNewDataTypeManager()); 132 WillOnce(ReturnNewDataTypeManager());
153 133 dtc_ = new UIDataTypeController(syncable::PREFERENCES,
154 134 factory,
135 profile_.get(),
136 service_.get());
137 EXPECT_CALL(*factory, CreateGenericChangeProcessor(_, _, _)).
138 WillOnce(CreateAndSaveChangeProcessor(&change_processor_));
155 service_->RegisterDataTypeController(dtc_); 139 service_->RegisterDataTypeController(dtc_);
156 profile_->GetTokenService()->IssueAuthTokenForTest( 140 profile_->GetTokenService()->IssueAuthTokenForTest(
157 GaiaConstants::kSyncService, "token"); 141 GaiaConstants::kSyncService, "token");
158 142
159 service_->Initialize(); 143 service_->Initialize();
160 MessageLoop::current()->Run(); 144 MessageLoop::current()->Run();
161 return true; 145 return true;
162 } 146 }
163 147
164 const Value& GetPreferenceValue(const std::string& name) { 148 const Value& GetPreferenceValue(const std::string& name) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 std::string ValueString(const Value& value) { 186 std::string ValueString(const Value& value) {
203 std::string serialized; 187 std::string serialized;
204 JSONStringValueSerializer json(&serialized); 188 JSONStringValueSerializer json(&serialized);
205 json.Serialize(value); 189 json.Serialize(value);
206 return serialized; 190 return serialized;
207 } 191 }
208 192
209 scoped_ptr<TestingProfile> profile_; 193 scoped_ptr<TestingProfile> profile_;
210 TestingPrefService* prefs_; 194 TestingPrefService* prefs_;
211 195
212 PreferenceDataTypeController* dtc_; 196 UIDataTypeController* dtc_;
213 PrefModelAssociator* pref_sync_service_; 197 PrefModelAssociator* pref_sync_service_;
214 SyncableServiceAdapter* model_associator_;
215 GenericChangeProcessor* change_processor_; 198 GenericChangeProcessor* change_processor_;
216 199
217 std::string example_url0_; 200 std::string example_url0_;
218 std::string example_url1_; 201 std::string example_url1_;
219 std::string example_url2_; 202 std::string example_url2_;
220 std::string not_synced_preference_name_; 203 std::string not_synced_preference_name_;
221 std::string not_synced_preference_default_value_; 204 std::string not_synced_preference_default_value_;
222 std::string non_default_charset_value_; 205 std::string non_default_charset_value_;
223 }; 206 };
224 207
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 EXPECT_FALSE(pref->IsDefaultValue()); 568 EXPECT_FALSE(pref->IsDefaultValue());
586 // There should be no synced value. 569 // There should be no synced value.
587 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); 570 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL);
588 // Switch kHomePage back to unmanaged. 571 // Switch kHomePage back to unmanaged.
589 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); 572 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage);
590 // The original value should be picked up. 573 // The original value should be picked up.
591 EXPECT_TRUE(pref->IsDefaultValue()); 574 EXPECT_TRUE(pref->IsDefaultValue());
592 // There should still be no synced value. 575 // There should still be no synced value.
593 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); 576 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL);
594 } 577 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_autofill_unittest.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698