| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 43 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 44 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 44 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 45 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 45 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
| 46 #include "chrome/browser/sync/protocol/sync.pb.h" | 46 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 47 #include "chrome/browser/sync/sessions/sync_session.h" | 47 #include "chrome/browser/sync/sessions/sync_session.h" |
| 48 #include "chrome/browser/sync/syncable/directory_manager.h" | 48 #include "chrome/browser/sync/syncable/directory_manager.h" |
| 49 #include "chrome/browser/sync/syncable/syncable.h" | 49 #include "chrome/browser/sync/syncable/syncable.h" |
| 50 #include "chrome/browser/sync/syncable/syncable_id.h" | 50 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 51 #include "chrome/browser/sync/test/engine/test_user_share.h" | 51 #include "chrome/browser/sync/test/engine/test_user_share.h" |
| 52 #include "chrome/browser/sync/util/cryptographer.h" | 52 #include "chrome/browser/sync/util/cryptographer.h" |
| 53 #include "chrome/browser/sync/util/time.h" | |
| 54 #include "chrome/test/base/values_test_util.h" | 53 #include "chrome/test/base/values_test_util.h" |
| 55 #include "content/browser/browser_thread.h" | 54 #include "content/browser/browser_thread.h" |
| 56 #include "testing/gmock/include/gmock/gmock.h" | 55 #include "testing/gmock/include/gmock/gmock.h" |
| 57 #include "testing/gtest/include/gtest/gtest.h" | 56 #include "testing/gtest/include/gtest/gtest.h" |
| 58 | 57 |
| 59 using browser_sync::Cryptographer; | 58 using browser_sync::Cryptographer; |
| 60 using browser_sync::HasArgsAsList; | 59 using browser_sync::HasArgsAsList; |
| 61 using browser_sync::HasDetailsAsDictionary; | 60 using browser_sync::HasDetailsAsDictionary; |
| 62 using browser_sync::KeyParams; | 61 using browser_sync::KeyParams; |
| 63 using browser_sync::JsArgList; | 62 using browser_sync::JsArgList; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 90 | 89 |
| 91 void ExpectInt64Value(int64 expected_value, | 90 void ExpectInt64Value(int64 expected_value, |
| 92 const DictionaryValue& value, const std::string& key) { | 91 const DictionaryValue& value, const std::string& key) { |
| 93 std::string int64_str; | 92 std::string int64_str; |
| 94 EXPECT_TRUE(value.GetString(key, &int64_str)); | 93 EXPECT_TRUE(value.GetString(key, &int64_str)); |
| 95 int64 val = 0; | 94 int64 val = 0; |
| 96 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); | 95 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); |
| 97 EXPECT_EQ(expected_value, val); | 96 EXPECT_EQ(expected_value, val); |
| 98 } | 97 } |
| 99 | 98 |
| 100 void ExpectTimeValue(const base::Time& expected_value, | |
| 101 const DictionaryValue& value, const std::string& key) { | |
| 102 std::string time_str; | |
| 103 EXPECT_TRUE(value.GetString(key, &time_str)); | |
| 104 EXPECT_EQ(browser_sync::GetTimeDebugString(expected_value), time_str); | |
| 105 } | |
| 106 | |
| 107 // Makes a non-folder child of the root node. Returns the id of the | 99 // Makes a non-folder child of the root node. Returns the id of the |
| 108 // newly-created node. | 100 // newly-created node. |
| 109 int64 MakeNode(UserShare* share, | 101 int64 MakeNode(UserShare* share, |
| 110 ModelType model_type, | 102 ModelType model_type, |
| 111 const std::string& client_tag) { | 103 const std::string& client_tag) { |
| 112 WriteTransaction trans(FROM_HERE, share); | 104 WriteTransaction trans(FROM_HERE, share); |
| 113 ReadNode root_node(&trans); | 105 ReadNode root_node(&trans); |
| 114 root_node.InitByRootLookup(); | 106 root_node.InitByRootLookup(); |
| 115 WriteNode node(&trans); | 107 WriteNode node(&trans); |
| 116 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); | 108 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { | 506 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { |
| 515 EXPECT_EQ("Top-level folder", type_str); | 507 EXPECT_EQ("Top-level folder", type_str); |
| 516 } else if (expected_model_type == syncable::UNSPECIFIED) { | 508 } else if (expected_model_type == syncable::UNSPECIFIED) { |
| 517 EXPECT_EQ("Unspecified", type_str); | 509 EXPECT_EQ("Unspecified", type_str); |
| 518 } else { | 510 } else { |
| 519 ADD_FAILURE(); | 511 ADD_FAILURE(); |
| 520 } | 512 } |
| 521 } | 513 } |
| 522 if (is_detailed) { | 514 if (is_detailed) { |
| 523 ExpectInt64Value(node.GetParentId(), value, "parentId"); | 515 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
| 524 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); | 516 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); |
| 525 ExpectInt64Value(node.GetExternalId(), value, "externalId"); | 517 ExpectInt64Value(node.GetExternalId(), value, "externalId"); |
| 526 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); | 518 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); |
| 527 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); | 519 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); |
| 528 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); | 520 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); |
| 529 { | 521 { |
| 530 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); | 522 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); |
| 531 Value* entry = NULL; | 523 Value* entry = NULL; |
| 532 EXPECT_TRUE(value.Get("entry", &entry)); | 524 EXPECT_TRUE(value.Get("entry", &entry)); |
| 533 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); | 525 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); |
| 534 } | 526 } |
| (...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1458 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); | 1450 EXPECT_EQ(syncable::BOOKMARKS, node2.GetModelType()); |
| 1459 // We should de-canonicalize the title in GetTitle(), but the title in the | 1451 // We should de-canonicalize the title in GetTitle(), but the title in the |
| 1460 // specifics should be stored in the server legal form. | 1452 // specifics should be stored in the server legal form. |
| 1461 EXPECT_EQ(raw_title2, node2.GetTitle()); | 1453 EXPECT_EQ(raw_title2, node2.GetTitle()); |
| 1462 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); | 1454 EXPECT_EQ(title2, node2.GetBookmarkSpecifics().title()); |
| 1463 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); | 1455 EXPECT_EQ(url2, node2.GetBookmarkSpecifics().url()); |
| 1464 } | 1456 } |
| 1465 } | 1457 } |
| 1466 | 1458 |
| 1467 } // namespace browser_sync | 1459 } // namespace browser_sync |
| OLD | NEW |