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

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

Issue 5705004: [SYNC] Sessions datatype refactor. Most things related to sessions under-the-... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Tests! And the refactors that helped them. And Rebase. And Comments. Created 10 years 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
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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) { 163 TEST_F(ProfileSyncServiceSessionTest, WriteSessionToNode) {
164 CreateRootTask task(this); 164 CreateRootTask task(this);
165 ASSERT_TRUE(StartSyncService(&task, false)); 165 ASSERT_TRUE(StartSyncService(&task, false));
166 ASSERT_TRUE(task.success()); 166 ASSERT_TRUE(task.success());
167 ASSERT_EQ(model_associator_->GetSessionService(), helper_.service()); 167 ASSERT_EQ(model_associator_->GetSessionService(), helper_.service());
168 168
169 // Check that the DataTypeController associated the models. 169 // Check that the DataTypeController associated the models.
170 bool has_nodes; 170 bool has_nodes;
171 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); 171 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes));
172 ASSERT_TRUE(has_nodes); 172 ASSERT_TRUE(has_nodes);
173 ASSERT_TRUE(model_associator_->ChromeModelHasUserCreatedNodes(&has_nodes));
174 ASSERT_TRUE(has_nodes);
175 std::string machine_tag = model_associator_->GetCurrentMachineTag(); 173 std::string machine_tag = model_associator_->GetCurrentMachineTag();
176 int64 sync_id; 174 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag);
177 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, 175 ASSERT_NE(sync_api::kInvalidId, sync_id);
178 &sync_id));
179 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id);
180 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics(
181 model_associator_->GetChromeNodeFromSyncId(sync_id));
182 ASSERT_TRUE(sync_specifics != NULL);
183 176
184 // Check that we can get the correct session specifics back from the node. 177 // Check that we can get the correct session specifics back from the node.
185 sync_api::ReadTransaction trans(sync_service_-> 178 sync_api::ReadTransaction trans(sync_service_->
186 backend()->GetUserShareHandle()); 179 backend()->GetUserShareHandle());
187 sync_api::ReadNode node(&trans); 180 sync_api::ReadNode node(&trans);
188 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, 181 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS,
189 machine_tag)); 182 machine_tag));
190 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics()); 183 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics());
191 ASSERT_EQ(sync_specifics->session_tag(), specifics.session_tag());
192 ASSERT_EQ(machine_tag, specifics.session_tag()); 184 ASSERT_EQ(machine_tag, specifics.session_tag());
185 ASSERT_TRUE(specifics.has_header());
186 const sync_pb::SessionHeader& header_s = specifics.header();
187 ASSERT_EQ(0, header_s.window_size());
193 } 188 }
194 189
195 // Test that we can fill this machine's session, write it to a node, 190 // Test that we can fill this machine's session, write it to a node,
196 // and then retrieve it. 191 // and then retrieve it.
197 TEST_F(ProfileSyncServiceSessionTest, WriteFilledSessionToNode) { 192 TEST_F(ProfileSyncServiceSessionTest, WriteFilledSessionToNode) {
198 CreateRootTask task(this); 193 CreateRootTask task(this);
199 ASSERT_TRUE(StartSyncService(&task, false)); 194 ASSERT_TRUE(StartSyncService(&task, false));
200 ASSERT_TRUE(task.success()); 195 ASSERT_TRUE(task.success());
201 196
202 // Check that the DataTypeController associated the models. 197 // Check that the DataTypeController associated the models.
203 bool has_nodes; 198 bool has_nodes;
204 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); 199 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes));
205 ASSERT_TRUE(has_nodes); 200 ASSERT_TRUE(has_nodes);
206 AddTab(browser(), GURL("http://foo/1")); 201 AddTab(browser(), GURL("http://foo/1"));
207 NavigateAndCommitActiveTab(GURL("http://foo/2")); 202 NavigateAndCommitActiveTab(GURL("http://foo/2"));
208 AddTab(browser(), GURL("http://bar/1")); 203 AddTab(browser(), GURL("http://bar/1"));
209 NavigateAndCommitActiveTab(GURL("http://bar/2")); 204 NavigateAndCommitActiveTab(GURL("http://bar/2"));
210 205
211 // Report a saved session, thus causing the ChangeProcessor to write to a 206 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes));
212 // node. 207 ASSERT_TRUE(has_nodes);
213 NotificationService::current()->Notify(
214 NotificationType::SESSION_SERVICE_SAVED,
215 Source<Profile>(profile()),
216 NotificationService::NoDetails());
217 std::string machine_tag = model_associator_->GetCurrentMachineTag(); 208 std::string machine_tag = model_associator_->GetCurrentMachineTag();
218 int64 sync_id; 209 int64 sync_id = model_associator_->GetSyncIdFromSessionTag(machine_tag);
219 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, 210 ASSERT_NE(sync_api::kInvalidId, sync_id);
220 &sync_id));
221 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id);
222 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics(
223 model_associator_->GetChromeNodeFromSyncId(sync_id));
224 ASSERT_TRUE(sync_specifics != NULL);
225 211
226 // Check that this machine's data is not included in the foreign windows. 212 // Check that this machine's data is not included in the foreign windows.
227 ScopedVector<ForeignSession> foreign_sessions; 213 std::vector<const ForeignSession*> foreign_sessions;
228 model_associator_->GetSessionData(&foreign_sessions.get()); 214 model_associator_->GetAllForeignSessions(&foreign_sessions);
229 ASSERT_EQ(foreign_sessions.size(), 0U); 215 ASSERT_EQ(foreign_sessions.size(), 0U);
230 216
231 // Get the windows for this machine from the node and check that they were 217 // Get the tabs for this machine from the node and check that they were
232 // filled. 218 // filled.
233 sync_api::ReadTransaction trans(sync_service_-> 219 SessionModelAssociator::TabLinksMap tab_map = model_associator_->tab_map_;
234 backend()->GetUserShareHandle()); 220 ASSERT_EQ(2U, tab_map.size());
235 sync_api::ReadNode node(&trans); 221 // Tabs are ordered by sessionid in tab_map, so should be able to traverse
236 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS, 222 // the tree based on order of tabs created
237 machine_tag)); 223 SessionModelAssociator::TabLinksMap::iterator iter = tab_map.begin();
238 model_associator_->AppendForeignSessionWithID(sync_id, 224 ASSERT_EQ(2, iter->second.tab()->controller().entry_count());
239 &foreign_sessions.get(), &trans); 225 ASSERT_EQ(GURL("http://foo/1"), iter->second.tab()->controller().
240 ASSERT_EQ(foreign_sessions.size(), 1U); 226 GetEntryAtIndex(0)->virtual_url());
241 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); 227 ASSERT_EQ(GURL("http://foo/2"), iter->second.tab()->controller().
242 ASSERT_EQ(2U, foreign_sessions[0]->windows[0]->tabs.size()); 228 GetEntryAtIndex(1)->virtual_url());
243 ASSERT_EQ(2U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size()); 229 iter++;
244 ASSERT_EQ(GURL("http://bar/1"), 230 ASSERT_EQ(2, iter->second.tab()->controller().entry_count());
245 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); 231 ASSERT_EQ(GURL("http://bar/1"), iter->second.tab()->controller().
246 ASSERT_EQ(GURL("http://bar/2"), 232 GetEntryAtIndex(0)->virtual_url());
247 foreign_sessions[0]->windows[0]->tabs[0]->navigations[1].virtual_url()); 233 ASSERT_EQ(GURL("http://bar/2"), iter->second.tab()->controller().
248 ASSERT_EQ(2U, foreign_sessions[0]->windows[0]->tabs[1]->navigations.size()); 234 GetEntryAtIndex(1)->virtual_url());
249 ASSERT_EQ(GURL("http://foo/1"),
250 foreign_sessions[0]->windows[0]->tabs[1]->navigations[0].virtual_url());
251 ASSERT_EQ(GURL("http://foo/2"),
252 foreign_sessions[0]->windows[0]->tabs[1]->navigations[1].virtual_url());
253 const sync_pb::SessionSpecifics& specifics(node.GetSessionSpecifics());
254 ASSERT_EQ(sync_specifics->session_tag(), specifics.session_tag());
255 ASSERT_EQ(machine_tag, specifics.session_tag());
256 } 235 }
257 236
258 // Test that we fail on a failed model association. 237 // Test that we fail on a failed model association.
259 TEST_F(ProfileSyncServiceSessionTest, FailModelAssociation) { 238 TEST_F(ProfileSyncServiceSessionTest, FailModelAssociation) {
260 ASSERT_TRUE(StartSyncService(NULL, true)); 239 ASSERT_TRUE(StartSyncService(NULL, true));
261 ASSERT_TRUE(sync_service_->unrecoverable_error_detected()); 240 ASSERT_TRUE(sync_service_->unrecoverable_error_detected());
262 } 241 }
263 242
264 // Write a foreign session to a node, and then retrieve it. 243 // Write a foreign session to a node, and then retrieve it.
265 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNode) { 244 TEST_F(ProfileSyncServiceSessionTest, WriteForeignSessionToNode) {
266 CreateRootTask task(this); 245 CreateRootTask task(this);
267 ASSERT_TRUE(StartSyncService(&task, false)); 246 ASSERT_TRUE(StartSyncService(&task, false));
268 ASSERT_TRUE(task.success()); 247 ASSERT_TRUE(task.success());
269 248
270 // Check that the DataTypeController associated the models. 249 // Check that the DataTypeController associated the models.
271 bool has_nodes; 250 bool has_nodes;
272 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes)); 251 ASSERT_TRUE(model_associator_->SyncModelHasUserCreatedNodes(&has_nodes));
273 ASSERT_TRUE(has_nodes); 252 ASSERT_TRUE(has_nodes);
274 253
275 // Fill an instance of session specifics with a foreign session's data. 254 // Fill an instance of session specifics with a foreign session's data.
276 sync_pb::SessionSpecifics specifics; 255 sync_pb::SessionSpecifics meta_specifics;
277 std::string machine_tag = "session_sync123"; 256 std::string machine_tag = "session_sync123";
278 specifics.set_session_tag(machine_tag); 257 meta_specifics.set_session_tag(machine_tag);
279 sync_pb::SessionWindow* window = specifics.add_session_window(); 258 sync_pb::SessionHeader* header_s = meta_specifics.mutable_header();
280 window->set_selected_tab_index(1); 259 sync_pb::SessionWindow* window_s = header_s->add_window();
281 window->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_NORMAL); 260 window_s->add_tab(0);
282 sync_pb::SessionTab* tab = window->add_session_tab(); 261 window_s->set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_NORMAL);
262 window_s->set_selected_tab_index(1);
263
264 sync_pb::SessionSpecifics tab_specifics;
265 tab_specifics.set_session_tag(machine_tag);
266 sync_pb::SessionTab* tab = tab_specifics.mutable_tab();
283 tab->set_tab_visual_index(13); 267 tab->set_tab_visual_index(13);
284 tab->set_current_navigation_index(3); 268 tab->set_current_navigation_index(3);
285 tab->set_pinned(true); 269 tab->set_pinned(true);
286 tab->set_extension_app_id("app_id"); 270 tab->set_extension_app_id("app_id");
287 sync_pb::TabNavigation* navigation = tab->add_navigation(); 271 sync_pb::TabNavigation* navigation = tab->add_navigation();
288 navigation->set_index(12); 272 navigation->set_index(12);
289 navigation->set_virtual_url("http://foo/1"); 273 navigation->set_virtual_url("http://foo/1");
290 navigation->set_referrer("referrer"); 274 navigation->set_referrer("referrer");
291 navigation->set_title("title"); 275 navigation->set_title("title");
292 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED); 276 navigation->set_page_transition(sync_pb::TabNavigation_PageTransition_TYPED);
293 277
294 // Update the server with the session specifics. 278 // Update the server with the session specifics.
295 { 279 {
296 sync_api::WriteTransaction trans(sync_service_-> 280 model_associator_->AssociateForeignSpecifics(meta_specifics, 0);
297 backend()->GetUserShareHandle()); 281 model_associator_->AssociateForeignSpecifics(tab_specifics, 0);
298 sync_api::ReadNode root(&trans);
299 ASSERT_TRUE(root.InitByTagLookup(kSessionsTag));
300 model_associator_->UpdateSyncModel(&specifics, &trans, &root);
301 model_associator_->UpdateFromSyncModel(&trans);
302 } 282 }
303 283
304 // Check that the foreign session was written to a node and retrieve the data. 284 // Check that the foreign session was associated and retrieve the data.
305 int64 sync_id; 285 std::vector<const ForeignSession*> foreign_sessions;
306 ASSERT_TRUE(model_associator_->GetSyncIdForTaggedNode(&machine_tag, 286 model_associator_->GetAllForeignSessions(&foreign_sessions);
307 &sync_id));
308 ASSERT_EQ(model_associator_->GetSyncIdFromChromeId(machine_tag), sync_id);
309 scoped_ptr<const sync_pb::SessionSpecifics> sync_specifics(
310 model_associator_->GetChromeNodeFromSyncId(sync_id));
311 ASSERT_TRUE(sync_specifics != NULL);
312 ScopedVector<ForeignSession> foreign_sessions;
313 model_associator_->GetSessionData(&foreign_sessions.get());
314 ASSERT_EQ(1U, foreign_sessions.size()); 287 ASSERT_EQ(1U, foreign_sessions.size());
288 ASSERT_EQ(machine_tag, foreign_sessions[0]->foreign_session_tag);
315 ASSERT_EQ(1U, foreign_sessions[0]->windows.size()); 289 ASSERT_EQ(1U, foreign_sessions[0]->windows.size());
316 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs.size()); 290 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs.size());
317 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size()); 291 ASSERT_EQ(1U, foreign_sessions[0]->windows[0]->tabs[0]->navigations.size());
318 ASSERT_EQ(foreign_sessions[0]->foreign_session_tag, machine_tag); 292 ASSERT_EQ(foreign_sessions[0]->foreign_session_tag, machine_tag);
319 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->selected_tab_index); 293 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->selected_tab_index);
320 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->type); 294 ASSERT_EQ(1, foreign_sessions[0]->windows[0]->type);
321 ASSERT_EQ(13, foreign_sessions[0]->windows[0]->tabs[0]->tab_visual_index); 295 ASSERT_EQ(13, foreign_sessions[0]->windows[0]->tabs[0]->tab_visual_index);
322 ASSERT_EQ(3, 296 ASSERT_EQ(3,
323 foreign_sessions[0]->windows[0]->tabs[0]->current_navigation_index); 297 foreign_sessions[0]->windows[0]->tabs[0]->current_navigation_index);
324 ASSERT_TRUE(foreign_sessions[0]->windows[0]->tabs[0]->pinned); 298 ASSERT_TRUE(foreign_sessions[0]->windows[0]->tabs[0]->pinned);
325 ASSERT_EQ("app_id", 299 ASSERT_EQ("app_id",
326 foreign_sessions[0]->windows[0]->tabs[0]->extension_app_id); 300 foreign_sessions[0]->windows[0]->tabs[0]->extension_app_id);
327 ASSERT_EQ(12, 301 ASSERT_EQ(12,
328 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].index()); 302 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].index());
329 ASSERT_EQ(GURL("referrer"), 303 ASSERT_EQ(GURL("referrer"),
330 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].referrer()); 304 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].referrer());
331 ASSERT_EQ(string16(ASCIIToUTF16("title")), 305 ASSERT_EQ(string16(ASCIIToUTF16("title")),
332 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].title()); 306 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].title());
333 ASSERT_EQ(PageTransition::TYPED, 307 ASSERT_EQ(PageTransition::TYPED,
334 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].transition()); 308 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].transition());
335 ASSERT_EQ(GURL("http://foo/1"), 309 ASSERT_EQ(GURL("http://foo/1"),
336 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url()); 310 foreign_sessions[0]->windows[0]->tabs[0]->navigations[0].virtual_url());
337 sync_api::WriteTransaction trans(sync_service_->
338 backend()->GetUserShareHandle());
339 sync_api::ReadNode node(&trans);
340 ASSERT_TRUE(node.InitByClientTagLookup(syncable::SESSIONS,
341 machine_tag));
342 const sync_pb::SessionSpecifics& specifics_(node.GetSessionSpecifics());
343 ASSERT_EQ(sync_specifics->session_tag(), specifics_.session_tag());
344 ASSERT_EQ(machine_tag, specifics_.session_tag());
345 } 311 }
346 312
347 // Test the DataTypeController on update. 313 // Test the DataTypeController on update.
348 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) { 314 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionUpdate) {
349 CreateRootTask task(this); 315 CreateRootTask task(this);
350 ASSERT_TRUE(StartSyncService(&task, false)); 316 ASSERT_TRUE(StartSyncService(&task, false));
351 ASSERT_TRUE(task.success()); 317 ASSERT_TRUE(task.success());
352 int64 node_id = model_associator_->GetSyncIdFromChromeId( 318 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
353 model_associator_->GetCurrentMachineTag()); 319 model_associator_->GetCurrentMachineTag());
354 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); 320 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord);
355 record->action = SyncManager::ChangeRecord::ACTION_UPDATE; 321 record->action = SyncManager::ChangeRecord::ACTION_UPDATE;
356 record->id = node_id; 322 record->id = node_id;
357 ASSERT_FALSE(notified_of_update_); 323 ASSERT_FALSE(notified_of_update_);
358 { 324 {
359 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); 325 sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
360 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 326 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
361 } 327 }
362 ASSERT_TRUE(notified_of_update_); 328 ASSERT_TRUE(notified_of_update_);
363 } 329 }
364 330
365 // Test the DataTypeController on add. 331 // Test the DataTypeController on add.
366 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) { 332 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionAdd) {
367 CreateRootTask task(this); 333 CreateRootTask task(this);
368 ASSERT_TRUE(StartSyncService(&task, false)); 334 ASSERT_TRUE(StartSyncService(&task, false));
369 ASSERT_TRUE(task.success()); 335 ASSERT_TRUE(task.success());
370 336
371 int64 node_id = model_associator_->GetSyncIdFromChromeId( 337 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
372 model_associator_->GetCurrentMachineTag()); 338 model_associator_->GetCurrentMachineTag());
373 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); 339 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord);
374 record->action = SyncManager::ChangeRecord::ACTION_ADD; 340 record->action = SyncManager::ChangeRecord::ACTION_ADD;
375 record->id = node_id; 341 record->id = node_id;
376 ASSERT_FALSE(notified_of_update_); 342 ASSERT_FALSE(notified_of_update_);
377 { 343 {
378 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); 344 sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
379 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 345 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
380 } 346 }
381 ASSERT_TRUE(notified_of_update_); 347 ASSERT_TRUE(notified_of_update_);
382 } 348 }
383 349
384 // Test the DataTypeController on delete. 350 // Test the DataTypeController on delete.
385 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) { 351 TEST_F(ProfileSyncServiceSessionTest, UpdatedSyncNodeActionDelete) {
386 CreateRootTask task(this); 352 CreateRootTask task(this);
387 ASSERT_TRUE(StartSyncService(&task, false)); 353 ASSERT_TRUE(StartSyncService(&task, false));
388 ASSERT_TRUE(task.success()); 354 ASSERT_TRUE(task.success());
389 355
390 int64 node_id = model_associator_->GetSyncIdFromChromeId( 356 int64 node_id = model_associator_->GetSyncIdFromSessionTag(
391 model_associator_->GetCurrentMachineTag()); 357 model_associator_->GetCurrentMachineTag());
392 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord); 358 scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord);
393 record->action = SyncManager::ChangeRecord::ACTION_DELETE; 359 record->action = SyncManager::ChangeRecord::ACTION_DELETE;
394 record->id = node_id; 360 record->id = node_id;
395 ASSERT_FALSE(notified_of_update_); 361 ASSERT_FALSE(notified_of_update_);
396 { 362 {
397 sync_api::WriteTransaction trans(backend()->GetUserShareHandle()); 363 sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
398 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1); 364 change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
399 } 365 }
400 ASSERT_TRUE(notified_of_update_); 366 ASSERT_TRUE(notified_of_update_);
401 } 367 }
368 // Test the TabNodePool when it starts off empty
tim (not reviewing) 2011/01/04 14:32:47 nit - you should end comments with a period.
Nicolas Zea 2011/01/06 01:14:13 Done.
369 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolEmpty) {
370 CreateRootTask task(this);
371 ASSERT_TRUE(StartSyncService(&task, false));
372 ASSERT_TRUE(task.success());
373
374 std::vector<int64> node_ids;
375 ASSERT_EQ(0U, model_associator_->tab_pool_.capacity());
376 ASSERT_TRUE(model_associator_->tab_pool_.empty());
377 ASSERT_TRUE(model_associator_->tab_pool_.full());
378 const size_t num_ids = 10;
379 for (size_t i = 0; i < num_ids; ++i) {
380 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
381 ASSERT_GT(id, -1);
382 node_ids.push_back(id);
383 }
384 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
385 ASSERT_TRUE(model_associator_->tab_pool_.empty());
386 ASSERT_FALSE(model_associator_->tab_pool_.full());
387 for (size_t i = 0; i < num_ids; ++i) {
388 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
389 }
390 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
391 ASSERT_FALSE(model_associator_->tab_pool_.empty());
392 ASSERT_TRUE(model_associator_->tab_pool_.full());
393 }
394
395 // Test the TabNodePool when it starts off with nodes
396 TEST_F(ProfileSyncServiceSessionTest, TabNodePoolNonEmpty) {
397 CreateRootTask task(this);
398 ASSERT_TRUE(StartSyncService(&task, false));
399 ASSERT_TRUE(task.success());
400
401 const size_t num_starting_nodes = 3;
402 for (size_t i = 0; i < num_starting_nodes; ++i) {
403 model_associator_->tab_pool_.AddTabNode(i);
404 }
405
406 std::vector<int64> node_ids;
407 ASSERT_EQ(num_starting_nodes, model_associator_->tab_pool_.capacity());
408 ASSERT_FALSE(model_associator_->tab_pool_.empty());
409 ASSERT_TRUE(model_associator_->tab_pool_.full());
410 const size_t num_ids = 10;
411 for (size_t i = 0; i < num_ids; ++i) {
412 int64 id = model_associator_->tab_pool_.GetFreeTabNode();
413 ASSERT_GT(id, -1);
414 node_ids.push_back(id);
415 }
416 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
417 ASSERT_TRUE(model_associator_->tab_pool_.empty());
418 ASSERT_FALSE(model_associator_->tab_pool_.full());
419 for (size_t i = 0; i < num_ids; ++i) {
420 model_associator_->tab_pool_.FreeTabNode(node_ids[i]);
421 }
422 ASSERT_EQ(num_ids, model_associator_->tab_pool_.capacity());
423 ASSERT_FALSE(model_associator_->tab_pool_.empty());
424 ASSERT_TRUE(model_associator_->tab_pool_.full());
425 }
402 426
403 } // namespace browser_sync 427 } // namespace browser_sync
404 428
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698