Skip to content

Commit

Permalink
Remove assert_throws use in various remaining tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky authored and gsnedders committed Jan 24, 2020
1 parent fb44665 commit 9e1d3cb
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 48 deletions.
4 changes: 2 additions & 2 deletions WebIDL/ecmascript-binding/es-exceptions/exceptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
/**
* This file just picks one case where browsers are supposed to throw an
* exception, and tests the heck out of whether it meets the spec. In the
* future, all these checks should be in assert_throws(), but we don't want
* every browser failing every assert_throws() check until they fix every
* future, all these checks should be in assert_throws_dom(), but we don't want
* every browser failing every assert_throws_dom() check until they fix every
* single bug in their exception-throwing.
*
* We don't go out of our way to test everything that's already tested by
Expand Down
22 changes: 16 additions & 6 deletions common/test-setting-immutable-prototype.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
self.testSettingImmutablePrototypeToNewValueOnly =
(prefix, target, newValue, newValueString, { isSameOriginDomain }) => {
(prefix, target, newValue, newValueString, { isSameOriginDomain },
targetGlobal = window) => {
test(() => {
assert_throws_js(TypeError, () => {
Object.setPrototypeOf(target, newValue);
Expand All @@ -9,14 +10,21 @@ self.testSettingImmutablePrototypeToNewValueOnly =
let dunderProtoError = "SecurityError";
let dunderProtoErrorName = "\"SecurityError\" DOMException";
if (isSameOriginDomain) {
dunderProtoError = new TypeError();
// We're going to end up calling the __proto__ setter, which will
// enter the Realm of targetGlobal before throwing.
dunderProtoError = targetGlobal.TypeError;
dunderProtoErrorName = "TypeError";
}

test(() => {
assert_throws(dunderProtoError, function() {
const func = function() {
target.__proto__ = newValue;
});
};
if (isSameOriginDomain) {
assert_throws_js(dunderProtoError, func);
} else {
assert_throws_dom(dunderProtoError, func);
}
}, `${prefix}: setting the prototype to ${newValueString} via __proto__ should throw a ${dunderProtoErrorName}`);

test(() => {
Expand All @@ -25,8 +33,10 @@ self.testSettingImmutablePrototypeToNewValueOnly =
};

self.testSettingImmutablePrototype =
(prefix, target, originalValue, { isSameOriginDomain }, newValue = {}, newValueString = "an empty object") => {
testSettingImmutablePrototypeToNewValueOnly(prefix, target, newValue, newValueString, { isSameOriginDomain });
(prefix, target, originalValue, { isSameOriginDomain }, targetGlobal = window) => {
const newValue = {};
const newValueString = "an empty object";
testSettingImmutablePrototypeToNewValueOnly(prefix, target, newValue, newValueString, { isSameOriginDomain }, targetGlobal);

const originalValueString = originalValue === null ? "null" : "its original value";

Expand Down
2 changes: 1 addition & 1 deletion css/css-properties-values-api/register-property.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

test(function() {
CSS.registerProperty({name: '--re-register', syntax: '<length>', initialValue: '0px', inherits: false});
assert_throws({name: 'InvalidModificationError'},
assert_throws_dom('InvalidModificationError',
() => CSS.registerProperty({name: '--re-register', syntax: '<percentage>', initialValue: '0%', inherits: false}));
}, "registerProperty fails for an already registered property");

Expand Down
4 changes: 2 additions & 2 deletions css/support/parsing-testcommon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function test_invalid_selector(selector) {
const stringifiedSelector = JSON.stringify(selector);

test(function(){
assert_throws(
assert_throws_dom(
DOMException.SYNTAX_ERR,
() => document.querySelector(selector),
stringifiedSelector + " should throw in querySelector");
Expand All @@ -89,7 +89,7 @@ function test_invalid_selector(selector) {
const {sheet} = style;
document.head.removeChild(style);

assert_throws(
assert_throws_dom(
DOMException.SYNTAX_ERR,
() => sheet.insertRule(selector + "{}"),
stringifiedSelector + " should throw in insertRule");
Expand Down
2 changes: 1 addition & 1 deletion domxpath/001.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

function test_xpath_throws(path, error_code, resolver) {
resolver = resolver ? resolver : null;
assert_throws(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)})
assert_throws_dom(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)})
}

function ns_resolver(x) {
Expand Down
2 changes: 1 addition & 1 deletion domxpath/002.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

function test_xpath_throws(path, error_code, resolver) {
resolver = resolver ? resolver : null;
assert_throws(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)})
assert_throws_dom(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)})
}

function ns_resolver(x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
assert_not_equals(origProto, null);
}, "Same-origin-domain prerequisite check: the original prototype is accessible");

testSettingImmutablePrototype("Same-origin-domain", targetLocation, origProto, { isSameOriginDomain: true });
testSettingImmutablePrototype("Same-origin-domain", targetLocation, origProto, { isSameOriginDomain: true }, frames[0]);

done();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
assert_not_equals(origProto, null);
}, "Same-origin-domain prerequisite check: the original prototype is accessible");

testSettingImmutablePrototype("Same-origin-domain", target, origProto, { isSameOriginDomain: true });
testSettingImmutablePrototype("Same-origin-domain", target, origProto, { isSameOriginDomain: true }, frames[0]);

done();
};
Expand Down
2 changes: 1 addition & 1 deletion orientation-sensor/orientation-sensor-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function checkPopulateMatrix(t, sensorProvider, sensorType) {
() => sensor.populateMatrix(new Float32Array(15)));

// Throws if no orientation data available.
assert_throws({ name: 'NotReadableError' },
assert_throws_dom('NotReadableError',
() => sensor.populateMatrix(new Float32Array(16)));

// Throws if passed SharedArrayBuffer view.
Expand Down
2 changes: 1 addition & 1 deletion shadow-dom/Document-prototype-adoptNode.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
function testAdoptNode(mode) {
test(function () {
var newDocument = document.implementation.createHTMLDocument();
assert_throws({'name': 'HierarchyRequestError'}, function () {
assert_throws_dom('HierarchyRequestError', function () {
var element = document.createElement('div');
var shadowRoot = element.attachShadow({mode: mode});
newDocument.adoptNode(shadowRoot);
Expand Down
8 changes: 4 additions & 4 deletions trusted-types/TrustedTypePolicy-createXXX.tentative.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
[ s => s, "whatever" ],
[ s => null, "" ],
[ s => "well, " + s, "well, whatever" ],
[ s => { throw new Error() }, new Error() ],
[ s => { throw new Error() }, Error ],
[ s => { aGlobalVarForSideEffectTesting = s; return s }, "whatever" ],
[ s => aGlobalVarForSideEffectTesting + s, "whateverwhatever" ],
[ aGlobalFunction.bind(aGlobalObject), "well, whatever" ],
Expand All @@ -66,7 +66,7 @@
[ s => s, INPUTS.SCRIPTURL ],
[ s => null, "" ],
[ s => s + "#duck", INPUTS.SCRIPTURL + "#duck" ],
[ s => { throw new Error() }, new Error() ],
[ s => { throw new Error() }, Error ],
[ s => s + "#" + aGlobalVarForSideEffectTesting,
INPUTS.SCRIPTURL + "#global" ],
[ anotherGlobalFunction.bind(aGlobalObject), INPUTS.SCRIPTURL + "#well," ],
Expand Down Expand Up @@ -99,8 +99,8 @@
for (let [index, [policy_fn, value]] of test_cases.entries()) {
let subtest_name = "TestPolicy" + trusted_class.name + index;
test(t => {
if (value instanceof Error) {
assert_throws(value, () => builder(subtest_name, policy_fn));
if (typeof value == "object") {
assert_throws_js(value, () => builder(subtest_name, policy_fn));
} else {
assert_equals("" + builder(subtest_name, policy_fn), value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
// test_fn();
// assert_equals(element[property], value);
// } else {
// assert_throws(..., test_fn, ...);
// assert_throws_js(..., test_fn, ...);
// }
//
// Below is the same logic, but extended to handle the various edge
Expand Down
2 changes: 1 addition & 1 deletion web-animations/interfaces/KeyframeEffect/constructor.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
test(t => {
const test_error = { name: 'test' };

assert_throws(test_error, () => {
assert_throws_exactly(test_error, () => {
new KeyframeEffect(target, { get left() { throw test_error }})
});
}, 'KeyframeEffect constructor propagates exceptions generated by accessing'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@
test(() => {
const test_error = { name: 'test' };
const bad_keyframe = { get left() { throw test_error; } };
assert_throws(test_error, () => {
assert_throws_exactly(test_error, () => {
new KeyframeEffect(null, createIterable([
{ done: false, value: { left: '100px' } },
{ done: false, value: bad_keyframe },
Expand Down Expand Up @@ -390,7 +390,7 @@
return { next() { throw test_error; } };
},
};
assert_throws(test_error, () => {
assert_throws_exactly(test_error, () => {
new KeyframeEffect(null, keyframe_obj);
});
}, 'If a custom iterator throws from next(), the exception should be rethrown');
Expand All @@ -404,7 +404,7 @@
throw test_error;
},
};
assert_throws(test_error, () => {
assert_throws_exactly(test_error, () => {
new KeyframeEffect(null, keyframe_obj);
});
}, 'Accessing a Symbol.iterator property that throws should rethrow');
Expand Down
2 changes: 1 addition & 1 deletion web-nfc/NDEFRecord_constructor.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
}, 'NDEFRecord constructor with record type string being treated as case sensitive');

test(() => {
assert_throws(new TypeError, () => new NDEFRecord(createRecord(
assert_throws_js(TypeError, () => new NDEFRecord(createRecord(
'example.com:hellö', test_buffer_data)),
'The external type must be an ASCII string.');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

function check_args(arg1, arg2, err, desc) {
test(function() {
assert_throws(err, function() {
assert_throws_dom(err, function() {
ac.createIIRFilter(arg1, arg2)
})
}, desc)
Expand Down
5 changes: 3 additions & 2 deletions webmessaging/without-ports/026.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<script>
async_test(function() {
var obj = {};
obj.__defineGetter__( "field", function(){ throw new Error("getter_should_propagate_exceptions"); });
var err = new Error("getter_should_propagate_exceptions");
obj.__defineGetter__( "field", function(){ throw err });

assert_throws(new Error("getter_should_propagate_exceptions"), function() {
assert_throws_exactly(err, function() {
postMessage(obj, '*');
});
this.done();
Expand Down
10 changes: 5 additions & 5 deletions webrtc/RTCPeerConnection-constructor.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
'{}': false,

// certificates
'{ certificates: null }': new TypeError,
'{ certificates: null }': TypeError,
'{ certificates: undefined }': false,
'{ certificates: [] }': false,
'{ certificates: [null] }': new TypeError,
'{ certificates: [undefined] }': new TypeError,
'{ certificates: [null] }': TypeError,
'{ certificates: [undefined] }': TypeError,

// iceCandidatePoolSize
'{ iceCandidatePoolSize: toNumberThrows }': new TypeError,
'{ iceCandidatePoolSize: toNumberThrows }': TypeError,
}

for (const arg in testArgs) {
const expr = 'new RTCPeerConnection(' + arg + ')';
test(function() {
const throws = testArgs[arg];
if (throws) {
assert_throws(throws, function() {
assert_throws_js(throws, function() {
eval(expr);
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions webstorage/storage_setitem.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
storage.clear();

storage.setItem("age", "10");
assert_throws(test_error, function() {
assert_throws_exactly(test_error, function() {
storage.setItem("age",
{ toString: function() { throw test_error; } });
});
Expand All @@ -111,7 +111,7 @@
storage.clear();

storage.setItem("age", "10");
assert_throws(test_error, function() {
assert_throws_exactly(test_error, function() {
storage["age"] =
{ toString: function() { throw test_error; } };
});
Expand Down
21 changes: 15 additions & 6 deletions webvtt/api/VTTRegion/constructor.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@
assert_equals(region.scroll, "");

checkValues([-1, 101], "IndexSizeError");
checkValues([-Infinity, Infinity, NaN], new TypeError);
checkValues([-Infinity, Infinity, NaN], TypeError);

function assert_throws_something(error, func) {
if (typeof error == "string") {
assert_throws_dom(error, func);
} else {
assert_throws_js(error, func);
}
}

function checkValues(invalidValues, exception) {
for (var value of invalidValues) {
assert_throws(exception, function() { region.viewportAnchorX = value; });
assert_throws_something(exception, function() { region.viewportAnchorX = value; });
assert_equals(region.viewportAnchorX, 0);
assert_throws(exception, function() { region.viewportAnchorY = value; });
assert_throws_something(exception, function() { region.viewportAnchorY = value; });
assert_equals(region.viewportAnchorY, 100);
assert_throws(exception, function() { region.regionAnchorX = value; });
assert_throws_something(exception, function() { region.regionAnchorX = value; });
assert_equals(region.regionAnchorX, 0);
assert_throws(exception, function() { region.regionAnchorY = value; });
assert_throws_something(exception, function() { region.regionAnchorY = value; });
assert_equals(region.regionAnchorY, 100);
assert_throws(exception, function() { region.width = value; });
assert_throws_something(exception, function() { region.width = value; });
assert_equals(region.width, 100);
}
}
Expand Down
17 changes: 12 additions & 5 deletions xhr/send-data-es-object.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ function do_test(obj, expected, name) {
});
client.open('POST', 'resources/content.py')
if (expected.exception) {
assert_throws(expected.exception, function(){client.send(obj)})
if (expected.exception.identity) {
assert_throws_exactly(expected.exception.identity,
function(){client.send(obj)})
} else {
assert_throws_js(expected.exception.ctor,
function(){client.send(obj)})
}
test.done()
} else {
client.send(obj)
Expand Down Expand Up @@ -43,8 +49,9 @@ var myFakeDoc1 = {valueOf:function(){return document}}
do_test(myFakeDoc1, '[object Object]', 'object whose valueOf() returns a document - ignore valueOf(), stringify')

var myFakeDoc2 = {toString:function(){return document}}
var expectedError = self.GLOBAL.isWorker() ? new ReferenceError() : new TypeError();
do_test(myFakeDoc2, {exception:expectedError}, 'object whose toString() returns a document, expected to throw')
var expectedError = self.GLOBAL.isWorker() ? ReferenceError : TypeError;
do_test(myFakeDoc2, {exception: { ctor: expectedError } }, 'object whose toString() returns a document, expected to throw')

var myThrower = {toString:function(){throw {name:'FooError', message:'bar'}}}
do_test(myThrower, {exception:{name:'FooError'}}, 'object whose toString() throws, expected to throw')
var err = {name:'FooError', message:'bar'};
var myThrower = {toString:function(){throw err;}};
do_test(myThrower, {exception: { identity: err }}, 'object whose toString() throws, expected to throw')

0 comments on commit 9e1d3cb

Please sign in to comment.