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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host_unittest.cc

Issue 6764024: [Sync] Fix ConfigureDataTypes bug that leads to extra nudge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/glue/sync_backend_host.h"
6
7 #include <cstddef>
8
9 #include "base/message_loop.h"
10 #include "base/scoped_ptr.h"
11 #include "chrome/browser/sync/engine/model_safe_worker.h"
12 #include "chrome/browser/sync/engine/syncapi.h"
13 #include "chrome/browser/sync/glue/data_type_controller.h"
14 #include "chrome/browser/sync/syncable/model_type.h"
15 #include "chrome/test/testing_profile.h"
16 #include "content/browser/browser_thread.h"
17 #include "googleurl/src/gurl.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 // TODO(akalin): Remove this once we fix the TODO below.
22 #include "chrome/browser/prefs/pref_service.h"
23 #include "chrome/common/pref_names.h"
24
25 namespace browser_sync {
26
27 namespace {
28
29 class MockSyncFrontend : public SyncFrontend {
30 public:
31 virtual ~MockSyncFrontend() {}
32
33 MOCK_METHOD0(OnBackendInitialized, void());
34 MOCK_METHOD0(OnSyncCycleCompleted, void());
35 MOCK_METHOD0(OnAuthError, void());
36 MOCK_METHOD0(OnStopSyncingPermanently, void());
37 MOCK_METHOD0(OnClearServerDataSucceeded, void());
38 MOCK_METHOD0(OnClearServerDataFailed, void());
39 MOCK_METHOD1(OnPassphraseRequired, void(bool));
40 MOCK_METHOD0(OnPassphraseAccepted, void());
41 MOCK_METHOD1(OnEncryptionComplete, void(const syncable::ModelTypeSet&));
42 };
43
44 } // namespace
45
46 class SyncBackendHostTest : public testing::Test {
47 protected:
48 SyncBackendHostTest()
49 : ui_thread_(BrowserThread::UI, &ui_loop_) {}
50
51 private:
52 MessageLoop ui_loop_;
53 BrowserThread ui_thread_;
54 };
55
56 TEST_F(SyncBackendHostTest, InitShutdown) {
57 TestingProfile profile;
58 profile.CreateRequestContext();
59
60 SyncBackendHost backend(&profile);
61
62 // TODO(akalin): Handle this in SyncBackendHost instead of in
63 // ProfileSyncService, or maybe figure out a way to share the
64 // "register sync prefs" code.
65 PrefService* pref_service = profile.GetPrefs();
66 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, "");
67
68 MockSyncFrontend mock_frontend;
69 sync_api::SyncCredentials credentials;
70 credentials.email = "user@example.com";
71 credentials.sync_token = "sync_token";
72 backend.Initialize(&mock_frontend,
73 GURL("http://www.example.com"),
74 syncable::ModelTypeSet(),
75 profile.GetRequestContext(),
76 credentials,
77 true);
78 backend.Shutdown(false);
79 }
80
81 TEST_F(SyncBackendHostTest, MakePendingConfigModeState) {
82 // Empty.
83 {
84 DataTypeController::TypeMap data_type_controllers;
85 syncable::ModelTypeSet types;
86 ModelSafeRoutingInfo routing_info;
87
88 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
89 state(SyncBackendHost::MakePendingConfigModeState(
90 data_type_controllers, types, NULL, &routing_info));
91 EXPECT_TRUE(routing_info.empty());
92 EXPECT_FALSE(state->ready_task.get());
93 EXPECT_EQ(types, state->initial_types);
94 EXPECT_FALSE(state->deleted_type);
95 EXPECT_TRUE(state->added_types.none());
96 }
97
98 // No enabled types.
99 {
100 DataTypeController::TypeMap data_type_controllers;
101 data_type_controllers[syncable::BOOKMARKS] = NULL;
102 syncable::ModelTypeSet types;
103 ModelSafeRoutingInfo routing_info;
104
105 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
106 state(SyncBackendHost::MakePendingConfigModeState(
107 data_type_controllers, types, NULL, &routing_info));
108 EXPECT_TRUE(routing_info.empty());
109 EXPECT_FALSE(state->ready_task.get());
110 EXPECT_EQ(types, state->initial_types);
111 EXPECT_FALSE(state->deleted_type);
112 EXPECT_TRUE(state->added_types.none());
113 }
114
115 // Add type.
116 {
117 DataTypeController::TypeMap data_type_controllers;
118 data_type_controllers[syncable::BOOKMARKS] = NULL;
119 syncable::ModelTypeSet types;
120 types.insert(syncable::BOOKMARKS);
121 ModelSafeRoutingInfo routing_info;
122
123 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
124 state(SyncBackendHost::MakePendingConfigModeState(
125 data_type_controllers, types, NULL, &routing_info));
126
127 ModelSafeRoutingInfo expected_routing_info;
128 expected_routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
129 EXPECT_EQ(expected_routing_info, routing_info);
130 EXPECT_FALSE(state->ready_task.get());
131 EXPECT_EQ(types, state->initial_types);
132 EXPECT_FALSE(state->deleted_type);
133
134 syncable::ModelTypeBitSet expected_added_types;
135 expected_added_types.set(syncable::BOOKMARKS);
136 EXPECT_EQ(expected_added_types, state->added_types);
137 }
138
139 // Add existing type.
140 {
141 DataTypeController::TypeMap data_type_controllers;
142 data_type_controllers[syncable::BOOKMARKS] = NULL;
143 syncable::ModelTypeSet types;
144 types.insert(syncable::BOOKMARKS);
145 ModelSafeRoutingInfo routing_info;
146 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
147 ModelSafeRoutingInfo expected_routing_info = routing_info;
148
149 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
150 state(SyncBackendHost::MakePendingConfigModeState(
151 data_type_controllers, types, NULL, &routing_info));
152
153 EXPECT_EQ(expected_routing_info, routing_info);
154 EXPECT_FALSE(state->ready_task.get());
155 EXPECT_EQ(types, state->initial_types);
156 EXPECT_FALSE(state->deleted_type);
157 EXPECT_TRUE(state->added_types.none());
158 }
159
160 // Delete type.
161 {
162 DataTypeController::TypeMap data_type_controllers;
163 data_type_controllers[syncable::BOOKMARKS] = NULL;
164 syncable::ModelTypeSet types;
165 ModelSafeRoutingInfo routing_info;
166 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
167
168 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
169 state(SyncBackendHost::MakePendingConfigModeState(
170 data_type_controllers, types, NULL, &routing_info));
171
172 ModelSafeRoutingInfo expected_routing_info;
173 EXPECT_EQ(expected_routing_info, routing_info);
174 EXPECT_FALSE(state->ready_task.get());
175 EXPECT_EQ(types, state->initial_types);
176 EXPECT_TRUE(state->deleted_type);
177 EXPECT_TRUE(state->added_types.none());
178 }
179 }
180
181 // TODO(akalin): Write more SyncBackendHost unit tests.
182
183 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698