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 30 matching lines...) Expand all Loading... |
41 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 41 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
42 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 42 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
43 #include "chrome/browser/sync/protocol/proto_value_conversions.h" | 43 #include "chrome/browser/sync/protocol/proto_value_conversions.h" |
44 #include "chrome/browser/sync/protocol/sync.pb.h" | 44 #include "chrome/browser/sync/protocol/sync.pb.h" |
45 #include "chrome/browser/sync/sessions/sync_session.h" | 45 #include "chrome/browser/sync/sessions/sync_session.h" |
46 #include "chrome/browser/sync/syncable/directory_manager.h" | 46 #include "chrome/browser/sync/syncable/directory_manager.h" |
47 #include "chrome/browser/sync/syncable/syncable.h" | 47 #include "chrome/browser/sync/syncable/syncable.h" |
48 #include "chrome/browser/sync/syncable/syncable_id.h" | 48 #include "chrome/browser/sync/syncable/syncable_id.h" |
49 #include "chrome/browser/sync/test/engine/test_user_share.h" | 49 #include "chrome/browser/sync/test/engine/test_user_share.h" |
50 #include "chrome/browser/sync/util/cryptographer.h" | 50 #include "chrome/browser/sync/util/cryptographer.h" |
| 51 #include "chrome/browser/sync/util/time.h" |
51 #include "chrome/test/base/values_test_util.h" | 52 #include "chrome/test/base/values_test_util.h" |
52 #include "content/browser/browser_thread.h" | 53 #include "content/browser/browser_thread.h" |
53 #include "testing/gmock/include/gmock/gmock.h" | 54 #include "testing/gmock/include/gmock/gmock.h" |
54 #include "testing/gtest/include/gtest/gtest.h" | 55 #include "testing/gtest/include/gtest/gtest.h" |
55 | 56 |
56 using browser_sync::Cryptographer; | 57 using browser_sync::Cryptographer; |
57 using browser_sync::HasArgsAsList; | 58 using browser_sync::HasArgsAsList; |
58 using browser_sync::HasDetailsAsDictionary; | 59 using browser_sync::HasDetailsAsDictionary; |
59 using browser_sync::KeyParams; | 60 using browser_sync::KeyParams; |
60 using browser_sync::JsArgList; | 61 using browser_sync::JsArgList; |
(...skipping 27 matching lines...) Expand all Loading... |
88 | 89 |
89 void ExpectInt64Value(int64 expected_value, | 90 void ExpectInt64Value(int64 expected_value, |
90 const DictionaryValue& value, const std::string& key) { | 91 const DictionaryValue& value, const std::string& key) { |
91 std::string int64_str; | 92 std::string int64_str; |
92 EXPECT_TRUE(value.GetString(key, &int64_str)); | 93 EXPECT_TRUE(value.GetString(key, &int64_str)); |
93 int64 val = 0; | 94 int64 val = 0; |
94 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); | 95 EXPECT_TRUE(base::StringToInt64(int64_str, &val)); |
95 EXPECT_EQ(expected_value, val); | 96 EXPECT_EQ(expected_value, val); |
96 } | 97 } |
97 | 98 |
| 99 void ExpectTimeValue(const base::Time& expected_value, |
| 100 const DictionaryValue& value, const std::string& key) { |
| 101 std::string time_str; |
| 102 EXPECT_TRUE(value.GetString(key, &time_str)); |
| 103 EXPECT_EQ(browser_sync::GetTimeDebugString(expected_value), time_str); |
| 104 } |
| 105 |
98 // Makes a non-folder child of the root node. Returns the id of the | 106 // Makes a non-folder child of the root node. Returns the id of the |
99 // newly-created node. | 107 // newly-created node. |
100 int64 MakeNode(UserShare* share, | 108 int64 MakeNode(UserShare* share, |
101 ModelType model_type, | 109 ModelType model_type, |
102 const std::string& client_tag) { | 110 const std::string& client_tag) { |
103 WriteTransaction trans(FROM_HERE, share); | 111 WriteTransaction trans(FROM_HERE, share); |
104 ReadNode root_node(&trans); | 112 ReadNode root_node(&trans); |
105 root_node.InitByRootLookup(); | 113 root_node.InitByRootLookup(); |
106 WriteNode node(&trans); | 114 WriteNode node(&trans); |
107 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); | 115 EXPECT_TRUE(node.InitUniqueByCreation(model_type, root_node, client_tag)); |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { | 513 } else if (expected_model_type == syncable::TOP_LEVEL_FOLDER) { |
506 EXPECT_EQ("Top-level folder", type_str); | 514 EXPECT_EQ("Top-level folder", type_str); |
507 } else if (expected_model_type == syncable::UNSPECIFIED) { | 515 } else if (expected_model_type == syncable::UNSPECIFIED) { |
508 EXPECT_EQ("Unspecified", type_str); | 516 EXPECT_EQ("Unspecified", type_str); |
509 } else { | 517 } else { |
510 ADD_FAILURE(); | 518 ADD_FAILURE(); |
511 } | 519 } |
512 } | 520 } |
513 if (is_detailed) { | 521 if (is_detailed) { |
514 ExpectInt64Value(node.GetParentId(), value, "parentId"); | 522 ExpectInt64Value(node.GetParentId(), value, "parentId"); |
515 ExpectInt64Value(node.GetModificationTime(), value, "modificationTime"); | 523 ExpectTimeValue(node.GetModificationTime(), value, "modificationTime"); |
516 ExpectInt64Value(node.GetExternalId(), value, "externalId"); | 524 ExpectInt64Value(node.GetExternalId(), value, "externalId"); |
517 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); | 525 ExpectInt64Value(node.GetPredecessorId(), value, "predecessorId"); |
518 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); | 526 ExpectInt64Value(node.GetSuccessorId(), value, "successorId"); |
519 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); | 527 ExpectInt64Value(node.GetFirstChildId(), value, "firstChildId"); |
520 { | 528 { |
521 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); | 529 scoped_ptr<DictionaryValue> expected_entry(node.GetEntry()->ToValue()); |
522 Value* entry = NULL; | 530 Value* entry = NULL; |
523 EXPECT_TRUE(value.Get("entry", &entry)); | 531 EXPECT_TRUE(value.Get("entry", &entry)); |
524 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); | 532 EXPECT_TRUE(Value::Equals(entry, expected_entry.get())); |
525 } | 533 } |
(...skipping 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 ReadNode node(&trans); | 1555 ReadNode node(&trans); |
1548 EXPECT_TRUE(node.InitByIdLookup(node1)); | 1556 EXPECT_TRUE(node.InitByIdLookup(node1)); |
1549 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); | 1557 EXPECT_EQ(syncable::BOOKMARKS, node.GetModelType()); |
1550 EXPECT_EQ(title, node.GetTitle()); | 1558 EXPECT_EQ(title, node.GetTitle()); |
1551 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); | 1559 EXPECT_EQ(title, node.GetBookmarkSpecifics().title()); |
1552 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); | 1560 EXPECT_EQ(url, node.GetBookmarkSpecifics().url()); |
1553 } | 1561 } |
1554 } | 1562 } |
1555 | 1563 |
1556 } // namespace browser_sync | 1564 } // namespace browser_sync |
OLD | NEW |