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

Side by Side Diff: chrome/browser/sync/syncable/syncable_unittest.cc

Issue 7033043: [Sync] Speed up sync node browser/search in about:sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 6 months 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) 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 #include "chrome/browser/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/types.h> 9 #include <sys/types.h>
10 10
(...skipping 29 matching lines...) Expand all
40 #include "third_party/sqlite/sqlite3.h" 40 #include "third_party/sqlite/sqlite3.h"
41 41
42 using browser_sync::TestIdFactory; 42 using browser_sync::TestIdFactory;
43 using test::ExpectDictBooleanValue; 43 using test::ExpectDictBooleanValue;
44 using test::ExpectDictStringValue; 44 using test::ExpectDictStringValue;
45 45
46 namespace syncable { 46 namespace syncable {
47 47
48 class SyncableKernelTest : public testing::Test {}; 48 class SyncableKernelTest : public testing::Test {};
49 49
50 // TODO(akalin): Add unit tests for EntryKernel::ContainsString().
51
50 TEST_F(SyncableKernelTest, ToValue) { 52 TEST_F(SyncableKernelTest, ToValue) {
51 EntryKernel kernel; 53 EntryKernel kernel;
52 scoped_ptr<DictionaryValue> value(kernel.ToValue()); 54 scoped_ptr<DictionaryValue> value(kernel.ToValue());
53 if (value.get()) { 55 if (value.get()) {
54 // Not much to check without repeating the ToValue() code. 56 // Not much to check without repeating the ToValue() code.
55 EXPECT_TRUE(value->HasKey("isDirty")); 57 EXPECT_TRUE(value->HasKey("isDirty"));
56 // The extra +1 is for "isDirty". 58 // The extra +1 is for "isDirty".
57 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 1, 59 EXPECT_EQ(BIT_TEMPS_END - BEGIN_FIELDS + 1,
58 static_cast<int>(value->size())); 60 static_cast<int>(value->size()));
59 } else { 61 } else {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 100 }
99 protected: 101 protected:
100 ScopedTempDir temp_dir_; 102 ScopedTempDir temp_dir_;
101 FilePath db_path_; 103 FilePath db_path_;
102 }; 104 };
103 105
104 TEST_F(SyncableGeneralTest, General) { 106 TEST_F(SyncableGeneralTest, General) {
105 Directory dir; 107 Directory dir;
106 dir.Open(db_path_, "SimpleTest"); 108 dir.Open(db_path_, "SimpleTest");
107 109
110 int64 root_metahandle;
111 {
112 ReadTransaction rtrans(&dir, __FILE__, __LINE__);
113 Entry e(&rtrans, GET_BY_ID, rtrans.root_id());
114 ASSERT_TRUE(e.good());
115 root_metahandle = e.Get(META_HANDLE);
116 }
117
108 int64 written_metahandle; 118 int64 written_metahandle;
109 const Id id = TestIdFactory::FromNumber(99); 119 const Id id = TestIdFactory::FromNumber(99);
110 std::string name = "Jeff"; 120 std::string name = "Jeff";
111 // Test simple read operations on an empty DB. 121 // Test simple read operations on an empty DB.
112 { 122 {
113 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 123 ReadTransaction rtrans(&dir, __FILE__, __LINE__);
114 Entry e(&rtrans, GET_BY_ID, id); 124 Entry e(&rtrans, GET_BY_ID, id);
115 ASSERT_FALSE(e.good()); // Hasn't been written yet. 125 ASSERT_FALSE(e.good()); // Hasn't been written yet.
116 126
117 Directory::ChildHandles child_handles; 127 Directory::ChildHandles child_handles;
118 dir.GetChildHandles(&rtrans, rtrans.root_id(), &child_handles); 128 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles);
129 EXPECT_TRUE(child_handles.empty());
130
131 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles);
119 EXPECT_TRUE(child_handles.empty()); 132 EXPECT_TRUE(child_handles.empty());
120 } 133 }
121 134
122 // Test creating a new meta entry. 135 // Test creating a new meta entry.
123 { 136 {
124 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__); 137 WriteTransaction wtrans(&dir, UNITTEST, __FILE__, __LINE__);
125 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name); 138 MutableEntry me(&wtrans, CREATE, wtrans.root_id(), name);
126 ASSERT_TRUE(me.good()); 139 ASSERT_TRUE(me.good());
127 me.Put(ID, id); 140 me.Put(ID, id);
128 me.Put(BASE_VERSION, 1); 141 me.Put(BASE_VERSION, 1);
129 written_metahandle = me.Get(META_HANDLE); 142 written_metahandle = me.Get(META_HANDLE);
130 } 143 }
131 144
132 // Test GetChildHandles after something is now in the DB. 145 // Test GetChildHandles* after something is now in the DB.
133 // Also check that GET_BY_ID works. 146 // Also check that GET_BY_ID works.
134 { 147 {
135 ReadTransaction rtrans(&dir, __FILE__, __LINE__); 148 ReadTransaction rtrans(&dir, __FILE__, __LINE__);
136 Entry e(&rtrans, GET_BY_ID, id); 149 Entry e(&rtrans, GET_BY_ID, id);
137 ASSERT_TRUE(e.good()); 150 ASSERT_TRUE(e.good());
138 151
139 Directory::ChildHandles child_handles; 152 Directory::ChildHandles child_handles;
140 dir.GetChildHandles(&rtrans, rtrans.root_id(), &child_handles); 153 dir.GetChildHandlesById(&rtrans, rtrans.root_id(), &child_handles);
141 EXPECT_EQ(1u, child_handles.size()); 154 EXPECT_EQ(1u, child_handles.size());
142 155
143 for (Directory::ChildHandles::iterator i = child_handles.begin(); 156 for (Directory::ChildHandles::iterator i = child_handles.begin();
157 i != child_handles.end(); ++i) {
158 EXPECT_EQ(*i, written_metahandle);
159 }
160
161 dir.GetChildHandlesByHandle(&rtrans, root_metahandle, &child_handles);
162 EXPECT_EQ(1u, child_handles.size());
163
164 for (Directory::ChildHandles::iterator i = child_handles.begin();
144 i != child_handles.end(); ++i) { 165 i != child_handles.end(); ++i) {
145 EXPECT_EQ(*i, written_metahandle); 166 EXPECT_EQ(*i, written_metahandle);
146 } 167 }
147 } 168 }
148 169
149 // Test writing data to an entity. Also check that GET_BY_HANDLE works. 170 // Test writing data to an entity. Also check that GET_BY_HANDLE works.
150 static const char s[] = "Hello World."; 171 static const char s[] = "Hello World.";
151 { 172 {
152 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__); 173 WriteTransaction trans(&dir, UNITTEST, __FILE__, __LINE__);
153 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle); 174 MutableEntry e(&trans, GET_BY_HANDLE, written_metahandle);
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) { 1802 TEST_F(SyncableClientTagTest, TestClientTagIndexDuplicateServer) {
1782 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1803 EXPECT_TRUE(CreateWithDefaultTag(factory_.NewServerId(), true));
1783 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true)); 1804 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), true));
1784 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false)); 1805 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewServerId(), false));
1785 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false)); 1806 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), false));
1786 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true)); 1807 EXPECT_FALSE(CreateWithDefaultTag(factory_.NewLocalId(), true));
1787 } 1808 }
1788 1809
1789 } // namespace 1810 } // namespace
1790 } // namespace syncable 1811 } // namespace syncable
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698