Bug 1634569 - Remove hackaround for bug that can no longer happen. r=masayuki

This seems to come from bug 618907, which seems to be a hack-around code
that went away in bug 1595435.

If we open a window on mousedown such as it gains focus before this code
runs, we just steal the focus from it, which is undesired.

Also remove the test for bug 799299. It doesn't work anyways if the
browser is remote (this test only runs on non-e10s mode), and this
unifies the behavior with e10s and with content (see attached test-case,
which doesn't change behavior with and without my patch).

Differential Revision: https://phabricator.services.mozilla.com/D73901
This commit is contained in:
Emilio Cobos Álvarez 2020-05-06 06:18:13 +00:00
Родитель 50335b6776
Коммит 1e934bc543
6 изменённых файлов: 55 добавлений и 131 удалений

Просмотреть файл

@ -11,13 +11,15 @@ add_task(async function() {
let promiseTabOpened = BrowserTestUtils.waitForNewTab(
gBrowser,
FILE + "?opened",
FILE + "?open-click",
true
);
info("Opening second tab using a click");
await SpecialPowers.spawn(firstTab.linkedBrowser, [""], async function() {
content.document.querySelector("#open").click();
});
await BrowserTestUtils.synthesizeMouseAtCenter(
"#open-click",
{},
firstTab.linkedBrowser
);
info("Waiting for the second tab to be opened");
let secondTab = await promiseTabOpened;
@ -34,6 +36,43 @@ add_task(async function() {
is(gBrowser.selectedTab, secondTab, "Should've switched tabs");
BrowserTestUtils.removeTab(firstTab);
BrowserTestUtils.removeTab(secondTab);
await BrowserTestUtils.removeTab(firstTab);
await BrowserTestUtils.removeTab(secondTab);
});
add_task(async function() {
info("Opening first tab: " + FILE);
let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, FILE);
let promiseTabOpened = BrowserTestUtils.waitForNewTab(
gBrowser,
FILE + "?open-mousedown",
true
);
info("Opening second tab using a click");
await BrowserTestUtils.synthesizeMouseAtCenter(
"#open-mousedown",
{ type: "mousedown" },
firstTab.linkedBrowser
);
info("Waiting for the second tab to be opened");
let secondTab = await promiseTabOpened;
is(gBrowser.selectedTab, secondTab, "Should've switched tabs");
info("Ensuring we don't switch back");
await new Promise(resolve => {
// We need to wait for something _not_ happening, so we need to use an arbitrary setTimeout.
//
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(function() {
is(gBrowser.selectedTab, secondTab, "Should've remained in original tab");
resolve();
}, 500);
});
info("cleanup");
await BrowserTestUtils.removeTab(firstTab);
await BrowserTestUtils.removeTab(secondTab);
});

Просмотреть файл

@ -1,8 +1,15 @@
<!doctype html>
<script>
function openWindow() {
window.childWindow = window.open(location.href + "?opened", "", "");
function openWindow(id) {
window.childWindow = window.open(location.href + "?" + id, "", "");
}
</script>
<button id="open" onclick="openWindow()">Open window</button>
<button id="open-click" onclick="openWindow('open-click')">Open window</button>
<button id="focus" onclick="window.childWindow.focus()">Focus window</button>
<button id="open-mousedown">Open window</button>
<script>
document.getElementById("open-mousedown").addEventListener("mousedown", function(e) {
openWindow(this.id);
e.preventDefault();
});
</script>

Просмотреть файл

@ -3260,30 +3260,6 @@ nsresult EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
// if we're here, the event handler returned false, so stop
// any of our own processing of a drag. Workaround for bug 43258.
StopTrackingDragGesture(true);
// When the event was cancelled, there is currently a chrome document
// focused and a mousedown just occurred on a content document, ensure
// that the window that was clicked is focused.
EnsureDocument(mPresContext);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (mDocument && fm) {
nsCOMPtr<mozIDOMWindowProxy> window;
fm->GetFocusedWindow(getter_AddRefs(window));
auto* currentWindow = nsPIDOMWindowOuter::From(window);
if (currentWindow && mDocument->GetWindow() &&
currentWindow != mDocument->GetWindow() &&
!nsContentUtils::IsChromeDoc(mDocument)) {
nsCOMPtr<nsPIDOMWindowOuter> currentTop;
nsCOMPtr<nsPIDOMWindowOuter> newTop;
currentTop = currentWindow->GetInProcessTop();
newTop = mDocument->GetWindow()->GetInProcessTop();
nsCOMPtr<Document> currentDoc = currentWindow->GetExtantDoc();
if (nsContentUtils::IsChromeDoc(currentDoc) ||
(currentTop && newTop && currentTop != newTop)) {
fm->SetFocusedWindow(mDocument->GetWindow());
}
}
}
}
SetActiveManager(this, activeContent);
} break;

Просмотреть файл

@ -9,7 +9,6 @@ support-files =
file_clipboard_events_chrome.html
file_DOM_element_instanceof.xhtml
file_MozDomFullscreen.html
file_bug799299.xhtml
file_bug800817.xhtml
file_bug830858.xhtml
file_bug1224790-1_modal.xhtml
@ -42,7 +41,6 @@ support-files =
[test_DOM_element_instanceof.xhtml]
[test_activation.xhtml]
tags = fullscreen
[test_bug799299.xhtml]
[test_bug800817.xhtml]
[test_bug830858.xhtml]
[test_bug1224790-1.xhtml]

Просмотреть файл

@ -1,65 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=799299
-->
<window title="Mozilla Bug 799299"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=799299"
target="_blank">Mozilla Bug 799299</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 799299 **/
function sendClick(win) {
var wu = win.windowUtils;
wu.sendMouseEventToWindow("mousedown", 10, 10, 0, 0, 0);
wu.sendMouseEventToWindow("mouseup", 10, 10, 0, 0, 0);
}
function runTests() {
var b1 = document.getElementById("b1");
var b2 = document.getElementById("b2");
b1.contentWindow.focus();
window.arguments[0].is(document.activeElement, b1,
"Focused first iframe");
var didCallDummy = false;
b2.contentWindow.addEventListener("mousedown", function(e) { didCallDummy = true; });
sendClick(b2.contentWindow);
window.arguments[0].ok(didCallDummy, "dummy mousedown handler should fire");
window.arguments[0].is(document.activeElement, b2,
"Focus shifted to second iframe");
b1.contentWindow.focus();
window.arguments[0].is(document.activeElement, b1,
"Re-focused first iframe for the first time");
var didCallListener = false;
b2.contentWindow.addEventListener("mousedown", function(e) { didCallListener = true; e.preventDefault(); });
sendClick(b2.contentWindow);
window.arguments[0].ok(didCallListener, "mousedown handler should fire");
window.arguments[0].is(document.activeElement, b2,
"focus should move to the second iframe");
window.close();
window.arguments[0].SimpleTest.finish();
}
SimpleTest.waitForFocus(runTests);
]]>
</script>
<hbox flex="1">
<browser id="b1" type="content" src="about:blank" flex="1" style="border: 1px solid black;"/>
<browser id="b2" type="content" src="about:blank" flex="1" style="border: 1px solid black;"/>
</hbox>
</window>

Просмотреть файл

@ -1,31 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=799299
-->
<window title="Mozilla Bug 799299" onload="runTests()"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=799299"
target="_blank">Mozilla Bug 799299</a>
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
/** Test for Bug 799299 **/
function runTests() {
window.openDialog("file_bug799299.xhtml", "_blank", "chrome,width=600,height=550,noopener", window);
}
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>