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

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: Add TODO 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 {
tim (not reviewing) 2011/04/05 04:56:01 I've been waiting for MockSyncFrontend day for a v
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.
tim (not reviewing) 2011/04/05 04:56:01 what you lose is the convenience / peace of mind o
akalin 2011/04/05 09:55:45 I'm more concerned with there being a magic incant
64 PrefService* pref_service = profile.GetPrefs();
65 pref_service->RegisterStringPref(prefs::kEncryptionBootstrapToken, "");
66
67 MockSyncFrontend mock_frontend;
68 sync_api::SyncCredentials credentials;
69 credentials.email = "user@example.com";
70 credentials.sync_token = "sync_token";
71 backend.Initialize(&mock_frontend,
72 GURL("http://www.example.com"),
73 syncable::ModelTypeSet(),
74 profile.GetRequestContext(),
75 credentials,
76 true);
77 backend.Shutdown(false);
78 }
79
80 TEST_F(SyncBackendHostTest, GetPendingConfigModeState) {
81 // Empty.
82 {
83 DataTypeController::TypeMap data_type_controllers;
84 syncable::ModelTypeSet types;
85 ModelSafeRoutingInfo routing_info;
86
87 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
88 state(SyncBackendHost::GetPendingConfigModeState(
89 data_type_controllers, types, NULL, &routing_info));
90 EXPECT_TRUE(routing_info.empty());
91 EXPECT_FALSE(state->ready_task.get());
92 EXPECT_EQ(types, state->initial_types);
93 EXPECT_FALSE(state->deleted_type);
94 EXPECT_TRUE(state->added_types.none());
95 }
96
97 // No enabled types.
98 {
99 DataTypeController::TypeMap data_type_controllers;
100 data_type_controllers[syncable::BOOKMARKS] = NULL;
101 syncable::ModelTypeSet types;
102 ModelSafeRoutingInfo routing_info;
103
104 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
105 state(SyncBackendHost::GetPendingConfigModeState(
106 data_type_controllers, types, NULL, &routing_info));
107 EXPECT_TRUE(routing_info.empty());
108 EXPECT_FALSE(state->ready_task.get());
109 EXPECT_EQ(types, state->initial_types);
110 EXPECT_FALSE(state->deleted_type);
111 EXPECT_TRUE(state->added_types.none());
112 }
113
114 // Add type.
115 {
116 DataTypeController::TypeMap data_type_controllers;
117 data_type_controllers[syncable::BOOKMARKS] = NULL;
118 syncable::ModelTypeSet types;
119 types.insert(syncable::BOOKMARKS);
120 ModelSafeRoutingInfo routing_info;
121
122 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
123 state(SyncBackendHost::GetPendingConfigModeState(
124 data_type_controllers, types, NULL, &routing_info));
125
126 ModelSafeRoutingInfo expected_routing_info;
127 expected_routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
128 EXPECT_EQ(expected_routing_info, routing_info);
129 EXPECT_FALSE(state->ready_task.get());
130 EXPECT_EQ(types, state->initial_types);
131 EXPECT_FALSE(state->deleted_type);
132
133 syncable::ModelTypeBitSet expected_added_types;
134 expected_added_types.set(syncable::BOOKMARKS);
135 EXPECT_EQ(expected_added_types, state->added_types);
136 }
137
138 // Add existing type.
139 {
140 DataTypeController::TypeMap data_type_controllers;
141 data_type_controllers[syncable::BOOKMARKS] = NULL;
142 syncable::ModelTypeSet types;
143 types.insert(syncable::BOOKMARKS);
144 ModelSafeRoutingInfo routing_info;
145 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
146 ModelSafeRoutingInfo expected_routing_info = routing_info;
147
148 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
149 state(SyncBackendHost::GetPendingConfigModeState(
150 data_type_controllers, types, NULL, &routing_info));
151
152 EXPECT_EQ(expected_routing_info, routing_info);
153 EXPECT_FALSE(state->ready_task.get());
154 EXPECT_EQ(types, state->initial_types);
155 EXPECT_FALSE(state->deleted_type);
156 EXPECT_TRUE(state->added_types.none());
157 }
158
159 // Delete type.
160 {
161 DataTypeController::TypeMap data_type_controllers;
162 data_type_controllers[syncable::BOOKMARKS] = NULL;
163 syncable::ModelTypeSet types;
164 ModelSafeRoutingInfo routing_info;
165 routing_info[syncable::BOOKMARKS] = GROUP_PASSIVE;
166
167 scoped_ptr<SyncBackendHost::PendingConfigureDataTypesState>
168 state(SyncBackendHost::GetPendingConfigModeState(
169 data_type_controllers, types, NULL, &routing_info));
170
171 ModelSafeRoutingInfo expected_routing_info;
172 EXPECT_EQ(expected_routing_info, routing_info);
173 EXPECT_FALSE(state->ready_task.get());
174 EXPECT_EQ(types, state->initial_types);
175 EXPECT_TRUE(state->deleted_type);
176 EXPECT_TRUE(state->added_types.none());
177 }
178 }
179
180 // TODO(akalin): Write more SyncBackendHost unit tests.
181
182 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698