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

Unified Diff: components/sync/engine_impl/loopback_server/loopback_server.h

Issue 2969643002: Reland - Replace FakeServer's implementation with LoopbackServer invocations. (Closed)
Patch Set: Rebased on master. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/BUILD.gn ('k') | components/sync/engine_impl/loopback_server/loopback_server.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/engine_impl/loopback_server/loopback_server.h
diff --git a/components/sync/engine_impl/loopback_server/loopback_server.h b/components/sync/engine_impl/loopback_server/loopback_server.h
index a69c99e4ac7c7da84751a21b88d3da0642352830..0f5d5d0644f243cf1b900966fa149cdb88597048 100644
--- a/components/sync/engine_impl/loopback_server/loopback_server.h
+++ b/components/sync/engine_impl/loopback_server/loopback_server.h
@@ -22,11 +22,25 @@
#include "components/sync/protocol/loopback_server.pb.h"
#include "components/sync/protocol/sync.pb.h"
+namespace fake_server {
+class FakeServer;
+}
+
namespace syncer {
// A loopback version of the Sync server used for local profile serialization.
class LoopbackServer {
public:
+ class ObserverForTests {
+ public:
+ virtual ~ObserverForTests() {}
+
+ // Called after the server has processed a successful commit. The types
+ // updated as part of the commit are passed in |committed_model_types|.
+ virtual void OnCommit(const std::string& committer_id,
+ syncer::ModelTypeSet committed_model_types) = 0;
+ };
+
explicit LoopbackServer(const base::FilePath& persistent_file);
virtual ~LoopbackServer();
@@ -40,9 +54,16 @@ class LoopbackServer {
std::string* response);
private:
+ // Allow the FakeServer decorator to inspect the internals of this class.
+ friend class fake_server::FakeServer;
+
using EntityMap =
std::map<std::string, std::unique_ptr<LoopbackServerEntity>>;
+ using ResponseTypeProvider =
+ base::RepeatingCallback<sync_pb::CommitResponse::ResponseType(
+ const LoopbackServerEntity& entity)>;
+
// Gets LoopbackServer ready for syncing.
void Init();
@@ -102,6 +123,44 @@ class LoopbackServer {
// Returns the store birthday.
std::string GetStoreBirthday() const;
+ // Returns all entities stored by the server of the given |model_type|.
+ // This method is only used in tests.
+ std::vector<sync_pb::SyncEntity> GetSyncEntitiesByModelType(
+ syncer::ModelType model_type);
+
+ // 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. Used by test to verify the contents of the server state.
+ std::unique_ptr<base::DictionaryValue> GetEntitiesAsDictionaryValue();
+
+ // Modifies the entity on the server with the given |id|. The entity's
+ // EntitySpecifics are replaced with |updated_specifics| and its version is
+ // updated to n+1. If the given |id| does not exist or the ModelType of
+ // |updated_specifics| does not match the entity, false is returned.
+ // Otherwise, true is returned to represent a successful modification.
+ //
+ // This method sometimes updates entity data beyond EntitySpecifics. For
+ // example, in the case of a bookmark, changing the BookmarkSpecifics title
+ // field will modify the top-level entity's name field.
+ // This method is only used in tests.
+ bool ModifyEntitySpecifics(const std::string& id,
+ const sync_pb::EntitySpecifics& updated_specifics);
+
+ // This method is only used in tests.
+ bool ModifyBookmarkEntity(const std::string& id,
+ const std::string& parent_id,
+ const sync_pb::EntitySpecifics& updated_specifics);
+
+ // Use this callback to generate response types for entities. They will still
+ // be "committed" and stored as normal, this only affects the response type
+ // the client sees. This allows tests to still inspect what the client has
+ // done, although not as useful of a mechanism for multi client tests. Care
+ // should be taken when failing responses, as the client will go into
+ // exponential backoff, which can cause tests to be slow or time out.
+ // This method is only used in tests.
+ void OverrideResponseType(ResponseTypeProvider response_type_override);
+
// Serializes the server state to |proto|.
void SerializeState(sync_pb::LoopbackServerProto* proto) const;
@@ -114,6 +173,10 @@ class LoopbackServer {
// Loads all entities and server state from a protobuf file in |filename|.
bool LoadStateFromFile(const base::FilePath& filename);
+ void set_observer_for_tests(ObserverForTests* observer) {
+ observer_for_tests_ = observer;
+ }
+
// This is the last version number assigned to an entity. The next entity will
// have a version number of version_ + 1.
int64_t version_;
@@ -128,6 +191,12 @@ class LoopbackServer {
// Used to verify that LoopbackServer is only used from one thread.
base::ThreadChecker thread_checker_;
+
+ // Used to observe the completion of commit messages for the sake of testing.
+ ObserverForTests* observer_for_tests_;
+
+ // Response type override callback used in tests.
+ ResponseTypeProvider response_type_override_;
};
} // namespace syncer
« no previous file with comments | « components/sync/BUILD.gn ('k') | components/sync/engine_impl/loopback_server/loopback_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698