chromium/chrome/browser/controlled_frame/controlled_frame_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 <memory>
#include <string>

#include "base/test/gmock_expected_support.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/controlled_frame/controlled_frame_test_base.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/extensions/menu_manager.h"
#include "chrome/browser/extensions/service_worker_apitest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/isolated_web_apps/test/isolated_web_app_builder.h"
#include "chrome/common/chrome_features.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.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 "content/public/test/test_utils.h"
#include "content/public/test/web_transport_simple_test_server.h"
#include "extensions/browser/api/web_request/extension_web_request_event_router.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/guest_view/web_view/web_view_guest.h"
#include "extensions/test/extension_test_message_listener.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
#include "net/test/test_data_directory.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace controlled_frame {

namespace {

constexpr char kWebRequestOnBeforeRequestEventName[] =;
constexpr char kWebRequestOnAuthRequiredEventName[] =;
constexpr char kEvalSuccessStr[] =;

const extensions::MenuItem::Id CreateMenuItemId(
    const extensions::MenuItem::ExtensionKey& extension_key,
    const std::string& string_uid) {}

const content::EvalJsResult CreateContextMenuItem(
    content::RenderFrameHost* app_frame,
    const std::string& id,
    const std::string& title) {}

const content::EvalJsResult UpdateContextMenuItemTitle(
    content::RenderFrameHost* app_frame,
    const std::string& id,
    const std::string& new_title) {}

const content::EvalJsResult RemoveContextMenuItem(
    content::RenderFrameHost* app_frame,
    const std::string& id) {}

const content::EvalJsResult RemoveAllContextMenuItems(
    content::RenderFrameHost* app_frame) {}

const content::EvalJsResult SetBackgroundColorToWhite(
    extensions::WebViewGuest* guest) {}

const content::EvalJsResult ExecuteScriptRedBackgroundCode(
    content::RenderFrameHost* app_frame) {}

const content::EvalJsResult ExecuteScriptRedBackgroundFile(
    content::RenderFrameHost* app_frame) {}

const content::EvalJsResult VerifyBackgroundColorIsRed(
    extensions::WebViewGuest* guest) {}

// TODO(odejesush): Add tests for the rest of the Promise API methods.
const char* kControlledFramePromiseApiMethods[]{};

}  // namespace

class ControlledFrameApiTest : public ControlledFrameTestBase {};

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, ContextMenusCreate) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, ContextMenusUpdate) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, ContextMenusRemove) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, ContextMenusRemoveAll) {}

// This test checks if the Controlled Frame is able to intercept URL navigation
// requests.
IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, URLLoaderIsProxied) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, AuthRequestIsProxied) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, ExecuteScript) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, DisabledInDataIframe) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, DisabledInSandboxedIframe) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, DisabledInSrcdocIframe) {}

IN_PROC_BROWSER_TEST_F(ControlledFrameApiTest, DisabledInBlobIframe) {}

class ControlledFrameWebSocketApiTest : public ControlledFrameApiTest {};

IN_PROC_BROWSER_TEST_F(ControlledFrameWebSocketApiTest, WebSocketIsProxied) {}

class ControlledFrameWebTransportApiTest : public ControlledFrameApiTest {};

IN_PROC_BROWSER_TEST_F(ControlledFrameWebTransportApiTest,
                       WebTransportIsProxied) {}

class ControlledFramePromiseApiTest
    : public ControlledFrameApiTest,
      public testing::WithParamInterface<const char*> {};

IN_PROC_BROWSER_TEST_P(ControlledFramePromiseApiTest, PromiseAPIs) {}

INSTANTIATE_TEST_SUITE_P();

class ControlledFrameServiceWorkerTest
    : public extensions::ServiceWorkerBasedBackgroundTest {};

// This test ensures that loading an extension Service Worker does not cause a
// crash, and that Controlled Frame is not allowed in the Service Worker
// context. For more details, see https://crbug.com/1462384.
// This test is the same as ServiceWorkerBasedBackgroundTest.Basic.
IN_PROC_BROWSER_TEST_F(ControlledFrameServiceWorkerTest, PRE_Basic) {}

// After browser restarts, this test step ensures that opening a tab fires
// tabs.onCreated event listener to the extension without explicitly loading the
// extension. This is because the extension registered a listener before browser
// restarted in PRE_Basic.
IN_PROC_BROWSER_TEST_F(ControlledFrameServiceWorkerTest, Basic) {}

class ControlledFrameNotAvailableChannelTest
    : public ControlledFrameApiTest,
      public testing::WithParamInterface<version_info::Channel> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ControlledFrameNotAvailableChannelTest, Test) {}

class ControlledFrameAvailabilityTest
    : public ControlledFrameApiTest,
      public testing::WithParamInterface<
          ::std::tuple<version_info::Channel, FeatureSetting, FlagSetting>> {};

INSTANTIATE_TEST_SUITE_P();

IN_PROC_BROWSER_TEST_P(ControlledFrameAvailabilityTest, Verify) {}

}  // namespace controlled_frame