Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for the event handler IDL attribute compilation realm #4089

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated from</title>

<h1>Navigate from here</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated to</title>

<h1>Navigate to here</h1>
80 changes: 53 additions & 27 deletions html/webappapis/animation-frames/callback-exception.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,53 @@
<!doctype html>
<html>
<head>
<title>requestAnimationFrame callback exception reported to error handler</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://w3c.github.io/web-performance/specs/RequestAnimationFrame/Overview.html#dom-windowanimationtiming-requestanimationframe"/>
</head>
<body>
<div id="log"></div>
<script>
var custom_exception = 'requestAnimationFrameException';
setup({allow_uncaught_exception : true});
async_test(function (t) {
addEventListener("error",function(e) {
t.step(function() {
assert_equals(e.error.message, custom_exception);
t.done();
})
});
window.requestAnimationFrame(function () {
throw new Error(custom_exception);
});
}, "requestAnimationFrame callback exceptions are reported to error handler");
</script>
</body>
</html>
<!DOCTYPE html>
<meta charset="utf-8">
<title>requestAnimationFrame callback exception reported to error handler</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#run-the-animation-frame-callbacks">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe id="navigate-me" src="callback-exception-support-1.html"></iframe>

<script>
"use strict";
setup({ allow_uncaught_exception: true });

const exceptionMessage = "requestAnimationFrameException";

async_test(t => {
window.addEventListener("error", t.step_func_done(ev => {
assert_equals(ev.constructor, ErrorEvent);
assert_equals(ev.error.message, exceptionMessage);
}));

requestAnimationFrame(() => {
throw new Error(exceptionMessage);
});
}, "requestAnimationFrame errors in an active document should fire an error event");

async_test(t => {
const iframe = document.querySelector("#navigate-me");
const windowProxy = iframe.contentWindow;

window.onload = t.step_func(() => {
windowProxy.onerror = t.unreached_func("The pre-navigation Window's onerror must not be called");

const oldRAF = windowProxy.requestAnimationFrame;
iframe.addEventListener("load", t.step_func(() => {
const newRAF = windowProxy.requestAnimationFrame;
assert_not_equals(oldRAF, newRAF, "Sanity check: navigation changed the requestAnimationFrame");
assert_equals(windowProxy.onerror, null, "Sanity check: after navigation reset onerror");

windowProxy.onerror = t.unreached_func("The post-navigation Window's onerror must not be called");

oldRAF(() => {
throw new Error(exceptionMessage);
});

// The test passes if no error events have been fired within this time.
t.step_timeout(t.step_func_done(), 2000);
}));
windowProxy.location.href = "callback-exception-support-2.html";
});
}, "requestAnimationFrame errors in navigated-away-from documents should not fire any error events");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated from</title>

<h1>Navigate from here</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated to</title>

<h1>Navigate to here</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Event handler IDL attribute realm</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#getting-the-current-value-of-the-event-handler">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe></iframe>
<iframe></iframe>

<iframe id="navigate-me" src="event-handler-idl-attribute-realm-support-1.html"></iframe>

<script>
"use strict";
setup({ allow_uncaught_exception: true });

test(() => {
const frame0Document = frames[0].document.documentElement;
const frame1Body = frames[1].document.body;

frame1Body.setAttribute("onclick", "void(0)");
frame0Document.appendChild(frame1Body);
const get = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "onclick").get;
const f = get.call(frame1Body);

assert_equals(f.constructor, frames[0].Function, "The function must be created in the element's document's global");
}, "Event handler IDL attributes must return a function from the element's document's realm");

async_test(t => {
window.addEventListener("error", t.step_func_done(ev => {
assert_equals(ev.constructor, ErrorEvent);
}));
document.body.setAttribute("onclick", "1 *-* 'syntax error'");

assert_equals(document.body.onclick, null, "Attempting to compile a syntax error must give null");
}, "Event handler IDL attribute compilation errors in an active document should fire an error event");

async_test(t => {
const iframe = document.querySelector("#navigate-me");
const windowProxy = iframe.contentWindow;

window.onload = t.step_func(() => {
windowProxy.onerror = t.unreached_func("The pre-navigation Window's onerror must not be called");

const oldDocument = windowProxy.document;
iframe.addEventListener("load", t.step_func(() => {
const newDocument = windowProxy.document;
assert_not_equals(oldDocument, newDocument, "Sanity check: navigation changed the document");
assert_equals(windowProxy.onerror, null, "Sanity check: after navigation reset onerror");

windowProxy.onerror = t.unreached_func("The post-navigation Window's onerror must not be called");

oldDocument.body.setAttribute("onclick", "1 *-* 'syntax error'");
const onclick = oldDocument.body.onclick;

assert_equals(onclick, null, "Attempting to compile a syntax error must give null");

// The test passes if no error events have been fired within this time.
t.step_timeout(t.step_func_done(), 2000);
}));
windowProxy.location.href = "event-handler-idl-attribute-realm-support-2.html";
});
}, "Event handler IDL attribute compilation errors in navigated-away-from documents should not fire any error events");
</script>
4 changes: 4 additions & 0 deletions html/webappapis/timers/compile-errors-support-1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated from</title>

