| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/task.h" | 10 #include "base/task.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 std::string ValueString(const Value& value) { | 166 std::string ValueString(const Value& value) { |
| 167 std::string serialized; | 167 std::string serialized; |
| 168 JSONStringValueSerializer json(&serialized); | 168 JSONStringValueSerializer json(&serialized); |
| 169 json.Serialize(value); | 169 json.Serialize(value); |
| 170 return serialized; | 170 return serialized; |
| 171 } | 171 } |
| 172 | 172 |
| 173 friend class AddPreferenceEntriesTask; | 173 friend class AddPreferenceEntriesTask; |
| 174 | 174 |
| 175 scoped_ptr<TestingProfile> profile_; | 175 scoped_ptr<TestingProfile> profile_; |
| 176 PrefService* prefs_; | 176 TestingPrefService* prefs_; |
| 177 | 177 |
| 178 PreferenceModelAssociator* model_associator_; | 178 PreferenceModelAssociator* model_associator_; |
| 179 PreferenceChangeProcessor* change_processor_; | 179 PreferenceChangeProcessor* change_processor_; |
| 180 std::string example_url0_; | 180 std::string example_url0_; |
| 181 std::string example_url1_; | 181 std::string example_url1_; |
| 182 std::string example_url2_; | 182 std::string example_url2_; |
| 183 std::wstring not_synced_preference_name_; | 183 std::wstring not_synced_preference_name_; |
| 184 std::string not_synced_preference_default_value_; | 184 std::string not_synced_preference_default_value_; |
| 185 std::string non_default_charset_value_; | 185 std::string non_default_charset_value_; |
| 186 }; | 186 }; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 record->action = SyncManager::ChangeRecord::ACTION_ADD; | 404 record->action = SyncManager::ChangeRecord::ACTION_ADD; |
| 405 record->id = node_id; | 405 record->id = node_id; |
| 406 { | 406 { |
| 407 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); | 407 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
| 408 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); | 408 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 409 } | 409 } |
| 410 | 410 |
| 411 // Nothing interesting happens on the client when it gets an update | 411 // Nothing interesting happens on the client when it gets an update |
| 412 // of an unknown preference. We just should not crash. | 412 // of an unknown preference. We just should not crash. |
| 413 } | 413 } |
| 414 |
| 415 TEST_F(ProfileSyncServicePreferenceTest, ManagedPreferences) { |
| 416 // Make the homepage preference managed. |
| 417 scoped_ptr<Value> managed_value( |
| 418 Value::CreateStringValue(L"http://example.com")); |
| 419 prefs_->SetManagedPref(prefs::kHomePage, managed_value->DeepCopy()); |
| 420 |
| 421 CreateRootTask task(this, syncable::PREFERENCES); |
| 422 ASSERT_TRUE(StartSyncService(&task, false)); |
| 423 ASSERT_TRUE(task.success()); |
| 424 |
| 425 // Changing the homepage preference should not sync anything. |
| 426 scoped_ptr<Value> user_value( |
| 427 Value::CreateStringValue(L"http://chromium..com")); |
| 428 prefs_->SetUserPref(prefs::kHomePage, user_value->DeepCopy()); |
| 429 EXPECT_EQ(NULL, GetSyncedValue(prefs::kHomePage)); |
| 430 |
| 431 // An incoming sync transaction shouldn't change the user value. |
| 432 scoped_ptr<Value> sync_value( |
| 433 Value::CreateStringValue(L"http://crbug.com")); |
| 434 int64 node_id = SetSyncedValue(prefs::kHomePage, *sync_value); |
| 435 ASSERT_NE(node_id, sync_api::kInvalidId); |
| 436 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); |
| 437 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; |
| 438 record->id = node_id; |
| 439 { |
| 440 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); |
| 441 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); |
| 442 } |
| 443 EXPECT_TRUE(managed_value->Equals(prefs_->GetManagedPref(prefs::kHomePage))); |
| 444 EXPECT_TRUE(user_value->Equals(prefs_->GetUserPref(prefs::kHomePage))); |
| 445 } |
| OLD | NEW |