Commit 6fbfb4cb authored by Mikel Astiz's avatar Mikel Astiz Committed by Commit Bot

Avoid late keyed services with TestingProfile

This patch migrates tests away from deprecated APIs and adopts
TestingProfile::Builder for tests in
/chrome/browser/android/webapps.

Rationale: creating or overriding keyed services after the profile has
been created is problematic and known to cause hard-to-debug test
flakiness, because it bypasses BrowserContextDependencyManager and often
leading to use-after-free.

This CL was uploaded by git cl split.

R=dominickn@chromium.org

Bug: 1106699
Change-Id: I7e4f896a89aefad57d56d41ed2e269995769e31a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2315155
Auto-Submit: Mikel Astiz <mastiz@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Mikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791557}
parent 3f0d1137
......@@ -18,7 +18,9 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/flags/android/chrome_feature_list.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/installable/installable_manager.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/common/web_application_info.h"
......@@ -208,9 +210,6 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
ASSERT_TRUE(profile()->CreateHistoryService(false, true));
profile()->CreateFaviconService();
// Manually inject the TestInstallableManager as a "InstallableManager"
// WebContentsUserData. We can't directly call ::CreateForWebContents due to
// typing issues since TestInstallableManager doesn't directly inherit from
......@@ -224,6 +223,13 @@ class AddToHomescreenDataFetcherTest : public ChromeRenderViewHostTestHarness {
NavigateAndCommit(GURL(kDefaultStartUrl));
}
TestingProfile::TestingFactories GetTestingFactories() const override {
return {{HistoryServiceFactory::GetInstance(),
HistoryServiceFactory::GetDefaultFactory()},
{FaviconServiceFactory::GetInstance(),
FaviconServiceFactory::GetDefaultFactory()}};
}
std::unique_ptr<AddToHomescreenDataFetcher> BuildFetcher(
AddToHomescreenDataFetcher::Observer* observer) {
return std::make_unique<AddToHomescreenDataFetcher>(web_contents(), 500,
......
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