How to use add_test_done_callback method in wpt

Best JavaScript code snippet using wpt

testharness.js

Source:testharness.js Github

copy

Full Screen

...543 // should be registered prior to the resolution of the544 // user-provided Promise to avoid timeouts in cases where the545 // Promise does not settle but a `step` function has thrown an546 // error.547 add_test_done_callback(test, resolve);548 Promise.resolve(promise)549 .catch(test.step_func(550 function(value) {551 if (value instanceof AssertionError) {552 throw value;553 }554 assert(false, "promise_test", null,555 "Unhandled rejection with value: ${value}", {value:value});556 }))557 .then(function() {558 test.done();559 });560 });561 });562 }563 function promise_rejects(test, expected, promise, description) {564 return promise.then(test.unreached_func("Should have rejected: " + description)).catch(function(e) {565 assert_throws(expected, function() { throw e }, description);566 });567 }568 /**569 * This constructor helper allows DOM events to be handled using Promises,570 * which can make it a lot easier to test a very specific series of events,571 * including ensuring that unexpected events are not fired at any point.572 */573 function EventWatcher(test, watchedNode, eventTypes, timeoutPromise)574 {575 if (typeof eventTypes == 'string') {576 eventTypes = [eventTypes];577 }578 var waitingFor = null;579 // This is null unless we are recording all events, in which case it580 // will be an Array object.581 var recordedEvents = null;582 var eventHandler = test.step_func(function(evt) {583 assert_true(!!waitingFor,584 'Not expecting event, but got ' + evt.type + ' event');585 assert_equals(evt.type, waitingFor.types[0],586 'Expected ' + waitingFor.types[0] + ' event, but got ' +587 evt.type + ' event instead');588 if (Array.isArray(recordedEvents)) {589 recordedEvents.push(evt);590 }591 if (waitingFor.types.length > 1) {592 // Pop first event from array593 waitingFor.types.shift();594 return;595 }596 // We need to null out waitingFor before calling the resolve function597 // since the Promise's resolve handlers may call wait_for() which will598 // need to set waitingFor.599 var resolveFunc = waitingFor.resolve;600 waitingFor = null;601 // Likewise, we should reset the state of recordedEvents.602 var result = recordedEvents || evt;603 recordedEvents = null;604 resolveFunc(result);605 });606 for (var i = 0; i < eventTypes.length; i++) {607 watchedNode.addEventListener(eventTypes[i], eventHandler, false);608 }609 /**610 * Returns a Promise that will resolve after the specified event or611 * series of events has occurred.612 *613 * @param options An optional options object. If the 'record' property614 * on this object has the value 'all', when the Promise615 * returned by this function is resolved, *all* Event616 * objects that were waited for will be returned as an617 * array.618 *619 * For example,620 *621 * ```js622 * const watcher = new EventWatcher(t, div, [ 'animationstart',623 * 'animationiteration',624 * 'animationend' ]);625 * return watcher.wait_for([ 'animationstart', 'animationend' ],626 * { record: 'all' }).then(evts => {627 * assert_equals(evts[0].elapsedTime, 0.0);628 * assert_equals(evts[1].elapsedTime, 2.0);629 * });630 * ```631 */632 this.wait_for = function(types, options) {633 if (waitingFor) {634 return Promise.reject('Already waiting for an event or events');635 }636 if (typeof types == 'string') {637 types = [types];638 }639 if (options && options.record && options.record === 'all') {640 recordedEvents = [];641 }642 return new Promise(function(resolve, reject) {643 var timeout = test.step_func(function() {644 // If the timeout fires after the events have been received645 // or during a subsequent call to wait_for, ignore it.646 if (!waitingFor || waitingFor.resolve !== resolve)647 return;648 // This should always fail, otherwise we should have649 // resolved the promise.650 assert_true(waitingFor.types.length == 0,651 'Timed out waiting for ' + waitingFor.types.join(', '));652 var result = recordedEvents;653 recordedEvents = null;654 var resolveFunc = waitingFor.resolve;655 waitingFor = null;656 resolveFunc(result);657 });658 if (timeoutPromise) {659 timeoutPromise().then(timeout);660 }661 waitingFor = {662 types: types,663 resolve: resolve,664 reject: reject665 };666 });667 };668 function stop_watching() {669 for (var i = 0; i < eventTypes.length; i++) {670 watchedNode.removeEventListener(eventTypes[i], eventHandler, false);671 }672 };673 test._add_cleanup(stop_watching);674 return this;675 }676 expose(EventWatcher, 'EventWatcher');677 function setup(func_or_properties, maybe_properties)678 {679 var func = null;680 var properties = {};681 if (arguments.length === 2) {682 func = func_or_properties;683 properties = maybe_properties;684 } else if (func_or_properties instanceof Function) {685 func = func_or_properties;686 } else {687 properties = func_or_properties;688 }689 tests.setup(func, properties);690 test_environment.on_new_harness_properties(properties);691 }692 function done() {693 if (tests.tests.length === 0) {694 tests.set_file_is_test();695 }696 if (tests.file_is_test) {697 // file is test files never have asynchronous cleanup logic,698 // meaning the fully-synchronous `done` function can be used here.699 tests.tests[0].done();700 }701 tests.end_wait();702 }703 function generate_tests(func, args, properties) {704 forEach(args, function(x, i)705 {706 var name = x[0];707 test(function()708 {709 func.apply(this, x.slice(1));710 },711 name,712 Array.isArray(properties) ? properties[i] : properties);713 });714 }715 function on_event(object, event, callback)716 {717 object.addEventListener(event, callback, false);718 }719 function step_timeout(f, t) {720 var outer_this = this;721 var args = Array.prototype.slice.call(arguments, 2);722 return setTimeout(function() {723 f.apply(outer_this, args);724 }, t * tests.timeout_multiplier);725 }726 expose(test, 'test');727 expose(async_test, 'async_test');728 expose(promise_test, 'promise_test');729 expose(promise_rejects, 'promise_rejects');730 expose(generate_tests, 'generate_tests');731 expose(setup, 'setup');732 expose(done, 'done');733 expose(on_event, 'on_event');734 expose(step_timeout, 'step_timeout');735 /*736 * Return a string truncated to the given length, with ... added at the end737 * if it was longer.738 */739 function truncate(s, len)740 {741 if (s.length > len) {742 return s.substring(0, len - 3) + "...";743 }744 return s;745 }746 /*747 * Return true if object is probably a Node object.748 */749 function is_node(object)750 {751 // I use duck-typing instead of instanceof, because752 // instanceof doesn't work if the node is from another window (like an753 // iframe's contentWindow):754 // http://www.w3.org/Bugs/Public/show_bug.cgi?id=12295755 try {756 var has_node_properties = ("nodeType" in object &&757 "nodeName" in object &&758 "nodeValue" in object &&759 "childNodes" in object);760 } catch (e) {761 // We're probably cross-origin, which means we aren't a node762 return false;763 }764 if (has_node_properties) {765 try {766 object.nodeType;767 } catch (e) {768 // The object is probably Node.prototype or another prototype769 // object that inherits from it, and not a Node instance.770 return false;771 }772 return true;773 }774 return false;775 }776 var replacements = {777 "0": "0",778 "1": "x01",779 "2": "x02",780 "3": "x03",781 "4": "x04",782 "5": "x05",783 "6": "x06",784 "7": "x07",785 "8": "b",786 "9": "t",787 "10": "n",788 "11": "v",789 "12": "f",790 "13": "r",791 "14": "x0e",792 "15": "x0f",793 "16": "x10",794 "17": "x11",795 "18": "x12",796 "19": "x13",797 "20": "x14",798 "21": "x15",799 "22": "x16",800 "23": "x17",801 "24": "x18",802 "25": "x19",803 "26": "x1a",804 "27": "x1b",805 "28": "x1c",806 "29": "x1d",807 "30": "x1e",808 "31": "x1f",809 "0xfffd": "ufffd",810 "0xfffe": "ufffe",811 "0xffff": "uffff",812 };813 /*814 * Convert a value to a nice, human-readable string815 */816 function format_value(val, seen)817 {818 if (!seen) {819 seen = [];820 }821 if (typeof val === "object" && val !== null) {822 if (seen.indexOf(val) >= 0) {823 return "[...]";824 }825 seen.push(val);826 }827 if (Array.isArray(val)) {828 return "[" + val.map(function(x) {return format_value(x, seen);}).join(", ") + "]";829 }830 switch (typeof val) {831 case "string":832 val = val.replace("\\", "\\\\");833 for (var p in replacements) {834 var replace = "\\" + replacements[p];835 val = val.replace(RegExp(String.fromCharCode(p), "g"), replace);836 }837 return '"' + val.replace(/"/g, '\\"') + '"';838 case "boolean":839 case "undefined":840 return String(val);841 case "number":842 // In JavaScript, -0 === 0 and String(-0) == "0", so we have to843 // special-case.844 if (val === -0 && 1/val === -Infinity) {845 return "-0";846 }847 return String(val);848 case "object":849 if (val === null) {850 return "null";851 }852 // Special-case Node objects, since those come up a lot in my tests. I853 // ignore namespaces.854 if (is_node(val)) {855 switch (val.nodeType) {856 case Node.ELEMENT_NODE:857 var ret = "<" + val.localName;858 for (var i = 0; i < val.attributes.length; i++) {859 ret += " " + val.attributes[i].name + '="' + val.attributes[i].value + '"';860 }861 ret += ">" + val.innerHTML + "</" + val.localName + ">";862 return "Element node " + truncate(ret, 60);863 case Node.TEXT_NODE:864 return 'Text node "' + truncate(val.data, 60) + '"';865 case Node.PROCESSING_INSTRUCTION_NODE:866 return "ProcessingInstruction node with target " + format_value(truncate(val.target, 60)) + " and data " + format_value(truncate(val.data, 60));867 case Node.COMMENT_NODE:868 return "Comment node <!--" + truncate(val.data, 60) + "-->";869 case Node.DOCUMENT_NODE:870 return "Document node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");871 case Node.DOCUMENT_TYPE_NODE:872 return "DocumentType node";873 case Node.DOCUMENT_FRAGMENT_NODE:874 return "DocumentFragment node with " + val.childNodes.length + (val.childNodes.length == 1 ? " child" : " children");875 default:876 return "Node object of unknown type";877 }878 }879 /* falls through */880 default:881 try {882 return typeof val + ' "' + truncate(String(val), 1000) + '"';883 } catch(e) {884 return ("[stringifying object threw " + String(e) +885 " with type " + String(typeof e) + "]");886 }887 }888 }889 expose(format_value, "format_value");890 /*891 * Assertions892 */893 function assert_true(actual, description)894 {895 assert(actual === true, "assert_true", description,896 "expected true got ${actual}", {actual:actual});897 }898 expose(assert_true, "assert_true");899 function assert_false(actual, description)900 {901 assert(actual === false, "assert_false", description,902 "expected false got ${actual}", {actual:actual});903 }904 expose(assert_false, "assert_false");905 function same_value(x, y) {906 if (y !== y) {907 //NaN case908 return x !== x;909 }910 if (x === 0 && y === 0) {911 //Distinguish +0 and -0912 return 1/x === 1/y;913 }914 return x === y;915 }916 function assert_equals(actual, expected, description)917 {918 /*919 * Test if two primitives are equal or two objects920 * are the same object921 */922 if (typeof actual != typeof expected) {923 assert(false, "assert_equals", description,924 "expected (" + typeof expected + ") ${expected} but got (" + typeof actual + ") ${actual}",925 {expected:expected, actual:actual});926 return;927 }928 assert(same_value(actual, expected), "assert_equals", description,929 "expected ${expected} but got ${actual}",930 {expected:expected, actual:actual});931 }932 expose(assert_equals, "assert_equals");933 function assert_not_equals(actual, expected, description)934 {935 /*936 * Test if two primitives are unequal or two objects937 * are different objects938 */939 assert(!same_value(actual, expected), "assert_not_equals", description,940 "got disallowed value ${actual}",941 {actual:actual});942 }943 expose(assert_not_equals, "assert_not_equals");944 function assert_in_array(actual, expected, description)945 {946 assert(expected.indexOf(actual) != -1, "assert_in_array", description,947 "value ${actual} not in array ${expected}",948 {actual:actual, expected:expected});949 }950 expose(assert_in_array, "assert_in_array");951 function assert_object_equals(actual, expected, description)952 {953 assert(typeof actual === "object" && actual !== null, "assert_object_equals", description,954 "value is ${actual}, expected object",955 {actual: actual});956 //This needs to be improved a great deal957 function check_equal(actual, expected, stack)958 {959 stack.push(actual);960 var p;961 for (p in actual) {962 assert(expected.hasOwnProperty(p), "assert_object_equals", description,963 "unexpected property ${p}", {p:p});964 if (typeof actual[p] === "object" && actual[p] !== null) {965 if (stack.indexOf(actual[p]) === -1) {966 check_equal(actual[p], expected[p], stack);967 }968 } else {969 assert(same_value(actual[p], expected[p]), "assert_object_equals", description,970 "property ${p} expected ${expected} got ${actual}",971 {p:p, expected:expected, actual:actual});972 }973 }974 for (p in expected) {975 assert(actual.hasOwnProperty(p),976 "assert_object_equals", description,977 "expected property ${p} missing", {p:p});978 }979 stack.pop();980 }981 check_equal(actual, expected, []);982 }983 expose(assert_object_equals, "assert_object_equals");984 function assert_array_equals(actual, expected, description)985 {986 assert(typeof actual === "object" && actual !== null && "length" in actual,987 "assert_array_equals", description,988 "value is ${actual}, expected array",989 {actual:actual});990 assert(actual.length === expected.length,991 "assert_array_equals", description,992 "lengths differ, expected ${expected} got ${actual}",993 {expected:expected.length, actual:actual.length});994 for (var i = 0; i < actual.length; i++) {995 assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),996 "assert_array_equals", description,997 "property ${i}, property expected to be ${expected} but was ${actual}",998 {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",999 actual:actual.hasOwnProperty(i) ? "present" : "missing"});1000 assert(same_value(expected[i], actual[i]),1001 "assert_array_equals", description,1002 "property ${i}, expected ${expected} but got ${actual}",1003 {i:i, expected:expected[i], actual:actual[i]});1004 }1005 }1006 expose(assert_array_equals, "assert_array_equals");1007 function assert_array_approx_equals(actual, expected, epsilon, description)1008 {1009 /*1010 * Test if two primitive arrays are equal within +/- epsilon1011 */1012 assert(actual.length === expected.length,1013 "assert_array_approx_equals", description,1014 "lengths differ, expected ${expected} got ${actual}",1015 {expected:expected.length, actual:actual.length});1016 for (var i = 0; i < actual.length; i++) {1017 assert(actual.hasOwnProperty(i) === expected.hasOwnProperty(i),1018 "assert_array_approx_equals", description,1019 "property ${i}, property expected to be ${expected} but was ${actual}",1020 {i:i, expected:expected.hasOwnProperty(i) ? "present" : "missing",1021 actual:actual.hasOwnProperty(i) ? "present" : "missing"});1022 assert(typeof actual[i] === "number",1023 "assert_array_approx_equals", description,1024 "property ${i}, expected a number but got a ${type_actual}",1025 {i:i, type_actual:typeof actual[i]});1026 assert(Math.abs(actual[i] - expected[i]) <= epsilon,1027 "assert_array_approx_equals", description,1028 "property ${i}, expected ${expected} +/- ${epsilon}, expected ${expected} but got ${actual}",1029 {i:i, expected:expected[i], actual:actual[i], epsilon:epsilon});1030 }1031 }1032 expose(assert_array_approx_equals, "assert_array_approx_equals");1033 function assert_approx_equals(actual, expected, epsilon, description)1034 {1035 /*1036 * Test if two primitive numbers are equal within +/- epsilon1037 */1038 assert(typeof actual === "number",1039 "assert_approx_equals", description,1040 "expected a number but got a ${type_actual}",1041 {type_actual:typeof actual});1042 assert(Math.abs(actual - expected) <= epsilon,1043 "assert_approx_equals", description,1044 "expected ${expected} +/- ${epsilon} but got ${actual}",1045 {expected:expected, actual:actual, epsilon:epsilon});1046 }1047 expose(assert_approx_equals, "assert_approx_equals");1048 function assert_less_than(actual, expected, description)1049 {1050 /*1051 * Test if a primitive number is less than another1052 */1053 assert(typeof actual === "number",1054 "assert_less_than", description,1055 "expected a number but got a ${type_actual}",1056 {type_actual:typeof actual});1057 assert(actual < expected,1058 "assert_less_than", description,1059 "expected a number less than ${expected} but got ${actual}",1060 {expected:expected, actual:actual});1061 }1062 expose(assert_less_than, "assert_less_than");1063 function assert_greater_than(actual, expected, description)1064 {1065 /*1066 * Test if a primitive number is greater than another1067 */1068 assert(typeof actual === "number",1069 "assert_greater_than", description,1070 "expected a number but got a ${type_actual}",1071 {type_actual:typeof actual});1072 assert(actual > expected,1073 "assert_greater_than", description,1074 "expected a number greater than ${expected} but got ${actual}",1075 {expected:expected, actual:actual});1076 }1077 expose(assert_greater_than, "assert_greater_than");1078 function assert_between_exclusive(actual, lower, upper, description)1079 {1080 /*1081 * Test if a primitive number is between two others1082 */1083 assert(typeof actual === "number",1084 "assert_between_exclusive", description,1085 "expected a number but got a ${type_actual}",1086 {type_actual:typeof actual});1087 assert(actual > lower && actual < upper,1088 "assert_between_exclusive", description,1089 "expected a number greater than ${lower} " +1090 "and less than ${upper} but got ${actual}",1091 {lower:lower, upper:upper, actual:actual});1092 }1093 expose(assert_between_exclusive, "assert_between_exclusive");1094 function assert_less_than_equal(actual, expected, description)1095 {1096 /*1097 * Test if a primitive number is less than or equal to another1098 */1099 assert(typeof actual === "number",1100 "assert_less_than_equal", description,1101 "expected a number but got a ${type_actual}",1102 {type_actual:typeof actual});1103 assert(actual <= expected,1104 "assert_less_than_equal", description,1105 "expected a number less than or equal to ${expected} but got ${actual}",1106 {expected:expected, actual:actual});1107 }1108 expose(assert_less_than_equal, "assert_less_than_equal");1109 function assert_greater_than_equal(actual, expected, description)1110 {1111 /*1112 * Test if a primitive number is greater than or equal to another1113 */1114 assert(typeof actual === "number",1115 "assert_greater_than_equal", description,1116 "expected a number but got a ${type_actual}",1117 {type_actual:typeof actual});1118 assert(actual >= expected,1119 "assert_greater_than_equal", description,1120 "expected a number greater than or equal to ${expected} but got ${actual}",1121 {expected:expected, actual:actual});1122 }1123 expose(assert_greater_than_equal, "assert_greater_than_equal");1124 function assert_between_inclusive(actual, lower, upper, description)1125 {1126 /*1127 * Test if a primitive number is between to two others or equal to either of them1128 */1129 assert(typeof actual === "number",1130 "assert_between_inclusive", description,1131 "expected a number but got a ${type_actual}",1132 {type_actual:typeof actual});1133 assert(actual >= lower && actual <= upper,1134 "assert_between_inclusive", description,1135 "expected a number greater than or equal to ${lower} " +1136 "and less than or equal to ${upper} but got ${actual}",1137 {lower:lower, upper:upper, actual:actual});1138 }1139 expose(assert_between_inclusive, "assert_between_inclusive");1140 function assert_regexp_match(actual, expected, description) {1141 /*1142 * Test if a string (actual) matches a regexp (expected)1143 */1144 assert(expected.test(actual),1145 "assert_regexp_match", description,1146 "expected ${expected} but got ${actual}",1147 {expected:expected, actual:actual});1148 }1149 expose(assert_regexp_match, "assert_regexp_match");1150 function assert_class_string(object, class_string, description) {1151 assert_equals({}.toString.call(object), "[object " + class_string + "]",1152 description);1153 }1154 expose(assert_class_string, "assert_class_string");1155 function assert_own_property(object, property_name, description) {1156 assert(object.hasOwnProperty(property_name),1157 "assert_own_property", description,1158 "expected property ${p} missing", {p:property_name});1159 }1160 expose(assert_own_property, "assert_own_property");1161 function assert_not_own_property(object, property_name, description) {1162 assert(!object.hasOwnProperty(property_name),1163 "assert_not_own_property", description,1164 "unexpected property ${p} is found on object", {p:property_name});1165 }1166 expose(assert_not_own_property, "assert_not_own_property");1167 function _assert_inherits(name) {1168 return function (object, property_name, description)1169 {1170 assert(typeof object === "object" || typeof object === "function",1171 name, description,1172 "provided value is not an object");1173 assert("hasOwnProperty" in object,1174 name, description,1175 "provided value is an object but has no hasOwnProperty method");1176 assert(!object.hasOwnProperty(property_name),1177 name, description,1178 "property ${p} found on object expected in prototype chain",1179 {p:property_name});1180 assert(property_name in object,1181 name, description,1182 "property ${p} not found in prototype chain",1183 {p:property_name});1184 };1185 }1186 expose(_assert_inherits("assert_inherits"), "assert_inherits");1187 expose(_assert_inherits("assert_idl_attribute"), "assert_idl_attribute");1188 function assert_readonly(object, property_name, description)1189 {1190 var initial_value = object[property_name];1191 try {1192 //Note that this can have side effects in the case where1193 //the property has PutForwards1194 object[property_name] = initial_value + "a"; //XXX use some other value here?1195 assert(same_value(object[property_name], initial_value),1196 "assert_readonly", description,1197 "changing property ${p} succeeded",1198 {p:property_name});1199 } finally {1200 object[property_name] = initial_value;1201 }1202 }1203 expose(assert_readonly, "assert_readonly");1204 /**1205 * Assert an Exception with the expected code is thrown.1206 *1207 * @param {object|number|string} code The expected exception code.1208 * @param {Function} func Function which should throw.1209 * @param {string} description Error description for the case that the error is not thrown.1210 */1211 function assert_throws(code, func, description)1212 {1213 try {1214 func.call(this);1215 assert(false, "assert_throws", description,1216 "${func} did not throw", {func:func});1217 } catch (e) {1218 if (e instanceof AssertionError) {1219 throw e;1220 }1221 assert(typeof e === "object",1222 "assert_throws", description,1223 "${func} threw ${e} with type ${type}, not an object",1224 {func:func, e:e, type:typeof e});1225 assert(e !== null,1226 "assert_throws", description,1227 "${func} threw null, not an object",1228 {func:func});1229 if (code === null) {1230 throw new AssertionError('Test bug: need to pass exception to assert_throws()');1231 }1232 if (typeof code === "object") {1233 assert("name" in e && e.name == code.name,1234 "assert_throws", description,1235 "${func} threw ${actual} (${actual_name}) expected ${expected} (${expected_name})",1236 {func:func, actual:e, actual_name:e.name,1237 expected:code,1238 expected_name:code.name});1239 return;1240 }1241 var code_name_map = {1242 INDEX_SIZE_ERR: 'IndexSizeError',1243 HIERARCHY_REQUEST_ERR: 'HierarchyRequestError',1244 WRONG_DOCUMENT_ERR: 'WrongDocumentError',1245 INVALID_CHARACTER_ERR: 'InvalidCharacterError',1246 NO_MODIFICATION_ALLOWED_ERR: 'NoModificationAllowedError',1247 NOT_FOUND_ERR: 'NotFoundError',1248 NOT_SUPPORTED_ERR: 'NotSupportedError',1249 INUSE_ATTRIBUTE_ERR: 'InUseAttributeError',1250 INVALID_STATE_ERR: 'InvalidStateError',1251 SYNTAX_ERR: 'SyntaxError',1252 INVALID_MODIFICATION_ERR: 'InvalidModificationError',1253 NAMESPACE_ERR: 'NamespaceError',1254 INVALID_ACCESS_ERR: 'InvalidAccessError',1255 TYPE_MISMATCH_ERR: 'TypeMismatchError',1256 SECURITY_ERR: 'SecurityError',1257 NETWORK_ERR: 'NetworkError',1258 ABORT_ERR: 'AbortError',1259 URL_MISMATCH_ERR: 'URLMismatchError',1260 QUOTA_EXCEEDED_ERR: 'QuotaExceededError',1261 TIMEOUT_ERR: 'TimeoutError',1262 INVALID_NODE_TYPE_ERR: 'InvalidNodeTypeError',1263 DATA_CLONE_ERR: 'DataCloneError'1264 };1265 var name = code in code_name_map ? code_name_map[code] : code;1266 var name_code_map = {1267 IndexSizeError: 1,1268 HierarchyRequestError: 3,1269 WrongDocumentError: 4,1270 InvalidCharacterError: 5,1271 NoModificationAllowedError: 7,1272 NotFoundError: 8,1273 NotSupportedError: 9,1274 InUseAttributeError: 10,1275 InvalidStateError: 11,1276 SyntaxError: 12,1277 InvalidModificationError: 13,1278 NamespaceError: 14,1279 InvalidAccessError: 15,1280 TypeMismatchError: 17,1281 SecurityError: 18,1282 NetworkError: 19,1283 AbortError: 20,1284 URLMismatchError: 21,1285 QuotaExceededError: 22,1286 TimeoutError: 23,1287 InvalidNodeTypeError: 24,1288 DataCloneError: 25,1289 EncodingError: 0,1290 NotReadableError: 0,1291 UnknownError: 0,1292 ConstraintError: 0,1293 DataError: 0,1294 TransactionInactiveError: 0,1295 ReadOnlyError: 0,1296 VersionError: 0,1297 OperationError: 0,1298 NotAllowedError: 01299 };1300 if (!(name in name_code_map)) {1301 throw new AssertionError('Test bug: unrecognized DOMException code "' + code + '" passed to assert_throws()');1302 }1303 var required_props = { code: name_code_map[name] };1304 if (required_props.code === 0 ||1305 ("name" in e &&1306 e.name !== e.name.toUpperCase() &&1307 e.name !== "DOMException")) {1308 // New style exception: also test the name property.1309 required_props.name = name;1310 }1311 //We'd like to test that e instanceof the appropriate interface,1312 //but we can't, because we don't know what window it was created1313 //in. It might be an instanceof the appropriate interface on some1314 //unknown other window. TODO: Work around this somehow?1315 for (var prop in required_props) {1316 assert(prop in e && e[prop] == required_props[prop],1317 "assert_throws", description,1318 "${func} threw ${e} that is not a DOMException " + code + ": property ${prop} is equal to ${actual}, expected ${expected}",1319 {func:func, e:e, prop:prop, actual:e[prop], expected:required_props[prop]});1320 }1321 }1322 }1323 expose(assert_throws, "assert_throws");1324 function assert_unreached(description) {1325 assert(false, "assert_unreached", description,1326 "Reached unreachable code");1327 }1328 expose(assert_unreached, "assert_unreached");1329 function assert_any(assert_func, actual, expected_array)1330 {1331 var args = [].slice.call(arguments, 3);1332 var errors = [];1333 var passed = false;1334 forEach(expected_array,1335 function(expected)1336 {1337 try {1338 assert_func.apply(this, [actual, expected].concat(args));1339 passed = true;1340 } catch (e) {1341 errors.push(e.message);1342 }1343 });1344 if (!passed) {1345 throw new AssertionError(errors.join("\n\n"));1346 }1347 }1348 expose(assert_any, "assert_any");1349 function Test(name, properties)1350 {1351 if (tests.file_is_test && tests.tests.length) {1352 throw new Error("Tried to create a test with file_is_test");1353 }1354 this.name = name;1355 this.phase = (tests.is_aborted || tests.phase === tests.phases.COMPLETE) ?1356 this.phases.COMPLETE : this.phases.INITIAL;1357 this.status = this.NOTRUN;1358 this.timeout_id = null;1359 this.index = null;1360 this.properties = properties;1361 this.timeout_length = settings.test_timeout;1362 if (this.timeout_length !== null) {1363 this.timeout_length *= tests.timeout_multiplier;1364 }1365 this.message = null;1366 this.stack = null;1367 this.steps = [];1368 this._is_promise_test = false;1369 this.cleanup_callbacks = [];1370 this._user_defined_cleanup_count = 0;1371 this._done_callbacks = [];1372 // Tests declared following harness completion are likely an indication1373 // of a programming error, but they cannot be reported1374 // deterministically.1375 if (tests.phase === tests.phases.COMPLETE) {1376 return;1377 }1378 tests.push(this);1379 }1380 Test.statuses = {1381 PASS:0,1382 FAIL:1,1383 TIMEOUT:2,1384 NOTRUN:31385 };1386 Test.prototype = merge({}, Test.statuses);1387 Test.prototype.phases = {1388 INITIAL:0,1389 STARTED:1,1390 HAS_RESULT:2,1391 CLEANING:3,1392 COMPLETE:41393 };1394 Test.prototype.structured_clone = function()1395 {1396 if (!this._structured_clone) {1397 var msg = this.message;1398 msg = msg ? String(msg) : msg;1399 this._structured_clone = merge({1400 name:String(this.name),1401 properties:merge({}, this.properties),1402 phases:merge({}, this.phases)1403 }, Test.statuses);1404 }1405 this._structured_clone.status = this.status;1406 this._structured_clone.message = this.message;1407 this._structured_clone.stack = this.stack;1408 this._structured_clone.index = this.index;1409 this._structured_clone.phase = this.phase;1410 return this._structured_clone;1411 };1412 Test.prototype.step = function(func, this_obj)1413 {1414 if (this.phase > this.phases.STARTED) {1415 return;1416 }1417 this.phase = this.phases.STARTED;1418 //If we don't get a result before the harness times out that will be a test timeout1419 this.set_status(this.TIMEOUT, "Test timed out");1420 tests.started = true;1421 tests.notify_test_state(this);1422 if (this.timeout_id === null) {1423 this.set_timeout();1424 }1425 this.steps.push(func);1426 if (arguments.length === 1) {1427 this_obj = this;1428 }1429 try {1430 return func.apply(this_obj, Array.prototype.slice.call(arguments, 2));1431 } catch (e) {1432 if (this.phase >= this.phases.HAS_RESULT) {1433 return;1434 }1435 var message = String((typeof e === "object" && e !== null) ? e.message : e);1436 var stack = e.stack ? e.stack : null;1437 this.set_status(this.FAIL, message, stack);1438 this.phase = this.phases.HAS_RESULT;1439 this.done();1440 }1441 };1442 Test.prototype.step_func = function(func, this_obj)1443 {1444 var test_this = this;1445 if (arguments.length === 1) {1446 this_obj = test_this;1447 }1448 return function()1449 {1450 return test_this.step.apply(test_this, [func, this_obj].concat(1451 Array.prototype.slice.call(arguments)));1452 };1453 };1454 Test.prototype.step_func_done = function(func, this_obj)1455 {1456 var test_this = this;1457 if (arguments.length === 1) {1458 this_obj = test_this;1459 }1460 return function()1461 {1462 if (func) {1463 test_this.step.apply(test_this, [func, this_obj].concat(1464 Array.prototype.slice.call(arguments)));1465 }1466 test_this.done();1467 };1468 };1469 Test.prototype.unreached_func = function(description)1470 {1471 return this.step_func(function() {1472 assert_unreached(description);1473 });1474 };1475 Test.prototype.step_timeout = function(f, timeout) {1476 var test_this = this;1477 var args = Array.prototype.slice.call(arguments, 2);1478 return setTimeout(this.step_func(function() {1479 return f.apply(test_this, args);1480 }), timeout * tests.timeout_multiplier);1481 }1482 /*1483 * Private method for registering cleanup functions. `testharness.js`1484 * internals should use this method instead of the public `add_cleanup`1485 * method in order to hide implementation details from the harness status1486 * message in the case errors.1487 */1488 Test.prototype._add_cleanup = function(callback) {1489 this.cleanup_callbacks.push(callback);1490 };1491 /*1492 * Schedule a function to be run after the test result is known, regardless1493 * of passing or failing state. The behavior of this function will not1494 * influence the result of the test, but if an exception is thrown, the1495 * test harness will report an error.1496 */1497 Test.prototype.add_cleanup = function(callback) {1498 this._user_defined_cleanup_count += 1;1499 this._add_cleanup(callback);1500 };1501 Test.prototype.set_timeout = function()1502 {1503 if (this.timeout_length !== null) {1504 var this_obj = this;1505 this.timeout_id = setTimeout(function()1506 {1507 this_obj.timeout();1508 }, this.timeout_length);1509 }1510 };1511 Test.prototype.set_status = function(status, message, stack)1512 {1513 this.status = status;1514 this.message = message;1515 this.stack = stack ? stack : null;1516 };1517 Test.prototype.timeout = function()1518 {1519 this.timeout_id = null;1520 this.set_status(this.TIMEOUT, "Test timed out");1521 this.phase = this.phases.HAS_RESULT;1522 this.done();1523 };1524 Test.prototype.force_timeout = Test.prototype.timeout;1525 /**1526 * Update the test status, initiate "cleanup" functions, and signal test1527 * completion.1528 */1529 Test.prototype.done = function()1530 {1531 if (this.phase >= this.phases.CLEANING) {1532 return;1533 }1534 if (this.phase <= this.phases.STARTED) {1535 this.set_status(this.PASS, null);1536 }1537 if (global_scope.clearTimeout) {1538 clearTimeout(this.timeout_id);1539 }1540 this.cleanup();1541 };1542 function add_test_done_callback(test, callback)1543 {1544 if (test.phase === test.phases.COMPLETE) {1545 callback();1546 return;1547 }1548 test._done_callbacks.push(callback);1549 }1550 /*1551 * Invoke all specified cleanup functions. If one or more produce an error,1552 * the context is in an unpredictable state, so all further testing should1553 * be cancelled.1554 */1555 Test.prototype.cleanup = function() {1556 var error_count = 0;1557 var bad_value_count = 0;1558 function on_error() {1559 error_count += 1;1560 // Abort tests immediately so that tests declared within subsequent1561 // cleanup functions are not run.1562 tests.abort();1563 }1564 var this_obj = this;1565 var results = [];1566 this.phase = this.phases.CLEANING;1567 forEach(this.cleanup_callbacks,1568 function(cleanup_callback) {1569 var result;1570 try {1571 result = cleanup_callback();1572 } catch (e) {1573 on_error();1574 return;1575 }1576 if (!is_valid_cleanup_result(this_obj, result)) {1577 bad_value_count += 1;1578 // Abort tests immediately so that tests declared1579 // within subsequent cleanup functions are not run.1580 tests.abort();1581 }1582 results.push(result);1583 });1584 if (!this._is_promise_test) {1585 cleanup_done(this_obj, error_count, bad_value_count);1586 } else {1587 all_async(results,1588 function(result, done) {1589 if (result && typeof result.then === "function") {1590 result1591 .then(null, on_error)1592 .then(done);1593 } else {1594 done();1595 }1596 },1597 function() {1598 cleanup_done(this_obj, error_count, bad_value_count);1599 });1600 }1601 };1602 /**1603 * Determine if the return value of a cleanup function is valid for a given1604 * test. Any test may return the value `undefined`. Tests created with1605 * `promise_test` may alternatively return "thenable" object values.1606 */1607 function is_valid_cleanup_result(test, result) {1608 if (result === undefined) {1609 return true;1610 }1611 if (test._is_promise_test) {1612 return result && typeof result.then === "function";1613 }1614 return false;1615 }1616 function cleanup_done(test, error_count, bad_value_count) {1617 if (error_count || bad_value_count) {1618 var total = test._user_defined_cleanup_count;1619 tests.status.status = tests.status.ERROR;1620 tests.status.message = "Test named '" + test.name +1621 "' specified " + total +1622 " 'cleanup' function" + (total > 1 ? "s" : "");1623 if (error_count) {1624 tests.status.message += ", and " + error_count + " failed";1625 }1626 if (bad_value_count) {1627 var type = test._is_promise_test ?1628 "non-thenable" : "non-undefined";1629 tests.status.message += ", and " + bad_value_count +1630 " returned a " + type + " value";1631 }1632 tests.status.message += ".";1633 tests.status.stack = null;1634 }1635 test.phase = test.phases.COMPLETE;1636 tests.result(test);1637 forEach(test._done_callbacks,1638 function(callback) {1639 callback();1640 });1641 test._done_callbacks.length = 0;1642 }1643 /*1644 * A RemoteTest object mirrors a Test object on a remote worker. The1645 * associated RemoteWorker updates the RemoteTest object in response to1646 * received events. In turn, the RemoteTest object replicates these events1647 * on the local document. This allows listeners (test result reporting1648 * etc..) to transparently handle local and remote events.1649 */1650 function RemoteTest(clone) {1651 var this_obj = this;1652 Object.keys(clone).forEach(1653 function(key) {1654 this_obj[key] = clone[key];1655 });1656 this.index = null;1657 this.phase = this.phases.INITIAL;1658 this.update_state_from(clone);1659 this._done_callbacks = [];1660 tests.push(this);1661 }1662 RemoteTest.prototype.structured_clone = function() {1663 var clone = {};1664 Object.keys(this).forEach(1665 (function(key) {1666 var value = this[key];1667 // `RemoteTest` instances are responsible for managing1668 // their own "done" callback functions, so those functions1669 // are not relevant in other execution contexts. Because of1670 // this (and because Function values cannot be serialized1671 // for cross-realm transmittance), the property should not1672 // be considered when cloning instances.1673 if (key === '_done_callbacks' ) {1674 return;1675 }1676 if (typeof value === "object" && value !== null) {1677 clone[key] = merge({}, value);1678 } else {1679 clone[key] = value;1680 }1681 }).bind(this));1682 clone.phases = merge({}, this.phases);1683 return clone;1684 };1685 /**1686 * `RemoteTest` instances are objects which represent tests running in1687 * another realm. They do not define "cleanup" functions (if necessary,1688 * such functions are defined on the associated `Test` instance within the1689 * external realm). However, `RemoteTests` may have "done" callbacks (e.g.1690 * as attached by the `Tests` instance responsible for tracking the overall1691 * test status in the parent realm). The `cleanup` method delegates to1692 * `done` in order to ensure that such callbacks are invoked following the1693 * completion of the `RemoteTest`.1694 */1695 RemoteTest.prototype.cleanup = function() {1696 this.done();1697 };1698 RemoteTest.prototype.phases = Test.prototype.phases;1699 RemoteTest.prototype.update_state_from = function(clone) {1700 this.status = clone.status;1701 this.message = clone.message;1702 this.stack = clone.stack;1703 if (this.phase === this.phases.INITIAL) {1704 this.phase = this.phases.STARTED;1705 }1706 };1707 RemoteTest.prototype.done = function() {1708 this.phase = this.phases.COMPLETE;1709 forEach(this._done_callbacks,1710 function(callback) {1711 callback();1712 });1713 }1714 /*1715 * A RemoteContext listens for test events from a remote test context, such1716 * as another window or a worker. These events are then used to construct1717 * and maintain RemoteTest objects that mirror the tests running in the1718 * remote context.1719 *1720 * An optional third parameter can be used as a predicate to filter incoming1721 * MessageEvents.1722 */1723 function RemoteContext(remote, message_target, message_filter) {1724 this.running = true;1725 this.started = false;1726 this.tests = new Array();1727 this.early_exception = null;1728 var this_obj = this;1729 // If remote context is cross origin assigning to onerror is not1730 // possible, so silently catch those errors.1731 try {1732 remote.onerror = function(error) { this_obj.remote_error(error); };1733 } catch (e) {1734 // Ignore.1735 }1736 // Keeping a reference to the remote object and the message handler until1737 // remote_done() is seen prevents the remote object and its message channel1738 // from going away before all the messages are dispatched.1739 this.remote = remote;1740 this.message_target = message_target;1741 this.message_handler = function(message) {1742 var passesFilter = !message_filter || message_filter(message);1743 // The reference to the `running` property in the following1744 // condition is unnecessary because that value is only set to1745 // `false` after the `message_handler` function has been1746 // unsubscribed.1747 // TODO: Simplify the condition by removing the reference.1748 if (this_obj.running && message.data && passesFilter &&1749 (message.data.type in this_obj.message_handlers)) {1750 this_obj.message_handlers[message.data.type].call(this_obj, message.data);1751 }1752 };1753 if (self.Promise) {1754 this.done = new Promise(function(resolve) {1755 this_obj.doneResolve = resolve;1756 });1757 }1758 this.message_target.addEventListener("message", this.message_handler);1759 }1760 RemoteContext.prototype.remote_error = function(error) {1761 if (error.preventDefault) {1762 error.preventDefault();1763 }1764 // Defer interpretation of errors until the testing protocol has1765 // started and the remote test's `allow_uncaught_exception` property1766 // is available.1767 if (!this.started) {1768 this.early_exception = error;1769 } else if (!this.allow_uncaught_exception) {1770 this.report_uncaught(error);1771 }1772 };1773 RemoteContext.prototype.report_uncaught = function(error) {1774 var message = error.message || String(error);1775 var filename = (error.filename ? " " + error.filename: "");1776 // FIXME: Display remote error states separately from main document1777 // error state.1778 tests.set_status(tests.status.ERROR,1779 "Error in remote" + filename + ": " + message,1780 error.stack);1781 };1782 RemoteContext.prototype.start = function(data) {1783 this.started = true;1784 this.allow_uncaught_exception = data.properties.allow_uncaught_exception;1785 if (this.early_exception && !this.allow_uncaught_exception) {1786 this.report_uncaught(this.early_exception);1787 }1788 };1789 RemoteContext.prototype.test_state = function(data) {1790 var remote_test = this.tests[data.test.index];1791 if (!remote_test) {1792 remote_test = new RemoteTest(data.test);1793 this.tests[data.test.index] = remote_test;1794 }1795 remote_test.update_state_from(data.test);1796 tests.notify_test_state(remote_test);1797 };1798 RemoteContext.prototype.test_done = function(data) {1799 var remote_test = this.tests[data.test.index];1800 remote_test.update_state_from(data.test);1801 remote_test.done();1802 tests.result(remote_test);1803 };1804 RemoteContext.prototype.remote_done = function(data) {1805 if (tests.status.status === null &&1806 data.status.status !== data.status.OK) {1807 tests.set_status(data.status.status, data.status.message, data.status.sack);1808 }1809 this.message_target.removeEventListener("message", this.message_handler);1810 this.running = false;1811 // If remote context is cross origin assigning to onerror is not1812 // possible, so silently catch those errors.1813 try {1814 this.remote.onerror = null;1815 } catch (e) {1816 // Ignore.1817 }1818 this.remote = null;1819 this.message_target = null;1820 if (this.doneResolve) {1821 this.doneResolve();1822 }1823 if (tests.all_done()) {1824 tests.complete();1825 }1826 };1827 RemoteContext.prototype.message_handlers = {1828 start: RemoteContext.prototype.start,1829 test_state: RemoteContext.prototype.test_state,1830 result: RemoteContext.prototype.test_done,1831 complete: RemoteContext.prototype.remote_done1832 };1833 /*1834 * Harness1835 */1836 function TestsStatus()1837 {1838 this.status = null;1839 this.message = null;1840 this.stack = null;1841 }1842 TestsStatus.statuses = {1843 OK:0,1844 ERROR:1,1845 TIMEOUT:21846 };1847 TestsStatus.prototype = merge({}, TestsStatus.statuses);1848 TestsStatus.prototype.structured_clone = function()1849 {1850 if (!this._structured_clone) {1851 var msg = this.message;1852 msg = msg ? String(msg) : msg;1853 this._structured_clone = merge({1854 status:this.status,1855 message:msg,1856 stack:this.stack1857 }, TestsStatus.statuses);1858 }1859 return this._structured_clone;1860 };1861 function Tests()1862 {1863 this.tests = [];1864 this.num_pending = 0;1865 this.phases = {1866 INITIAL:0,1867 SETUP:1,1868 HAVE_TESTS:2,1869 HAVE_RESULTS:3,1870 COMPLETE:41871 };1872 this.phase = this.phases.INITIAL;1873 this.properties = {};1874 this.wait_for_finish = false;1875 this.processing_callbacks = false;1876 this.allow_uncaught_exception = false;1877 this.file_is_test = false;1878 this.timeout_multiplier = 1;1879 this.timeout_length = test_environment.test_timeout();1880 this.timeout_id = null;1881 this.start_callbacks = [];1882 this.test_state_callbacks = [];1883 this.test_done_callbacks = [];1884 this.all_done_callbacks = [];1885 this.pending_remotes = [];1886 this.status = new TestsStatus();1887 var this_obj = this;1888 test_environment.add_on_loaded_callback(function() {1889 if (this_obj.all_done()) {1890 this_obj.complete();1891 }1892 });1893 this.set_timeout();1894 }1895 Tests.prototype.setup = function(func, properties)1896 {1897 if (this.phase >= this.phases.HAVE_RESULTS) {1898 return;1899 }1900 if (this.phase < this.phases.SETUP) {1901 this.phase = this.phases.SETUP;1902 }1903 this.properties = properties;1904 for (var p in properties) {1905 if (properties.hasOwnProperty(p)) {1906 var value = properties[p];1907 if (p == "allow_uncaught_exception") {1908 this.allow_uncaught_exception = value;1909 } else if (p == "explicit_done" && value) {1910 this.wait_for_finish = true;1911 } else if (p == "explicit_timeout" && value) {1912 this.timeout_length = null;1913 if (this.timeout_id)1914 {1915 clearTimeout(this.timeout_id);1916 }1917 } else if (p == "timeout_multiplier") {1918 this.timeout_multiplier = value;1919 if (this.timeout_length) {1920 this.timeout_length *= this.timeout_multiplier;1921 }1922 }1923 }1924 }1925 if (func) {1926 try {1927 func();1928 } catch (e) {1929 this.status.status = this.status.ERROR;1930 this.status.message = String(e);1931 this.status.stack = e.stack ? e.stack : null;1932 }1933 }1934 this.set_timeout();1935 };1936 Tests.prototype.set_file_is_test = function() {1937 if (this.tests.length > 0) {1938 throw new Error("Tried to set file as test after creating a test");1939 }1940 this.wait_for_finish = true;1941 this.file_is_test = true;1942 // Create the test, which will add it to the list of tests1943 async_test();1944 };1945 Tests.prototype.set_status = function(status, message, stack)1946 {1947 this.status.status = status;1948 this.status.message = message;1949 this.status.stack = stack ? stack : null;1950 };1951 Tests.prototype.set_timeout = function() {1952 if (global_scope.clearTimeout) {1953 var this_obj = this;1954 clearTimeout(this.timeout_id);1955 if (this.timeout_length !== null) {1956 this.timeout_id = setTimeout(function() {1957 this_obj.timeout();1958 }, this.timeout_length);1959 }1960 }1961 };1962 Tests.prototype.timeout = function() {1963 var test_in_cleanup = null;1964 if (this.status.status === null) {1965 forEach(this.tests,1966 function(test) {1967 // No more than one test is expected to be in the1968 // "CLEANUP" phase at any time1969 if (test.phase === test.phases.CLEANING) {1970 test_in_cleanup = test;1971 }1972 test.phase = test.phases.COMPLETE;1973 });1974 // Timeouts that occur while a test is in the "cleanup" phase1975 // indicate that some global state was not properly reverted. This1976 // invalidates the overall test execution, so the timeout should be1977 // reported as an error and cancel the execution of any remaining1978 // tests.1979 if (test_in_cleanup) {1980 this.status.status = this.status.ERROR;1981 this.status.message = "Timeout while running cleanup for " +1982 "test named \"" + test_in_cleanup.name + "\".";1983 tests.status.stack = null;1984 } else {1985 this.status.status = this.status.TIMEOUT;1986 }1987 }1988 this.complete();1989 };1990 Tests.prototype.end_wait = function()1991 {1992 this.wait_for_finish = false;1993 if (this.all_done()) {1994 this.complete();1995 }1996 };1997 Tests.prototype.push = function(test)1998 {1999 if (this.phase < this.phases.HAVE_TESTS) {2000 this.start();2001 }2002 this.num_pending++;2003 test.index = this.tests.push(test);2004 this.notify_test_state(test);2005 };2006 Tests.prototype.notify_test_state = function(test) {2007 var this_obj = this;2008 forEach(this.test_state_callbacks,2009 function(callback) {2010 callback(test, this_obj);2011 });2012 };2013 Tests.prototype.all_done = function() {2014 return this.tests.length > 0 && test_environment.all_loaded &&2015 (this.num_pending === 0 || this.is_aborted) && !this.wait_for_finish &&2016 !this.processing_callbacks &&2017 !this.pending_remotes.some(function(w) { return w.running; });2018 };2019 Tests.prototype.start = function() {2020 this.phase = this.phases.HAVE_TESTS;2021 this.notify_start();2022 };2023 Tests.prototype.notify_start = function() {2024 var this_obj = this;2025 forEach (this.start_callbacks,2026 function(callback)2027 {2028 callback(this_obj.properties);2029 });2030 };2031 Tests.prototype.result = function(test)2032 {2033 // If the harness has already transitioned beyond the `HAVE_RESULTS`2034 // phase, subsequent tests should not cause it to revert.2035 if (this.phase <= this.phases.HAVE_RESULTS) {2036 this.phase = this.phases.HAVE_RESULTS;2037 }2038 this.num_pending--;2039 this.notify_result(test);2040 };2041 Tests.prototype.notify_result = function(test) {2042 var this_obj = this;2043 this.processing_callbacks = true;2044 forEach(this.test_done_callbacks,2045 function(callback)2046 {2047 callback(test, this_obj);2048 });2049 this.processing_callbacks = false;2050 if (this_obj.all_done()) {2051 this_obj.complete();2052 }2053 };2054 Tests.prototype.complete = function() {2055 if (this.phase === this.phases.COMPLETE) {2056 return;2057 }2058 var this_obj = this;2059 var all_complete = function() {2060 this_obj.phase = this_obj.phases.COMPLETE;2061 this_obj.notify_complete();2062 };2063 var incomplete = filter(this.tests,2064 function(test) {2065 return test.phase < test.phases.COMPLETE;2066 });2067 /**2068 * To preserve legacy behavior, overall test completion must be2069 * signaled synchronously.2070 */2071 if (incomplete.length === 0) {2072 all_complete();2073 return;2074 }2075 all_async(incomplete,2076 function(test, testDone)2077 {2078 if (test.phase === test.phases.INITIAL) {2079 test.phase = test.phases.COMPLETE;2080 testDone();2081 } else {2082 add_test_done_callback(test, testDone);2083 test.cleanup();2084 }2085 },2086 all_complete);2087 };2088 /**2089 * Update the harness status to reflect an unrecoverable harness error that2090 * should cancel all further testing. Update all previously-defined tests2091 * which have not yet started to indicate that they will not be executed.2092 */2093 Tests.prototype.abort = function() {2094 this.status.status = this.status.ERROR;2095 this.is_aborted = true;2096 forEach(this.tests,...

