Files
brave-core/renderer/test/serial_api_browsertest.cc
T
Mario Sanchez Prada d7bdc1c8fa Adapt test expectation to new format of the Javascript error message
The format changed from "Cannot set property '%' of %" to  "Cannot
read properties of % (reading '%')") recently in V8.

This fixes the following browser test:

  * SerialAPIBrowserTest.SerialAPIDisabled

V8 change:

https://chromium.googlesource.com/v8/v8/+/c0fd89c3c089e888c4f4e8582e56db7066fa779b

commit c0fd89c3c089e888c4f4e8582e56db7066fa779b
Author: Patrick Thier <pthier@chromium.org>
Date:   Thu Jun 17 11:15:41 2021 +0000

    Reland "Reland "Reland "Improve error messages for property access on null/undefined"""

    This is a reland of 819c3ae2f87fc7ad634fe4356de6653bb3cb3b87

    Original change's description:
    > Reland "Reland "Improve error messages for property access on null/undefined""
    >
    > This is a reland of 8b18c5e6a534d7c459a16aebdd4fe05133db6dea
    >
    > Original change's description:
    > > Reland "Improve error messages for property access on null/undefined"
    > >
    > > This is a reland of 24c626c1f7809ce725e56152ab2928696a2f8e9e
    > >
    > > Original change's description:
    > > > Improve error messages for property access on null/undefined
    > > >
    > > > Only print the property name when accessing null/undefined if we can
    > > > convert it to a string without causing side effects.
    > > > If we can't, omit the property name in the error message.
    > > > This should avoid confusion when the key is an object with toString().
    > > > E.g. undefined[{toString:()=>'a'}] doesn't print 'read property [object
    > > > Object]' anymore, which was misleading since the property accessed would
    > > > be 'a', but we can't evaluate the key without side effects.
    > > >
    > > > Bug: v8:11365
    > > > Change-Id: If82d1adb42561d4851e2bd2ca297a1c71738aee8
    > > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2960211
    > > > Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    > > > Commit-Queue: Patrick Thier <pthier@chromium.org>
    > > > Cr-Commit-Position: refs/heads/master@{#75250}
    > >
    > > Bug: v8:11365
    > > Change-Id: Ie2312337f4f1915faa31528a728d90833d80dbd1
    > > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2979599
    > > Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    > > Commit-Queue: Patrick Thier <pthier@chromium.org>
    > > Cr-Commit-Position: refs/heads/master@{#75571}
    >
    > Bug: v8:11365
    > Change-Id: I90360641ecd870bd93247aa6d91dfb0ad049cfb8
    > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3008219
    > Auto-Submit: Patrick Thier <pthier@chromium.org>
    > Commit-Queue: Toon Verwaest <verwaest@chromium.org>
    > Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    > Cr-Commit-Position: refs/heads/master@{#75604}

    Bug: v8:11365
    Change-Id: I002b537144f328ccbbdcd655e26e5dc87c49c6f5
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3013935
    Reviewed-by: Toon Verwaest <verwaest@chromium.org>
    Commit-Queue: Patrick Thier <pthier@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#75645}
2021-08-18 10:58:36 -04:00

68 lines
2.3 KiB
C++

/* Copyright (c) 2021 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/path_service.h"
#include "brave/common/brave_paths.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
class SerialAPIBrowserTest : public InProcessBrowserTest {
public:
SerialAPIBrowserTest() : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
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_.ServeFilesFromDirectory(test_data_dir);
}
~SerialAPIBrowserTest() override = default;
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
EXPECT_TRUE(https_server_.Start());
// Map all hosts to localhost.
host_resolver()->AddRule("*", "127.0.0.1");
}
content::WebContents* web_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}
content::RenderFrameHost* main_frame() {
return web_contents()->GetMainFrame();
}
protected:
net::EmbeddedTestServer https_server_;
};
IN_PROC_BROWSER_TEST_F(SerialAPIBrowserTest, SerialAPIDisabled) {
const GURL url = https_server_.GetURL("/simple.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
auto result = content::EvalJs(main_frame(), R"((async () => {
let ports = await navigator.serial.getPorts();
return ports.length;
})())");
EXPECT_TRUE(result.error.find(
"Cannot read properties of undefined (reading 'getPorts')") !=
std::string::npos)
<< result.error;
}