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

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

Issue 3129007: FBTF: Forward declare everything possible in testing_profile.h (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: argh mac problems now Created 10 years, 4 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
OLDNEW
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/string_piece.h" 10 #include "base/string_piece.h"
11 #include "base/task.h" 11 #include "base/task.h"
12 #include "chrome/browser/sync/abstract_profile_sync_service_test.h" 12 #include "chrome/browser/sync/abstract_profile_sync_service_test.h"
13 #include "chrome/browser/sync/engine/syncapi.h" 13 #include "chrome/browser/sync/engine/syncapi.h"
14 #include "chrome/browser/sync/glue/preference_change_processor.h" 14 #include "chrome/browser/sync/glue/preference_change_processor.h"
15 #include "chrome/browser/sync/glue/preference_data_type_controller.h" 15 #include "chrome/browser/sync/glue/preference_data_type_controller.h"
16 #include "chrome/browser/sync/glue/preference_model_associator.h" 16 #include "chrome/browser/sync/glue/preference_model_associator.h"
17 #include "chrome/browser/sync/glue/sync_backend_host.h" 17 #include "chrome/browser/sync/glue/sync_backend_host.h"
18 #include "chrome/browser/sync/profile_sync_test_util.h" 18 #include "chrome/browser/sync/profile_sync_test_util.h"
19 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" 19 #include "chrome/browser/sync/protocol/preference_specifics.pb.h"
20 #include "chrome/browser/sync/syncable/model_type.h" 20 #include "chrome/browser/sync/syncable/model_type.h"
21 #include "chrome/browser/sync/test_profile_sync_service.h" 21 #include "chrome/browser/sync/test_profile_sync_service.h"
22 #include "chrome/common/json_value_serializer.h" 22 #include "chrome/common/json_value_serializer.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/testing_pref_service.h"
24 #include "chrome/test/testing_profile.h" 25 #include "chrome/test/testing_profile.h"
25 #include "testing/gmock/include/gmock/gmock.h" 26 #include "testing/gmock/include/gmock/gmock.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using base::JSONReader; 29 using base::JSONReader;
29 using browser_sync::PreferenceChangeProcessor; 30 using browser_sync::PreferenceChangeProcessor;
30 using browser_sync::PreferenceDataTypeController; 31 using browser_sync::PreferenceDataTypeController;
31 using browser_sync::PreferenceModelAssociator; 32 using browser_sync::PreferenceModelAssociator;
32 using browser_sync::SyncBackendHost; 33 using browser_sync::SyncBackendHost;
33 using sync_api::SyncManager; 34 using sync_api::SyncManager;
34 using testing::_; 35 using testing::_;
35 using testing::Return; 36 using testing::Return;
36 37
37 typedef std::map<const std::string, const Value*> PreferenceValues; 38 typedef std::map<const std::string, const Value*> PreferenceValues;
38 39
39 class ProfileSyncServicePreferenceTest 40 class ProfileSyncServicePreferenceTest
40 : public AbstractProfileSyncServiceTest { 41 : public AbstractProfileSyncServiceTest {
41 protected: 42 protected:
42 ProfileSyncServicePreferenceTest() 43 ProfileSyncServicePreferenceTest()
43 : example_url0_("http://example.com/0"), 44 : example_url0_("http://example.com/0"),
44 example_url1_("http://example.com/1"), 45 example_url1_("http://example.com/1"),
45 example_url2_("http://example.com/2"), 46 example_url2_("http://example.com/2"),
46 not_synced_preference_name_("nonsense_pref_name"), 47 not_synced_preference_name_("nonsense_pref_name"),
47 not_synced_preference_default_value_("default"), 48 not_synced_preference_default_value_("default"),
48 non_default_charset_value_("foo") {} 49 non_default_charset_value_("foo") {}
49 50
50 virtual void SetUp() { 51 virtual void SetUp() {
51 profile_.reset(new TestingProfile()); 52 profile_.reset(new TestingProfile());
52 profile_->set_has_history_service(true); 53 profile_->set_has_history_service(true);
53 prefs_ = profile_->GetPrefs(); 54 prefs_ = profile_->GetTestingPrefService();
54 55
55 prefs_->RegisterStringPref(not_synced_preference_name_.c_str(), 56 prefs_->RegisterStringPref(not_synced_preference_name_.c_str(),
56 not_synced_preference_default_value_); 57 not_synced_preference_default_value_);
57 } 58 }
58 59
59 virtual void TearDown() { 60 virtual void TearDown() {
60 service_.reset(); 61 service_.reset();
61 profile_.reset(); 62 profile_.reset();
62 MessageLoop::current()->RunAllPending(); 63 MessageLoop::current()->RunAllPending();
63 } 64 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 450
450 scoped_ptr<Value> initial_value( 451 scoped_ptr<Value> initial_value(
451 Value::CreateStringValue("http://example.com/initial")); 452 Value::CreateStringValue("http://example.com/initial"));
452 profile_->GetPrefs()->Set(prefs::kHomePage, *initial_value); 453 profile_->GetPrefs()->Set(prefs::kHomePage, *initial_value);
453 scoped_ptr<const Value> actual(GetSyncedValue(prefs::kHomePage)); 454 scoped_ptr<const Value> actual(GetSyncedValue(prefs::kHomePage));
454 EXPECT_TRUE(initial_value->Equals(actual.get())); 455 EXPECT_TRUE(initial_value->Equals(actual.get()));
455 456
456 // Switch kHomePage to managed and set a different value. 457 // Switch kHomePage to managed and set a different value.
457 scoped_ptr<Value> managed_value( 458 scoped_ptr<Value> managed_value(
458 Value::CreateStringValue("http://example.com/managed")); 459 Value::CreateStringValue("http://example.com/managed"));
459 profile_->GetPrefs()->SetManagedPref(prefs::kHomePage, 460 profile_->GetTestingPrefService()->SetManagedPref(
460 managed_value->DeepCopy()); 461 prefs::kHomePage, managed_value->DeepCopy());
461 462
462 // Sync node should be gone. 463 // Sync node should be gone.
463 EXPECT_EQ(sync_api::kInvalidId, 464 EXPECT_EQ(sync_api::kInvalidId,
464 model_associator_->GetSyncIdFromChromeId(prefs::kHomePage)); 465 model_associator_->GetSyncIdFromChromeId(prefs::kHomePage));
465 466
466 // Change the sync value. 467 // Change the sync value.
467 scoped_ptr<Value> sync_value( 468 scoped_ptr<Value> sync_value(
468 Value::CreateStringValue("http://example.com/sync")); 469 Value::CreateStringValue("http://example.com/sync"));
469 int64 node_id = SetSyncedValue(prefs::kHomePage, *sync_value); 470 int64 node_id = SetSyncedValue(prefs::kHomePage, *sync_value);
470 ASSERT_NE(node_id, sync_api::kInvalidId); 471 ASSERT_NE(node_id, sync_api::kInvalidId);
471 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); 472 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord);
472 record->action = SyncManager::ChangeRecord::ACTION_ADD; 473 record->action = SyncManager::ChangeRecord::ACTION_ADD;
473 record->id = node_id; 474 record->id = node_id;
474 { 475 {
475 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); 476 sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
476 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 477 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
477 } 478 }
478 479
479 // The pref value should still be the one dictated by policy. 480 // The pref value should still be the one dictated by policy.
480 EXPECT_TRUE(managed_value->Equals(&GetPreferenceValue(prefs::kHomePage))); 481 EXPECT_TRUE(managed_value->Equals(&GetPreferenceValue(prefs::kHomePage)));
481 482
482 // Switch kHomePage back to unmanaged. 483 // Switch kHomePage back to unmanaged.
483 profile_->GetPrefs()->RemoveManagedPref(prefs::kHomePage); 484 profile_->GetTestingPrefService()->RemoveManagedPref(prefs::kHomePage);
484 485
485 // Sync value should be picked up. 486 // Sync value should be picked up.
486 EXPECT_TRUE(sync_value->Equals(&GetPreferenceValue(prefs::kHomePage))); 487 EXPECT_TRUE(sync_value->Equals(&GetPreferenceValue(prefs::kHomePage)));
487 } 488 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698