Full Screen

Full Screen

harness.js

Source:harness.js Github

copy

Full Screen

...526 // should be registered prior to the resolution of the527 // user-provided Promise to avoid timeouts in cases where the528 // Promise does not settle but a `step` function has thrown an529 // error.530 add_test_done_callback(test, resolve);531 Promise.resolve(promise)532 .catch(test.step_func(533 function(value) {534 if (value instanceof assert.AssertionError) {535 throw value;536 }537 console.log(value.stack)538 assert(false, "promise_test", null,539 "Unhandled rejection with value: ${value}", {value:value});540 }))541 .then(function() {542 test.done();543 });544 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1add_test_done_callback(function() { 2 console.log("test done callback");3});4add_completion_callback(function() { 5 console.log("completion callback");6});7add_result_callback(function() { 8 console.log("result callback");9});10add_error_callback(function() { 11 console.log("error callback");12});13add_log_callback(function() { 14 console.log("log callback");15});16add_status_callback(function() { 17 console.log("status callback");18});19add_step_callback(function() { 20 console.log("step callback");21});22add_start_callback(function() { 23 console.log("start callback");24});25add_done_callback(function() { 26 console.log("done callback");27});28add_timeout_callback(function() { 29 console.log("timeout callback");30});31add_comment_callback(function() { 32 console.log("comment callback");33});34add_debug_callback(function() { 35 console.log("debug callback");36});37add_info_callback(function() { 38 console.log("info callback");39});40add_warning_callback(function() { 41 console.log("warning callback");42});43add_exception_callback(function() { 44 console.log("exception callback");45});46add_test_start_callback(function() { 47 console.log("test start callback");48});49add_test_done_callback(function() { 50 console.log("test done callback");51});52add_test_result_callback(function() { 53 console.log("test result callback");54});

