Commit 74ea7417 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Use syncer::TestSyncService in HistoryNoticeUtilsTest

One less subclass of FakeSyncService to maintain :)

Bug: 859874
Change-Id: I29d0f367227f59c2ab3b08eefefbd1b21bb35019
Reviewed-on: https://chromium-review.googlesource.com/c/1318922Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606397}
parent 3f9a5af5
......@@ -12,7 +12,7 @@
#include "base/test/bind_test_util.h"
#include "components/history/core/test/fake_web_history_service.h"
#include "components/sync/base/model_type.h"
#include "components/sync/driver/fake_sync_service.h"
#include "components/sync/driver/test_sync_service.h"
#include "components/version_info/version_info.h"
#include "net/http/http_status_code.h"
#include "net/url_request/url_request_test_util.h"
......@@ -20,66 +20,17 @@
namespace browsing_data {
namespace {
class TestSyncService : public syncer::FakeSyncService {
public:
// Getters (FakeSyncService implementation). ---------------------------------
int GetDisableReasons() const override { return DISABLE_REASON_NONE; }
TransportState GetTransportState() const override {
return IsFirstSetupComplete()
? TransportState::ACTIVE
: TransportState::PENDING_DESIRED_CONFIGURATION;
}
bool IsFirstSetupComplete() const override {
return is_first_setup_complete_;
}
syncer::ModelTypeSet GetActiveDataTypes() const override {
return active_data_types_;
}
bool IsUsingSecondaryPassphrase() const override {
return using_secondary_passphrase_;
}
// Setters. ------------------------------------------------------------------
void set_first_setup_complete(bool complete) {
is_first_setup_complete_ = complete;
}
void set_active_data_types(syncer::ModelTypeSet data_types) {
active_data_types_ = data_types;
}
void set_using_secondary_passphrase(bool passphrase) {
using_secondary_passphrase_ = passphrase;
}
private:
bool is_first_setup_complete_ = false;
syncer::ModelTypeSet active_data_types_;
bool using_secondary_passphrase_ = false;
};
} // namespace
class HistoryNoticeUtilsTest : public ::testing::Test {
public:
HistoryNoticeUtilsTest() {}
void SetUp() override {
sync_service_.reset(new TestSyncService());
sync_service_ = std::make_unique<syncer::TestSyncService>();
history_service_ = std::make_unique<history::FakeWebHistoryService>();
history_service_->SetupFakeResponse(true /* success */, net::HTTP_OK);
}
TestSyncService* sync_service() {
return sync_service_.get();
}
syncer::TestSyncService* sync_service() { return sync_service_.get(); }
history::FakeWebHistoryService* history_service() {
return history_service_.get();
......@@ -106,7 +57,7 @@ class HistoryNoticeUtilsTest : public ::testing::Test {
private:
scoped_refptr<net::URLRequestContextGetter> url_request_context_;
std::unique_ptr<TestSyncService> sync_service_;
std::unique_ptr<syncer::TestSyncService> sync_service_;
std::unique_ptr<history::FakeWebHistoryService> history_service_;
base::MessageLoop message_loop_;
......@@ -117,28 +68,25 @@ TEST_F(HistoryNoticeUtilsTest, NotSyncing) {
}
TEST_F(HistoryNoticeUtilsTest, SyncingWithWrongParameters) {
sync_service()->set_first_setup_complete(true);
// Regardless of the state of the web history...
history_service()->SetWebAndAppActivityEnabled(true);
history_service()->SetOtherFormsOfBrowsingHistoryPresent(true);
// ...the response is false if there's custom passphrase...
sync_service()->set_active_data_types(syncer::ModelTypeSet::All());
sync_service()->set_using_secondary_passphrase(true);
sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
sync_service()->SetIsUsingSecondaryPassphrase(true);
ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
// ...or even if there's no custom passphrase, but we're not syncing history.
syncer::ModelTypeSet only_passwords(syncer::PASSWORDS);
sync_service()->set_active_data_types(only_passwords);
sync_service()->set_using_secondary_passphrase(false);
sync_service()->SetActiveDataTypes(only_passwords);
sync_service()->SetIsUsingSecondaryPassphrase(false);
ExpectShouldPopupDialogAboutOtherFormsOfBrowsingHistoryWithResult(false);
}
TEST_F(HistoryNoticeUtilsTest, WebHistoryStates) {
// If history Sync is active...
sync_service()->set_first_setup_complete(true);
sync_service()->set_active_data_types(syncer::ModelTypeSet::All());
sync_service()->SetActiveDataTypes(syncer::ModelTypeSet::All());
// ...the result is true if both web history queries return true...
history_service()->SetWebAndAppActivityEnabled(true);
......
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