Files
brave-core/renderer/test/file_system_access_browsertest.cc
Claudio DeSouza 323469a7f5 [cr140] EvalJsResult::error private
This field has been made private and matchers have been provided to
support the cases where the check if for the error condition.

Chromium changes:
https://chromium.googlesource.com/chromium/src/+/c28317921afe79d71fdc07444288b8d07b990aea

commit c28317921afe79d71fdc07444288b8d07b990aea
Author: Chris Fredrickson <cfredric@chromium.org>
Date:   Sun Jul 27 14:18:43 2025 -0700

    Make EvalJsResult::error private

    Making this field private will allow us to more easily change its name,
    and/or change the internal representation of the class (e.g. use a
    std::variant instead of holding *both* the success and error values),
    and define move ctor/assignment ops without allowing callers to violate
    the invariants of the class.

    Bug: 431787497
    Change-Id: I91d856c6df9442e896a21268eee80a455e755063
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6788313
    Reviewed-by: Avi Drissman <avi@chromium.org>
    Auto-Submit: Chris Fredrickson <cfredric@chromium.org>
    Commit-Queue: Chris Fredrickson <cfredric@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#1492549}
2025-08-19 19:54:30 +01:00

88 lines
3.1 KiB
C++

/* Copyright (c) 2020 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 "base/test/scoped_feature_list.h"
#include "brave/components/constants/brave_paths.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/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 "third_party/blink/public/common/features.h"
#include "url/gurl.h"
class FileSystemAccessBrowserTest : public InProcessBrowserTest,
public ::testing::WithParamInterface<bool> {
public:
FileSystemAccessBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
~FileSystemAccessBrowserTest() override = default;
bool IsFileSystemAccessAPIEnabled() { return GetParam(); }
void SetUp() override {
if (IsFileSystemAccessAPIEnabled()) {
scoped_feature_list_.InitAndEnableFeature(
blink::features::kFileSystemAccessAPI);
}
InProcessBrowserTest::SetUp();
}
void SetUpOnMainThread() override {
InProcessBrowserTest::SetUpOnMainThread();
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);
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* primary_main_frame() {
return web_contents()->GetPrimaryMainFrame();
}
protected:
net::EmbeddedTestServer https_server_;
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_P(FileSystemAccessBrowserTest, FilePicker) {
EXPECT_EQ(
IsFileSystemAccessAPIEnabled(),
base::FeatureList::IsEnabled(blink::features::kFileSystemAccessAPI));
const GURL url = https_server_.GetURL("/simple.html");
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
if (IsFileSystemAccessAPIEnabled()) {
EXPECT_EQ(
content::EvalJs(primary_main_frame(), "typeof self.showOpenFilePicker"),
base::Value("function"));
} else {
EXPECT_THAT(
content::EvalJs(primary_main_frame(), "self.showOpenFilePicker()"),
content::EvalJsResult::ErrorIs(
testing::HasSubstr("self.showOpenFilePicker is not a function")));
}
}
INSTANTIATE_TEST_SUITE_P(FileSystemAccessBrowserTest,
FileSystemAccessBrowserTest,
::testing::Bool());