chromium/chrome/browser/extensions/user_script_world_browsertest.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 "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "extensions/browser/script_executor.h"
#include "extensions/common/extension_builder.h"
#include "extensions/test/result_catcher.h"
#include "extensions/test/test_extension_dir.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace extensions {

namespace {

constexpr char kCheckIfEvalAllowedScriptSource[] =;

constexpr char kGetMessagingProperties[] =;

}  // namespace

class UserScriptWorldBrowserTest : public ExtensionApiTest {};

// Tests that a user script world for an extension executed in an
// isolated world and has limited access to extension APIs.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       LimitedAPIsAreAvailableInUserScriptWorlds) {}

// Tests that, by default, the user script world's CSP is the same as the
// extension's CSP, but it can be updated to a more relaxed value.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       UserScriptWorldCspDefaultsToExtensionsAndCanBeUpdated) {}

// Tests that an update to the user script world's CSP does not apply to any
// already-created user script worlds.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       CspUpdatesDoNotApplyToExistingUserScriptWorlds) {}

// Tests that newly-created documents may greedily initialize isolated world CSP
// values.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       CspMayBeGreedilyInitializedOnDocumentCreation) {}

// Tests sending a message from a user script. This is sent via
// runtime.sendMessage from the user script, and should be received via
// runtime.onUserScriptMessage in the background script.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest, SendMessageAPI) {}

// Tests opening a message port from a user script. This is sent via
// runtime.connect() from the user script, and should be received via
// runtime.onUserScriptConnect in the background script.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest, ConnectAPI) {}

// Tests that attempting to message another extension from a user script throws
// an error.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       TryingToSendMessageToOtherExtensionTriggersError) {}

// Verifies that messaging APIs are exposed if and only if the user script world
// is configured to allow them.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       MessagingAPIsAreNotExposedIfEnableMessagingIsFalse) {}

// Tests injection into different user script worlds in the renderer.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       DifferentUserScriptWorldsAreIsolated) {}

// Tests that different user script worlds have unique configurations for CSP.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       UniquePropertiesPerUserScriptWorld_CSP) {}

// Tests clearing configurations for user script worlds.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       ClearingUserScriptWorldConfigurations) {}

// Tests that different user script worlds have unique configurations for
// enabling messaging.
IN_PROC_BROWSER_TEST_F(UserScriptWorldBrowserTest,
                       UniquePropertiesPerUserScriptWorld_Messaging) {}

}  // namespace extensions