chromium/chrome/browser/web_applications/test/fake_web_app_provider.h

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEB_APPLICATIONS_TEST_FAKE_WEB_APP_PROVIDER_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_TEST_FAKE_WEB_APP_PROVIDER_H_

#include <memory>

#include "base/callback_list.h"
#include "base/functional/callback.h"
#include "base/memory/scoped_refptr.h"
#include "build/build_config.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "testing/gmock/include/gmock/gmock.h"

class KeyedService;
class Profile;

namespace content {
class BrowserContext;
}

namespace web_app {

class AbstractWebAppDatabaseFactory;
class ExternallyManagedAppManager;
class FileUtilsWrapper;
class IsolatedWebAppInstallationManager;
class IsolatedWebAppUpdateManager;
class OsIntegrationManager;
class PreinstalledWebAppManager;
class WebAppCommandManager;
class WebAppCommandScheduler;
class WebAppIconManager;
class WebAppInstallFinalizer;
class WebAppInstallManager;
class WebAppOriginAssociationManager;
class WebAppPolicyManager;
class WebAppRegistrarMutable;
class WebAppSyncBridge;
class WebAppTranslationManager;
class WebAppUiManager;
class WebContentsManager;

#if BUILDFLAG(IS_CHROMEOS)
class WebAppRunOnOsLoginManager;
#endif

// This is a tool that allows unit tests (enabled by default) and browser tests
// (disabled by default) to use a 'fake' version of the WebAppProvider system.
// This means that most of the dependencies are faked out. Specifically:
// * The database is in-memory.
// * Integration with Chrome Sync is off.
// * OS integration (saving shortcuts on disk, etc) doesn't execute, but does
//   save its 'expected' state to the database.
// * All access to `WebContents` is redirected to the `FakeWebContentsManager`
//   (accessible via `GetFakeWebContentsManager()`), which stores & returns
//   results for any interaction here.
//
// Other features & notes:
// * FakeWebAppProvider is used by default in unit tests, as the
//   `TestingProfile` hardcodes the usage of this fake version in the
//   `KeyedServiceFactory` for the profile,
// * The system in NOT 'started' by default, which means commands and other
//   operations will not run. This allows tests to do any customization they may
//   want by calling `FakeWebAppProvider::Get()` and interacting with this
//   object before the system is started.
//   * Generally the system is then started by calling
//     `web_app::test::AwaitStartWebAppProviderAndSubsystems(profile());`, which
//     waits for the system to be `ready()`, but also for any external install
//     managers to finish startup as well.
// * To use this in browser tests, you must use the FakeWebAppProviderCreator
//   below.
//
// Future improvements:
// * TODO(http://b/257529391): Isolate the extensions system dependency to
//   allow faking that as well.
// * TODO(http://b/279198384): Make better default for external manager behavior
//   in unittests. Perhaps don't start them by default unless they specified.
// * TODO(http://b/279198562): Create a `FakeWebAppCommandScheduler`, allowing
//   external systems to fully fake out usage of this system if they desire.
class FakeWebAppProvider : public WebAppProvider {};

// Used in BrowserTests to ensure that the WebAppProvider that is create on
// profile startup is the FakeWebAppProvider. Hooks into the
// BrowserContextKeyedService initialization pipeline.
class FakeWebAppProviderCreator {};

}  // namespace web_app

#endif  // CHROME_BROWSER_WEB_APPLICATIONS_TEST_FAKE_WEB_APP_PROVIDER_H_