summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorpvalenzuela@chromium.org <pvalenzuela@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 03:29:12 +0000
committerpvalenzuela@chromium.org <pvalenzuela@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 03:29:12 +0000
commitb3a902786b286083c762765044c51b43449f8fdf (patch)
tree25ba94d81ea62480a09937c0c7160d9d72e1a560 /sync
parent0f89d989dd8b20bbac93ccc52af663071e36f2f6 (diff)
downloadchromium_src-b3a902786b286083c762765044c51b43449f8fdf.zip
chromium_src-b3a902786b286083c762765044c51b43449f8fdf.tar.gz
chromium_src-b3a902786b286083c762765044c51b43449f8fdf.tar.bz2
Add initial FakeServer verification for Sync tests
This CL adds a method to FakeServer to export current data using base::Value. This data is consumed by a new class, FakeServerVerifier, that provides methods for verifying the data in integration tests. The initial verification is rather simple. For example, only entity names are compared and bookmark folders are not considered. BUG=NONE Review URL: https://codereview.chromium.org/242143002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/sync_tests.gypi5
-rw-r--r--sync/test/fake_server/fake_server.cc37
-rw-r--r--sync/test/fake_server/fake_server.h7
-rw-r--r--sync/test/fake_server/fake_server_verifier.cc99
-rw-r--r--sync/test/fake_server/fake_server_verifier.h53
5 files changed, 198 insertions, 3 deletions
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index 2eefc68..f6f88b7 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -103,7 +103,8 @@
'dependencies': [
'../base/base.gyp:base',
'../net/net.gyp:net',
- '../third_party/protobuf/protobuf.gyp:protobuf_lite',
+ '../testing/gtest.gyp:gtest',
+ '../third_party/protobuf/protobuf.gyp:protobuf_lite',
'sync',
],
'export_dependent_settings': [
@@ -120,6 +121,8 @@
'test/fake_server/fake_server_http_post_provider.h',
'test/fake_server/fake_server_network_resources.cc',
'test/fake_server/fake_server_network_resources.h',
+ 'test/fake_server/fake_server_verifier.cc',
+ 'test/fake_server/fake_server_verifier.h',
'test/fake_server/permanent_entity.cc',
'test/fake_server/permanent_entity.h',
'test/fake_server/tombstone_entity.cc',
diff --git a/sync/test/fake_server/fake_server.cc b/sync/test/fake_server/fake_server.cc
index 3827a85..d758e5d 100644
--- a/sync/test/fake_server/fake_server.cc
+++ b/sync/test/fake_server/fake_server.cc
@@ -32,6 +32,7 @@ using std::vector;
using base::AutoLock;
using syncer::GetModelType;
using syncer::ModelType;
+using syncer::ModelTypeSet;
// The default birthday value.
static const char kDefaultBirthday[] = "1234567890";
@@ -98,7 +99,7 @@ class UpdateSieve {
// Returns the data type IDs of types being synced for the first time.
vector<ModelType> GetFirstTimeTypes(
- syncer::ModelTypeSet created_permanent_entity_types) const {
+ ModelTypeSet created_permanent_entity_types) const {
vector<ModelType> types;
ModelTypeToVersionMap::const_iterator it;
@@ -171,7 +172,7 @@ bool FakeServer::CreateDefaultPermanentItems(
const vector<ModelType>& first_time_types) {
for (vector<ModelType>::const_iterator it = first_time_types.begin();
it != first_time_types.end(); ++it) {
- if (!syncer::ModelTypeSet::All().Has(*it)) {
+ if (!ModelTypeSet::All().Has(*it)) {
NOTREACHED() << "An unexpected ModelType was encountered.";
}
@@ -456,4 +457,36 @@ bool FakeServer::HandleCommitRequest(
return true;
}
+scoped_ptr<base::DictionaryValue> FakeServer::GetEntitiesAsDictionaryValue() {
+ scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue());
+
+ // Initialize an empty ListValue for all ModelTypes.
+ ModelTypeSet all_types = ModelTypeSet::All();
+ for (ModelTypeSet::Iterator it = all_types.First(); it.Good(); it.Inc()) {
+ dictionary->Set(ModelTypeToString(it.Get()), new base::ListValue());
+ }
+
+ for (EntityMap::const_iterator it = entities_.begin(); it != entities_.end();
+ ++it) {
+ FakeServerEntity* entity = it->second;
+ if (entity->IsDeleted() || entity->IsFolder()) {
+ // Tombstones are ignored as they don't represent current data. Folders
+ // are also ignored as current verification infrastructure does not
+ // consider them.
+ continue;
+ }
+ base::ListValue* list_value;
+ if (!dictionary->GetList(ModelTypeToString(entity->GetModelType()),
+ &list_value)) {
+ return scoped_ptr<base::DictionaryValue>();
+ }
+ // TODO(pvalenzuela): Store more data for each entity so additional
+ // verification can be performed. One example of additional verification
+ // is checking the correctness of the bookmark hierarchy.
+ list_value->Append(new base::StringValue(entity->GetName()));
+ }
+
+ return dictionary.Pass();
+}
+
} // namespace fake_server
diff --git a/sync/test/fake_server/fake_server.h b/sync/test/fake_server/fake_server.h
index a13cc98..0621bbc 100644
--- a/sync/test/fake_server/fake_server.h
+++ b/sync/test/fake_server/fake_server.h
@@ -11,6 +11,7 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
+#include "base/values.h"
#include "sync/internal_api/public/base/model_type.h"
#include "sync/protocol/sync.pb.h"
#include "sync/test/fake_server/fake_server_entity.h"
@@ -30,6 +31,12 @@ class FakeServer {
int* response_code,
std::string* response);
+ // Creates a DicionaryValue representation of all entities present in the
+ // server. The dictionary keys are the strings generated by ModelTypeToString
+ // and the values are ListValues containing StringValue versions of entity
+ // names.
+ scoped_ptr<base::DictionaryValue> GetEntitiesAsDictionaryValue();
+
private:
typedef std::map<std::string, FakeServerEntity*> EntityMap;
diff --git a/sync/test/fake_server/fake_server_verifier.cc b/sync/test/fake_server/fake_server_verifier.cc
new file mode 100644
index 0000000..9c02075
--- /dev/null
+++ b/sync/test/fake_server/fake_server_verifier.cc
@@ -0,0 +1,99 @@
+// Copyright 2014 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.
+
+#include "sync/test/fake_server/fake_server_verifier.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "sync/test/fake_server/fake_server.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using std::string;
+using testing::AssertionFailure;
+using testing::AssertionResult;
+using testing::AssertionSuccess;
+
+namespace {
+
+AssertionResult DictionaryCreationAssertionFailure() {
+ return AssertionFailure() << "FakeServer failed to create an entities "
+ << "dictionary.";
+}
+
+AssertionResult VerificationCountAssertionFailure(size_t actual_count,
+ size_t expected_count) {
+ return AssertionFailure() << "Actual count: " << actual_count << "; "
+ << "Expected count: " << expected_count;
+}
+
+AssertionResult UnknownTypeAssertionFailure(const string& model_type) {
+ return AssertionFailure() << "Verification not attempted. Unknown ModelType: "
+ << model_type;
+}
+
+} // namespace
+
+namespace fake_server {
+
+FakeServerVerifier::FakeServerVerifier(FakeServer* fake_server)
+ : fake_server_(fake_server) { }
+
+FakeServerVerifier::~FakeServerVerifier() {}
+
+AssertionResult FakeServerVerifier::VerifyEntityCountByType(
+ size_t expected_count,
+ syncer::ModelType model_type) const {
+ scoped_ptr<base::DictionaryValue> entities =
+ fake_server_->GetEntitiesAsDictionaryValue();
+ if (!entities.get()) {
+ return DictionaryCreationAssertionFailure();
+ }
+
+ string model_type_string = ModelTypeToString(model_type);
+ base::ListValue* entity_list = NULL;
+ if (!entities->GetList(model_type_string, &entity_list)) {
+ return UnknownTypeAssertionFailure(model_type_string);
+ } else if (expected_count != entity_list->GetSize()) {
+ return VerificationCountAssertionFailure(entity_list->GetSize(),
+ expected_count);
+ }
+
+ return AssertionSuccess();
+}
+
+AssertionResult FakeServerVerifier::VerifyEntityCountByTypeAndName(
+ size_t expected_count,
+ syncer::ModelType model_type,
+ const string& name) const {
+ scoped_ptr<base::DictionaryValue> entities =
+ fake_server_->GetEntitiesAsDictionaryValue();
+ if (!entities.get()) {
+ return DictionaryCreationAssertionFailure();
+ }
+
+ string model_type_string = ModelTypeToString(model_type);
+ base::ListValue* entity_list = NULL;
+ size_t actual_count = 0;
+ if (entities->GetList(model_type_string, &entity_list)) {
+ scoped_ptr<base::Value> name_value(new base::StringValue(name));
+ for (base::ListValue::const_iterator it = entity_list->begin();
+ it != entity_list->end(); ++it) {
+ if (name_value->Equals(*it)) {
+ actual_count++;
+ }
+ }
+ }
+
+ if (!entity_list) {
+ return UnknownTypeAssertionFailure(model_type_string);
+ } else if (actual_count != expected_count) {
+ return VerificationCountAssertionFailure(actual_count, expected_count)
+ << "; Name: " << name;
+ }
+
+ return AssertionSuccess();
+}
+
+} // namespace fake_server
diff --git a/sync/test/fake_server/fake_server_verifier.h b/sync/test/fake_server/fake_server_verifier.h
new file mode 100644
index 0000000..c214286
--- /dev/null
+++ b/sync/test/fake_server/fake_server_verifier.h
@@ -0,0 +1,53 @@
+// Copyright 2014 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.
+
+#ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_VERIFIER_H_
+#define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_VERIFIER_H_
+
+#include <string>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "sync/internal_api/public/base/model_type.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace fake_server {
+
+class FakeServer;
+
+// Provides methods to verify the state of a FakeServer. The main use case of
+// this class is verifying committed data so that it does not have to be synced
+// down to another test client for verification. These methods are not present
+// on FakeServer so that its interface is not polluted.
+class FakeServerVerifier {
+ public:
+ // Creates a FakeServerVerifier for |fake_server|. This class does not take
+ // ownership of |fake_server|.
+ explicit FakeServerVerifier(FakeServer* fake_server);
+ virtual ~FakeServerVerifier();
+
+ // Returns a successful result if there are |expected_count| entities with the
+ // given |model_type|. A failure is returned if the count does not match or
+ // verification can't take place.
+ testing::AssertionResult VerifyEntityCountByType(
+ size_t expected_count,
+ syncer::ModelType model_type) const;
+
+ // Returns a successful result if there are |expected_count| entities with the
+ // given |model_type| and |name|. A failure is returned if the count does not
+ // match or verification can't take place.
+ testing::AssertionResult VerifyEntityCountByTypeAndName(
+ size_t expected_count,
+ syncer::ModelType model_type,
+ const std::string& name) const;
+
+ private:
+ FakeServer* const fake_server_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeServerVerifier);
+};
+
+} // namespace fake_server
+
+#endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_VERIFIER_H_