Skip to content

Commit

Permalink
Update audit.js and fix error catching logic in should().throw()
Browse files Browse the repository at this point in the history
Fetch/update audit.js in non-WPT layout tests and also fix the error
in the error catching logic in should().throw() assertion.

The updated code checks if the |error| object passed by try/catch
is "DOMException". This is unnecessarily specific, so this CL changes
the check to look for the "Error" type, which is more generic.

Bug: 865614
Test: All layout tests pass.
Change-Id: I16acacb26c194a0ff950aca05e931195bf55167f
  • Loading branch information
hoch authored and Chrome-bot committed Aug 24, 2018
1 parent b146527 commit 851a3b5
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions webaudio/resources/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,23 @@ window.Audit = (function() {

/**
* Check if |actual| operation wrapped in a function throws an exception
* 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.
* with a expected error type correctly. |expected| is optional. If it is an
* instance of DOMException, then the description can be provided to be more
* strict about the exception type. It also can be other error types.
*
* @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 });
* should(() => { new SomeConstructor(); }, 'A bad construction')
* .throw(DOMException, 'NotSupportedError');
* should(() => { let c = d; }, 'Assigning d to c')
* .throw(ReferenceError);
* should(() => { let e = f; }, 'Assigning e to f')
* .throw(ReferenceError, { omitErrorMessage: true });
*
* @result
* "PASS A bad code threw an exception of ReferenceError: b is not
* defined."
* "PASS A bad construction threw NotSupportedError."
* "PASS Assigning d to c threw ReferenceError: d is not defined."
* "PASS Assigning e to f threw ReferenceError: [error message
* omitted]."
Expand All @@ -313,17 +315,15 @@ window.Audit = (function() {
// The expected error type was not given.
didThrowCorrectly = true;
passDetail = '${actual} threw ' + error.name + errorMessage + '.';
} else if (typeof(this._expected) == "string" &&
error instanceof DOMException &&
error.name === this._expected) {
// A DOMException was thrown and expected, and the names match
} else if (this._expected === DOMException &&
this._expectedDescription === error.name) {
// Handles DOMException with the associated name.
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.
} else if (this._expected == error.constructor) {
// Handles other error types.
didThrowCorrectly = true;
passDetail = '${actual} threw ${expected}' + errorMessage + '.';
passDetail = '${actual} threw ' + error.name + errorMessage + '.';
} else {
didThrowCorrectly = false;
failDetail =
Expand Down

0 comments on commit 851a3b5

Please sign in to comment.