Commit 57a237b7 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Extract mock autofill web data service

This can be helpful for other tests that require a mock as well

Change-Id: Ic68a3693c0eb92aa6717b9527ef51fe29be6ddbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040442Reviewed-by: default avatarParastoo Geranmayeh <parastoog@google.com>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740337}
parent 9f915433
......@@ -469,6 +469,8 @@ jumbo_static_library("test_support") {
"webdata/autofill_sync_bridge_test_util.h",
"webdata/mock_autofill_webdata_backend.cc",
"webdata/mock_autofill_webdata_backend.h",
"webdata/mock_autofill_webdata_service.cc",
"webdata/mock_autofill_webdata_service.h",
]
public_deps = [ ":browser" ]
......
......@@ -22,6 +22,7 @@
#include "components/autofill/core/browser/test_autofill_clock.h"
#include "components/autofill/core/browser/webdata/autofill_entry.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/browser/webdata/mock_autofill_webdata_service.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_prefs.h"
......@@ -43,26 +44,6 @@ namespace autofill {
namespace {
class MockWebDataService : public AutofillWebDataService {
public:
MockWebDataService()
: AutofillWebDataService(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get()) {}
MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
MOCK_METHOD1(CancelRequest, void(int));
MOCK_METHOD4(GetFormValuesForElementName,
WebDataServiceBase::Handle(const base::string16& name,
const base::string16& prefix,
int limit,
WebDataServiceConsumer* consumer));
MOCK_METHOD1(RemoveExpiredAutocompleteEntries,
WebDataServiceBase::Handle(WebDataServiceConsumer* consumer));
protected:
~MockWebDataService() override {}
};
class MockAutofillClient : public TestAutofillClient {
public:
MockAutofillClient() : prefs_(test::PrefServiceForTesting()) {}
......@@ -109,7 +90,7 @@ class AutocompleteHistoryManagerTest : public testing::Test {
// Set time to some arbitrary date.
test_clock.SetNow(base::Time::FromDoubleT(1546889367));
web_data_service_ = base::MakeRefCounted<MockWebDataService>();
web_data_service_ = base::MakeRefCounted<MockAutofillWebDataService>();
autocomplete_manager_ = std::make_unique<AutocompleteHistoryManager>();
autocomplete_manager_->Init(web_data_service_, prefs_.get(), false);
}
......@@ -152,7 +133,7 @@ class AutocompleteHistoryManagerTest : public testing::Test {
}
base::test::SingleThreadTaskEnvironment task_environment_;
scoped_refptr<MockWebDataService> web_data_service_;
scoped_refptr<MockAutofillWebDataService> web_data_service_;
std::unique_ptr<AutocompleteHistoryManager> autocomplete_manager_;
std::unique_ptr<PrefService> prefs_;
TestAutofillClock test_clock;
......
// 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 "components/autofill/core/browser/webdata/mock_autofill_webdata_service.h"
#include "base/threading/thread_task_runner_handle.h"
namespace autofill {
MockAutofillWebDataService::MockAutofillWebDataService()
: AutofillWebDataService(base::ThreadTaskRunnerHandle::Get(),
base::ThreadTaskRunnerHandle::Get()) {}
MockAutofillWebDataService::~MockAutofillWebDataService() = default;
} // namespace autofill
// 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 COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_MOCK_AUTOFILL_WEBDATA_SERVICE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_MOCK_AUTOFILL_WEBDATA_SERVICE_H_
#include "base/strings/string16.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/autofill/core/common/form_field_data.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace autofill {
class MockAutofillWebDataService : public AutofillWebDataService {
public:
MockAutofillWebDataService();
MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
MOCK_METHOD1(CancelRequest, void(int));
MOCK_METHOD4(GetFormValuesForElementName,
WebDataServiceBase::Handle(const base::string16& name,
const base::string16& prefix,
int limit,
WebDataServiceConsumer* consumer));
MOCK_METHOD1(RemoveExpiredAutocompleteEntries,
WebDataServiceBase::Handle(WebDataServiceConsumer* consumer));
protected:
~MockAutofillWebDataService() override;
};
} // namespace autofill
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_MOCK_AUTOFILL_WEBDATA_SERVICE_H_
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