1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Unit tests for the SyncApi. Note that a lot of the underlying
// functionality is provided by the Syncable layer, which has its own
// unit tests. We'll test SyncApi specific things in this harness.
#include "base/scoped_ptr.h"
#include "base/scoped_temp_dir.h"
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/syncable/syncable.h"
#include "chrome/test/sync/engine/test_directory_setter_upper.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace sync_api {
class SyncApiTest : public testing::Test {
public:
virtual void SetUp() {
setter_upper_.SetUp();
share_.dir_manager.reset(setter_upper_.manager());
share_.authenticated_name = setter_upper_.name();
}
virtual void TearDown() {
share_.dir_manager.release();
setter_upper_.TearDown();
}
protected:
UserShare share_;
browser_sync::TestDirectorySetterUpper setter_upper_;
};
TEST_F(SyncApiTest, SanityCheckTest) {
{
ReadTransaction trans(&share_);
EXPECT_TRUE(trans.GetWrappedTrans() != NULL);
}
{
WriteTransaction trans(&share_);
EXPECT_TRUE(trans.GetWrappedTrans() != NULL);
}
{
// No entries but root should exist
ReadTransaction trans(&share_);
ReadNode node(&trans);
// Metahandle 1 can be root, sanity check 2
EXPECT_FALSE(node.InitByIdLookup(2));
}
}
TEST_F(SyncApiTest, BasicTagWrite) {
{
WriteTransaction trans(&share_);
ReadNode root_node(&trans);
root_node.InitByRootLookup();
EXPECT_EQ(root_node.GetFirstChildId(), 0);
WriteNode wnode(&trans);
EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
root_node, "testtag"));
wnode.SetIsFolder(false);
}
{
ReadTransaction trans(&share_);
ReadNode node(&trans);
EXPECT_TRUE(node.InitByClientTagLookup("testtag"));
ReadNode root_node(&trans);
root_node.InitByRootLookup();
EXPECT_NE(node.GetId(), 0);
EXPECT_EQ(node.GetId(), root_node.GetFirstChildId());
}
}
TEST_F(SyncApiTest, ReadMissingTagsFails) {
{
ReadTransaction trans(&share_);
ReadNode node(&trans);
EXPECT_FALSE(node.InitByClientTagLookup("testtag"));
}
{
WriteTransaction trans(&share_);
WriteNode node(&trans);
EXPECT_FALSE(node.InitByClientTagLookup("testtag"));
}
}
// TODO(chron): Hook this all up to the server and write full integration tests
// for update->undelete behavior.
TEST_F(SyncApiTest, TestDeleteBehavior) {
int64 node_id;
int64 folder_id;
std::wstring test_title(L"test1");
{
WriteTransaction trans(&share_);
ReadNode root_node(&trans);
root_node.InitByRootLookup();
// we'll use this spare folder later
WriteNode folder_node(&trans);
EXPECT_TRUE(folder_node.InitByCreation(syncable::BOOKMARKS,
root_node, NULL));
folder_id = folder_node.GetId();
WriteNode wnode(&trans);
EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
root_node, "testtag"));
wnode.SetIsFolder(false);
wnode.SetTitle(test_title);
node_id = wnode.GetId();
}
// Ensure we can delete something with a tag.
{
WriteTransaction trans(&share_);
WriteNode wnode(&trans);
EXPECT_TRUE(wnode.InitByClientTagLookup("testtag"));
EXPECT_FALSE(wnode.GetIsFolder());
EXPECT_EQ(wnode.GetTitle(), test_title);
wnode.Remove();
}
// Lookup of a node which was deleted should return failure,
// but have found some data about the node.
{
ReadTransaction trans(&share_);
ReadNode node(&trans);
EXPECT_FALSE(node.InitByClientTagLookup("testtag"));
// Note that for proper function of this API this doesn't need to be
// filled, we're checking just to make sure the DB worked in this test.
EXPECT_EQ(node.GetTitle(), test_title);
}
{
WriteTransaction trans(&share_);
ReadNode folder_node(&trans);
EXPECT_TRUE(folder_node.InitByIdLookup(folder_id));
WriteNode wnode(&trans);
// This will undelete the tag.
EXPECT_TRUE(wnode.InitUniqueByCreation(syncable::BOOKMARKS,
folder_node, "testtag"));
EXPECT_EQ(wnode.GetIsFolder(), false);
EXPECT_EQ(wnode.GetParentId(), folder_node.GetId());
EXPECT_EQ(wnode.GetId(), node_id);
EXPECT_NE(wnode.GetTitle(), test_title); // Title should be cleared
wnode.SetTitle(test_title);
}
// Now look up should work.
{
ReadTransaction trans(&share_);
ReadNode node(&trans);
EXPECT_TRUE(node.InitByClientTagLookup("testtag"));
EXPECT_EQ(node.GetTitle(), test_title);
EXPECT_EQ(node.GetModelType(), syncable::BOOKMARKS);
}
}
} // namespace browser_sync
|