Skip to content

Commit 38972d9

Browse files
committed
Log uncaught exceptions in promise_test
1 parent 95b97e2 commit 38972d9

4 files changed

Lines changed: 75 additions & 0 deletions

File tree

.taskcluster.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tasks:
88
$map:
99
$flatten:
1010
$match: {
11+
True: [{name: firefox, channel: nightly}, {name: chrome, channel: dev}],
1112
event.ref == "refs/heads/master": [{name: firefox, channel: nightly}, {name: chrome, channel: dev}],
1213
event.ref == "refs/heads/epochs/daily": [{name: firefox, channel: stable}, {name: chrome, channel: stable}],
1314
event.ref == "refs/heads/epochs/weekly": [{name: firefox, channel: beta}, {name: chrome, channel: beta}]

dom/example.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<title>Example</title>
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
<div id="log"></div>
6+
<script>
7+
setTimeout(function() { throw new Error('this error is expected'); }, 0);
8+
9+
test(function() {}, 'first synchronous test');
10+
11+
test(function() {}, 'second synchronous test');
12+
13+
async_test(function(t) {
14+
setTimeout(function() { t.done(); }, 0);
15+
}, 'first async_test');
16+
17+
async_test(function(t) {
18+
setTimeout(function() { t.done(); }, 0);
19+
}, 'second async_test');
20+
21+
async_test(function(t) {
22+
setTimeout(function() { t.done(); }, 0);
23+
}, 'third async_test');
24+
25+
26+
promise_test(function() {
27+
return Promise.resolve();
28+
}, 'first promise_test');
29+
30+
promise_test(function() {
31+
return Promise.resolve();
32+
}, 'second promise_test');
33+
34+
promise_test(function() {
35+
return Promise.resolve();
36+
}, 'third promise_test');
37+
38+
promise_test(function() {
39+
return Promise.resolve();
40+
}, 'fourth promise_test');
41+
</script>
42+

encrypted-media/log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main(request, response):
2+
with open('../artifacts/suspicious.txt', 'a') as handle:
3+
handle.write('%s - %s\n' % (
4+
request.headers.get('referer'), request.GET['name']
5+
))
6+
return ''

resources/testharness.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ policies and contribution forms [3].
2626
test_timeout:null,
2727
message_events: ["start", "test_state", "result", "completion"]
2828
};
29+
var counts = {
30+
async_tests: 0,
31+
promise_tests: 0,
32+
uncaught_exceptions: 0
33+
};
2934

3035
var xhtml_ns = "http://www.w3.org/1999/xhtml";
3136

@@ -564,6 +569,7 @@ policies and contribution forms [3].
564569

565570
function async_test(func, name, properties)
566571
{
572+
counts.async_tests += 1;
567573
if (typeof func !== "function") {
568574
properties = name;
569575
name = func;
@@ -580,6 +586,9 @@ policies and contribution forms [3].
580586

581587
function promise_test(func, name, properties) {
582588
var test = async_test(name, properties);
589+
counts.promise_tests += 1;
590+
counts.async_tests -= 1;
591+
583592
test._is_promise_test = true;
584593

585594
// If there is no promise tests queue make one.
@@ -2353,6 +2362,21 @@ policies and contribution forms [3].
23532362
}
23542363
}
23552364

2365+
if (counts.uncaught_exceptions && counts.promise_tests) {
2366+
var xhr = new XMLHttpRequest();
2367+
var summary = [
2368+
counts.uncaught_exceptions,
2369+
counts.async_tests,
2370+
counts.promise_tests
2371+
].join(',');
2372+
xhr.open(
2373+
'GET',
2374+
'/encrypted-media/log.py?name=' + encodeURIComponent(summary),
2375+
false
2376+
);
2377+
xhr.send(null);
2378+
}
2379+
23562380
forEach (this.all_done_callbacks,
23572381
function(callback)
23582382
{
@@ -3246,6 +3270,8 @@ policies and contribution forms [3].
32463270

32473271
if (global_scope.addEventListener) {
32483272
var error_handler = function(e) {
3273+
counts.uncaught_exceptions +=1;
3274+
32493275
if (tests.tests.length === 0 && !tests.allow_uncaught_exception) {
32503276
tests.set_file_is_test();
32513277
}

0 commit comments

Comments
 (0)