Backed out changeset 86a2163e7a47 (bug 1709125) for failures on test_hover_mouseleave.html. CLOSED TREE

This commit is contained in:
Csoregi Natalia 2021-05-08 18:54:14 +03:00
parent 6edb9f65b4
commit 0b62baa16a
8 changed files with 14 additions and 194 deletions

View File

@ -4328,16 +4328,25 @@ bool Document::HasFocus(ErrorResult& rv) const {
return false;
}
BrowsingContext* bc = GetBrowsingContext();
if (!bc) {
// Is there a focused DOMWindow?
nsCOMPtr<mozIDOMWindowProxy> focusedWindow;
fm->GetFocusedWindow(getter_AddRefs(focusedWindow));
if (!focusedWindow) {
return false;
}
if (!fm->IsInActiveWindow(bc)) {
return false;
nsPIDOMWindowOuter* piWindow = nsPIDOMWindowOuter::From(focusedWindow);
// Are we an ancestor of the focused DOMWindow?
for (Document* currentDoc = piWindow->GetDoc(); currentDoc;
currentDoc = currentDoc->GetInProcessParentDocument()) {
if (currentDoc == this) {
// Yes, we are an ancestor
return true;
}
}
return fm->IsSameOrAncestor(bc, fm->GetFocusedBrowsingContext());
return false;
}
void Document::GetDesignMode(nsAString& aDesignMode) {

View File

@ -344,12 +344,9 @@ class nsFocusManager final : public nsIFocusManager,
mozilla::dom::BrowsingContext* aContext) const;
bool IsSameOrAncestor(mozilla::dom::BrowsingContext* aPossibleAncestor,
nsPIDOMWindowOuter* aWindow) const;
public:
bool IsSameOrAncestor(mozilla::dom::BrowsingContext* aPossibleAncestor,
mozilla::dom::BrowsingContext* aContext) const;
protected:
/**
* Returns the window that is the lowest common ancestor of both aWindow
* and aContext, or null if they share no common ancestor.

View File

@ -1,16 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>document.hasFocus() with focus in an iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
test(function() {
assert_equals(e.data, "PASS", 'Check result');
}, "Check result");
w.close();
done();
};
var w = window.open("support/hasfocus-different-site-outer.sub.html");
</script>

View File

@ -1,16 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>document.hasFocus() with focus in an iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
test(function() {
assert_equals(e.data, "PASS", 'Check result');
}, "Check result");
w.close();
done();
};
var w = window.open("support/hasfocus-same-site-outer.html");
</script>

View File

@ -1,50 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hasFocus() outer</title>
<script>
var w = null;
var hadInitialFocus = false;
var hadLostFocus = false;
window.onmessage = function(e) {
if (e.data == "restored") {
if (hadInitialFocus && hadLostFocus) {
let verdict = document.hasFocus() ? "PASS" : "FAIL: hasFocus false";
window.opener.postMessage(verdict, "*");
} else {
window.opener.postMessage("FAIL: should have failed already", "*");
}
} else if (e.data == "focused") {
w = window.open("hasfocus-other.html");
} else if (e.data == "noblur") {
window.opener.postMessage("FAIL: no inner blur", "*");
} else if (e.data == "opened") {
if (document.hasFocus()) {
w.close();
window.opener.postMessage("FAIL: focus not lost when other window opened", "*");
} else {
hadLostFocus = true;
window.frames[0].postMessage("hasfocus", "*");
}
} else if (e.data == "close") {
w.close();
} else if (e.data == "wrongfocus") {
w.close();
window.opener.postMessage("FAIL: hasFocus was true in iframe", "*");
}
}
window.onload = function() {
if (document.hasFocus()) {
hadInitialFocus = true;
window.frames[0].postMessage("focus", "*");
} else {
window.opener.postMessage("FAIL: did not have initial focus", "*");
}
}
</script>
</head>
<body>
<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/hasfocus-inner.html"></iframe>
</body>
</html>

View File

@ -1,41 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hasFocus inner</title>
<script>
var seenFocus = false;
var seenBlur = false;
window.onmessage = function(e) {
if (e.data == "focus") {
let input = document.getElementsByTagName("input")[0];
input.onblur = function() {
seenBlur = true;
}
input.onfocus = function() {
if (seenFocus) {
if (seenBlur) {
window.parent.postMessage("restored", "*");
} else {
window.parent.postMessage("noblur", "*");
}
} else {
seenFocus = true;
window.parent.postMessage("focused", "*");
}
}
input.focus();
} else if (e.data == "hasfocus") {
if (document.hasFocus()) {
window.parent.postMessage("wrongfocus", "*");
} else {
window.parent.postMessage("close", "*");
}
}
}
</script>
</head>
<body>
<input>
</body>
</html>

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Outer</title>
<script>
window.onload = function() {
window.opener.postMessage("opened", "*")
}
</script>
</head>
<body>
</body>
</html>

View File

@ -1,50 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hasFocus() outer</title>
<script>
var w = null;
var hadInitialFocus = false;
var hadLostFocus = false;
window.onmessage = function(e) {
if (e.data == "restored") {
if (hadInitialFocus && hadLostFocus) {
let verdict = document.hasFocus() ? "PASS" : "FAIL: hasFocus false";
window.opener.postMessage(verdict, "*");
} else {
window.opener.postMessage("FAIL: should have failed already", "*");
}
} else if (e.data == "focused") {
w = window.open("hasfocus-other.html");
} else if (e.data == "noblur") {
window.opener.postMessage("FAIL: no inner blur", "*");
} else if (e.data == "opened") {
if (document.hasFocus()) {
w.close();
window.opener.postMessage("FAIL: focus not lost when other window opened", "*");
} else {
hadLostFocus = true;
window.frames[0].postMessage("hasfocus", "*");
}
} else if (e.data == "close") {
w.close();
} else if (e.data == "wrongfocus") {
w.close();
window.opener.postMessage("FAIL: hasFocus was true in iframe", "*");
}
}
window.onload = function() {
if (document.hasFocus()) {
hadInitialFocus = true;
window.frames[0].postMessage("focus", "*");
} else {
window.opener.postMessage("FAIL: did not have initial focus", "*");
}
}
</script>
</head>
<body>
<iframe src="hasfocus-inner.html"></iframe>
</body>
</html>