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

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

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 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/strings/string_piece.h" 15 #include "base/strings/string_piece.h"
16 #include "chrome/browser/invalidation_service_factory.h"
16 #include "chrome/browser/prefs/pref_model_associator.h" 17 #include "chrome/browser/prefs/pref_model_associator.h"
17 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/browser/signin/signin_manager.h" 19 #include "chrome/browser/signin/signin_manager.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 20 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/browser/signin/token_service_factory.h" 21 #include "chrome/browser/signin/token_service_factory.h"
21 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 22 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
22 #include "chrome/browser/sync/glue/generic_change_processor.h" 23 #include "chrome/browser/sync/glue/generic_change_processor.h"
23 #include "chrome/browser/sync/glue/sync_backend_host.h" 24 #include "chrome/browser/sync/glue/sync_backend_host.h"
24 #include "chrome/browser/sync/glue/ui_data_type_controller.h" 25 #include "chrome/browser/sync/glue/ui_data_type_controller.h"
25 #include "chrome/browser/sync/profile_sync_service_factory.h" 26 #include "chrome/browser/sync/profile_sync_service_factory.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 example_url1_("http://example.com/1"), 116 example_url1_("http://example.com/1"),
116 example_url2_("http://example.com/2"), 117 example_url2_("http://example.com/2"),
117 not_synced_preference_name_("nonsense_pref_name"), 118 not_synced_preference_name_("nonsense_pref_name"),
118 not_synced_preference_default_value_("default"), 119 not_synced_preference_default_value_("default"),
119 non_default_charset_value_("foo") {} 120 non_default_charset_value_("foo") {}
120 121
121 virtual void SetUp() { 122 virtual void SetUp() {
122 AbstractProfileSyncServiceTest::SetUp(); 123 AbstractProfileSyncServiceTest::SetUp();
123 profile_.reset(new TestingProfile()); 124 profile_.reset(new TestingProfile());
124 profile_->CreateRequestContext(); 125 profile_->CreateRequestContext();
126 InvalidationServiceFactory::GetInstance()->SetTestingFactory(
127 profile_.get(),
128 InvalidationServiceFactory::BuildTestServiceInstanceFor);
125 prefs_ = profile_->GetTestingPrefService(); 129 prefs_ = profile_->GetTestingPrefService();
126 130
127 prefs_->registry()->RegisterStringPref( 131 prefs_->registry()->RegisterStringPref(
128 not_synced_preference_name_.c_str(), 132 not_synced_preference_name_.c_str(),
129 not_synced_preference_default_value_, 133 not_synced_preference_default_value_,
130 PrefRegistrySyncable::UNSYNCABLE_PREF); 134 PrefRegistrySyncable::UNSYNCABLE_PREF);
131 } 135 }
132 136
133 virtual void TearDown() { 137 virtual void TearDown() {
134 profile_.reset(); 138 profile_.reset();
135 AbstractProfileSyncServiceTest::TearDown(); 139 AbstractProfileSyncServiceTest::TearDown();
136 } 140 }
137 141
138 int GetSyncPreferenceCount() { 142 int GetSyncPreferenceCount() {
139 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare()); 143 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
140 syncer::ReadNode node(&trans); 144 syncer::ReadNode node(&trans);
141 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::PREFERENCES)) != 145 if (node.InitByTagLookup(syncer::ModelTypeToRootTag(syncer::PREFERENCES)) !=
142 syncer::BaseNode::INIT_OK) 146 syncer::BaseNode::INIT_OK)
143 return 0; 147 return 0;
144 return node.GetTotalNodeCount() - 1; 148 return node.GetTotalNodeCount() - 1;
145 } 149 }
146 150
147 bool StartSyncService(const base::Closure& callback, 151 bool StartSyncService(const base::Closure& callback,
148 bool will_fail_association) { 152 bool will_fail_association) {
149 if (sync_service_) 153 if (sync_service_)
150 return false; 154 return false;
151 155
152 SigninManager* signin = SigninManagerFactory::GetForProfile(profile_.get()); 156 SigninManager* signin =
157 SigninManagerFactory::GetForProfile(profile_.get());
153 signin->SetAuthenticatedUsername("test"); 158 signin->SetAuthenticatedUsername("test");
154 sync_service_ = static_cast<TestProfileSyncService*>( 159 sync_service_ = static_cast<TestProfileSyncService*>(
155 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse( 160 ProfileSyncServiceFactory::GetInstance()->SetTestingFactoryAndUse(
156 profile_.get(), &TestProfileSyncService::BuildAutoStartAsyncInit)); 161 profile_.get(), &TestProfileSyncService::BuildAutoStartAsyncInit));
157 sync_service_->set_backend_init_callback(callback); 162 sync_service_->set_backend_init_callback(callback);
158 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>( 163 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>(
159 prefs_->GetSyncableService(syncer::PREFERENCES)); 164 prefs_->GetSyncableService(syncer::PREFERENCES));
160 if (!pref_sync_service_) 165 if (!pref_sync_service_)
161 return false; 166 return false;
162 ProfileSyncComponentsFactoryMock* components = 167 ProfileSyncComponentsFactoryMock* components =
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 EXPECT_FALSE(pref->IsDefaultValue()); 681 EXPECT_FALSE(pref->IsDefaultValue());
677 // There should be no synced value. 682 // There should be no synced value.
678 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); 683 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL);
679 // Switch kHomePage back to unmanaged. 684 // Switch kHomePage back to unmanaged.
680 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage); 685 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage);
681 // The original value should be picked up. 686 // The original value should be picked up.
682 EXPECT_TRUE(pref->IsDefaultValue()); 687 EXPECT_TRUE(pref->IsDefaultValue());
683 // There should still be no synced value. 688 // There should still be no synced value.
684 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL); 689 EXPECT_TRUE(GetSyncedValue(prefs::kHomePage) == NULL);
685 } 690 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698