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