Skip to content

Commit

Permalink
Merge 5932d75 into a99ba66
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Nov 3, 2016
2 parents a99ba66 + 5932d75 commit a87c397
Show file tree
Hide file tree
Showing 13 changed files with 271 additions and 27 deletions.
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.
setTimeout(t.step_func_done(), 10);
}));
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.
setTimeout(t.step_func_done(), 10);
}));
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.
setTimeout(t.step_func_done(), 10);
}));
windowProxy.location.href = "compile-errors-support-2.html";
});
}, "setTimeout compilation errors in navigated-away-from documents should not fire any error events");
</script>
35 changes: 35 additions & 0 deletions workers/Worker_ErrorEvent_after_navigation.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!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.
setTimeout(t.step_func_done(), 300);
}));
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>
23 changes: 23 additions & 0 deletions workers/support/error-after-some-time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"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": {
console.log("got here");
self.addEventListener("error", ev => {
throw new Error("Error event must not be fired");
});
}
}

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

0 comments on commit a87c397

Please sign in to comment.