chromium/chrome/browser/extensions/extension_startup_browsertest.cc

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

#include <stddef.h>
#include <stdint.h>

#include <vector>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/one_shot_event.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/scoped_multi_source_observation.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/scoped_test_mv2_enabler.h"
#include "chrome/browser/prefs/chrome_pref_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/browser/user_script_loader.h"
#include "extensions/browser/user_script_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_handlers/content_scripts_handler.h"
#include "extensions/common/switches.h"
#include "extensions/test/test_content_script_load_waiter.h"
#include "net/base/filename_util.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif

FeatureSwitch;
ExtensionRegistry;

// This file contains high-level startup tests for the extensions system. We've
// had many silly bugs where command line flags did not get propagated correctly
// into the services, so we didn't start correctly.

// A waiter for manifest content script loads. The waiter finishes when all of
// its observed extensions have finished loading their manifest scripts.
class ManifestContentScriptWaiter
    : public extensions::UserScriptLoader::Observer {};

class ExtensionStartupTestBase : public InProcessBrowserTest {};

// ExtensionsStartupTest
// Ensures that we can startup the browser with --enable-extensions and some
// extensions installed and see them run and do basic things.
ExtensionStartupTest;

IN_PROC_BROWSER_TEST_F(ExtensionStartupTest, Test) {}

// Tests that disallowing file access on an extension prevents it from injecting
// script into a page with a file URL.
IN_PROC_BROWSER_TEST_F(ExtensionStartupTest, NoFileAccess) {}

// ExtensionsLoadTest
// Ensures that we can startup the browser with --load-extension and see them
// run.
class ExtensionsLoadTest : public ExtensionStartupTestBase {};

IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest, Test) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)

IN_PROC_BROWSER_TEST_F(ExtensionsLoadTest,
                       SigninProfileCommandLineExtensionsDontLoad) {
  // The --load-extension command line flag should not be applied to the sign-in
  // profile.
  EXPECT_EQ(0, GetNonComponentEnabledExtensionCount(
                   ash::ProfileHelper::GetSigninProfile()));
}

#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// ExtensionsLoadMultipleTest
// Ensures that we can startup the browser with multiple extensions
// via --load-extension=X1,X2,X3.
class ExtensionsLoadMultipleTest : public ExtensionStartupTestBase {};

IN_PROC_BROWSER_TEST_F(ExtensionsLoadMultipleTest, Test) {}

// TODO(catmullings): Remove test in future chrome release, perhaps M59.
class DeprecatedLoadComponentExtensionSwitchBrowserTest
    : public extensions::ExtensionBrowserTest {};

void DeprecatedLoadComponentExtensionSwitchBrowserTest::SetUpCommandLine(
    base::CommandLine* command_line) {}

// Tests that the --load-component-extension flag is not supported.
IN_PROC_BROWSER_TEST_F(DeprecatedLoadComponentExtensionSwitchBrowserTest,
                       DefunctLoadComponentExtensionFlag) {}

class DisableExtensionsExceptBrowserTest
    : public extensions::ExtensionBrowserTest {};

void DisableExtensionsExceptBrowserTest::SetUpCommandLine(
    base::CommandLine* command_line) {}

// Tests disabling all extensions except those listed
// (--disable-extensions-except).
IN_PROC_BROWSER_TEST_F(DisableExtensionsExceptBrowserTest,
                       DisableExtensionsExceptFlag) {}