// Copyright 2013 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_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_TEST_BASE_H_
#define CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_TEST_BASE_H_

#include <memory>

#include "base/files/file_path.h"
#include "chrome/test/base/web_ui_mocha_browser_test.h"
#include "extensions/browser/install_verifier.h"
#include "extensions/browser/scoped_ignore_content_verifier_for_test.h"
#include "extensions/buildflags/buildflags.h"

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/extensions/scoped_test_mv2_enabler.h"
#endif  // !BUILDFLAG(IS_ANDROID)

#if BUILDFLAG(IS_WIN)
#include "base/base_paths_win.h"
#include "base/test/scoped_path_override.h"
#endif  // BUILDFLAG(IS_WIN)

static_assert(BUILDFLAG(ENABLE_EXTENSIONS_CORE));

namespace extensions {
class Extension;
class ScopedTestDialogAutoConfirm;
}  // namespace extensions

// C++ base class used by Extensions tests in chrome/test/data/webui/extensions/
// and chrome/browser/ui/webui/extensions/.
class ExtensionSettingsTestBase : public WebUIMochaBrowserTest {
 public:
  ExtensionSettingsTestBase();

  ExtensionSettingsTestBase(const ExtensionSettingsTestBase&) = delete;
  ExtensionSettingsTestBase& operator=(const ExtensionSettingsTestBase&) =
      delete;

  ~ExtensionSettingsTestBase() override;

 protected:
  void InstallGoodExtension();

  void InstallErrorsExtension();

  void InstallSharedModule();

  void InstallPackagedApp();

  void InstallHostedApp();

  void InstallPlatformApp();

  // Installs chrome/test/data/extensions/options_page_in_view extension
  // and returns it back to the caller.  Can return null upon failure.
  const extensions::Extension* InstallExtensionWithInPageOptions();

  void SetAutoConfirmUninstall();

  // Sets the DevMode status for the current profile.
  void SetDevModeEnabled(bool enabled);

  const base::FilePath& test_data_dir() { return test_data_dir_; }

 private:
  const extensions::Extension* InstallExtension(const base::FilePath& path);

  const base::FilePath test_data_dir_;

#if BUILDFLAG(IS_WIN)
  // This is needed to stop tests creating a shortcut in the Windows start menu.
  // The override needs to last until the test is destroyed, because Windows
  // shortcut tasks which create the shortcut can run after the test body
  // returns.
  base::ScopedPathOverride override_start_dir{base::DIR_START_MENU};
#endif  // BUILDFLAG(IS_WIN)

  // Disable extension content verification.
  extensions::ScopedIgnoreContentVerifierForTest ignore_content_verification_;

  // Disable extension install verification.
  extensions::ScopedInstallVerifierBypassForTest ignore_install_verification_;

  std::unique_ptr<extensions::ScopedTestDialogAutoConfirm>
      uninstall_auto_confirm_;

#if !BUILDFLAG(IS_ANDROID)
  // TODO(https://crbug.com/40804030): Remove this when updated to use MV3.
  extensions::ScopedTestMV2Enabler mv2_enabler_;
#endif  // BUILDFLAG(IS_ANDROID)
};

#endif  // CHROME_BROWSER_UI_WEBUI_EXTENSIONS_EXTENSION_SETTINGS_TEST_BASE_H_
