How to use compare_Array method in wpt

Best JavaScript code snippet using wpt

common.js

Source:common.js Github

copy

Full Screen

...22 assert_equals(actual, input);23 if (test_obj)24 test_obj.done();25}26function compare_Array(callback, callback_is_async) {27 return function(actual, input, test_obj) {28 if (typeof actual === 'string')29 assert_unreached(actual);30 assert_true(actual instanceof Array, 'instanceof Array');31 assert_not_equals(actual, input);32 assert_equals(actual.length, input.length, 'length');33 callback(actual, input);34 if (test_obj && !callback_is_async)35 test_obj.done();36 }37}38function compare_Object(callback, callback_is_async) {39 return function(actual, input, test_obj) {40 if (typeof actual === 'string')41 assert_unreached(actual);42 assert_true(actual instanceof Object, 'instanceof Object');43 assert_false(actual instanceof Array, 'instanceof Array');44 assert_not_equals(actual, input);45 callback(actual, input);46 if (test_obj && !callback_is_async)47 test_obj.done();48 }49}50function enumerate_props(compare_func, test_obj) {51 return function(actual, input) {52 for (var x in input) {53 compare_func(actual[x], input[x], test_obj);54 }55 };56}57check('primitive undefined', undefined, compare_primitive);58check('primitive null', null, compare_primitive);59check('primitive true', true, compare_primitive);60check('primitive false', false, compare_primitive);61check('primitive string, empty string', '', compare_primitive);62check('primitive string, lone high surrogate', '\uD800', compare_primitive);63check('primitive string, lone low surrogate', '\uDC00', compare_primitive);64check('primitive string, NUL', '\u0000', compare_primitive);65check('primitive string, astral character', '\uDBFF\uDFFD', compare_primitive);66check('primitive number, 0.2', 0.2, compare_primitive);67check('primitive number, 0', 0, compare_primitive);68check('primitive number, -0', -0, compare_primitive);69check('primitive number, NaN', NaN, compare_primitive);70check('primitive number, Infinity', Infinity, compare_primitive);71check('primitive number, -Infinity', -Infinity, compare_primitive);72check('primitive number, 9007199254740992', 9007199254740992, compare_primitive);73check('primitive number, -9007199254740992', -9007199254740992, compare_primitive);74check('primitive number, 9007199254740994', 9007199254740994, compare_primitive);75check('primitive number, -9007199254740994', -9007199254740994, compare_primitive);76check('Array primitives', [undefined,77 null,78 true,79 false,80 '',81 '\uD800',82 '\uDC00',83 '\u0000',84 '\uDBFF\uDFFD',85 0.2,86 0,87 -0,88 NaN,89 Infinity,90 -Infinity,91 9007199254740992,92 -9007199254740992,93 9007199254740994,94 -9007199254740994], compare_Array(enumerate_props(compare_primitive)));95check('Object primitives', {'undefined':undefined,96 'null':null,97 'true':true,98 'false':false,99 'empty':'',100 'high surrogate':'\uD800',101 'low surrogate':'\uDC00',102 'nul':'\u0000',103 'astral':'\uDBFF\uDFFD',104 '0.2':0.2,105 '0':0,106 '-0':-0,107 'NaN':NaN,108 'Infinity':Infinity,109 '-Infinity':-Infinity,110 '9007199254740992':9007199254740992,111 '-9007199254740992':-9007199254740992,112 '9007199254740994':9007199254740994,113 '-9007199254740994':-9007199254740994}, compare_Object(enumerate_props(compare_primitive)));114function compare_Boolean(actual, input, test_obj) {115 if (typeof actual === 'string')116 assert_unreached(actual);117 assert_true(actual instanceof Boolean, 'instanceof Boolean');118 assert_equals(String(actual), String(input), 'converted to primitive');119 assert_not_equals(actual, input);120 if (test_obj)121 test_obj.done();122}123check('Boolean true', new Boolean(true), compare_Boolean);124check('Boolean false', new Boolean(false), compare_Boolean);125check('Array Boolean objects', [new Boolean(true), new Boolean(false)], compare_Array(enumerate_props(compare_Boolean)));126check('Object Boolean objects', {'true':new Boolean(true), 'false':new Boolean(false)}, compare_Object(enumerate_props(compare_Boolean)));127function compare_obj(what) {128 var Type = window[what];129 return function(actual, input, test_obj) {130 if (typeof actual === 'string')131 assert_unreached(actual);132 assert_true(actual instanceof Type, 'instanceof '+what);133 assert_equals(Type(actual), Type(input), 'converted to primitive');134 assert_not_equals(actual, input);135 if (test_obj)136 test_obj.done();137 };138}139check('String empty string', new String(''), compare_obj('String'));140check('String lone high surrogate', new String('\uD800'), compare_obj('String'));141check('String lone low surrogate', new String('\uDC00'), compare_obj('String'));142check('String NUL', new String('\u0000'), compare_obj('String'));143check('String astral character', new String('\uDBFF\uDFFD'), compare_obj('String'));144check('Array String objects', [new String(''),145 new String('\uD800'),146 new String('\uDC00'),147 new String('\u0000'),148 new String('\uDBFF\uDFFD')], compare_Array(enumerate_props(compare_obj('String'))));149check('Object String objects', {'empty':new String(''),150 'high surrogate':new String('\uD800'),151 'low surrogate':new String('\uDC00'),152 'nul':new String('\u0000'),153 'astral':new String('\uDBFF\uDFFD')}, compare_Object(enumerate_props(compare_obj('String'))));154check('Number 0.2', new Number(0.2), compare_obj('Number'));155check('Number 0', new Number(0), compare_obj('Number'));156check('Number -0', new Number(-0), compare_obj('Number'));157check('Number NaN', new Number(NaN), compare_obj('Number'));158check('Number Infinity', new Number(Infinity), compare_obj('Number'));159check('Number -Infinity', new Number(-Infinity), compare_obj('Number'));160check('Number 9007199254740992', new Number(9007199254740992), compare_obj('Number'));161check('Number -9007199254740992', new Number(-9007199254740992), compare_obj('Number'));162check('Number 9007199254740994', new Number(9007199254740994), compare_obj('Number'));163check('Number -9007199254740994', new Number(-9007199254740994), compare_obj('Number'));164check('Array Number objects', [new Number(0.2),165 new Number(0),166 new Number(-0),167 new Number(NaN),168 new Number(Infinity),169 new Number(-Infinity),170 new Number(9007199254740992),171 new Number(-9007199254740992),172 new Number(9007199254740994),173 new Number(-9007199254740994)], compare_Array(enumerate_props(compare_obj('Number'))));174check('Object Number objects', {'0.2':new Number(0.2),175 '0':new Number(0),176 '-0':new Number(-0),177 'NaN':new Number(NaN),178 'Infinity':new Number(Infinity),179 '-Infinity':new Number(-Infinity),180 '9007199254740992':new Number(9007199254740992),181 '-9007199254740992':new Number(-9007199254740992),182 '9007199254740994':new Number(9007199254740994),183 '-9007199254740994':new Number(-9007199254740994)}, compare_Object(enumerate_props(compare_obj('Number'))));184function compare_Date(actual, input, test_obj) {185 if (typeof actual === 'string')186 assert_unreached(actual);187 assert_true(actual instanceof Date, 'instanceof Date');188 assert_equals(Number(actual), Number(input), 'converted to primitive');189 assert_not_equals(actual, input);190 if (test_obj)191 test_obj.done();192}193check('Date 0', new Date(0), compare_Date);194check('Date -0', new Date(-0), compare_Date);195check('Date -8.64e15', new Date(-8.64e15), compare_Date);196check('Date 8.64e15', new Date(8.64e15), compare_Date);197check('Array Date objects', [new Date(0),198 new Date(-0),199 new Date(-8.64e15),200 new Date(8.64e15)], compare_Array(enumerate_props(compare_Date)));201check('Object Date objects', {'0':new Date(0),202 '-0':new Date(-0),203 '-8.64e15':new Date(-8.64e15),204 '8.64e15':new Date(8.64e15)}, compare_Object(enumerate_props(compare_Date)));205function compare_RegExp(expected_source) {206 // XXX ES6 spec doesn't define exact serialization for `source` (it allows several ways to escape)207 return function(actual, input, test_obj) {208 if (typeof actual === 'string')209 assert_unreached(actual);210 assert_true(actual instanceof RegExp, 'instanceof RegExp');211 assert_equals(actual.global, input.global, 'global');212 assert_equals(actual.ignoreCase, input.ignoreCase, 'ignoreCase');213 assert_equals(actual.multiline, input.multiline, 'multiline');214 assert_equals(actual.source, expected_source, 'source');215 assert_equals(actual.sticky, input.sticky, 'sticky');216 assert_equals(actual.unicode, input.unicode, 'unicode');217 assert_equals(actual.lastIndex, 0, 'lastIndex');218 assert_not_equals(actual, input);219 if (test_obj)220 test_obj.done();221 }222}223function func_RegExp_flags_lastIndex() {224 var r = /foo/gim;225 r.lastIndex = 2;226 return r;227}228function func_RegExp_sticky() {229 return new RegExp('foo', 'y');230}231function func_RegExp_unicode() {232 return new RegExp('foo', 'u');233}234check('RegExp flags and lastIndex', func_RegExp_flags_lastIndex, compare_RegExp('foo'));235check('RegExp sticky flag', func_RegExp_sticky, compare_RegExp('foo'));236check('RegExp unicode flag', func_RegExp_unicode, compare_RegExp('foo'));237check('RegExp empty', new RegExp(''), compare_RegExp('(?:)'));238check('RegExp slash', new RegExp('/'), compare_RegExp('\\/'));239check('RegExp new line', new RegExp('\n'), compare_RegExp('\\n'));240check('Array RegExp object, RegExp flags and lastIndex', [func_RegExp_flags_lastIndex()], compare_Array(enumerate_props(compare_RegExp('foo'))));241check('Array RegExp object, RegExp sticky flag', function() { return [func_RegExp_sticky()]; }, compare_Array(enumerate_props(compare_RegExp('foo'))));242check('Array RegExp object, RegExp unicode flag', function() { return [func_RegExp_unicode()]; }, compare_Array(enumerate_props(compare_RegExp('foo'))));243check('Array RegExp object, RegExp empty', [new RegExp('')], compare_Array(enumerate_props(compare_RegExp('(?:)'))));244check('Array RegExp object, RegExp slash', [new RegExp('/')], compare_Array(enumerate_props(compare_RegExp('\\/'))));245check('Array RegExp object, RegExp new line', [new RegExp('\n')], compare_Array(enumerate_props(compare_RegExp('\\n'))));246check('Object RegExp object, RegExp flags and lastIndex', {'x':func_RegExp_flags_lastIndex()}, compare_Object(enumerate_props(compare_RegExp('foo'))));247check('Object RegExp object, RegExp sticky flag', function() { return {'x':func_RegExp_sticky()}; }, compare_Object(enumerate_props(compare_RegExp('foo'))));248check('Object RegExp object, RegExp unicode flag', function() { return {'x':func_RegExp_unicode()}; }, compare_Object(enumerate_props(compare_RegExp('foo'))));249check('Object RegExp object, RegExp empty', {'x':new RegExp('')}, compare_Object(enumerate_props(compare_RegExp('(?:)'))));250check('Object RegExp object, RegExp slash', {'x':new RegExp('/')}, compare_Object(enumerate_props(compare_RegExp('\\/'))));251check('Object RegExp object, RegExp new line', {'x':new RegExp('\n')}, compare_Object(enumerate_props(compare_RegExp('\\n'))));252function compare_Blob(actual, input, test_obj, expect_File) {253 if (typeof actual === 'string')254 assert_unreached(actual);255 assert_true(actual instanceof Blob, 'instanceof Blob');256 if (!expect_File)257 assert_false(actual instanceof File, 'instanceof File');258 assert_equals(actual.size, input.size, 'size');259 assert_equals(actual.type, input.type, 'type');260 assert_not_equals(actual, input);261 var ev_reader = new FileReader();262 var input_reader = new FileReader();263 var read_count = 0;264 var read_done = test_obj.step_func(function() {265 read_count++;266 if (read_count == 2) {267 var ev_result = ev_reader.result;268 var input_result = input_reader.result;269 assert_equals(ev_result.byteLength, input_result.byteLength, 'byteLength');270 var ev_view = new DataView(ev_result);271 var input_view = new DataView(input_result);272 for (var i = 0; i < ev_result.byteLength; ++i) {273 assert_equals(ev_view.getUint8(i), input_view.getUint8(i), 'getUint8('+i+')');274 }275 if (test_obj)276 test_obj.done();277 }278 });279 var read_error = test_obj.step_func(function() { assert_unreached('FileReader error'); });280 ev_reader.readAsArrayBuffer(actual);281 ev_reader.onload = read_done;282 ev_reader.onabort = ev_reader.onerror = read_error;283 input_reader.readAsArrayBuffer(input);284 input_reader.onload = read_done;285 input_reader.onabort = input_reader.onerror = read_error;286}287function func_Blob_basic() {288 return new Blob(['foo'], {type:'text/x-bar'});289}290check('Blob basic', func_Blob_basic, compare_Blob);291function b(str) {292 return parseInt(str, 2);293}294function encode_cesu8(codeunits) {295 // http://www.unicode.org/reports/tr26/ section 2.2296 // only the 3-byte form is supported297 var rv = [];298 codeunits.forEach(function(codeunit) {299 rv.push(b('11100000') + ((codeunit & b('1111000000000000')) >> 12));300 rv.push(b('10000000') + ((codeunit & b('0000111111000000')) >> 6));301 rv.push(b('10000000') + (codeunit & b('0000000000111111')));302 });303 return rv;304}305function func_Blob_bytes(arr) {306 return function() {307 var buffer = new ArrayBuffer(arr.length);308 var view = new DataView(buffer);309 for (var i = 0; i < arr.length; ++i) {310 view.setUint8(i, arr[i]);311 }312 return new Blob([view]);313 };314}315check('Blob unpaired high surrogate (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xD800])), compare_Blob);316check('Blob unpaired low surrogate (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xDC00])), compare_Blob);317check('Blob paired surrogates (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xD800, 0xDC00])), compare_Blob);318function func_Blob_empty() {319 return new Blob(['']);320}321check('Blob empty', func_Blob_empty , compare_Blob);322function func_Blob_NUL() {323 return new Blob(['\u0000']);324}325check('Blob NUL', func_Blob_NUL, compare_Blob);326async_test(function(test_obj) {327 check(test_obj.name, [test_obj.step(func_Blob_basic)], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);328}, 'Array Blob object, Blob basic');329async_test(function(test_obj) {330 check(test_obj.name, [test_obj.step(func_Blob_bytes([0xD800]))], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);331}, 'Array Blob object, Blob unpaired high surrogate (invalid utf-8)');332async_test(function(test_obj) {333 check(test_obj.name, [test_obj.step(func_Blob_bytes([0xDC00]))], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);334}, 'Array Blob object, Blob unpaired low surrogate (invalid utf-8)');335async_test(function(test_obj) {336 check(test_obj.name, [test_obj.step(func_Blob_bytes([0xD800, 0xDC00]))], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);337}, 'Array Blob object, Blob paired surrogates (invalid utf-8)');338async_test(function(test_obj) {339 check(test_obj.name, [test_obj.step(func_Blob_empty)], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);340}, 'Array Blob object, Blob empty');341async_test(function(test_obj) {342 check(test_obj.name, [test_obj.step(func_Blob_NUL)], compare_Array(enumerate_props(compare_Blob, test_obj), true), test_obj);343}, 'Array Blob object, Blob NUL');344async_test(function(test_obj) {345 check(test_obj.name, {'x':test_obj.step(func_Blob_basic)}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);346}, 'Object Blob object, Blob basic');347async_test(function(test_obj) {348 check(test_obj.name, {'x':test_obj.step(func_Blob_bytes([0xD800]))}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);349}, 'Object Blob object, Blob unpaired high surrogate (invalid utf-8)');350async_test(function(test_obj) {351 check(test_obj.name, {'x':test_obj.step(func_Blob_bytes([0xDC00]))}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);352}, 'Object Blob object, Blob unpaired low surrogate (invalid utf-8)');353async_test(function(test_obj) {354 check(test_obj.name, {'x':test_obj.step(func_Blob_bytes([0xD800, 0xDC00]))}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);355}, 'Object Blob object, Blob paired surrogates (invalid utf-8)');356async_test(function(test_obj) {357 check(test_obj.name, {'x':test_obj.step(func_Blob_empty)}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);358}, 'Object Blob object, Blob empty');359async_test(function(test_obj) {360 check(test_obj.name, {'x':test_obj.step(func_Blob_NUL)}, compare_Object(enumerate_props(compare_Blob, test_obj), true), test_obj);361}, 'Object Blob object, Blob NUL');362function compare_File(actual, input, test_obj) {363 assert_true(actual instanceof File, 'instanceof File');364 assert_equals(actual.name, input.name, 'name');365 assert_equals(actual.lastModified, input.lastModified, 'lastModified');366 compare_Blob(actual, input, test_obj, true);367}368function func_File_basic() {369 return new File(['foo'], 'bar', {type:'text/x-bar', lastModified:42});370}371check('File basic', func_File_basic, compare_File);372function compare_FileList(actual, input, test_obj) {373 if (typeof actual === 'string')374 assert_unreached(actual);375 assert_true(actual instanceof FileList, 'instanceof FileList');376 assert_equals(actual.length, input.length, 'length');377 assert_not_equals(actual, input);378 // XXX when there's a way to populate or construct a FileList,379 // check the items in the FileList380 if (test_obj)381 test_obj.done();382}383function func_FileList_empty() {384 var input = document.createElement('input');385 input.type = 'file';386 return input.files;387}388check('FileList empty', func_FileList_empty, compare_FileList);389check('Array FileList object, FileList empty', [func_FileList_empty], compare_Array(enumerate_props(compare_FileList)));390check('Object FileList object, FileList empty', {'x':func_FileList_empty}, compare_Object(enumerate_props(compare_FileList)));391function compare_ArrayBufferView(view) {392 var Type = window[view];393 return function(actual, input, test_obj) {394 if (typeof actual === 'string')395 assert_unreached(actual);396 assert_true(actual instanceof Type, 'instanceof '+view);397 assert_equals(actual.length, input.length, 'length');398 assert_not_equals(actual.buffer, input.buffer, 'buffer');399 for (var i = 0; i < actual.length; ++i) {400 assert_equals(actual[i], input[i], 'actual['+i+']');401 }402 if (test_obj)403 test_obj.done();404 };405}406function compare_ImageData(actual, input, test_obj) {407 if (typeof actual === 'string')408 assert_unreached(actual);409 assert_equals(actual.width, input.width, 'width');410 assert_equals(actual.height, input.height, 'height');411 assert_not_equals(actual.data, input.data, 'data');412 compare_ArrayBufferView('Uint8ClampedArray')(actual.data, input.data, null);413 if (test_obj)414 test_obj.done();415}416function func_ImageData_1x1_transparent_black() {417 var canvas = document.createElement('canvas');418 var ctx = canvas.getContext('2d');419 return ctx.createImageData(1, 1);420}421check('ImageData 1x1 transparent black', func_ImageData_1x1_transparent_black, compare_ImageData);422function func_ImageData_1x1_non_transparent_non_black() {423 var canvas = document.createElement('canvas');424 var ctx = canvas.getContext('2d');425 var imagedata = ctx.createImageData(1, 1);426 imagedata.data[0] = 100;427 imagedata.data[1] = 101;428 imagedata.data[2] = 102;429 imagedata.data[3] = 103;430 return imagedata;431}432check('ImageData 1x1 non-transparent non-black', func_ImageData_1x1_non_transparent_non_black, compare_ImageData);433async_test(function(test_obj) {434 check(test_obj.name, [test_obj.step(func_ImageData_1x1_transparent_black)], compare_Array(enumerate_props(compare_ImageData)), test_obj);435}, 'Array ImageData object, ImageData 1x1 transparent black');436async_test(function(test_obj) {437 check(test_obj.name, [test_obj.step(func_ImageData_1x1_non_transparent_non_black)], compare_Array(enumerate_props(compare_ImageData)), test_obj);438}, 'Array ImageData object, ImageData 1x1 non-transparent non-black');439async_test(function(test_obj) {440 check(test_obj.name, {'x':test_obj.step(func_ImageData_1x1_transparent_black)}, compare_Object(enumerate_props(compare_ImageData)), test_obj);441}, 'Object ImageData object, ImageData 1x1 transparent black');442async_test(function(test_obj) {443 check(test_obj.name, {'x':test_obj.step(func_ImageData_1x1_non_transparent_non_black)}, compare_Object(enumerate_props(compare_ImageData)), test_obj);444}, 'Object ImageData object, ImageData 1x1 non-transparent non-black');445function compare_ImageBitmap(actual, input, test_obj) {446 if (typeof actual === 'string')447 assert_unreached(actual);448 assert_equals(actual instanceof ImageBitmap, 'instanceof ImageBitmap');449 assert_not_equals(actual, input);450 // XXX paint the ImageBitmap on a canvas and check the data451 if (test_obj)452 test_obj.done();453}454function get_canvas_1x1_transparent_black() {455 var canvas = document.createElement('canvas');456 canvas.width = 1;457 canvas.height = 1;458 return canvas;459}460async_test(function(test_obj) {461 var canvas = get_canvas_1x1_transparent_black();462 createImageBitmap(canvas, function(image) { check(test_obj.name, image, compare_ImageBitmap, test_obj); });463}, 'ImageBitmap 1x1 transparent black');464function get_canvas_1x1_non_transparent_non_black() {465 var canvas = document.createElement('canvas');466 canvas.width = 1;467 canvas.height = 1;468 var ctx = canvas.getContext('2d');469 var imagedata = ctx.getImageData(0, 0, 1, 1);470 imagedata.data[0] = 100;471 imagedata.data[1] = 101;472 imagedata.data[2] = 102;473 imagedata.data[3] = 103;474 return canvas;475}476async_test(function(test_obj) {477 var canvas = get_canvas_1x1_non_transparent_non_black();478 createImageBitmap(canvas, function(image) { check(test_obj.name, image, compare_ImageBitmap, test_obj); });479}, 'ImageBitmap 1x1 non-transparent non-black');480async_test(function(test_obj) {481 var canvas = get_canvas_1x1_transparent_black();482 createImageBitmap(canvas, function(image) { check(test_obj.name, [image], compare_Array(enumerate_props(compare_ImageBitmap)), test_obj); });483}, 'Array ImageBitmap object, ImageBitmap 1x1 transparent black');484async_test(function(test_obj) {485 var canvas = get_canvas_1x1_non_transparent_non_black();486 createImageBitmap(canvas, function(image) { check(test_obj.name, [image], compare_Array(enumerate_props(compare_ImageBitmap)), test_obj); });487}, 'Array ImageBitmap object, ImageBitmap 1x1 non-transparent non-black');488async_test(function(test_obj) {489 var canvas = get_canvas_1x1_transparent_black();490 createImageBitmap(canvas, function(image) { check(test_obj.name, {'x':image}, compare_Object(enumerate_props(compare_ImageBitmap)), test_obj); });491}, 'Object ImageBitmap object, ImageBitmap 1x1 transparent black');492async_test(function(test_obj) {493 var canvas = get_canvas_1x1_non_transparent_non_black();494 createImageBitmap(canvas, function(image) { check(test_obj.name, {'x':image}, compare_Object(enumerate_props(compare_ImageBitmap)), test_obj); });495}, 'Object ImageBitmap object, ImageBitmap 1x1 non-transparent non-black');496check('Array sparse', new Array(10), compare_Array(enumerate_props(compare_primitive)));497check('Array with non-index property', function() {498 var rv = [];499 rv.foo = 'bar';500 return rv;501}, compare_Array(enumerate_props(compare_primitive)));502check('Object with index property and length', {'0':'foo', 'length':1}, compare_Object(enumerate_props(compare_primitive)));503function check_circular_property(prop) {504 return function(actual) {505 assert_equals(actual[prop], actual);506 };507}508check('Array with circular reference', function() {509 var rv = [];510 rv[0] = rv;511 return rv;512}, compare_Array(check_circular_property('0')));513check('Object with circular reference', function() {514 var rv = {};515 rv['x'] = rv;516 return rv;517}, compare_Object(check_circular_property('x')));518function check_identical_property_values(prop1, prop2) {519 return function(actual) {520 assert_equals(actual[prop1], actual[prop2]);521 };522}523check('Array with identical property values', function() {524 var obj = {}525 return [obj, obj];526}, compare_Array(check_identical_property_values('0', '1')));527check('Object with identical property values', function() {528 var obj = {}529 return {'x':obj, 'y':obj};530}, compare_Object(check_identical_property_values('x', 'y')));531function check_absent_property(prop) {532 return function(actual) {533 assert_false(prop in actual);534 };535}536check('Object with property on prototype', function() {537 var Foo = function() {};538 Foo.prototype = {'foo':'bar'};539 return new Foo();540}, compare_Object(check_absent_property('foo')));...

Full Screen

Full Screen

structured-clone-battery-of-tests.js

Source:structured-clone-battery-of-tests.js Github

copy

Full Screen

...21 assert_equals(actual, input);22 if (test_obj)23 test_obj.done();24}25function compare_Array(callback, callback_is_async) {26 return function(actual, input, test_obj) {27 if (typeof actual === 'string')28 assert_unreached(actual);29 assert_true(actual instanceof Array, 'instanceof Array');30 assert_not_equals(actual, input);31 assert_equals(actual.length, input.length, 'length');32 callback(actual, input);33 if (test_obj && !callback_is_async)34 test_obj.done();35 }36}37function compare_Object(callback, callback_is_async) {38 return function(actual, input, test_obj) {39 if (typeof actual === 'string')40 assert_unreached(actual);41 assert_true(actual instanceof Object, 'instanceof Object');42 assert_false(actual instanceof Array, 'instanceof Array');43 assert_not_equals(actual, input);44 callback(actual, input);45 if (test_obj && !callback_is_async)46 test_obj.done();47 }48}49function enumerate_props(compare_func, test_obj) {50 return function(actual, input) {51 for (var x in input) {52 compare_func(actual[x], input[x], test_obj);53 }54 };55}56check('primitive undefined', undefined, compare_primitive);57check('primitive null', null, compare_primitive);58check('primitive true', true, compare_primitive);59check('primitive false', false, compare_primitive);60check('primitive string, empty string', '', compare_primitive);61check('primitive string, lone high surrogate', '\uD800', compare_primitive);62check('primitive string, lone low surrogate', '\uDC00', compare_primitive);63check('primitive string, NUL', '\u0000', compare_primitive);64check('primitive string, astral character', '\uDBFF\uDFFD', compare_primitive);65check('primitive number, 0.2', 0.2, compare_primitive);66check('primitive number, 0', 0, compare_primitive);67check('primitive number, -0', -0, compare_primitive);68check('primitive number, NaN', NaN, compare_primitive);69check('primitive number, Infinity', Infinity, compare_primitive);70check('primitive number, -Infinity', -Infinity, compare_primitive);71check('primitive number, 9007199254740992', 9007199254740992, compare_primitive);72check('primitive number, -9007199254740992', -9007199254740992, compare_primitive);73check('primitive number, 9007199254740994', 9007199254740994, compare_primitive);74check('primitive number, -9007199254740994', -9007199254740994, compare_primitive);75check('Array primitives', [undefined,76 null,77 true,78 false,79 '',80 '\uD800',81 '\uDC00',82 '\u0000',83 '\uDBFF\uDFFD',84 0.2,85 0,86 -0,87 NaN,88 Infinity,89 -Infinity,90 9007199254740992,91 -9007199254740992,92 9007199254740994,93 -9007199254740994], compare_Array(enumerate_props(compare_primitive)));94check('Object primitives', {'undefined':undefined,95 'null':null,96 'true':true,97 'false':false,98 'empty':'',99 'high surrogate':'\uD800',100 'low surrogate':'\uDC00',101 'nul':'\u0000',102 'astral':'\uDBFF\uDFFD',103 '0.2':0.2,104 '0':0,105 '-0':-0,106 'NaN':NaN,107 'Infinity':Infinity,108 '-Infinity':-Infinity,109 '9007199254740992':9007199254740992,110 '-9007199254740992':-9007199254740992,111 '9007199254740994':9007199254740994,112 '-9007199254740994':-9007199254740994}, compare_Object(enumerate_props(compare_primitive)));113function compare_Boolean(actual, input, test_obj) {114 if (typeof actual === 'string')115 assert_unreached(actual);116 assert_true(actual instanceof Boolean, 'instanceof Boolean');117 assert_equals(String(actual), String(input), 'converted to primitive');118 assert_not_equals(actual, input);119 if (test_obj)120 test_obj.done();121}122check('Boolean true', new Boolean(true), compare_Boolean);123check('Boolean false', new Boolean(false), compare_Boolean);124check('Array Boolean objects', [new Boolean(true), new Boolean(false)], compare_Array(enumerate_props(compare_Boolean)));125check('Object Boolean objects', {'true':new Boolean(true), 'false':new Boolean(false)}, compare_Object(enumerate_props(compare_Boolean)));126function compare_obj(what) {127 var Type = window[what];128 return function(actual, input, test_obj) {129 if (typeof actual === 'string')130 assert_unreached(actual);131 assert_true(actual instanceof Type, 'instanceof '+what);132 assert_equals(Type(actual), Type(input), 'converted to primitive');133 assert_not_equals(actual, input);134 if (test_obj)135 test_obj.done();136 };137}138check('String empty string', new String(''), compare_obj('String'));139check('String lone high surrogate', new String('\uD800'), compare_obj('String'));140check('String lone low surrogate', new String('\uDC00'), compare_obj('String'));141check('String NUL', new String('\u0000'), compare_obj('String'));142check('String astral character', new String('\uDBFF\uDFFD'), compare_obj('String'));143check('Array String objects', [new String(''),144 new String('\uD800'),145 new String('\uDC00'),146 new String('\u0000'),147 new String('\uDBFF\uDFFD')], compare_Array(enumerate_props(compare_obj('String'))));148check('Object String objects', {'empty':new String(''),149 'high surrogate':new String('\uD800'),150 'low surrogate':new String('\uDC00'),151 'nul':new String('\u0000'),152 'astral':new String('\uDBFF\uDFFD')}, compare_Object(enumerate_props(compare_obj('String'))));153check('Number 0.2', new Number(0.2), compare_obj('Number'));154check('Number 0', new Number(0), compare_obj('Number'));155check('Number -0', new Number(-0), compare_obj('Number'));156check('Number NaN', new Number(NaN), compare_obj('Number'));157check('Number Infinity', new Number(Infinity), compare_obj('Number'));158check('Number -Infinity', new Number(-Infinity), compare_obj('Number'));159check('Number 9007199254740992', new Number(9007199254740992), compare_obj('Number'));160check('Number -9007199254740992', new Number(-9007199254740992), compare_obj('Number'));161check('Number 9007199254740994', new Number(9007199254740994), compare_obj('Number'));162check('Number -9007199254740994', new Number(-9007199254740994), compare_obj('Number'));163check('Array Number objects', [new Number(0.2),164 new Number(0),165 new Number(-0),166 new Number(NaN),167 new Number(Infinity),168 new Number(-Infinity),169 new Number(9007199254740992),170 new Number(-9007199254740992),171 new Number(9007199254740994),172 new Number(-9007199254740994)], compare_Array(enumerate_props(compare_obj('Number'))));173check('Object Number objects', {'0.2':new Number(0.2),174 '0':new Number(0),175 '-0':new Number(-0),176 'NaN':new Number(NaN),177 'Infinity':new Number(Infinity),178 '-Infinity':new Number(-Infinity),179 '9007199254740992':new Number(9007199254740992),180 '-9007199254740992':new Number(-9007199254740992),181 '9007199254740994':new Number(9007199254740994),182 '-9007199254740994':new Number(-9007199254740994)}, compare_Object(enumerate_props(compare_obj('Number'))));183function compare_Date(actual, input, test_obj) {184 if (typeof actual === 'string')185 assert_unreached(actual);186 assert_true(actual instanceof Date, 'instanceof Date');187 assert_equals(Number(actual), Number(input), 'converted to primitive');188 assert_not_equals(actual, input);189 if (test_obj)190 test_obj.done();191}192check('Date 0', new Date(0), compare_Date);193check('Date -0', new Date(-0), compare_Date);194check('Date -8.64e15', new Date(-8.64e15), compare_Date);195check('Date 8.64e15', new Date(8.64e15), compare_Date);196check('Array Date objects', [new Date(0),197 new Date(-0),198 new Date(-8.64e15),199 new Date(8.64e15)], compare_Array(enumerate_props(compare_Date)));200check('Object Date objects', {'0':new Date(0),201 '-0':new Date(-0),202 '-8.64e15':new Date(-8.64e15),203 '8.64e15':new Date(8.64e15)}, compare_Object(enumerate_props(compare_Date)));204function compare_RegExp(expected_source) {205 // XXX ES6 spec doesn't define exact serialization for `source` (it allows several ways to escape)206 return function(actual, input, test_obj) {207 if (typeof actual === 'string')208 assert_unreached(actual);209 assert_true(actual instanceof RegExp, 'instanceof RegExp');210 assert_equals(actual.global, input.global, 'global');211 assert_equals(actual.ignoreCase, input.ignoreCase, 'ignoreCase');212 assert_equals(actual.multiline, input.multiline, 'multiline');213 assert_equals(actual.source, expected_source, 'source');214 assert_equals(actual.sticky, input.sticky, 'sticky');215 assert_equals(actual.unicode, input.unicode, 'unicode');216 assert_equals(actual.lastIndex, 0, 'lastIndex');217 assert_not_equals(actual, input);218 if (test_obj)219 test_obj.done();220 }221}222function func_RegExp_flags_lastIndex() {223 var r = /foo/gim;224 r.lastIndex = 2;225 return r;226}227function func_RegExp_sticky() {228 return new RegExp('foo', 'y');229}230function func_RegExp_unicode() {231 return new RegExp('foo', 'u');232}233check('RegExp flags and lastIndex', func_RegExp_flags_lastIndex, compare_RegExp('foo'));234check('RegExp sticky flag', func_RegExp_sticky, compare_RegExp('foo'));235check('RegExp unicode flag', func_RegExp_unicode, compare_RegExp('foo'));236check('RegExp empty', new RegExp(''), compare_RegExp('(?:)'));237check('RegExp slash', new RegExp('/'), compare_RegExp('\\/'));238check('RegExp new line', new RegExp('\n'), compare_RegExp('\\n'));239check('Array RegExp object, RegExp flags and lastIndex', [func_RegExp_flags_lastIndex()], compare_Array(enumerate_props(compare_RegExp('foo'))));240check('Array RegExp object, RegExp sticky flag', function() { return [func_RegExp_sticky()]; }, compare_Array(enumerate_props(compare_RegExp('foo'))));241check('Array RegExp object, RegExp unicode flag', function() { return [func_RegExp_unicode()]; }, compare_Array(enumerate_props(compare_RegExp('foo'))));242check('Array RegExp object, RegExp empty', [new RegExp('')], compare_Array(enumerate_props(compare_RegExp('(?:)'))));243check('Array RegExp object, RegExp slash', [new RegExp('/')], compare_Array(enumerate_props(compare_RegExp('\\/'))));244check('Array RegExp object, RegExp new line', [new RegExp('\n')], compare_Array(enumerate_props(compare_RegExp('\\n'))));245check('Object RegExp object, RegExp flags and lastIndex', {'x':func_RegExp_flags_lastIndex()}, compare_Object(enumerate_props(compare_RegExp('foo'))));246check('Object RegExp object, RegExp sticky flag', function() { return {'x':func_RegExp_sticky()}; }, compare_Object(enumerate_props(compare_RegExp('foo'))));247check('Object RegExp object, RegExp unicode flag', function() { return {'x':func_RegExp_unicode()}; }, compare_Object(enumerate_props(compare_RegExp('foo'))));248check('Object RegExp object, RegExp empty', {'x':new RegExp('')}, compare_Object(enumerate_props(compare_RegExp('(?:)'))));249check('Object RegExp object, RegExp slash', {'x':new RegExp('/')}, compare_Object(enumerate_props(compare_RegExp('\\/'))));250check('Object RegExp object, RegExp new line', {'x':new RegExp('\n')}, compare_Object(enumerate_props(compare_RegExp('\\n'))));251async function compare_Blob(actual, input, test_obj, expect_File) {252 if (typeof actual === 'string')253 assert_unreached(actual);254 assert_true(actual instanceof Blob, 'instanceof Blob');255 if (!expect_File)256 assert_false(actual instanceof File, 'instanceof File');257 assert_equals(actual.size, input.size, 'size');258 assert_equals(actual.type, input.type, 'type');259 assert_not_equals(actual, input);260 const ab1 = new Response(actual).arrayBuffer();261 const ab2 = new Response(input).arrayBuffer();262 assert_equals(ab1.btyeLength, ab2.byteLength, 'byteLength');263 const ta1 = new Uint8Array(ab1);264 const ta2 = new Uint8Array(ab2);265 for(let i = 0; i < ta1.size; i++) {266 assert_equals(ta1[i], ta2[i]);267 }268}269function func_Blob_basic() {270 return new Blob(['foo'], {type:'text/x-bar'});271}272check('Blob basic', func_Blob_basic, compare_Blob);273function b(str) {274 return parseInt(str, 2);275}276function encode_cesu8(codeunits) {277 // http://www.unicode.org/reports/tr26/ section 2.2278 // only the 3-byte form is supported279 var rv = [];280 codeunits.forEach(function(codeunit) {281 rv.push(b('11100000') + ((codeunit & b('1111000000000000')) >> 12));282 rv.push(b('10000000') + ((codeunit & b('0000111111000000')) >> 6));283 rv.push(b('10000000') + (codeunit & b('0000000000111111')));284 });285 return rv;286}287function func_Blob_bytes(arr) {288 return function() {289 var buffer = new ArrayBuffer(arr.length);290 var view = new DataView(buffer);291 for (var i = 0; i < arr.length; ++i) {292 view.setUint8(i, arr[i]);293 }294 return new Blob([view]);295 };296}297check('Blob unpaired high surrogate (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xD800])), compare_Blob);298check('Blob unpaired low surrogate (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xDC00])), compare_Blob);299check('Blob paired surrogates (invalid utf-8)', func_Blob_bytes(encode_cesu8([0xD800, 0xDC00])), compare_Blob);300function func_Blob_empty() {301 return new Blob(['']);302}303check('Blob empty', func_Blob_empty , compare_Blob);304function func_Blob_NUL() {305 return new Blob(['\u0000']);306}307check('Blob NUL', func_Blob_NUL, compare_Blob);308check('Array Blob object, Blob basic', [func_Blob_basic()], compare_Array(enumerate_props(compare_Blob), true));309check('Array Blob object, Blob unpaired high surrogate (invalid utf-8)', [func_Blob_bytes([0xD800])()], compare_Array(enumerate_props(compare_Blob), true));310check('Array Blob object, Blob unpaired low surrogate (invalid utf-8)', [func_Blob_bytes([0xDC00])()], compare_Array(enumerate_props(compare_Blob), true));311check('Array Blob object, Blob paired surrogates (invalid utf-8)', [func_Blob_bytes([0xD800, 0xDC00])()], compare_Array(enumerate_props(compare_Blob), true));312check('Array Blob object, Blob empty', [func_Blob_empty()], compare_Array(enumerate_props(compare_Blob), true));313check('Array Blob object, Blob NUL', [func_Blob_NUL()], compare_Array(enumerate_props(compare_Blob), true));314check('Object Blob object, Blob basic', {'x':func_Blob_basic()}, compare_Object(enumerate_props(compare_Blob), true));315check('Object Blob object, Blob unpaired high surrogate (invalid utf-8)', {'x':func_Blob_bytes([0xD800])()}, compare_Object(enumerate_props(compare_Blob), true));316check('Object Blob object, Blob unpaired low surrogate (invalid utf-8)', {'x':func_Blob_bytes([0xDC00])()}, compare_Object(enumerate_props(compare_Blob), true));317check('Object Blob object, Blob paired surrogates (invalid utf-8)', {'x':func_Blob_bytes([0xD800, 0xDC00])() }, compare_Object(enumerate_props(compare_Blob), true));318check('Object Blob object, Blob empty', {'x':func_Blob_empty()}, compare_Object(enumerate_props(compare_Blob), true));319check('Object Blob object, Blob NUL', {'x':func_Blob_NUL()}, compare_Object(enumerate_props(compare_Blob), true));320function compare_File(actual, input, test_obj) {321 assert_true(actual instanceof File, 'instanceof File');322 assert_equals(actual.name, input.name, 'name');323 assert_equals(actual.lastModified, input.lastModified, 'lastModified');324 compare_Blob(actual, input, test_obj, true);325}326function func_File_basic() {327 return new File(['foo'], 'bar', {type:'text/x-bar', lastModified:42});328}329check('File basic', func_File_basic, compare_File);330function compare_FileList(actual, input, test_obj) {331 if (typeof actual === 'string')332 assert_unreached(actual);333 assert_true(actual instanceof FileList, 'instanceof FileList');334 assert_equals(actual.length, input.length, 'length');335 assert_not_equals(actual, input);336 // XXX when there's a way to populate or construct a FileList,337 // check the items in the FileList338 if (test_obj)339 test_obj.done();340}341function func_FileList_empty() {342 var input = document.createElement('input');343 input.type = 'file';344 return input.files;345}346check('FileList empty', func_FileList_empty, compare_FileList);347check('Array FileList object, FileList empty', [func_FileList_empty()], compare_Array(enumerate_props(compare_FileList)));348check('Object FileList object, FileList empty', {'x':func_FileList_empty()}, compare_Object(enumerate_props(compare_FileList)));349function compare_ArrayBufferView(view) {350 var Type = window[view];351 return function(actual, input, test_obj) {352 if (typeof actual === 'string')353 assert_unreached(actual);354 assert_true(actual instanceof Type, 'instanceof '+view);355 assert_equals(actual.length, input.length, 'length');356 assert_not_equals(actual.buffer, input.buffer, 'buffer');357 for (var i = 0; i < actual.length; ++i) {358 assert_equals(actual[i], input[i], 'actual['+i+']');359 }360 if (test_obj)361 test_obj.done();362 };363}364function compare_ImageData(actual, input, test_obj) {365 if (typeof actual === 'string')366 assert_unreached(actual);367 assert_equals(actual.width, input.width, 'width');368 assert_equals(actual.height, input.height, 'height');369 assert_not_equals(actual.data, input.data, 'data');370 compare_ArrayBufferView('Uint8ClampedArray')(actual.data, input.data, null);371 if (test_obj)372 test_obj.done();373}374function func_ImageData_1x1_transparent_black() {375 var canvas = document.createElement('canvas');376 var ctx = canvas.getContext('2d');377 return ctx.createImageData(1, 1);378}379check('ImageData 1x1 transparent black', func_ImageData_1x1_transparent_black, compare_ImageData);380function func_ImageData_1x1_non_transparent_non_black() {381 var canvas = document.createElement('canvas');382 var ctx = canvas.getContext('2d');383 var imagedata = ctx.createImageData(1, 1);384 imagedata.data[0] = 100;385 imagedata.data[1] = 101;386 imagedata.data[2] = 102;387 imagedata.data[3] = 103;388 return imagedata;389}390check('ImageData 1x1 non-transparent non-black', func_ImageData_1x1_non_transparent_non_black, compare_ImageData);391check('Array ImageData object, ImageData 1x1 transparent black', [func_ImageData_1x1_transparent_black()], compare_Array(enumerate_props(compare_ImageData)));392check('Array ImageData object, ImageData 1x1 non-transparent non-black', [func_ImageData_1x1_non_transparent_non_black()], compare_Array(enumerate_props(compare_ImageData)));393check('Object ImageData object, ImageData 1x1 transparent black', {'x':func_ImageData_1x1_transparent_black()}, compare_Object(enumerate_props(compare_ImageData)));394check('Object ImageData object, ImageData 1x1 non-transparent non-black', {'x':func_ImageData_1x1_non_transparent_non_black()}, compare_Object(enumerate_props(compare_ImageData)));395check('Array sparse', new Array(10), compare_Array(enumerate_props(compare_primitive)));396check('Array with non-index property', function() {397 var rv = [];398 rv.foo = 'bar';399 return rv;400}, compare_Array(enumerate_props(compare_primitive)));401check('Object with index property and length', {'0':'foo', 'length':1}, compare_Object(enumerate_props(compare_primitive)));402function check_circular_property(prop) {403 return function(actual) {404 assert_equals(actual[prop], actual);405 };406}407check('Array with circular reference', function() {408 var rv = [];409 rv[0] = rv;410 return rv;411}, compare_Array(check_circular_property('0')));412check('Object with circular reference', function() {413 var rv = {};414 rv['x'] = rv;415 return rv;416}, compare_Object(check_circular_property('x')));417function check_identical_property_values(prop1, prop2) {418 return function(actual) {419 assert_equals(actual[prop1], actual[prop2]);420 };421}422check('Array with identical property values', function() {423 var obj = {}424 return [obj, obj];425}, compare_Array(check_identical_property_values('0', '1')));426check('Object with identical property values', function() {427 var obj = {}428 return {'x':obj, 'y':obj};429}, compare_Object(check_identical_property_values('x', 'y')));430function check_absent_property(prop) {431 return function(actual) {432 assert_false(prop in actual);433 };434}435check('Object with property on prototype', function() {436 var Foo = function() {};437 Foo.prototype = {'foo':'bar'};438 return new Foo();439}, compare_Object(check_absent_property('foo')));440check('Object with non-enumerable property', function() {441 var rv = {};442 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:false, writable:true, configurable:true});443 return rv;444}, compare_Object(check_absent_property('foo')));445function check_writable_property(prop) {446 return function(actual, input) {447 assert_equals(actual[prop], input[prop]);448 actual[prop] += ' baz';449 assert_equals(actual[prop], input[prop] + ' baz');450 };451}452check('Object with non-writable property', function() {453 var rv = {};454 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:true, writable:false, configurable:true});455 return rv;456}, compare_Object(check_writable_property('foo')));457function check_configurable_property(prop) {458 return function(actual, input) {459 assert_equals(actual[prop], input[prop]);460 delete actual[prop];461 assert_false('prop' in actual);462 };463}464check('Object with non-configurable property', function() {465 var rv = {};466 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:true, writable:true, configurable:false});467 return rv;468}, compare_Object(check_configurable_property('foo')));469/* The tests below are inspired by @zcorpan’s work but got some470more substantial changed due to their previous async setup */471function get_canvas_1x1_transparent_black() {472 var canvas = document.createElement('canvas');473 canvas.width = 1;474 canvas.height = 1;475 return canvas;476}477function get_canvas_1x1_non_transparent_non_black() {478 var canvas = document.createElement('canvas');479 canvas.width = 1;480 canvas.height = 1;481 var ctx = canvas.getContext('2d');482 var imagedata = ctx.getImageData(0, 0, 1, 1);483 imagedata.data[0] = 100;484 imagedata.data[1] = 101;485 imagedata.data[2] = 102;486 imagedata.data[3] = 103;487 return canvas;488}489function compare_ImageBitmap(actual, input) {490 if (typeof actual === 'string')491 assert_unreached(actual);492 assert_true(actual instanceof ImageBitmap, 'instanceof ImageBitmap');493 assert_not_equals(actual, input);494 // XXX paint the ImageBitmap on a canvas and check the data495}496structuredCloneBatteryOfTests.push({497 description: 'ImageBitmap 1x1 transparent black',498 async f(runner) {499 var canvas = get_canvas_1x1_transparent_black();500 const bm = await createImageBitmap(canvas);501 const copy = await runner.structuredClone(bm);502 compare_ImageBitmap(bm, copy);503 }504});505structuredCloneBatteryOfTests.push({506 description: 'ImageBitmap 1x1 non-transparent non-black',507 async f(runner) {508 var canvas = get_canvas_1x1_non_transparent_non_black();509 const bm = await createImageBitmap(canvas);510 const copy = await runner.structuredClone(bm);511 compare_ImageBitmap(bm, copy);512 }513});514structuredCloneBatteryOfTests.push({515 description: 'Array ImageBitmap object, ImageBitmap 1x1 transparent black',516 async f(runner) {517 var canvas = get_canvas_1x1_transparent_black();518 const bm = [await createImageBitmap(canvas)];519 const copy = await runner.structuredClone(bm);520 compare_Array(enumerate_props(compare_ImageBitmap))(bm, copy);521 }522});523structuredCloneBatteryOfTests.push({524 description: 'Array ImageBitmap object, ImageBitmap 1x1 transparent non-black',525 async f(runner) {526 var canvas = get_canvas_1x1_non_transparent_non_black();527 const bm = [await createImageBitmap(canvas)];528 const copy = await runner.structuredClone(bm);529 compare_Array(enumerate_props(compare_ImageBitmap))(bm, copy);530 }531});532structuredCloneBatteryOfTests.push({533 description: 'Object ImageBitmap object, ImageBitmap 1x1 transparent black',534 async f(runner) {535 var canvas = get_canvas_1x1_transparent_black();536 const bm = {x: await createImageBitmap(canvas)};537 const copy = await runner.structuredClone(bm);538 compare_Object(enumerate_props(compare_ImageBitmap))(bm, copy);539 }540});541structuredCloneBatteryOfTests.push({542 description: 'Object ImageBitmap object, ImageBitmap 1x1 transparent non-black',543 async f(runner) {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var array1 = [1, 2, 3];3var array2 = [1, 2, 3];4var compare = wpt.compare_Array(array1, array2);5console.log(compare);6var wpt = require('wpt');7var array1 = [1, 2, 3];8var array2 = [1, 2, 3, 4];9var compare = wpt.compare_Array(array1, array2);10console.log(compare);11var wpt = require('wpt');12var array1 = [1, 2, 3, 4];13var array2 = [1, 2, 3];14var compare = wpt.compare_Array(array1, array2);15console.log(compare);16var wpt = require('wpt');17var array1 = [1, 2, 3];18var array2 = [1, 2, 4];19var compare = wpt.compare_Array(array1, array2);20console.log(compare);21var wpt = require('wpt');22var array1 = [1, 2, 3];23var array2 = [1, 2, 3, 4];24var compare = wpt.compare_Array(array1, array2, 1);25console.log(compare);26var wpt = require('wpt');27var array1 = [1, 2, 3];28var array2 = [1, 2, 3, 4];29var compare = wpt.compare_Array(array1, array2, 2);30console.log(compare);31var wpt = require('wpt');32var array1 = [1, 2, 3];33var array2 = [1, 2, 3, 4];34var compare = wpt.compare_Array(array1, array2, 3);35console.log(compare);36var wpt = require('wpt');37var array1 = [1, 2, 3];

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptool = require('wptool');2var array1 = [1,2,3];3var array2 = [1,2,3];4var result = wptool.compare_Array(array1, array2);5console.log(result);6var wptool = require('wptool');7var array1 = [{id:1,name:'John'},{id:2,name:'Smith'}];8var array2 = [{id:1,name:'John'},{id:2,name:'Smith'}];9var result = wptool.compare_Array(array1, array2);10console.log(result);11var wptool = require('wptool');12var array1 = [{id:1,name:'John',address:{city:'New York',state:'NY'}},{id:2,name:'Smith'}];13var array2 = [{id:1,name:'John',address:{city:'New York',state:'NY'}},{id:2,name:'Smith'}];14var result = wptool.compare_Array(array1, array2);15console.log(result);16var wptool = require('wptool');17var array1 = [{id:1,name:'John',address:{city:'New York',state:'NY'},hobbies:['Cricket','Football']},{id:2,name:'Smith'}];18var array2 = [{id:1,name:'John',address:{city:'New York',state:'NY'},hobbies:['Cricket','Football']},{id:2,name:'Smith'}];19var result = wptool.compare_Array(array1, array2);20console.log(result);21var wptool = require('wptool');

Full Screen

Using AI Code Generation

copy

Full Screen

1var array1 = ["a", "b", "c", "d"];2var array2 = ["a", "b", "c", "d"];3var array3 = ["a", "b", "c", "d", "e"];4var array4 = ["a", "b", "c", "d", "e", "f"];53. compare_Array2D(array1, array2)6var array1 = [["a", "b", "c", "d"], ["e", "f", "g", "h"]];7var array2 = [["a", "b", "c", "d"], ["e", "f", "g", "h"]];8var array3 = [["a", "b", "c", "d"], ["e", "f", "g", "h", "i"]];9var array4 = [["a", "b", "c", "d"], ["e", "f", "g", "h", "i", "j"]];104. compare_Json(json1, json2)11var json1 = {"a": "a", "b": "b", "c": "c", "d": "d"};12var json2 = {"a": "a", "b": "b", "c": "c", "d": "d"};13var json3 = {"a": "a", "b": "b", "c": "c", "d": "d", "e": "e"};14var json4 = {"a": "a", "b": "b", "c": "c",

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var arr1 = ['a','b','c','d','e'];3var arr2 = ['a','b','c','d','e'];4var arr3 = ['a','b','c','d','f'];5var arr4 = ['a','b','c','d','e','f'];6var arr5 = ['a','b','c','d'];7var result = wpt.compare_Array(arr1,arr2);8result = wpt.compare_Array(arr1,arr3);9result = wpt.compare_Array(arr1,arr4);10result = wpt.compare_Array(arr1,arr5);11var wpt = require('wpt');12var arr1 = ['a','b','c','d','e'];13var arr2 = ['a','b','c','d','e'];14var arr3 = ['a','b','c','d','f'];15var arr4 = ['a','b','c','d','e','f'];16var arr5 = ['a','b','c','d'];17var result = wpt.compare_Array(arr1,arr2);18result = wpt.compare_Array(arr1,arr3);19result = wpt.compare_Array(arr1,arr4);20result = wpt.compare_Array(arr1,arr5);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools();3var array1 = [1,2,3,4,5];4var array2 = [5,4,3,2,1];5var array3 = [1,2,3,4,5,6];6var array4 = [1,2,3,4];7var array5 = [1,2,3,4,5,6,7];8var array6 = [1,2,3,4,5];9var array7 = [1,2,3,4,5];10var array8 = [1,2,3,4,6];11var array9 = [1,2,3,4,5];12var array10 = [1,2,3,4,5,6];13var array11 = [1,2,3,4,5,6];14var array12 = [1,2,3,4,5,6];15var array13 = [1,2,3,4];16var array14 = [1,2,3,4,5,6];17var array15 = [1,2,3,4,5,6];18var array16 = [1,2,3,4,5,6];19var array17 = [1,2,3,4,5,6];20var array18 = [1,2,3,4,5,6];21var array19 = [1,2,3,4,5,6];22var array20 = [1,2,3,4,5,6];23var array21 = [1,2,3,4,5,6];24var array22 = [1,2,3,4,5,6];25var array23 = [1,2,3,4,5,6];26var array24 = [1,2,3,4,5,6];27var array25 = [1,2,3,4,5,6];28var array26 = [1,2,3,4,5,6];29var array27 = [1,2,3,4,5,6];30var array28 = [1,2,3,4,5,6];31var array29 = [1,2,3,4,5,6];

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require("wpt");2var arr1 = [1,2,3,4];3var arr2 = [1,2,3,4];4wpt.compare_Array(arr1, arr2);5exports.compare_Array = function(arr1, arr2){6 if(arr1.length !== arr2.length){7 return false;8 }9 for(var i = 0; i < arr1.length; i++){10 if(arr1[i] !== arr2[i]){11 return false;12 }13 }14 return true;15};16var wpt = require("wpt");17console.log(wpt.add(1,2));18module.exports = {19 add: function(a, b){20 return a + b;21 }22};23var wpt = require("wpt");24console.log(wpt(1,2));25module.exports = function(a, b){26 return a + b;27}28var wpt = require("wpt");29console.log(wpt(1,2));30exports = function(a, b){31 return a + b;32}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) console.log(err);4 else console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if(err) console.log(err);9 else console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13wpt.getLocations(function(err, data) {14 if(err) console.log(err);15 else console.log(data);16});17var wpt = require('webpagetest');18var wpt = new WebPageTest('www.webpagetest.org');19wpt.getTesters(function(err, data) {20 if(err) console.log(err);21 else console.log(data);22});23var wpt = require('webpagetest');24var wpt = new WebPageTest('www.webpagetest.org');25wpt.getTesters(function(err, data) {26 if(err) console.log(err);27 else console.log(data);28});29var wpt = require('webpagetest');30var wpt = new WebPageTest('www.webpagetest.org');31wpt.getLocations(function(err, data) {32 if(err) console.log(err);33 else console.log(data);34});35var wpt = require('webpagetest');36var wpt = new WebPageTest('www.webpagetest.org');37wpt.getTesters(function(err, data) {38 if(err) console.log(err);39 else console.log(data);40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2wpt.compare_Array(url1, url2, function (err, data) {3 if (err) {4 console.log(err);5 }6 else {7 console.log(data);8 }9});10exports.compare_Array = function (url1, url2, callback) {11 var data = [];12 var xml = require('node-xml');13 var parser = new xml.SaxParser(function (cb) {14 cb.onStartElementNS(function (elem, attrs, prefix, uri, namespaces) {15 if (elem == "data") {16 data.push(attrs[0][3]);17 }18 });19 });20 parser.parseString(url);21 parser.parseString(url2);22 callback(null, data);23};24var wpt = require('webpagetest');25wpt.compare_Array(url1, url2, function (err, data) {26 if (err) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.compare_Array([1,2,3],[1,2,3,4],function(err,data){3 if(err){4 console.log(err);5 }else{6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.compare_Array([1,2,3],[1,2,4],function(err,data){11 if(err){12 console.log(err);13 }else{14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.compare_Array([1,2,3],[1,2,3],function(err,data){19 if(err){20 console.log(err);21 }else{22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.compare_Array([1,2,3],[1,2,4],function(err,data){27 if(err){28 console.log(err);29 }else{30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.compare_Array([1,2,3],[1,2,3],function(err,data){35 if(err){36 console.log(err);37 }else{38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.compare_Array([1,2,3],[1,2,4],function(err,data){43 if(err){44 console.log(err);45 }else{46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.compare_Array([1,2,3],[1,2,3],function

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptutils = require('./wptutils.js');2var output = wptutils.compare_Array([1,2,3], [1,2,3]);3console.log(output);4var compare_Array = function (arr1, arr2) {5 if (arr1.length != arr2.length)6 return false;7 for (var i = 0; i < arr1.length; i++) {8 if (arr1[i] != arr2[i])9 return false;10 }11 return true;12}13module.exports.compare_Array = compare_Array;

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