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

Side by Side Diff: components/syncable_prefs/pref_service_syncable_unittest.cc

Issue 2078893002: Add callback list to PrefModelAssociator after sync data is loaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_domain_scoped_settings
Patch Set: minor change Created 4 years, 5 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
« no previous file with comments | « components/syncable_prefs/pref_service_syncable.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/syncable_prefs/pref_service_syncable.h" 5 #include "components/syncable_prefs/pref_service_syncable.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 28 matching lines...) Expand all
39 const char kExampleUrl1[] = "http://example.com/1"; 39 const char kExampleUrl1[] = "http://example.com/1";
40 const char kExampleUrl2[] = "http://example.com/2"; 40 const char kExampleUrl2[] = "http://example.com/2";
41 const char kStringPrefName[] = "string_pref_name"; 41 const char kStringPrefName[] = "string_pref_name";
42 const char kListPrefName[] = "list_pref_name"; 42 const char kListPrefName[] = "list_pref_name";
43 const char kUnsyncedPreferenceName[] = "nonsense_pref_name"; 43 const char kUnsyncedPreferenceName[] = "nonsense_pref_name";
44 const char kUnsyncedPreferenceDefaultValue[] = "default"; 44 const char kUnsyncedPreferenceDefaultValue[] = "default";
45 const char kDefaultCharsetPrefName[] = "default_charset"; 45 const char kDefaultCharsetPrefName[] = "default_charset";
46 const char kNonDefaultCharsetValue[] = "foo"; 46 const char kNonDefaultCharsetValue[] = "foo";
47 const char kDefaultCharsetValue[] = "utf-8"; 47 const char kDefaultCharsetValue[] = "utf-8";
48 48
49 void Increment(int* num) {
50 (*num)++;
51 }
52
49 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient { 53 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient {
50 public: 54 public:
51 TestPrefModelAssociatorClient() {} 55 TestPrefModelAssociatorClient() {}
52 ~TestPrefModelAssociatorClient() override {} 56 ~TestPrefModelAssociatorClient() override {}
53 57
54 // PrefModelAssociatorClient implementation. 58 // PrefModelAssociatorClient implementation.
55 bool IsMergeableListPreference(const std::string& pref_name) const override { 59 bool IsMergeableListPreference(const std::string& pref_name) const override {
56 return pref_name == kListPrefName; 60 return pref_name == kListPrefName;
57 } 61 }
58 62
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 kListPrefName, 118 kListPrefName,
115 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 119 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
116 prefs_.registry()->RegisterStringPref( 120 prefs_.registry()->RegisterStringPref(
117 kDefaultCharsetPrefName, 121 kDefaultCharsetPrefName,
118 kDefaultCharsetValue, 122 kDefaultCharsetValue,
119 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 123 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
120 124
121 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>( 125 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>(
122 prefs_.GetSyncableService(syncer::PREFERENCES)); 126 prefs_.GetSyncableService(syncer::PREFERENCES));
123 ASSERT_TRUE(pref_sync_service_); 127 ASSERT_TRUE(pref_sync_service_);
124 next_pref_remote_sync_node_id_ = 0;
125 } 128 }
126 129
127 syncer::SyncChange MakeRemoteChange(int64_t id, 130 syncer::SyncChange MakeRemoteChange(int64_t id,
128 const std::string& name, 131 const std::string& name,
129 const base::Value& value, 132 const base::Value& value,
130 SyncChange::SyncChangeType type) { 133 SyncChange::SyncChangeType type) {
131 std::string serialized; 134 std::string serialized;
132 JSONStringValueSerializer json(&serialized); 135 JSONStringValueSerializer json(&serialized);
133 if (!json.Serialize(value)) 136 if (!json.Serialize(value))
134 return syncer::SyncChange(); 137 return syncer::SyncChange();
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 InitWithNoSyncData(); 551 InitWithNoSyncData();
549 552
550 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); 553 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
551 syncer::SyncChangeList list; 554 syncer::SyncChangeList list;
552 list.push_back(MakeRemoteChange( 555 list.push_back(MakeRemoteChange(
553 1, kStringPrefName, *null_value, SyncChange::ACTION_DELETE)); 556 1, kStringPrefName, *null_value, SyncChange::ACTION_DELETE));
554 pref_sync_service_->ProcessSyncChanges(FROM_HERE, list); 557 pref_sync_service_->ProcessSyncChanges(FROM_HERE, list);
555 EXPECT_TRUE(pref->IsDefaultValue()); 558 EXPECT_TRUE(pref->IsDefaultValue());
556 } 559 }
557 560
561 TEST_F(PrefServiceSyncableTest, RegisterMergeDataFinishedCallback) {
562 int num_callbacks = 0;
563
564 prefs_.RegisterMergeDataFinishedCallback(
565 base::Bind(&Increment, &num_callbacks));
566 EXPECT_EQ(0, num_callbacks);
567
568 InitWithNoSyncData();
569 EXPECT_EQ(1, num_callbacks);
570 }
571
558 } // namespace 572 } // namespace
559 573
560 } // namespace syncable_prefs 574 } // namespace syncable_prefs
OLDNEW
« no previous file with comments | « components/syncable_prefs/pref_service_syncable.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698