Skip to content

Commit

Permalink
Code review fixes for: Disable navigator.keyboard API when fingerprin…
Browse files Browse the repository at this point in the history
…ting protection is on.
  • Loading branch information
mkarolin committed Nov 16, 2021
1 parent 5529f91 commit 2653b6b
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions browser/farbling/brave_navigator_keyboard_api_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
#include "chrome/common/chrome_content_client.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "components/permissions/permission_request.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "url/gurl.h"

using brave_shields::ControlType;

const char kGetLayoutMapScript[] =
"(async function testKeyboardAPI() {"
" keyboardLayoutMap = await navigator.keyboard.getLayoutMap();"
" return keyboardLayoutMap.get('KeyA');"
"})()";
namespace {

constexpr char kGetLayoutMapScript[] =
R"(navigator.keyboard.getLayoutMap instanceof Function)";

} // namespace

class BraveNavigatorKeyboardAPIBrowserTest : public InProcessBrowserTest {
public:
Expand All @@ -36,11 +35,11 @@ class BraveNavigatorKeyboardAPIBrowserTest : public InProcessBrowserTest {
brave::RegisterPathProvider();
base::FilePath test_data_dir;
base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir);
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_OK);
https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES);
https_server_.ServeFilesFromDirectory(test_data_dir);
EXPECT_TRUE(https_server_.Start());
top_level_page_url_ = https_server_.GetURL("a.com", "/");
test_url_ = https_server_.GetURL("a.com", "/simple.html");
top_level_page_url_ = https_server_.GetURL("a.test", "/");
test_url_ = https_server_.GetURL("a.test", "/simple.html");
}

BraveNavigatorKeyboardAPIBrowserTest(
Expand All @@ -50,12 +49,6 @@ class BraveNavigatorKeyboardAPIBrowserTest : public InProcessBrowserTest {

~BraveNavigatorKeyboardAPIBrowserTest() override {}

void SetUpCommandLine(base::CommandLine* command_line) override {
// HTTPS server only serves a valid cert for localhost, so this is needed
// to load pages from other hosts without an error
command_line->AppendSwitch(switches::kIgnoreCertificateErrors);
}

void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();

Expand Down Expand Up @@ -113,7 +106,7 @@ IN_PROC_BROWSER_TEST_F(BraveNavigatorKeyboardAPIBrowserTest,
// get real navigator.keyboard.getLayoutMap key
AllowFingerprinting();
EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), test_url()));
EXPECT_EQ("a", EvalJs(contents(), kGetLayoutMapScript));
EXPECT_EQ(true, EvalJs(contents(), kGetLayoutMapScript));

// Fingerprinting level: standard (default)
// navigator.keyboard will be null
Expand Down

0 comments on commit 2653b6b

Please sign in to comment.