* Revert changes from https://github.com/brave/brave-core/pull/23416

* Restore Missing Test

* Re-order tests
This commit is contained in:
Fanboynz
2026-03-12 22:12:29 +09:00
committed by GitHub
parent 2e8215f2e2
commit 46cff7013b
2 changed files with 6 additions and 77 deletions
@@ -5,32 +5,19 @@
#include "third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h"
#include "base/compiler_specific.h"
#include "base/notreached.h"
#include "brave/third_party/blink/renderer/core/farbling/brave_session_cache.h"
#include "third_party/blink/renderer/platform/graphics/image_data_buffer.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "ui/gfx/skia_span_util.h"
namespace {
bool IsGoogleMaps(const blink::KURL& url) {
const auto host = url.Host().ToString();
if (!host.StartsWith("google.") && !host.Contains(".google.")) {
return false;
}
const auto path = url.GetPath();
return path == "/maps" || path.ToString().StartsWith("/maps/");
}
} // namespace
// SAFETY: writable_addr() returns a valid pointer to a contiguous buffer
// of exactly computeByteSize() bytes owned by the SkPixmap.
#define BRAVE_GET_IMAGE_DATA \
if (ExecutionContext* context = ExecutionContext::From(script_state)) { \
if (!IsGoogleMaps(context->Url())) { \
SkPixmap image_data_pixmap = image_data->GetSkPixmap(); \
brave::BraveSessionCache::From(*context).PerturbPixels( \
gfx::SkPixmapToWritableSpan(image_data_pixmap)); \
} \
SkPixmap image_data_pixmap = image_data->GetSkPixmap(); \
brave::BraveSessionCache::From(*context).PerturbPixels( \
gfx::SkPixmapToWritableSpan(image_data_pixmap)); \
}
#define BRAVE_BASE_RENDERING_CONTEXT_2D_MEASURE_TEXT \
@@ -22,7 +22,6 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/google/core/common/google_switches.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/test/browser_test.h"
@@ -33,13 +32,10 @@
#include "net/http/http_request_headers.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "url/origin.h"
using brave_shields::ControlType;
using net::test_server::HttpRequest;
using net::test_server::HttpResponse;
namespace {
@@ -77,7 +73,6 @@ constexpr char kImageScript[] = R"(
constexpr int kExpectedImageDataHashFarblingBalanced = 208;
constexpr int kExpectedImageDataHashFarblingOff = 0;
constexpr int kExpectedImageDataHashFarblingBalancedGoogleCom = 212;
constexpr char kEmptyCookie[] = "";
@@ -101,19 +96,6 @@ GURL GetOriginURL(const GURL& url) {
return url::Origin::Create(url).GetURL();
}
// Remaps requests from /maps/simple.html to /simple.html
std::unique_ptr<HttpResponse> HandleGoogleMapsFileRequest(
const base::FilePath& server_root,
const HttpRequest& request) {
HttpRequest new_request(request);
if (!new_request.relative_url.starts_with("/maps")) {
// This handler is only relevant for a Google Maps url.
return nullptr;
}
new_request.relative_url = new_request.relative_url.substr(5);
return HandleFileRequest(server_root, new_request);
}
} // namespace
class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
@@ -138,8 +120,6 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
https_server_.ServeFilesFromDirectory(test_data_dir);
https_server_.AddDefaultHandlers(GetChromeTestDataDir());
https_server_.RegisterDefaultHandler(
base::BindRepeating(&HandleGoogleMapsFileRequest, test_data_dir));
content::SetupCrossSiteRedirector(&https_server_);
https_server_.RegisterRequestMonitor(base::BindRepeating(
&BraveContentSettingsAgentImplBrowserTest::SaveReferrer,
@@ -164,16 +144,6 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
iframe_pattern_ = ContentSettingsPattern::FromString("https://b.test/*");
}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Since the HTTPS server only serves a valid cert for localhost,
// this is needed to load pages from "www.google.*" without an interstitial.
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
// The production code only allows known ports (80 for http and 443 for
// https), but the test server runs on a random port.
command_line->AppendSwitch(switches::kIgnoreGooglePortNumbers);
}
void SaveReferrer(const net::test_server::HttpRequest& request) {
base::AutoLock auto_lock(last_referrers_lock_);
@@ -456,34 +426,6 @@ IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
content::EvalJs(contents(), kGetImageDataScript));
}
IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
FarbleGetImageDataGoogleMapsException) {
// Farbling should be disabled on Google Maps
SetFingerprintingDefault();
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), https_server().GetURL("google.com", "/maps/simple.html")));
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
content::EvalJs(contents(), kGetImageDataScript));
// Farbling should not be disabled on other Google things
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), https_server().GetURL("google.com", "/simple.html")));
EXPECT_EQ(kExpectedImageDataHashFarblingBalancedGoogleCom,
content::EvalJs(contents(), kGetImageDataScript));
// Farbling should be disabled on google.co.uk maps
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), https_server().GetURL("google.co.uk", "/maps/simple.html")));
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
content::EvalJs(contents(), kGetImageDataScript));
// Farbling should be disabled on google.de maps
ASSERT_TRUE(ui_test_utils::NavigateToURL(
browser(), https_server().GetURL("google.de", "/maps/simple.html")));
EXPECT_EQ(kExpectedImageDataHashFarblingOff,
content::EvalJs(contents(), kGetImageDataScript));
}
IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
WebGLReadPixels) {
std::string origin = "a.test";