summaryrefslogtreecommitdiffstats
path: root/chrome/test/sync
diff options
context:
space:
mode:
authorchron@google.com <chron@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 01:41:34 +0000
committerchron@google.com <chron@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-20 01:41:34 +0000
commit82b1cd9fc88d353b541064e52c4ed408033a43cf (patch)
tree8c1f99401a75dc522d9cab6365638fe1eb8ac51c /chrome/test/sync
parentd6d807a12ec32b7bba68977bddad412c9dccc5a0 (diff)
downloadchromium_src-82b1cd9fc88d353b541064e52c4ed408033a43cf.zip
chromium_src-82b1cd9fc88d353b541064e52c4ed408033a43cf.tar.gz
chromium_src-82b1cd9fc88d353b541064e52c4ed408033a43cf.tar.bz2
Remove unique naming from syncer! This reduces the complexity. Modify the index to store things with parent id and metahandle instead of parent id and name.
Add a template function for extracting name from proto buffers. Refactor some unit tests to work without unique naming. Remove path calls since they make no sense without unique names. Remove find by parentID and names. Remove unique name resolution from conflict resolver. Remove syncable name class. TEST=included unit tests Review URL: http://codereview.chromium.org/371029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32583 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/sync')
-rwxr-xr-x[-rw-r--r--]chrome/test/sync/engine/mock_server_connection.cc12
-rwxr-xr-x[-rw-r--r--]chrome/test/sync/engine/mock_server_connection.h9
-rwxr-xr-xchrome/test/sync/engine/test_syncable_utils.cc60
-rwxr-xr-xchrome/test/sync/engine/test_syncable_utils.h38
4 files changed, 106 insertions, 13 deletions
diff --git a/chrome/test/sync/engine/mock_server_connection.cc b/chrome/test/sync/engine/mock_server_connection.cc
index 28525b2..fdfb334 100644..100755
--- a/chrome/test/sync/engine/mock_server_connection.cc
+++ b/chrome/test/sync/engine/mock_server_connection.cc
@@ -41,7 +41,7 @@ MockConnectionManager::MockConnectionManager(DirectoryManager* dirmgr,
fail_next_postbuffer_(false),
directory_manager_(dirmgr),
directory_name_(name),
- mid_commit_callback_function_(NULL),
+ mid_commit_callback_(NULL),
mid_commit_observer_(NULL),
throttling_(false),
fail_non_periodic_get_updates_(false),
@@ -59,9 +59,8 @@ void MockConnectionManager::SetCommitTimeRename(string prepend) {
commit_time_rename_prepended_string_ = prepend;
}
-void MockConnectionManager::SetMidCommitCallbackFunction(
- MockConnectionManager::TestCallbackFunction callback) {
- mid_commit_callback_function_ = callback;
+void MockConnectionManager::SetMidCommitCallback(Closure* callback) {
+ mid_commit_callback_ = callback;
}
void MockConnectionManager::SetMidCommitObserver(
@@ -131,9 +130,8 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params,
}
response.SerializeToString(params->buffer_out);
- if (mid_commit_callback_function_) {
- if (mid_commit_callback_function_(directory))
- mid_commit_callback_function_ = 0;
+ if (mid_commit_callback_) {
+ mid_commit_callback_->Run();
}
if (mid_commit_observer_) {
mid_commit_observer_->Observe();
diff --git a/chrome/test/sync/engine/mock_server_connection.h b/chrome/test/sync/engine/mock_server_connection.h
index f4a110c..e8fa974 100644..100755
--- a/chrome/test/sync/engine/mock_server_connection.h
+++ b/chrome/test/sync/engine/mock_server_connection.h
@@ -13,6 +13,7 @@
#include "chrome/browser/sync/engine/net/server_connection_manager.h"
#include "chrome/browser/sync/protocol/sync.pb.h"
#include "chrome/browser/sync/syncable/directory_manager.h"
+#include "chrome/browser/sync/util/closure.h"
using std::string;
using std::vector;
@@ -27,10 +28,6 @@ struct HttpResponse;
class MockConnectionManager : public browser_sync::ServerConnectionManager {
public:
- // A callback function type. These can be set to be called when server
- // activity would normally take place. This aids simulation of race
- // conditions.
- typedef bool (*TestCallbackFunction)(syncable::Directory* dir);
class MidCommitObserver {
public:
virtual void Observe() = 0;
@@ -49,7 +46,7 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager {
virtual bool IsUserAuthenticated();
// Control of commit response.
- void SetMidCommitCallbackFunction(TestCallbackFunction callback);
+ void SetMidCommitCallback(Closure* callback);
void SetMidCommitObserver(MidCommitObserver* observer);
// Set this if you want commit to perform commit time rename. Will request
@@ -209,7 +206,7 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager {
// The updates we'll return to the next request.
sync_pb::GetUpdatesResponse updates_;
- TestCallbackFunction mid_commit_callback_function_;
+ Closure* mid_commit_callback_;
MidCommitObserver* mid_commit_observer_;
// The AUTHENTICATE response we'll return for auth requests.
diff --git a/chrome/test/sync/engine/test_syncable_utils.cc b/chrome/test/sync/engine/test_syncable_utils.cc
new file mode 100755
index 0000000..e01d3f0
--- /dev/null
+++ b/chrome/test/sync/engine/test_syncable_utils.cc
@@ -0,0 +1,60 @@
+// Copyright (c) 2009 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.
+
+// Utilities to verify the state of items in unit tests.
+
+#include "chrome/test/sync/engine/test_syncable_utils.h"
+
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace syncable {
+
+int CountEntriesWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ Directory::ChildHandles child_handles;
+ rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
+ if (child_handles.size() <= 0) {
+ return 0;
+ }
+
+ int number_of_entries_with_name = 0;
+ for (Directory::ChildHandles::iterator i = child_handles.begin();
+ i != child_handles.end(); ++i) {
+ Entry e(rtrans, GET_BY_HANDLE, *i);
+ CHECK(e.good());
+ if (e.Get(NON_UNIQUE_NAME) == name) {
+ ++number_of_entries_with_name;
+ }
+ }
+ return number_of_entries_with_name;
+}
+
+Id GetFirstEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ Directory::ChildHandles child_handles;
+ rtrans->directory()->GetChildHandles(rtrans, parent_id, &child_handles);
+
+ for (Directory::ChildHandles::iterator i = child_handles.begin();
+ i != child_handles.end(); ++i) {
+ Entry e(rtrans, GET_BY_HANDLE, *i);
+ CHECK(e.good());
+ if (e.Get(NON_UNIQUE_NAME) == name) {
+ return e.Get(ID);
+ }
+ }
+
+ CHECK(false);
+ return Id();
+}
+
+Id GetOnlyEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name) {
+ CHECK(1 == CountEntriesWithName(rtrans, parent_id, name));
+ return GetFirstEntryWithName(rtrans, parent_id, name);
+}
+
+} // namespace syncable
diff --git a/chrome/test/sync/engine/test_syncable_utils.h b/chrome/test/sync/engine/test_syncable_utils.h
new file mode 100755
index 0000000..4d6ce9c
--- /dev/null
+++ b/chrome/test/sync/engine/test_syncable_utils.h
@@ -0,0 +1,38 @@
+// Copyright (c) 2009 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.
+//
+// Utilities that are useful in verifying the state of items in a
+// syncable database.
+
+#ifndef CHROME_TEST_SYNC_ENGINE_TEST_SYNCABLE_UTILS_H_
+#define CHROME_TEST_SYNC_ENGINE_TEST_SYNCABLE_UTILS_H_
+
+#include "chrome/browser/sync/syncable/syncable.h"
+
+namespace syncable {
+
+class BaseTransaction;
+class Id;
+
+// Count the number of entries with a given name inside of a parent.
+// Useful to check folder structure and for porting older tests that
+// rely on uniqueness inside of folders.
+int CountEntriesWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name);
+
+// Get the first entry ID with name in a parent. The entry *must* exist.
+Id GetFirstEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name);
+
+// Assert that there's only one entry by this name in this parent.
+// Return the Id.
+Id GetOnlyEntryWithName(BaseTransaction* rtrans,
+ const syncable::Id& parent_id,
+ const PathString& name);
+
+} // namespace syncable
+
+#endif // CHROME_TEST_SYNC_ENGINE_TEST_SYNCABLE_UTILS_H_