Commit d96f1ea6 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Rewrite SearchTabHelper unit tests in terms of TestSyncService

instead of ProfileSyncServiceMock. In general, it's always preferred to
use SyncService rather than ProfileSyncService, and in particular
there's no need for a mock here.

Bug: 910518
Change-Id: I7515ae070a7859ae767ec66acced9e0d5ec0e521
Reviewed-on: https://chromium-review.googlesource.com/c/1477680
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#633783}
parent 716496fe
...@@ -12,10 +12,9 @@ ...@@ -12,10 +12,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/time/time.h" #include "base/test/bind_test_util.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h" #include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
#include "chrome/browser/ui/search/search_ipc_router.h" #include "chrome/browser/ui/search/search_ipc_router.h"
#include "chrome/common/search/mock_embedded_search_client.h" #include "chrome/common/search/mock_embedded_search_client.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
...@@ -23,8 +22,8 @@ ...@@ -23,8 +22,8 @@
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "components/browser_sync/profile_sync_service.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/sync/driver/test_sync_service.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -73,7 +72,10 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { ...@@ -73,7 +72,10 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness {
content::BrowserContext* CreateBrowserContext() override { content::BrowserContext* CreateBrowserContext() override {
TestingProfile::TestingFactories factories = { TestingProfile::TestingFactories factories = {
{ProfileSyncServiceFactory::GetInstance(), {ProfileSyncServiceFactory::GetInstance(),
base::BindRepeating(&BuildMockProfileSyncService)}}; base::BindLambdaForTesting(
[](content::BrowserContext*) -> std::unique_ptr<KeyedService> {
return std::make_unique<syncer::TestSyncService>();
})}};
// Per comments on content::RenderViewHostTestHarness, it takes ownership of // Per comments on content::RenderViewHostTestHarness, it takes ownership of
// the returned object. // the returned object.
...@@ -91,18 +93,16 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness { ...@@ -91,18 +93,16 @@ class SearchTabHelperTest : public ChromeRenderViewHostTestHarness {
// Configure the account to |sync_history| or not. // Configure the account to |sync_history| or not.
void SetHistorySync(bool sync_history) { void SetHistorySync(bool sync_history) {
browser_sync::ProfileSyncServiceMock* sync_service = syncer::TestSyncService* sync_service =
static_cast<browser_sync::ProfileSyncServiceMock*>( static_cast<syncer::TestSyncService*>(
ProfileSyncServiceFactory::GetForProfile(profile())); ProfileSyncServiceFactory::GetForProfile(profile()));
ON_CALL(*sync_service->GetUserSettingsMock(), IsFirstSetupComplete()) sync_service->SetFirstSetupComplete(true);
.WillByDefault(Return(true));
syncer::ModelTypeSet types; syncer::ModelTypeSet types;
if (sync_history) { if (sync_history) {
types.Put(syncer::TYPED_URLS); types.Put(syncer::TYPED_URLS);
} }
ON_CALL(*sync_service->GetUserSettingsMock(), GetChosenDataTypes()) sync_service->SetPreferredDataTypes(types);
.WillByDefault(Return(types));
} }
identity::IdentityTestEnvironment* identity_test_env() { identity::IdentityTestEnvironment* identity_test_env() {
......
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