Commit 4522d34f authored by Paula Vidas's avatar Paula Vidas Committed by Commit Bot

[SyncInvalidations] Move ServerDeviceInfoMatchChecker to helper.

The class is moved to a helper file so it can be reused in tests for
sync invalidations.

Bug: 1135167
Change-Id: I30cbc76cd5ed032666c5827b007c94128a65ebb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450269
Commit-Queue: Paula Vidas <paulavidas@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarRushan Suleymanov <rushans@google.com>
Cr-Commit-Position: refs/heads/master@{#814150}
parent 0797869f
// Copyright 2020 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 "chrome/browser/sync/test/integration/device_info_helper.h"
ServerDeviceInfoMatchChecker::ServerDeviceInfoMatchChecker(
fake_server::FakeServer* fake_server,
const Matcher& matcher)
: fake_server_(fake_server), matcher_(matcher) {
fake_server->AddObserver(this);
}
ServerDeviceInfoMatchChecker::~ServerDeviceInfoMatchChecker() {
fake_server_->RemoveObserver(this);
}
void ServerDeviceInfoMatchChecker::OnCommit(
const std::string& committer_id,
syncer::ModelTypeSet committed_model_types) {
if (committed_model_types.Has(syncer::DEVICE_INFO)) {
CheckExitCondition();
}
}
bool ServerDeviceInfoMatchChecker::IsExitConditionSatisfied(std::ostream* os) {
std::vector<sync_pb::SyncEntity> entities =
fake_server_->GetSyncEntitiesByModelType(syncer::DEVICE_INFO);
testing::StringMatchResultListener result_listener;
const bool matches =
testing::ExplainMatchResult(matcher_, entities, &result_listener);
*os << result_listener.str();
return matches;
}
// Copyright 2020 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 CHROME_BROWSER_SYNC_TEST_INTEGRATION_DEVICE_INFO_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_DEVICE_INFO_HELPER_H_
#include <ostream>
#include <string>
#include "chrome/browser/sync/test/integration/status_change_checker.h"
#include "components/sync/protocol/sync.pb.h"
#include "components/sync/test/fake_server/fake_server.h"
#include "testing/gtest/include/gtest/gtest.h"
// A helper class that waits for a certain set of DeviceInfos on the FakeServer.
// The desired state is passed in as a GTest matcher.
class ServerDeviceInfoMatchChecker : public StatusChangeChecker,
fake_server::FakeServer::Observer {
public:
using Matcher = testing::Matcher<std::vector<sync_pb::SyncEntity>>;
ServerDeviceInfoMatchChecker(fake_server::FakeServer* fake_server,
const Matcher& matcher);
~ServerDeviceInfoMatchChecker() override;
ServerDeviceInfoMatchChecker(const ServerDeviceInfoMatchChecker&) = delete;
ServerDeviceInfoMatchChecker& operator=(const ServerDeviceInfoMatchChecker&) =
delete;
// FakeServer::Observer overrides.
void OnCommit(const std::string& committer_id,
syncer::ModelTypeSet committed_model_types) override;
// StatusChangeChecker overrides.
bool IsExitConditionSatisfied(std::ostream* os) override;
private:
fake_server::FakeServer* const fake_server_;
const Matcher matcher_;
};
#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_DEVICE_INFO_HELPER_H_
...@@ -2,13 +2,12 @@ ...@@ -2,13 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <ostream>
#include <string> #include <string>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/sync/test/integration/device_info_helper.h"
#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
#include "chrome/browser/sync/test/integration/status_change_checker.h"
#include "chrome/browser/sync/test/integration/sync_test.h" #include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "components/sync/base/model_type.h" #include "components/sync/base/model_type.h"
...@@ -66,48 +65,6 @@ sync_pb::DeviceInfoSpecifics CreateSpecifics(int suffix) { ...@@ -66,48 +65,6 @@ sync_pb::DeviceInfoSpecifics CreateSpecifics(int suffix) {
return specifics; return specifics;
} }
class ServerDeviceInfoMatchChecker : public StatusChangeChecker,
fake_server::FakeServer::Observer {
public:
using Matcher = testing::Matcher<std::vector<sync_pb::SyncEntity>>;
ServerDeviceInfoMatchChecker(fake_server::FakeServer* fake_server,
const Matcher& matcher)
: fake_server_(fake_server), matcher_(matcher) {
fake_server->AddObserver(this);
}
~ServerDeviceInfoMatchChecker() override {
fake_server_->RemoveObserver(this);
}
// FakeServer::Observer overrides.
void OnCommit(const std::string& committer_id,
syncer::ModelTypeSet committed_model_types) override {
if (committed_model_types.Has(syncer::DEVICE_INFO)) {
CheckExitCondition();
}
}
// StatusChangeChecker overrides.
bool IsExitConditionSatisfied(std::ostream* os) override {
std::vector<sync_pb::SyncEntity> entities =
fake_server_->GetSyncEntitiesByModelType(syncer::DEVICE_INFO);
testing::StringMatchResultListener result_listener;
const bool matches =
testing::ExplainMatchResult(matcher_, entities, &result_listener);
*os << result_listener.str();
return matches;
}
private:
fake_server::FakeServer* const fake_server_;
const Matcher matcher_;
DISALLOW_COPY_AND_ASSIGN(ServerDeviceInfoMatchChecker);
};
class SingleClientDeviceInfoSyncTest : public SyncTest { class SingleClientDeviceInfoSyncTest : public SyncTest {
public: public:
SingleClientDeviceInfoSyncTest() : SyncTest(SINGLE_CLIENT) {} SingleClientDeviceInfoSyncTest() : SyncTest(SINGLE_CLIENT) {}
......
...@@ -6641,6 +6641,8 @@ if (!is_fuchsia) { ...@@ -6641,6 +6641,8 @@ if (!is_fuchsia) {
"../browser/sync/test/integration/autofill_helper.h", "../browser/sync/test/integration/autofill_helper.h",
"../browser/sync/test/integration/configuration_refresher.cc", "../browser/sync/test/integration/configuration_refresher.cc",
"../browser/sync/test/integration/configuration_refresher.h", "../browser/sync/test/integration/configuration_refresher.h",
"../browser/sync/test/integration/device_info_helper.cc",
"../browser/sync/test/integration/device_info_helper.h",
"../browser/sync/test/integration/fake_server_invalidation_sender.cc", "../browser/sync/test/integration/fake_server_invalidation_sender.cc",
"../browser/sync/test/integration/fake_server_invalidation_sender.h", "../browser/sync/test/integration/fake_server_invalidation_sender.h",
"../browser/sync/test/integration/multi_client_status_change_checker.cc", "../browser/sync/test/integration/multi_client_status_change_checker.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment