Skip to content

Commit

Permalink
Add WPTs for testing the effect on activeElement of the containing do…
Browse files Browse the repository at this point in the history
…c when calling .focus() and .blur() on an OOP iframe.

Differential Revision: https://phabricator.services.mozilla.com/D81497

bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1649099
gecko-commit: 05cc29ef24ba11b59afb8954ef23d243f05b2bfd
gecko-reviewers: jgraham
  • Loading branch information
hsivonen authored and moz-wptsync-bot committed Sep 14, 2020
1 parent 0333bca commit 90ea6fe
Show file tree
Hide file tree
Showing 27 changed files with 610 additions and 3 deletions.
@@ -0,0 +1,36 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when focusing different-site iframe's contentWindow</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Handle trailing events separately to get make it easier to see
// if they are the only deviation from the expection.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,";
}
assert_false(endedWith, "Should have gotten innerbodyfocus after willspineventloop");
}, "Check trailing events");
test(function() {
// This is a Fission oddity
var endedWith = false;
if (actual.endsWith(",willspineventloop,innerbodyfocus,")) {
endedWith = true;
actual += "innerbodyblur,innerbodyfocus,";
}
assert_true(endedWith, "Should have gotten innerbodyfocus after willspineventloop");
}, "Check more trailing events");
test(function() {
assert_equals(actual, "outeronload,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:IFRAME,willspineventloop,innerbodyfocus,innerbodyblur,innerbodyfocus,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-focusing-different-site-iframe-outer-contentwindow.sub.html");
</script>
27 changes: 27 additions & 0 deletions focus/activeelement-after-focusing-different-site-iframe.html
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when focusing different-site iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Handle trailing events separately to get make it easier to see
// if they are the only deviation from the expection.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,innerbodyblur,";
}
assert_false(endedWith, "Should have gotten innerbodyfocus,innerbodyblur after willspineventloop");
}, "Check trailing events");
test(function() {
assert_equals(actual, "outeronload,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:BODY,willspineventloop,innerbodyfocus,innerbodyblur,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-focusing-different-site-iframe-outer.sub.html");
</script>
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when focusing same-site iframe's contentWindow</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Handle trailing events separately to get make it easier to see
// if they are the only deviation from the expection.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,";
}
assert_false(endedWith, "Should have gotten innerbodyfocus after willspineventloop");
}, "Check trailing events");
test(function() {
assert_equals(actual, "outeronload,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:IFRAME,willspineventloop,innerbodyfocus,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-focusing-same-site-iframe-outer-contentwindow.html");
</script>
27 changes: 27 additions & 0 deletions focus/activeelement-after-focusing-same-site-iframe.html
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when focusing same-site iframe</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Handle trailing events separately to get make it easier to see
// if they are the only deviation from the expection.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,innerbodyblur,";
}
assert_false(endedWith, "Should have gotten innerbodyfocus,innerbodyblur after willspineventloop");
}, "Check trailing events");
test(function() {
assert_equals(actual, "outeronload,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:BODY,willspineventloop,innerbodyfocus,innerbodyblur,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-focusing-same-site-iframe-outer.html");
</script>
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when immediately focusing different-site iframe's contentWindow</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Make the difference between Firefox and Chrome visible separately
// from the comparison of the entire log string failing to match.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,";
}
assert_true(endedWith, "Should not have gotten innerbodyfocus after willspineventloop");
}, "Check trailing events");
test(function() {
assert_equals(actual, "outerparser,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:IFRAME,willspineventloop,innerbodyfocus,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-immediately-focusing-different-site-iframe-outer-contentwindow.sub.html");
</script>
@@ -0,0 +1,16 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when immediately focusing different-site 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, "outerparser,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:BODY,willspineventloop,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-immediately-focusing-different-site-iframe-outer.sub.html");
</script>
@@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when immediately focusing same-site iframe's contentWindow</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
setup({explicit_done:true});
window.onmessage = function(e) {
var actual = e.data;
test(function() {
// Make the difference between Firefox and Chrome visible separately
// from the comparison of the entire log string failing to match.
var endedWith = false;
if (actual.endsWith(",willspineventloop,")) {
endedWith = true;
actual += "innerbodyfocus,";
}
assert_true(endedWith, "Should not have gotten innerbodyfocus after willspineventloop");
}, "Check trailing events");
test(function() {
assert_equals(actual, "outerparse,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:IFRAME,willspineventloop,innerbodyfocus,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-immediately-focusing-same-site-iframe-outer-contentwindow.html");
</script>
@@ -0,0 +1,16 @@
<!doctype html>
<meta charset=utf-8>
<title>activeElement when immediately focusing same-site 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, "outerparse,activeElement:BODY,willfocusiframe,didfocusiframe,activeElement:IFRAME,willbluriframe,didbluriframe,activeElement:BODY,willspineventloop,", 'Check log');
}, "Check result");
w.close();
done();
};
var w = window.open("support/activeelement-after-immediately-focusing-same-site-iframe-outer.html");
</script>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inner document</title>
</head>
<body>
<h1>Inner</h1>
<script>
document.body.onfocus = function() {
parent.postMessage("innerbodyfocus,", "*");
}
document.body.onblur = function() {
parent.postMessage("innerbodyblur,", "*");
}
</script>
</body>
</html>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inner document</title>
</head>
<body>
<h1>Inner</h1>
<script>
document.body.onfocus = function() {
parent.postMessage("innerbodyfocus,", "*");
}
document.body.onblur = function() {
parent.postMessage("innerbodyblur,", "*");
}
</script>
</body>
</html>
@@ -0,0 +1,29 @@
<!doctype html>
<meta charset="utf-8">
<title>activeElement when focusing different-site iframe's contenWindow</title>
<script>
let log = "";
function getLog() {
return log;
}
window.onmessage = function(e) {
log += e.data;
};
window.onload = function() {
log += "outeronload,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willfocusiframe,";
document.getElementsByTagName("iframe")[0].contentWindow.focus();
log += "didfocusiframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willbluriframe,";
document.getElementsByTagName("iframe")[0].contentWindow.blur();
log += "didbluriframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willspineventloop,"
opener.step_timeout(function() {
opener.postMessage(getLog(), "*");
}, 1500);
}
</script>
<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/activeelement-after-focusing-different-site-iframe-inner-contentwindow.html"></iframe>
@@ -0,0 +1,29 @@
<!doctype html>
<meta charset="utf-8">
<title>activeElement when focusing different-site iframe</title>
<script>
let log = "";
function getLog() {
return log;
}
window.onmessage = function(e) {
log += e.data;
};
window.onload = function() {
log += "outeronload,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willfocusiframe,";
document.getElementsByTagName("iframe")[0].focus();
log += "didfocusiframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willbluriframe,";
document.getElementsByTagName("iframe")[0].blur();
log += "didbluriframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willspineventloop,"
opener.step_timeout(function() {
opener.postMessage(getLog(), "*");
}, 1500);
}
</script>
<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/activeelement-after-focusing-different-site-iframe-inner.html"></iframe>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inner document</title>
</head>
<body>
<h1>Inner</h1>
<script>
document.body.onfocus = function() {
parent.postMessage("innerbodyfocus,", "*");
}
document.body.onblur = function() {
parent.postMessage("innerbodyblur,", "*");
}
</script>
</body>
</html>
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inner document</title>
</head>
<body>
<h1>Inner</h1>
<script>
document.body.onfocus = function() {
parent.postMessage("innerbodyfocus,", "*");
}
document.body.onblur = function() {
parent.postMessage("innerbodyblur,", "*");
}
</script>
</body>
</html>
@@ -0,0 +1,29 @@
<!doctype html>
<meta charset="utf-8">
<title>activeElement when focusing same-site iframe's contentWindow</title>
<script>
let log = "";
function getLog() {
return log;
}
window.onmessage = function(e) {
log += e.data;
};
window.onload = function() {
log += "outeronload,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willfocusiframe,";
document.getElementsByTagName("iframe")[0].contentWindow.focus();
log += "didfocusiframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willbluriframe,";
document.getElementsByTagName("iframe")[0].contentWindow.blur();
log += "didbluriframe,";
log += "activeElement:" + document.activeElement.tagName + ",";
log += "willspineventloop,"
opener.step_timeout(function() {
opener.postMessage(getLog(), "*");
}, 1500);
}
</script>
<iframe src="activeelement-after-focusing-same-site-iframe-inner-contentwindow.html"></iframe>

0 comments on commit 90ea6fe

Please sign in to comment.