[CodeHealth][cr146] `base::Contains` dissallowed when `.contains` suffices it This is being enforced by the compiler through a concept, and it only applies for cases where `base::Contains` is used without a projection. This change also carries out IWYU for `base::Contains`. Chromium changes: https://chromium.googlesource.com/chromium/src/+/4a17af8403373b7f7e7546ef61f30dfbe883d617 ``` commit 4a17af8403373b7f7e7546ef61f30dfbe883d617 Author: Victor Hugo Vianna Silva <victorvianna@google.com> Date: Tue Jan 13 07:30:34 2026 -0800 Disallow base::Contains() when contains() or find() methods available This is a temporary step towards deleting base::Contains(). Trying to call base::Contains(foo, bar) will now cause a static assertion failure if foo has contains() or find() methods. This effectively makes base::Contains() an alias to std::ranges::contains(). The result is we can replace instances of 'base::Contains' with 'std::ranges::contains' in upcoming CLs while being sure to not regress performance. Bug: 470391351 Change-Id: I8778f435ff8f5b52fb3bf336724f2dfef388907a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7415207 Commit-Queue: Francois Pierre Doray <fdoray@chromium.org> Reviewed-by: Francois Pierre Doray <fdoray@chromium.org> Cr-Commit-Position: refs/heads/main@{#1568392} ``` Bug: https://github.com/brave/brave-browser/issues/42557
77 lines
2.8 KiB
C++
77 lines
2.8 KiB
C++
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "brave/components/constants/network_constants.h"
|
|
#include "chrome/browser/ui/browser.h"
|
|
#include "chrome/test/base/in_process_browser_test.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/content_mock_cert_verifier.h"
|
|
#include "content/public/test/test_utils.h"
|
|
#include "net/dns/mock_host_resolver.h"
|
|
#include "net/http/http_request_headers.h"
|
|
#include "net/test/embedded_test_server/http_request.h"
|
|
|
|
class BraveAcceptHeaderBrowserTest : public InProcessBrowserTest {
|
|
public:
|
|
BraveAcceptHeaderBrowserTest()
|
|
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
|
|
|
|
void SetUpOnMainThread() override {
|
|
InProcessBrowserTest::SetUpOnMainThread();
|
|
mock_cert_verifier_.mock_cert_verifier()->set_default_result(net::OK);
|
|
host_resolver()->AddRule("*", "127.0.0.1");
|
|
|
|
https_server_.RegisterRequestMonitor(base::BindRepeating(
|
|
&BraveAcceptHeaderBrowserTest::HandleRequest, base::Unretained(this)));
|
|
|
|
ASSERT_TRUE(https_server_.Start());
|
|
}
|
|
|
|
void HandleRequest(const net::test_server::HttpRequest& request) {
|
|
base::AutoLock auto_lock(header_result_lock_);
|
|
auto it = request.headers.find(net::HttpRequestHeaders::kAccept);
|
|
ASSERT_TRUE(it != request.headers.end());
|
|
header_result_ =
|
|
it->second.find("application/signed-exchange") == std::string::npos;
|
|
}
|
|
|
|
void SetUpCommandLine(base::CommandLine* command_line) override {
|
|
InProcessBrowserTest::SetUpCommandLine(command_line);
|
|
mock_cert_verifier_.SetUpCommandLine(command_line);
|
|
}
|
|
|
|
void SetUpInProcessBrowserTestFixture() override {
|
|
InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
|
|
mock_cert_verifier_.SetUpInProcessBrowserTestFixture();
|
|
}
|
|
|
|
void TearDownInProcessBrowserTestFixture() override {
|
|
mock_cert_verifier_.TearDownInProcessBrowserTestFixture();
|
|
InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
|
|
}
|
|
|
|
const net::EmbeddedTestServer& https_server() { return https_server_; }
|
|
|
|
bool header_result() {
|
|
base::AutoLock auto_lock(header_result_lock_);
|
|
return header_result_;
|
|
}
|
|
|
|
private:
|
|
content::ContentMockCertVerifier mock_cert_verifier_;
|
|
net::test_server::EmbeddedTestServer https_server_;
|
|
mutable base::Lock header_result_lock_;
|
|
bool header_result_ = false;
|
|
};
|
|
|
|
IN_PROC_BROWSER_TEST_F(BraveAcceptHeaderBrowserTest,
|
|
NotIncludesSignedExachange) {
|
|
GURL target = https_server().GetURL("a.com", "/index.html");
|
|
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), target));
|
|
EXPECT_TRUE(header_result());
|
|
}
|