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

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: revise test 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 int kNumCallbacks = 0;
50 void CallbackFunc(int* num) {
51 (*num)++;
52 }
53
49 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient { 54 class TestPrefModelAssociatorClient : public PrefModelAssociatorClient {
50 public: 55 public:
51 TestPrefModelAssociatorClient() {} 56 TestPrefModelAssociatorClient() {}
52 ~TestPrefModelAssociatorClient() override {} 57 ~TestPrefModelAssociatorClient() override {}
53 58
54 // PrefModelAssociatorClient implementation. 59 // PrefModelAssociatorClient implementation.
55 bool IsMergeableListPreference(const std::string& pref_name) const override { 60 bool IsMergeableListPreference(const std::string& pref_name) const override {
56 return pref_name == kListPrefName; 61 return pref_name == kListPrefName;
57 } 62 }
58 63
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 kListPrefName, 119 kListPrefName,
115 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 120 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
116 prefs_.registry()->RegisterStringPref( 121 prefs_.registry()->RegisterStringPref(
117 kDefaultCharsetPrefName, 122 kDefaultCharsetPrefName,
118 kDefaultCharsetValue, 123 kDefaultCharsetValue,
119 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 124 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
120 125
121 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>( 126 pref_sync_service_ = reinterpret_cast<PrefModelAssociator*>(
122 prefs_.GetSyncableService(syncer::PREFERENCES)); 127 prefs_.GetSyncableService(syncer::PREFERENCES));
123 ASSERT_TRUE(pref_sync_service_); 128 ASSERT_TRUE(pref_sync_service_);
124 next_pref_remote_sync_node_id_ = 0;
125 } 129 }
126 130
127 syncer::SyncChange MakeRemoteChange(int64_t id, 131 syncer::SyncChange MakeRemoteChange(int64_t id,
128 const std::string& name, 132 const std::string& name,
129 const base::Value& value, 133 const base::Value& value,
130 SyncChange::SyncChangeType type) { 134 SyncChange::SyncChangeType type) {
131 std::string serialized; 135 std::string serialized;
132 JSONStringValueSerializer json(&serialized); 136 JSONStringValueSerializer json(&serialized);
133 if (!json.Serialize(value)) 137 if (!json.Serialize(value))
134 return syncer::SyncChange(); 138 return syncer::SyncChange();
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 InitWithNoSyncData(); 552 InitWithNoSyncData();
549 553
550 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue(); 554 std::unique_ptr<base::Value> null_value = base::Value::CreateNullValue();
551 syncer::SyncChangeList list; 555 syncer::SyncChangeList list;
552 list.push_back(MakeRemoteChange( 556 list.push_back(MakeRemoteChange(
553 1, kStringPrefName, *null_value, SyncChange::ACTION_DELETE)); 557 1, kStringPrefName, *null_value, SyncChange::ACTION_DELETE));
554 pref_sync_service_->ProcessSyncChanges(FROM_HERE, list); 558 pref_sync_service_->ProcessSyncChanges(FROM_HERE, list);
555 EXPECT_TRUE(pref->IsDefaultValue()); 559 EXPECT_TRUE(pref->IsDefaultValue());
556 } 560 }
557 561
562 TEST_F(PrefServiceSyncableTest, RegisterMergeDataFinishedCallback) {
563 EXPECT_EQ(0, kNumCallbacks);
564 prefs_.RegisterMergeDataFinishedCallback(
565 base::Bind(&CallbackFunc, &kNumCallbacks));
raymes 2016/07/14 02:58:51 can kNumCallbacks be a local variable?
lshang 2016/07/14 04:10:24 Done.
566 EXPECT_EQ(0, kNumCallbacks);
567 InitWithNoSyncData();
568 EXPECT_EQ(1, kNumCallbacks);
569 }
570
558 } // namespace 571 } // namespace
559 572
560 } // namespace syncable_prefs 573 } // 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