Commit 9a99a9df authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Ensure that chooser dialog is appearing on the active web contents

This change adds a check before creating a new chooser dialog that the
web contents it is being displayed over is the currently active one.

Bug: 1143057
Change-Id: I3a4e6fdb1745f2994e0e998fc2346d7485d118c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505746
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarAndy Paicu <andypaicu@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823300}
parent dc597a57
......@@ -184,6 +184,9 @@ base::OnceClosure ShowDeviceChooserDialog(
if (!browser)
return base::DoNothing();
if (browser->tab_strip_model()->GetActiveWebContents() != contents)
return base::DoNothing();
auto bubble = std::make_unique<ChooserBubbleUiViewDelegate>(
browser, contents, std::move(controller));
......
......@@ -317,4 +317,29 @@ IN_PROC_BROWSER_TEST_F(WebUsbTest, DISABLED_NavigateWithChooserCrossOrigin) {
EXPECT_FALSE(chrome::IsDeviceChooserShowingForTesting(browser()));
}
IN_PROC_BROWSER_TEST_F(WebUsbTest, ShowChooserInBackgroundTab) {
UseRealChooser();
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
// Create a new foreground tab that covers |web_contents|.
GURL url = embedded_test_server()->GetURL("localhost", "/simple_page.html");
ui_test_utils::NavigateToURLWithDisposition(
browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
ui_test_utils::BROWSER_TEST_WAIT_FOR_LOAD_STOP);
// Try to show the chooser in the background tab.
EXPECT_EQ("NotFoundError: No device selected.",
content::EvalJs(web_contents,
R"((async () => {
try {
await navigator.usb.requestDevice({ filters: [] });
return "Expected error, got success.";
} catch (e) {
return `${e.name}: ${e.message}`;
}
})())"));
}
} // namespace
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment