chromium/chrome/browser/extensions/api/user_scripts/user_scripts_apitest.cc

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

#include "build/build_config.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"
#include "extensions/browser/background_script_executor.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/script_executor.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/features/feature_developer_mode_only.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/dns/mock_host_resolver.h"

namespace extensions {

class UserScriptsAPITest : public ExtensionApiTest {};

UserScriptsAPITest::UserScriptsAPITest() {}

// TODO(crbug.com/40935741, crbug.com/335421977): Flaky on Linux debug and on
// "Linux ChromiumOS MSan Tests".
#if (BUILDFLAG(IS_LINUX) && !defined(NDEBUG)) || \
    (BUILDFLAG(IS_CHROMEOS) && defined(MEMORY_SANITIZER))
#define MAYBE_RegisterUserScripts
#else
#define MAYBE_RegisterUserScripts
#endif
IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, MAYBE_RegisterUserScripts) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, GetUserScripts) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, UnregisterUserScripts) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, UpdateUserScripts) {}

// TODO(crbug.com/335421977): Flaky on "Linux ChromiumOS MSan Tests".
#if BUILDFLAG(IS_CHROMEOS) && defined(MEMORY_SANITIZER)
#define MAYBE_ConfigureWorld
#else
#define MAYBE_ConfigureWorld
#endif
IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, MAYBE_ConfigureWorld) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITest, GetAndRemoveWorlds) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITest,
                       UserScriptInjectionOrderIsAlphabetical) {}

// Tests that registered user scripts are disabled when dev mode is disabled and
// are re-enabled if dev mode is turned back on.
IN_PROC_BROWSER_TEST_F(UserScriptsAPITest,
                       UserScriptsAreDisabledWhenDevModeIsDisabled) {}

// Base test fixture for tests spanning multiple sessions where a custom arg is
// set before the test is run.
class PersistentUserScriptsAPITest : public UserScriptsAPITest {};

// Tests that registered user scripts persist across sessions. The test is run
// across three sessions.
IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest,
                       PRE_PRE_PersistentScripts) {}

IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest, PRE_PersistentScripts) {}

IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest, PersistentScripts) {}

// Tests that the world configuration of a registered user script is persisted
// across sessions. The test is run across three sessions.
IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest,
                       PRE_PRE_PersistentWorldConfiguration) {}

IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest,
                       PRE_PersistentWorldConfiguration) {}

IN_PROC_BROWSER_TEST_F(PersistentUserScriptsAPITest,
                       PersistentWorldConfiguration) {}

// A test suite that runs without developer mode enabled.
class UserScriptsAPITestWithoutDeveloperMode : public UserScriptsAPITest {};

// Verifies that the `chrome.userScripts` API is unavailable if the user doesn't
// have dev mode turned on.
IN_PROC_BROWSER_TEST_F(UserScriptsAPITestWithoutDeveloperMode,
                       UserScriptsAPIIsUnavailableWithoutDeveloperMode) {}

// Tests that registered user scripts are properly ignored when loading
// stored dynamic scripts if developer mode is disabled.
IN_PROC_BROWSER_TEST_F(UserScriptsAPITestWithoutDeveloperMode,
                       PRE_UserScriptsDisabledOnStartupIfDevModeOff) {}

IN_PROC_BROWSER_TEST_F(UserScriptsAPITestWithoutDeveloperMode,
                       UserScriptsDisabledOnStartupIfDevModeOff) {}

}  // namespace extensions