21
21
#include " components/content_settings/core/browser/host_content_settings_map.h"
22
22
#include " components/content_settings/core/common/content_settings.h"
23
23
#include " components/content_settings/core/common/content_settings_types.h"
24
+ #include " components/google/core/common/google_switches.h"
24
25
#include " components/network_session_configurator/common/network_switches.h"
25
26
#include " content/public/browser/render_frame_host.h"
26
27
#include " content/public/test/browser_test.h"
31
32
#include " net/http/http_request_headers.h"
32
33
#include " net/test/embedded_test_server/default_handlers.h"
33
34
#include " net/test/embedded_test_server/http_request.h"
35
+ #include " net/test/embedded_test_server/request_handler_util.h"
34
36
#include " testing/gmock/include/gmock/gmock.h"
35
37
#include " url/origin.h"
36
38
37
39
using brave_shields::ControlType;
40
+ using net::test_server::HttpRequest;
41
+ using net::test_server::HttpResponse;
38
42
39
43
namespace {
40
44
@@ -74,6 +78,7 @@ const int kExpectedImageDataHashFarblingBalanced = 172;
74
78
const int kExpectedImageDataHashFarblingOff = 0 ;
75
79
const int kExpectedImageDataHashFarblingMaximum =
76
80
kExpectedImageDataHashFarblingBalanced ;
81
+ const int kExpectedImageDataHashFarblingBalancedGoogleCom = 182 ;
77
82
78
83
const char kEmptyCookie [] = " " ;
79
84
@@ -97,6 +102,19 @@ GURL GetOriginURL(const GURL& url) {
97
102
return url::Origin::Create (url).GetURL ();
98
103
}
99
104
105
+ // Remaps requests from /maps/simple.html to /simple.html
106
+ std::unique_ptr<HttpResponse> HandleGoogleMapsFileRequest (
107
+ const base::FilePath& server_root,
108
+ const HttpRequest& request) {
109
+ HttpRequest new_request (request);
110
+ if (!new_request.relative_url .starts_with (" /maps" )) {
111
+ // This handler is only relevant for a Google Maps url.
112
+ return nullptr ;
113
+ }
114
+ new_request.relative_url = new_request.relative_url .substr (5 );
115
+ return HandleFileRequest (server_root, new_request);
116
+ }
117
+
100
118
} // namespace
101
119
102
120
class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
@@ -117,6 +135,8 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
117
135
https_server_.SetSSLConfig (net::EmbeddedTestServer::CERT_TEST_NAMES);
118
136
https_server_.ServeFilesFromDirectory (test_data_dir);
119
137
https_server_.AddDefaultHandlers (GetChromeTestDataDir ());
138
+ https_server_.RegisterDefaultHandler (
139
+ base::BindRepeating (&HandleGoogleMapsFileRequest, test_data_dir));
120
140
content::SetupCrossSiteRedirector (&https_server_);
121
141
https_server_.RegisterRequestMonitor (base::BindRepeating (
122
142
&BraveContentSettingsAgentImplBrowserTest::SaveReferrer,
@@ -143,6 +163,16 @@ class BraveContentSettingsAgentImplBrowserTest : public InProcessBrowserTest {
143
163
ContentSettingsPattern::FromString (" https://firstParty/*" );
144
164
}
145
165
166
+ void SetUpCommandLine (base::CommandLine* command_line) override {
167
+ // Since the HTTPS server only serves a valid cert for localhost,
168
+ // this is needed to load pages from "www.google.*" without an interstitial.
169
+ command_line->AppendSwitch (switches::kIgnoreCertificateErrors );
170
+
171
+ // The production code only allows known ports (80 for http and 443 for
172
+ // https), but the test server runs on a random port.
173
+ command_line->AppendSwitch (switches::kIgnoreGooglePortNumbers );
174
+ }
175
+
146
176
void SaveReferrer (const net::test_server::HttpRequest& request) {
147
177
base::AutoLock auto_lock (last_referrers_lock_);
148
178
@@ -430,6 +460,34 @@ IN_PROC_BROWSER_TEST_F(BraveContentSettingsAgentImplBrowserTest,
430
460
content::EvalJs (contents (), kGetImageDataScript ));
431
461
}
432
462
463
+ IN_PROC_BROWSER_TEST_F (BraveContentSettingsAgentImplBrowserTest,
464
+ FarbleGetImageDataGoogleMapsException) {
465
+ // Farbling should be disabled on Google Maps
466
+ SetFingerprintingDefault ();
467
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (
468
+ browser (), https_server ().GetURL (" google.com" , " /maps/simple.html" )));
469
+ EXPECT_EQ (kExpectedImageDataHashFarblingOff ,
470
+ content::EvalJs (contents (), kGetImageDataScript ));
471
+
472
+ // Farbling should not be disabled on other Google things
473
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (
474
+ browser (), https_server ().GetURL (" google.com" , " /simple.html" )));
475
+ EXPECT_EQ (kExpectedImageDataHashFarblingBalancedGoogleCom ,
476
+ content::EvalJs (contents (), kGetImageDataScript ));
477
+
478
+ // Farbling should be disabled on google.co.uk maps
479
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (
480
+ browser (), https_server ().GetURL (" google.co.uk" , " /maps/simple.html" )));
481
+ EXPECT_EQ (kExpectedImageDataHashFarblingOff ,
482
+ content::EvalJs (contents (), kGetImageDataScript ));
483
+
484
+ // Farbling should be disabled on google.de maps
485
+ ASSERT_TRUE (ui_test_utils::NavigateToURL (
486
+ browser (), https_server ().GetURL (" google.de" , " /maps/simple.html" )));
487
+ EXPECT_EQ (kExpectedImageDataHashFarblingOff ,
488
+ content::EvalJs (contents (), kGetImageDataScript ));
489
+ }
490
+
433
491
class BraveContentSettingsAgentImplV2BrowserTest
434
492
: public BraveContentSettingsAgentImplBrowserTest {
435
493
public:
0 commit comments