OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 // Unit tests for the SyncApi. Note that a lot of the underlying | 5 // Unit tests for the SyncApi. Note that a lot of the underlying |
6 // functionality is provided by the Syncable layer, which has its own | 6 // functionality is provided by the Syncable layer, which has its own |
7 // unit tests. We'll test SyncApi specific things in this harness. | 7 // unit tests. We'll test SyncApi specific things in this harness. |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <map> | 10 #include <map> |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, | 285 EXPECT_FALSE(node.InitByClientTagLookup(syncable::BOOKMARKS, |
286 "testtag")); | 286 "testtag")); |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 // TODO(chron): Hook this all up to the server and write full integration tests | 290 // TODO(chron): Hook this all up to the server and write full integration tests |
291 // for update->undelete behavior. | 291 // for update->undelete behavior. |
292 TEST_F(SyncApiTest, TestDeleteBehavior) { | 292 TEST_F(SyncApiTest, TestDeleteBehavior) { |
293 int64 node_id; | 293 int64 node_id; |
294 int64 folder_id; | 294 int64 folder_id; |
295 std::wstring test_title(L"test1"); | 295 std::string test_title("test1"); |
296 | 296 |
297 { | 297 { |
298 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 298 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
299 ReadNode root_node(&trans); | 299 ReadNode root_node(&trans); |
300 root_node.InitByRootLookup(); | 300 root_node.InitByRootLookup(); |
301 | 301 |
302 // we'll use this spare folder later | 302 // we'll use this spare folder later |
303 WriteNode folder_node(&trans); | 303 WriteNode folder_node(&trans); |
304 EXPECT_TRUE(folder_node.InitByCreation(syncable::BOOKMARKS, | 304 EXPECT_TRUE(folder_node.InitByCreation(syncable::BOOKMARKS, |
305 root_node, NULL)); | 305 root_node, NULL)); |
306 folder_id = folder_node.GetId(); | 306 folder_id = folder_node.GetId(); |
307 | 307 |
308 WriteNode wnode(&trans); | 308 WriteNode wnode(&trans); |
309 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, | 309 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, |
310 root_node, "testtag")); | 310 root_node, "testtag")); |
311 wnode.SetIsFolder(false); | 311 wnode.SetIsFolder(false); |
312 wnode.SetTitle(test_title); | 312 wnode.SetTitle(UTF8ToWide(test_title)); |
313 | 313 |
314 node_id = wnode.GetId(); | 314 node_id = wnode.GetId(); |
315 } | 315 } |
316 | 316 |
317 // Ensure we can delete something with a tag. | 317 // Ensure we can delete something with a tag. |
318 { | 318 { |
319 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); | 319 WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); |
320 WriteNode wnode(&trans); | 320 WriteNode wnode(&trans); |
321 EXPECT_TRUE(wnode.InitByClientTagLookup(syncable::BOOKMARKS, | 321 EXPECT_TRUE(wnode.InitByClientTagLookup(syncable::BOOKMARKS, |
322 "testtag")); | 322 "testtag")); |
(...skipping 21 matching lines...) Expand all Loading... |
344 EXPECT_TRUE(folder_node.InitByIdLookup(folder_id)); | 344 EXPECT_TRUE(folder_node.InitByIdLookup(folder_id)); |
345 | 345 |
346 WriteNode wnode(&trans); | 346 WriteNode wnode(&trans); |
347 // This will undelete the tag. | 347 // This will undelete the tag. |
348 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, | 348 EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS, |
349 folder_node, "testtag")); | 349 folder_node, "testtag")); |
350 EXPECT_EQ(wnode.GetIsFolder(), false); | 350 EXPECT_EQ(wnode.GetIsFolder(), false); |
351 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); | 351 EXPECT_EQ(wnode.GetParentId(), folder_node.GetId()); |
352 EXPECT_EQ(wnode.GetId(), node_id); | 352 EXPECT_EQ(wnode.GetId(), node_id); |
353 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared | 353 EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared |
354 wnode.SetTitle(test_title); | 354 wnode.SetTitle(UTF8ToWide(test_title)); |
355 } | 355 } |
356 | 356 |
357 // Now look up should work. | 357 // Now look up should work. |
358 { | 358 { |
359 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); | 359 ReadTransaction trans(FROM_HERE, test_user_share_.user_share()); |
360 ReadNode node(&trans); | 360 ReadNode node(&trans); |
361 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, | 361 EXPECT_TRUE(node.InitByClientTagLookup(syncable::BOOKMARKS, |
362 "testtag")); | 362 "testtag")); |
363 EXPECT_EQ(node.GetTitle(), test_title); | 363 EXPECT_EQ(node.GetTitle(), test_title); |
364 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); | 364 EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 namespace { | 438 namespace { |
439 | 439 |
440 void CheckNodeValue(const BaseNode& node, const DictionaryValue& value, | 440 void CheckNodeValue(const BaseNode& node, const DictionaryValue& value, |
441 bool is_detailed) { | 441 bool is_detailed) { |
442 ExpectInt64Value(node.GetId(), value, "id"); | 442 ExpectInt64Value(node.GetId(), value, "id"); |
443 { | 443 { |
444 bool is_folder = false; | 444 bool is_folder = false; |
445 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); | 445 EXPECT_TRUE(value.GetBoolean("isFolder", &is_folder)); |
446 EXPECT_EQ(node.GetIsFolder(), is_folder); | 446 EXPECT_EQ(node.GetIsFolder(), is_folder); |
447 } | 447 } |
448 ExpectDictStringValue(WideToUTF8(node.GetTitle()), value, "title"); | 448 ExpectDictStringValue(node.GetTitle(), value, "title"); |
449 { | 449 { |
450 ModelType expected_model_type = node.GetModelType(); | 450 ModelType expected_model_type = node.GetModelType(); |
451 std::string type_str; | 451 std::string type_str; |
452 EXPECT_TRUE(value.GetString("type", &type_str)); | 452 EXPECT_TRUE(value.GetString("type", &type_str)); |
453 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { | 453 if (expected_model_type >= syncable::FIRST_REAL_MODEL_TYPE) { |
454 ModelType model_type = | 454 ModelType model_type = |
455 syncable::ModelTypeFromString(type_str); | 455 syncable::ModelTypeFromString(type_str); |
456 EXPECT_EQ(expected_model_type, model_type); | 456 EXPECT_EQ(expected_model_type, model_type); |
457 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { | 457 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { |
458 EXPECT_EQ("Top-level folder", type_str); | 458 EXPECT_EQ("Top-level folder", type_str); |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 { | 1423 { |
1424 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1424 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
1425 ReadNode password_node(&trans); | 1425 ReadNode password_node(&trans); |
1426 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); | 1426 EXPECT_FALSE(password_node.InitByIdLookup(node_id)); |
1427 } | 1427 } |
1428 } | 1428 } |
1429 | 1429 |
1430 } // namespace | 1430 } // namespace |
1431 | 1431 |
1432 } // namespace browser_sync | 1432 } // namespace browser_sync |
OLD | NEW |