Bug 1472095 - Update web-platform-test's audit.js file throw() method to be able to pass in exactly the error or exception to expect. r=bz
MozReview-Commit-ID: EU5iuLe1BZV
--- a/testing/web-platform/tests/webaudio/resources/audit.js
+++ b/testing/web-platform/tests/webaudio/resources/audit.js
@@ -76,16 +76,23 @@ window.Audit = (function() {
String(target.slice(0, options.numberOfArrayElements)) + '...';
targetString = '[' + arrayElements + ']';
} else if (target === null) {
targetString = String(target);
} else {
targetString = '' + String(target).split(/[\s\]]/)[1];
}
break;
+ case 'function':
+ if (Error.isPrototypeOf(target)) {
+ targetString = "EcmaScript error " + target.name;
+ } else {
+ targetString = String(target);
+ }
+ break;
default:
targetString = String(target);
break;
}
return targetString;
}
@@ -262,17 +269,20 @@ window.Audit = (function() {
exist() {
return this._assert(
this._actual !== null && this._actual !== undefined,
'${actual} does exist.', '${actual} does not exist.');
}
/**
* Check if |actual| operation wrapped in a function throws an exception
- * with a expected error type correctly. |expected| is optional.
+ * with a expected error type correctly. |expected| is optional. If it is a
+ * String, then it is considered to be the name of a DOMException. It can
+ * also be an instance of either an Error or a DOMException, to be more
+ * strict about the actual error type.
*
* @example
* should(() => { let a = b; }, 'A bad code').throw();
* should(() => { let c = d; }, 'Assigning d to c.')
* .throw('ReferenceError');
* should(() => { let e = f; }, 'Assigning e to f.')
* .throw('ReferenceError', { omitErrorMessage: true });
*
@@ -298,18 +308,25 @@ window.Audit = (function() {
} catch (error) {
let errorMessage = this._options.omitErrorMessage ?
': [error message omitted]' :
': "' + error.message + '"';
if (this._expected === null || this._expected === undefined) {
// The expected error type was not given.
didThrowCorrectly = true;
passDetail = '${actual} threw ' + error.name + errorMessage + '.';
- } else if (error.name === this._expected) {
- // The expected error type match the actual one.
+ } else if (typeof(this._expected) == "string" &&
+ error instanceof DOMException &&
+ error.name === this._expected) {
+ // A DOMException was thrown and expected, and the names match
+ didThrowCorrectly = true;
+ passDetail = '${actual} threw ${expected}' + errorMessage + '.';
+ } else if (this._expected == error.constructor &&
+ this._expected.name == error.name) {
+ // The expected error type and names match the actual one.
didThrowCorrectly = true;
passDetail = '${actual} threw ${expected}' + errorMessage + '.';
} else {
didThrowCorrectly = false;
failDetail =
'${actual} threw "' + error.name + '" instead of ${expected}.';
}
}
--- a/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/audioparam-setValueCurve-exceptions.html
+++ b/testing/web-platform/tests/webaudio/the-audio-api/the-audioparam-interface/audioparam-setValueCurve-exceptions.html
@@ -125,25 +125,25 @@
// Elements of setValueCurve should be finite.
should(
() => {
g.gain.setValueCurveAtTime(
Float32Array.from([NaN, NaN]), time, 0.01);
},
'setValueCurveAtTime([NaN, NaN], ' + time + ', 0.01)')
- .throw('TypeError');
+ .throw(TypeError);
should(
() => {
g.gain.setValueCurveAtTime(
Float32Array.from([1, Infinity]), time, 0.01);
},
'setValueCurveAtTime([1, Infinity], ' + time + ', 0.01)')
- .throw('TypeError');
+ .throw(TypeError);
let d = context.createDelay();
// Check that we get warnings for out-of-range values and also throw for
// non-finite values.
should(
() => {
d.delayTime.setValueCurveAtTime(
Float32Array.from([1, 5]), time, 0.01);
@@ -153,17 +153,17 @@
should(
() => {
d.delayTime.setValueCurveAtTime(
Float32Array.from([1, 5, Infinity]), time, 0.01);
},
'delayTime.setValueCurveAtTime([1, 5, Infinity], ' + time +
', 0.01)')
- .throw('TypeError');
+ .throw(TypeError);
// One last test that prints out lots of digits for the time.
time = Math.PI / 100;
should(
() => {
g.gain.setValueCurveAtTime(curve, time, 0.01);
},
'setValueCurveAtTime(curve, ' + time + ', 0.01)')