How to use compare_Object method in wpt

Best JavaScript code snippet using wpt

common.js

Source:common.js Github

copy

Full Screen

...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')));541check('Object with non-enumerable property', function() {542 var rv = {};543 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:false, writable:true, configurable:true});544 return rv;545}, compare_Object(check_absent_property('foo')));546function check_writable_property(prop) {547 return function(actual, input) {548 assert_equals(actual[prop], input[prop]);549 actual[prop] += ' baz';550 assert_equals(actual[prop], input[prop] + ' baz');551 };552}553check('Object with non-writable property', function() {554 var rv = {};555 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:true, writable:false, configurable:true});556 return rv;557}, compare_Object(check_writable_property('foo')));558function check_configurable_property(prop) {559 return function(actual, input) {560 assert_equals(actual[prop], input[prop]);561 delete actual[prop];562 assert_false('prop' in actual);563 };564}565check('Object with non-configurable property', function() {566 var rv = {};567 Object.defineProperty(rv, 'foo', {value:'bar', enumerable:true, writable:true, configurable:false});568 return rv;...

Full Screen

Full Screen

structured-clone-battery-of-tests.js

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

copy

Full Screen

...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) {544 var canvas = get_canvas_1x1_non_transparent_non_black();545 const bm = {x: await createImageBitmap(canvas)};546 const copy = await runner.structuredClone(bm);547 compare_Object(enumerate_props(compare_ImageBitmap))(bm, copy);548 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var obj1 = {a:1, b:2, c:3};3var obj2 = {a:1, b:2, c:3};4var obj3 = {a:1, b:2, c:4};5var obj4 = {a:1, b:2, c:4, d:5};6var obj5 = {a:1, b:2, c:4, d:6};7var obj6 = {a:1, b:2, c:4, d:5, e:6};8var obj7 = {a:1, b:2, c:4, d:5, e:6, f:7};9var obj8 = {a:1, b:2, c:4, d:5, e:6, f:8};10var obj9 = {a:1, b:2, c:4, d:5, e:6, f:7};11var obj10 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8};12var obj11 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9};13var obj12 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9, i:10};14var obj13 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9, i:10};15var obj14 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9, i:10, j:11};16var obj15 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9, i:10, j:11, k:12};17var obj16 = {a:1, b:2, c:4, d:5, e:6, f:7, g:8, h:9,

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var obj1 = {a:1,b:2,c:3};3var obj2 = {a:1,b:2,c:3};4var obj3 = {a:1,b:2,c:4};5var obj4 = {a:1,b:2,c:3,d:4};6var obj5 = {a:1,b:2,c:3,d:4,e:5};7console.log(wpt.compare_Object(obj1,obj2));8console.log(wpt.compare_Object(obj1,obj3));9console.log(wpt.compare_Object(obj1,obj4));10console.log(wpt.compare_Object(obj1,obj5));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var obj1 = {a:1,b:2,c:3};3var obj2 = {a:1,b:2,c:3};4var obj3 = {a:1,b:2,c:4};5console.log(wptoolkit.compare_Object(obj1,obj2));6console.log(wptoolkit.compare_Object(obj1,obj3));7getRandomString()8var wptoolkit = require('wptoolkit');9console.log(wptoolkit.getRandomString(10));10getRandomNumber()11var wptoolkit = require('wptoolkit');12console.log(wptoolkit.getRandomNumber(10));13getRandomEmail()14var wptoolkit = require('wptoolkit');15console.log(wptoolkit.getRandomEmail(10));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4 videoParams: {5 }6};7wpt.runTest(options.url, options, function(err, data) {8 if (err) return console.error(err);9 console.log(data);10 var testid = data.data.testId;11 var firstTestUrl = data.data.summary;12 wpt.runTest(options.url, options, function(err, data) {13 if (err) return console.error(err);14 console.log(data);15 var secondTestUrl = data.data.summary;16 wpt.compareObjects(firstTestUrl, secondTestUrl, function(err, data) {17 if (err) return console.error(err);18 console.log(data);19 });20 });21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24var options = {25 videoParams: {26 }27};28wpt.runTest(options.url, options, function(err, data) {29 if (err) return console.error(err);30 console.log(data);31 var testid = data.data.testId;32 var firstTestUrl = data.data.summary;33 wpt.runTest(options.url, options, function(err, data) {34 if (err) return console.error(err);35 console.log(data);36 var secondTestUrl = data.data.summary;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wpt_object = new wpt();3var obj1 = {a:1,b:2,c:3};4var obj2 = {a:1,b:2,c:3};5var obj3 = {a:1,b:2,c:4};6wpt_object.compare_Object(obj1,obj2,function(err,result){7 console.log(result);8});9wpt_object.compare_Object(obj1,obj3,function(err,result){10 console.log(result);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var assert = require('assert');3wpt.compare_Object({a:1}, {a:1}, function(err, result) {4 assert.equal(result, true);5});6wpt.compare_Object({a:1}, {a:2}, function(err, result) {7 assert.equal(result, false);8});9wpt.compare_Object({a:1}, {a:1, b:1}, function(err, result) {10 assert.equal(result, false);11});12wpt.compare_Object({a:1, b:1}, {a:1}, function(err, result) {13 assert.equal(result, false);14});15wpt.compare_Object({a:1, b:1}, {a:1, b:1}, function(err, result) {16 assert.equal(result, true);17});18wpt.compare_Object({a:1, b:1}, {a:1, b:2}, function(err, result) {19 assert.equal(result, false);20});21wpt.compare_Object({a:1, b:1}, {a:1, b:1, c:1}, function(err, result) {22 assert.equal(result, false);23});24wpt.compare_Object({a:1, b:1, c:1}, {a:1, b:1}, function(err, result) {25 assert.equal(result, false);26});27wpt.compare_Object({a:1, b:1, c:1}, {a:1, b:1, c:1}, function(err, result) {28 assert.equal(result, true);29});30wpt.compare_Object({a:1, b:1, c:1}, {a:1, b:1, c:2}, function(err, result) {31 assert.equal(result, false);32});33wpt.compare_Object({a:1, b:1, c:1}, {a:1, b:1, c:1, d:1}, function(err, result) {34 assert.equal(result, false);35});36wpt.compare_Object({a:1, b:1, c:1, d:1}, {a:1, b:1, c:1}, function(err, result) {37 assert.equal(result, false);38});39wpt.compare_Object({a:1, b:1, c:1, d:1}, {a:1

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt.js');2var wpt = new wpt('www.webpagetest.org');3var test_id = '140410_7V_1G';4var test_id2 = '140410_8H_1G';5wpt.compare_Object(test_id, test_id2, function(err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12WPT.prototype.compare_Object = function(testId, testId2, callback) {13 var params = {14 };15 this.request(url, callback);16};17WPT.prototype.request = function(url, callback) {18 var self = this;19 var req = http.get(url, function(res) {20 var data = '';21 res.setEncoding('utf8');22 res.on('data', function(chunk) {23 data += chunk;24 });25 res.on('end', function() {26 if (res.statusCode == 200) {27 callback(null, JSON.parse(data));28 } else {29 callback(res.statusCode + ': ' + data, null);30 }31 });32 });33 req.on('error', function(e) {34 callback(e.message, null);35 });36};37{ [Error: getaddrinfo ENOTFOUND www.webpagetest.org www.webpagetest.org:80]38 port: 80 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('WebPageTest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.1c8b7f1f4b4d4b4d4b4d4b4d4b4d4b4d');3wpt.compare_Object('www.webpagetest.org', 'www.webpagetest.org', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10{11 "data": {12 "data": {13 "firstView": {

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