-
Notifications
You must be signed in to change notification settings - Fork 871
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2205 from brave/disable_ch
Issue 3539: Disabling client hints
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
chromium_src/third_party/blink/public/platform/disable_client_hints_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "base/bind.h" | ||
#include "base/path_service.h" | ||
#include "base/run_loop.h" | ||
#include "brave/common/brave_paths.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "net/dns/mock_host_resolver.h" | ||
#include "net/http/http_request_headers.h" | ||
#include "net/test/embedded_test_server/embedded_test_server.h" | ||
#include "net/test/embedded_test_server/http_request.h" | ||
#include "third_party/blink/public/common/client_hints/client_hints.h" | ||
|
||
const char kClientHints[] = "/ch.html"; | ||
|
||
class ClientHintsBrowserTest : public InProcessBrowserTest { | ||
public: | ||
ClientHintsBrowserTest() | ||
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS), | ||
count_client_hints_headers_seen_(0) { | ||
brave::RegisterPathProvider(); | ||
base::FilePath test_data_dir; | ||
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); | ||
|
||
https_server_.ServeFilesFromDirectory(test_data_dir); | ||
https_server_.RegisterRequestMonitor( | ||
base::BindRepeating(&ClientHintsBrowserTest::MonitorResourceRequest, | ||
base::Unretained(this))); | ||
|
||
EXPECT_TRUE(https_server_.Start()); | ||
|
||
client_hints_url_ = https_server_.GetURL(kClientHints); | ||
} | ||
|
||
~ClientHintsBrowserTest() override {} | ||
|
||
void SetUp() override { InProcessBrowserTest::SetUp(); } | ||
|
||
void SetUpOnMainThread() override { | ||
host_resolver()->AddRule("*", "127.0.0.1"); | ||
base::RunLoop().RunUntilIdle(); | ||
} | ||
|
||
void TearDownOnMainThread() override {} | ||
|
||
const GURL& client_hints_url() const { return client_hints_url_; } | ||
|
||
size_t count_client_hints_headers_seen() const { | ||
return count_client_hints_headers_seen_; | ||
} | ||
|
||
private: | ||
void MonitorResourceRequest(const net::test_server::HttpRequest& request) { | ||
for (size_t i = 0; i < blink::kClientHintsMappingsCount; ++i) { | ||
if (base::ContainsKey(request.headers, | ||
blink::kClientHintsHeaderMapping[i])) { | ||
count_client_hints_headers_seen_++; | ||
} | ||
} | ||
} | ||
|
||
net::EmbeddedTestServer https_server_; | ||
GURL client_hints_url_; | ||
size_t count_client_hints_headers_seen_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ClientHintsBrowserTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, ClientHintsDisabled) { | ||
ui_test_utils::NavigateToURL(browser(), client_hints_url()); | ||
EXPECT_EQ(0u, count_client_hints_headers_seen()); | ||
} |
30 changes: 30 additions & 0 deletions
30
chromium_src/third_party/blink/public/platform/web_client_hints_type.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* Copyright (c) 2019 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_CLIENT_HINTS_TYPE_H_ | ||
#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_CLIENT_HINTS_TYPE_H_ | ||
|
||
#include "third_party/blink/public/mojom/web_client_hints/web_client_hints_types.mojom-shared.h" | ||
|
||
namespace blink { | ||
|
||
// WebEnabledClientHints stores all the client hints along with whether the hint | ||
// is enabled or not. | ||
struct WebEnabledClientHints { | ||
WebEnabledClientHints() = default; | ||
|
||
bool IsEnabled(mojom::WebClientHintsType type) const { return false; } | ||
|
||
void SetIsEnabled(mojom::WebClientHintsType type, bool should_send) { | ||
enabled_types_[static_cast<int>(type)] = false; | ||
} | ||
|
||
bool enabled_types_[static_cast<int>(mojom::WebClientHintsType::kMaxValue) + | ||
1] = {}; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_CLIENT_HINTS_TYPE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<html> | ||
Hello World! | ||
<img src="non-existing-image.jpg"></img> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
HTTP/1.1 200 OK | ||
Accept-CH: dpr,device-memory,viewport-width,rtt,downlink,ect,lang,ua,arch,platform,model |