chromium/chrome/browser/extensions/api/web_request/web_request_api_unittest.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 <map>
#include <memory>
#include <tuple>

#include "base/containers/queue.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/time_formatting.h"
#include "base/json/json_reader.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/prefs/pref_member.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_task_environment.h"
#include "extensions/browser/api/declarative_net_request/test_utils.h"
#include "extensions/browser/api/web_request/extension_web_request_event_router.h"
#include "extensions/browser/api/web_request/upload_data_presenter.h"
#include "extensions/browser/api/web_request/web_request_api.h"
#include "extensions/browser/api/web_request/web_request_api_constants.h"
#include "extensions/browser/api/web_request/web_request_api_helpers.h"
#include "extensions/browser/api/web_request/web_request_info.h"
#include "extensions/common/api/declarative_net_request.h"
#include "extensions/common/api/web_request.h"
#include "extensions/common/constants.h"
#include "extensions/common/features/feature.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/http/http_util.h"
#include "services/network/public/cpp/features.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-message.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom-forward.h"

helpers;
keys;
web_request;
dnr_api;

Time;
CalculateOnAuthRequiredDelta;
CalculateOnBeforeRequestDelta;
CalculateOnBeforeSendHeadersDelta;
CalculateOnHeadersReceivedDelta;
CharListToString;
EventResponseDelta;
EventResponseDeltas;
ExtraInfoSpec;
InDecreasingExtensionInstallationTimeOrder;
MergeCancelOfResponses;
MergeOnBeforeRequestResponses;
RequestCookieModification;
ResponseCookieModification;
ResponseHeader;
ResponseHeaders;
StringToCharList;
ElementsAre;
DNRRequestAction;

namespace extensions {

namespace {

constexpr const char kExampleUrl[] =;

// Returns whether |warnings| contains an extension for |extension_id|.
bool HasIgnoredAction(const helpers::IgnoredActions& ignored_actions,
                      const std::string& extension_id,
                      web_request::IgnoredActionType action_type) {}

}  // namespace

class ExtensionWebRequestTest : public testing::Test {};

namespace {

// Create the numerical representation of |values|, strings passed as
// extraInfoSpec by the event handler. Returns true on success, otherwise false.
bool GenerateInfoSpec(content::BrowserContext* browser_context,
                      const std::string& values,
                      int* result) {}

}  // namespace

// Tests adding and removing listeners from the event router.
TEST_F(ExtensionWebRequestTest, AddAndRemoveListeners) {}

// Tests that when a browser_context shuts down, all data keyed to that
// context is removed.
TEST_F(ExtensionWebRequestTest, BrowserContextShutdown) {}

namespace {

void TestInitFromValue(content::BrowserContext* browser_context,
                       const std::string& values,
                       bool expected_return_code,
                       int expected_extra_info_spec) {}

}  // namespace

TEST_F(ExtensionWebRequestTest, InitFromValue) {}

TEST(ExtensionWebRequestHelpersTest,
     TestInDecreasingExtensionInstallationTimeOrder) {}

TEST(ExtensionWebRequestHelpersTest, TestStringToCharList) {}

TEST(ExtensionWebRequestHelpersTest, TestCalculateOnBeforeRequestDelta) {}

TEST(ExtensionWebRequestHelpersTest, TestCalculateOnBeforeSendHeadersDelta) {}

TEST(ExtensionWebRequestHelpersTest,
     TestCalculateOnBeforeSendHeadersDeltaWithExtraHeaders) {}

TEST(ExtensionWebRequestHelpersTest, TestCalculateOnHeadersReceivedDelta) {}

TEST(ExtensionWebRequestHelpersTest,
     TestCalculateOnHeadersReceivedDeltaWithExtraHeaders) {}

TEST(ExtensionWebRequestHelpersTest, TestCalculateOnAuthRequiredDelta) {}

TEST(ExtensionWebRequestHelpersTest, TestMergeCancelOfResponses) {}

TEST(ExtensionWebRequestHelpersTest, TestMergeOnBeforeRequestResponses) {}

// This tests that we can redirect to data:// urls, which is considered
// a kind of cancelling requests.
TEST(ExtensionWebRequestHelpersTest, TestMergeOnBeforeRequestResponses2) {}

// This tests that we can redirect to about:blank, which is considered
// a kind of cancelling requests.
TEST(ExtensionWebRequestHelpersTest, TestMergeOnBeforeRequestResponses3) {}

// This tests that WebSocket requests can not be redirected.
TEST(ExtensionWebRequestHelpersTest, TestMergeOnBeforeRequestResponses4) {}

// TODO(crbug.com/40137306): Separate this test into subtests to improve
// readability.
TEST(ExtensionWebRequestHelpersTest, TestMergeOnBeforeSendHeadersResponses) {}

namespace {

struct ExpectedHeader {};

// Applies the DNR actions in `info` to `base_headers` and compares the results
// to the expected headers in `expected_headers`.
void ExecuteDNRActionsAndCheckHeaders(
    const WebRequestInfo& info,
    net::HttpRequestHeaders base_headers,
    const std::vector<ExpectedHeader>& expected_headers) {}

}  // namespace

TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnBeforeSendHeadersResponses_DeclarativeNetRequest_Append) {}

TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnBeforeSendHeadersResponses_DeclarativeNetRequest_Set) {}

TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnBeforeSendHeadersResponses_DeclarativeNetRequest_Remove) {}

// Ensure conflicts between different extensions are handled correctly with
// header names being interpreted in a case insensitive manner. Regression test
// for crbug.com/956795.
TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnBeforeSendHeadersResponses_Conflicts) {}

TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnBeforeSendHeadersResponses_Cookies) {}

namespace {

std::string GetCookieExpirationDate(int delta_secs) {}

}  // namespace

TEST(ExtensionWebRequestHelpersTest,
     TestMergeCookiesInOnHeadersReceivedResponses) {}

TEST(ExtensionWebRequestHelpersTest, TestMergeOnHeadersReceivedResponses) {}

// Check that we do not delete too much
TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnHeadersReceivedResponsesDeletion) {}

// Tests whether onHeadersReceived can initiate a redirect.
// The URL merge logic is shared with onBeforeRequest, so we only need to test
// whether the URLs are merged at all.
TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnHeadersReceivedResponsesRedirect) {}

// Test conflict resolution for declarative net request actions modifying the
// same response header.
TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnHeadersReceivedResponses_DeclarativeNetRequest) {}

// Test that the appropriate metrics are logged for declarative net request
// actions which modify response headers.
TEST(ExtensionWebRequestHelpersTest,
     TestMergeOnHeadersReceivedResponses_DeclarativeNetRequestMetrics) {}

TEST(ExtensionWebRequestHelpersTest, TestMergeOnAuthRequiredResponses) {}

}  // namespace extensions