Full Screen

Using AI Code Generation

copy

Full Screen

1function done() {2 postMessage('DONE');3}4add_test_done_callback(done);5promise_test(function(test) {6 return new Promise(function(resolve, reject) {7 resolve();8 });9}, 'description');10promise_test(function(test) {11 return new Promise(function(resolve, reject) {12 resolve();13 });14}, 'description');

Full Screen

Using AI Code Generation

copy

Full Screen

1add_test_done_callback(function(status, message, stack) {2 if (status == 0) {3 console.log("Test Passed");4 } else {5 console.log("Test Failed");6 }7});8async_test(function(t) {9 ws.onopen = t.step_func(function(evt) {10 ws.send("Hello, World!");11 });12 ws.onmessage = t.step_func(function(evt) {13 assert_equals(evt.data, "Hello, World!");14 t.done();15 });16 ws.onerror = t.step_func(function(evt) {17 assert_unreached("onerror should not be invoked");18 });19 ws.onclose = t.step_func(function(evt) {20 assert_unreached("onclose should not be invoked");21 });22}, "Send a message and receive a message");23add_result_callback(function(test) {24 if (test.status == 0) {25 console.log("Test Passed");26 } else {27 console.log("Test Failed");28 }29});30async_test(function(t) {31 ws.onopen = t.step_func(function(evt) {32 ws.send("Hello, World!");33 });34 ws.onmessage = t.step_func(function(evt) {35 assert_equals(evt.data, "Hello, World!");36 t.done();37 });38 ws.onerror = t.step_func(function(evt) {39 assert_unreached("onerror should not be invoked");40 });41 ws.onclose = t.step_func(function(evt) {42 assert_unreached("onclose should not be invoked");43 });44}, "Send a message and receive a message");45add_result_callback(function(test) {46 if (test.status == 0) {47 console.log("Test Passed");48 } else {49 console.log("Test Failed");50 }51});52async_test(function(t) {53 ws.onopen = t.step_func(function(evt) {54 ws.send("Hello, World!");

Full Screen

Using AI Code Generation

copy

Full Screen

1add_test_done_callback(function() {2});3window.onload = function() {4 window.postMessage('test_done', '*');5};6add_test_done_callback(function() {7});8window.onload = function() {9 window.postMessage('test_done', '*');10};11add_test_done_callback(function() {12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('wptdriver');2wptdriver.add_test_done_callback(function() {3 console.log("All tests are completed.");4});5var wptdriver = require('wptdriver');6wptdriver.add_async_test_done_callback(function() {7 setTimeout(function() {8 console.log("All tests are completed.");9 }, 5000);10});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful