Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions browser/brave_wallet/brave_wallet_sign_message_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@ namespace brave_wallet {

namespace {

// Waits for signMessageResult to be set to a string value. After
// NotifySignMessageRequestProcessed() the result is delivered asynchronously
// to the renderer via mojo, so we must poll rather than reading it immediately.
constexpr char kWaitForSignMessageResult[] = R"(
new Promise((resolve, reject) => {
const deadline = Date.now() + 10000;
const check = () => {
if (typeof signMessageResult === 'string') {
const result = signMessageResult;
signMessageResult = undefined;
resolve(result);
} else if (Date.now() >= deadline) {
reject(new Error('Timeout: signMessageResult=' +
signMessageResult));
} else {
setTimeout(check, 10);
}
};
check();
}))";

bool WaitForWalletBubble(content::WebContents* web_contents) {
auto* tab_helper =
brave_wallet::BraveWalletTabHelper::FromWebContents(web_contents);
Expand Down Expand Up @@ -168,7 +189,7 @@ IN_PROC_BROWSER_TEST_F(BraveWalletSignMessageBrowserTest, UserApprovedRequest) {
EXPECT_TRUE(WaitForWalletBubble(web_contents()));
brave_wallet_service()->NotifySignMessageRequestProcessed(
true, request_index++, nullptr, std::nullopt);
EXPECT_EQ(EvalJs(web_contents(), "getSignMessageResult()").ExtractString(),
EXPECT_EQ(EvalJs(web_contents(), kWaitForSignMessageResult).ExtractString(),
"0x670651c072cac2a3f93cb862a17378f6849c66b4516e5d5a30210868a2840e"
"2a6a345a"
"4f84615c591c1a47260e798babe8f2f0cce03a09dac09df79c55d8e4401b");
Expand Down Expand Up @@ -196,7 +217,7 @@ IN_PROC_BROWSER_TEST_F(BraveWalletSignMessageBrowserTest, UserRejectedRequest) {
EXPECT_TRUE(WaitForWalletBubble(web_contents()));
brave_wallet_service()->NotifySignMessageRequestProcessed(
false, request_index++, nullptr, std::nullopt);
EXPECT_EQ(EvalJs(web_contents(), "getSignMessageResult()").ExtractString(),
EXPECT_EQ(EvalJs(web_contents(), kWaitForSignMessageResult).ExtractString(),
l10n_util::GetStringUTF8(IDS_WALLET_USER_REJECTED_REQUEST));
}
}
Expand Down Expand Up @@ -334,8 +355,30 @@ IN_PROC_BROWSER_TEST_F(BraveWalletSignMessageBrowserTest, SIWE) {
EXPECT_TRUE(WaitForWalletBubble(web_contents()));
brave_wallet_service()->NotifySignMessageRequestProcessed(
true, request_index++, nullptr, std::nullopt);
// The second sign message (wrong origin) is rejected immediately,
// overwriting signMessageResult with an error before the approved
// first message's signature arrives via mojo. Wait for the signature
// (starts with "0x") to be delivered to the renderer.
static constexpr char kWaitForSignResult[] = R"(
new Promise((resolve, reject) => {
const deadline = Date.now() + 10000;
const check = () => {
if (typeof signMessageResult === 'string' &&
signMessageResult.startsWith('0x')) {
const result = signMessageResult;
signMessageResult = undefined;
resolve(result);
} else if (Date.now() >= deadline) {
reject(new Error('Timeout: signMessageResult=' +
signMessageResult));
} else {
setTimeout(check, 10);
}
};
check();
}))";
// port is dynamic
EXPECT_TRUE(EvalJs(web_contents(), "getSignMessageResult()")
EXPECT_TRUE(EvalJs(web_contents(), kWaitForSignResult)
.ExtractString()
.starts_with("0x"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ BraveMultiContentsViewDelegateImpl::BraveMultiContentsViewDelegateImpl(
BraveMultiContentsViewDelegateImpl::~BraveMultiContentsViewDelegateImpl() =
default;

void BraveMultiContentsViewDelegateImpl::WebContentsFocused(
content::WebContents* contents) {
// https://github.com/brave/brave-browser/issues/53121
// On macOS, closing a split view detaches a web contents native view, which
// can synchronously trigger a focus change (via AppKit first responder
// transfer). This focus event propagates to ActivateTabAt(), but if we're
// already inside CloseAllTabs(), the TabStripModel reentrancy guard fires.
// Skip the activation when tabs are being closed.
if (tab_strip_model_->closing_all()) {
return;
}

MultiContentsViewDelegateImpl::WebContentsFocused(contents);
}

void BraveMultiContentsViewDelegateImpl::ResizeWebContents(double ratio,
bool done_resizing) {
// Upstream assumes active tab is split tab when resizing happens.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BraveMultiContentsViewDelegateImpl
~BraveMultiContentsViewDelegateImpl() override;

// MultiContentsViewDelegateImpl:
void WebContentsFocused(content::WebContents* contents) override;
void ResizeWebContents(double ratio, bool done_resizing) override;

private:
Expand Down
10 changes: 10 additions & 0 deletions test/filters/browser_tests.filter
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
-PasswordDialogViewTest.PopupAccountChooserWithMultipleCredentialsReturnEmpty
-ProfilePickerViewBrowserTest.ShowScreen_*
-RuntimeGetContextsApiTest.GetOffscreenDocumentContext
-RuntimeGetContextsApiTest.GetServiceWorkerContext
-SerialBlocklistTest.*
-SerialTest.*
-WebAppFileHandlingBrowserTest.*
Expand Down Expand Up @@ -1624,6 +1625,15 @@
-All/SoftNavigationTest.LayoutShift/*
-AutoPictureInPictureTabHelperBrowserTest.CachedBoundsIgnoredWhenPermissionPromtIsVisible
-AutoPictureInPictureTabHelperBrowserTest.ImmediatelyClosesAutopipIfTabIsAlreadyFocused

# Known upstream flake: 10.5% flake rate over 30 days per LUCI Analysis.
# Null pointer dereference in AutoPipSettingView::OnButtonPressed — widget
# destroyed before test can interact with the bubble view.
# Upstream Chromium test, no Brave modifications in this code path.
-AutoPictureInPictureTabHelperBrowserTest.PromptResultRecorded_VideoConferencingAllowOnce

-AutoPictureInPictureTabHelperBrowserTest.PromptResultRecorded_VideoConferencingAllowOnce
-AutoPictureInPictureTabHelperBrowserTest.OverlaySettingViewIsShownForDocumentPip
-AutoPictureInPictureTabHelperBrowserTest.RespectsAutoPictureInPictureContentSetting
-AutoPictureInPictureTabHelperBrowserTest.ShowsMostRecentlyHiddenTab
-AutoPictureInPictureWithVideoPlaybackBrowserTest.DevToolsMediaLogsRecordedForOpener
Expand Down
Loading