Skip to content

Commit

Permalink
Fix the error catching logic of should().throw() in audit.js
Browse files Browse the repository at this point in the history
Context: #12606

Change the logic of should.throw() so we can handle 3 cases -

should(someExpression).throw();
should(someExpression).throw(TypeError);
should(someExpression).throw(DOMException, 'NotSupportedError');

The generic error (except for DOMException) can be passed without
the second argument, but this change will enforce the second arg
when the expected error is a DOMException type.

This touches many test files, so the work will be done in several
steps:

1. Change audit.js on both locations (wpt, non-wpt)
2. Update affected test files with the script.
3. Update the rest of test files which can't be updated
  programmatically.

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 b848489
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 b848489

Please sign in to comment.