Commit d5684a76 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Fix flaky test DeepScanningReportingTest.ProcessesResponseCorrectly.

This test tried to use a service whose factory is null in test mode.
It would work if run standalone because the factory was _also_ not
properly registered on startup, so the testing factory would never be
set to null.  However, if run in a batch with other browser tests, a
previous test's access to the factory would register it; the next
browser startup would null its testing factory; and then this test
would crash.

This fixes both problems: registers the factory, and sets a non-null
testing factory.

Bug: none
Change-Id: I877cb9b7c58e82de17888b52d7d6ddc34f5bec27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2133626Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarVarun Khaneja <vakh@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755866}
parent 1be6a9e5
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router_factory.h" #include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router_factory.h"
#include "chrome/browser/extensions/api/preference/preference_api.h" #include "chrome/browser/extensions/api/preference/preference_api.h"
#include "chrome/browser/extensions/api/processes/processes_api.h" #include "chrome/browser/extensions/api/processes/processes_api.h"
#include "chrome/browser/extensions/api/safe_browsing_private/safe_browsing_private_event_router_factory.h"
#include "chrome/browser/extensions/api/sessions/sessions_api.h" #include "chrome/browser/extensions/api/sessions/sessions_api.h"
#include "chrome/browser/extensions/api/settings_overrides/settings_overrides_api.h" #include "chrome/browser/extensions/api/settings_overrides/settings_overrides_api.h"
#include "chrome/browser/extensions/api/settings_private/settings_private_event_router_factory.h" #include "chrome/browser/extensions/api/settings_private/settings_private_event_router_factory.h"
...@@ -116,6 +117,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() { ...@@ -116,6 +117,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
#endif #endif
extensions::PreferenceAPI::GetFactoryInstance(); extensions::PreferenceAPI::GetFactoryInstance();
extensions::ProcessesAPI::GetFactoryInstance(); extensions::ProcessesAPI::GetFactoryInstance();
extensions::SafeBrowsingPrivateEventRouterFactory::GetInstance();
extensions::SessionsAPI::GetFactoryInstance(); extensions::SessionsAPI::GetFactoryInstance();
extensions::SettingsPrivateEventRouterFactory::GetInstance(); extensions::SettingsPrivateEventRouterFactory::GetInstance();
extensions::SettingsOverridesAPI::GetFactoryInstance(); extensions::SettingsOverridesAPI::GetFactoryInstance();
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "chrome/browser/safe_browsing/dm_token_utils.h" #include "chrome/browser/safe_browsing/dm_token_utils.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_service.h" #include "chrome/browser/safe_browsing/download_protection/download_protection_service.h"
#include "chrome/browser/safe_browsing/download_protection/download_protection_util.h" #include "chrome/browser/safe_browsing/download_protection/download_protection_util.h"
#include "chrome/browser/safe_browsing/test_extension_event_observer.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
...@@ -354,11 +355,13 @@ class DeepScanningReportingTest : public DeepScanningRequestTest { ...@@ -354,11 +355,13 @@ class DeepScanningReportingTest : public DeepScanningRequestTest {
public: public:
void SetUp() override { void SetUp() override {
DeepScanningRequestTest::SetUp(); DeepScanningRequestTest::SetUp();
SetUpReporting();
}
void SetUpReporting() {
client_ = std::make_unique<policy::MockCloudPolicyClient>(); client_ = std::make_unique<policy::MockCloudPolicyClient>();
extensions::SafeBrowsingPrivateEventRouterFactory::GetInstance()
->SetTestingFactory(
profile_,
base::BindRepeating(&BuildSafeBrowsingPrivateEventRouter));
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile_) extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile_)
->SetCloudPolicyClientForTesting(client_.get()); ->SetCloudPolicyClientForTesting(client_.get());
extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile_) extensions::SafeBrowsingPrivateEventRouterFactory::GetForProfile(profile_)
...@@ -366,6 +369,7 @@ class DeepScanningReportingTest : public DeepScanningRequestTest { ...@@ -366,6 +369,7 @@ class DeepScanningReportingTest : public DeepScanningRequestTest {
download_protection_service_.GetFakeBinaryUploadService()); download_protection_service_.GetFakeBinaryUploadService());
download_protection_service_.GetFakeBinaryUploadService() download_protection_service_.GetFakeBinaryUploadService()
->SetAuthForTesting(true); ->SetAuthForTesting(true);
TestingBrowserProcess::GetGlobal()->local_state()->SetBoolean( TestingBrowserProcess::GetGlobal()->local_state()->SetBoolean(
prefs::kUnsafeEventsReportingEnabled, true); prefs::kUnsafeEventsReportingEnabled, 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