<h1>Navigate from here</h1>
4 changes: 4 additions & 0 deletions html/webappapis/timers/compile-errors-support-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>This frame will get navigated to</title>

<h1>Navigate to here</h1>
45 changes: 45 additions & 0 deletions html/webappapis/timers/compile-errors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>setTimeout compilation errors</title>
<link rel="help" href="https://html.spec.whatwg.org/multipage/webappapis.html#timer-initialisation-steps">
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe id="navigate-me" src="compile-errors-support-1.html"></iframe>

<script>
"use strict";
setup({ allow_uncaught_exception: true });

async_test(t => {
window.addEventListener("error", t.step_func_done(ev => {
assert_equals(ev.constructor, ErrorEvent);
}));
setTimeout("1 *-* 'syntax error'", 0);
}, "setTimeout compilation errors in an active document should fire an error event");

async_test(t => {
const iframe = document.querySelector("#navigate-me");
const windowProxy = iframe.contentWindow;

window.onload = t.step_func(() => {
windowProxy.onerror = t.unreached_func("The pre-navigation Window's onerror must not be called");

const oldSetTimeout = windowProxy.setTimeout;
iframe.addEventListener("load", t.step_func(() => {
const newSetTimeout = windowProxy.setTimeout;
assert_not_equals(oldSetTimeout, newSetTimeout, "Sanity check: navigation changed the setTimeout");
assert_equals(windowProxy.onerror, null, "Sanity check: after navigation reset onerror");

windowProxy.onerror = t.unreached_func("The post-navigation Window's onerror must not be called");

oldSetTimeout("1 *-* 'syntax error'", 0);

// The test passes if no error events have been fired within this time.
t.step_timeout(t.step_func_done(), 2000);
}));
windowProxy.location.href = "compile-errors-support-2.html";
});
}, "setTimeout compilation errors in navigated-away-from documents should not fire any error events");
</script>
34 changes: 34 additions & 0 deletions workers/Worker_ErrorEvent_after_navigation.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Worker error reporting in navigated-away-from documents</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe src="Worker_ErrorEvent_after_navigation_support-1.htm"></iframe>
<iframe id="navigate-me" src="Worker_ErrorEvent_after_navigation_support-1.htm"></iframe>

<script>
setup({ allow_uncaught_exception: true });

async_test(t => {
window.addEventListener("load", t.step_func(() => {
frames[0].doWorkerStuffAndExpectError(t);
}));
}, "Worker error reporting must work as normal, when no navigation is involved");

async_test(t => {
const iframe = document.querySelector("#navigate-me");
const windowProxy = iframe.contentWindow;

window.addEventListener("load", t.step_func(() => {
windowProxy.onerror = t.unreached_func("The navigated-away-from Window error event must never fire");
windowProxy.doWorkerStuffAndExpectNoError(t);

iframe.addEventListener("load", t.step_func(() => {
// The test passes if no error events have been fired within this time.
t.step_timeout(t.step_func_done(), 2000);
}));
windowProxy.location.href = "Worker_ErrorEvent_after_navigation_support-2.htm";
}));
}, "Worker error reporting must not work at all if the creator document has been navigated away from");
</script>
23 changes: 23 additions & 0 deletions workers/Worker_ErrorEvent_after_navigation_support-1.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Worker error reporting in navigated-away-from documents</title>

<script>
const Worker = window.Worker;

window.doWorkerStuffAndExpectNoError = t => {
const worker = new Worker("./support/error-after-some-time.js");
worker.onerror = t.unreached_func("The Worker object's error event must never fire");

worker.postMessage("no error expected");
};

window.doWorkerStuffAndExpectError = t => {
const worker = new Worker("./support/error-after-some-time.js");
worker.onerror = t.step_func_done(ev => {
parent.assert_equals(ev.constructor, ErrorEvent, "The worker error event must fire");
});

worker.postMessage("error expected");
};
</script>
3 changes: 3 additions & 0 deletions workers/Worker_ErrorEvent_after_navigation_support-2.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Navigate to me</title>
22 changes: 22 additions & 0 deletions workers/support/error-after-some-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

importScripts("/resources/testharness.js");

self.onmessage = ev => {
switch (ev.data) {
case "error expected": {
self.addEventListener("error", ev => {
assert_equals(ev.constructor, ErrorEvent, "The WorkerGlobalScope error event must fire");
assert_equals(ev.message, "boo", "The WorkerGlobalScope error event must have the correct message");
});
}

case "error not expected": {
self.addEventListener("error", ev => {
throw new Error("Error event must not be fired");
});
}
}

step_timeout(() => { throw new Error("boo"); }, 100);
};