010.html (4550B)
1 <!doctype html> 2 <title>message clone</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="../support/compare.js"></script> 6 <div id=log></div> 7 <script> 8 var err = new Error('foo'); 9 var date = new Date(); 10 11 var test_array = [ undefined, 12 null, 13 false, 14 true, 15 1, 16 NaN, 17 Infinity, 18 'foo', 19 date, 20 /foo/, 21 null/*self*/, 22 null/*err*/]; 23 24 var cloned_array = [ undefined, 25 null, 26 false, 27 true, 28 1, 29 NaN, 30 Infinity, 31 'foo', 32 date, 33 /foo/, 34 null/*self*/, 35 null/*err*/]; 36 37 var test_object = {a: undefined, 38 b: null, 39 c: false, 40 d: true, 41 e: 1, 42 f: NaN, 43 g: Infinity, 44 h: 'foo', 45 i: date, 46 j: /foo/, 47 k: null/*self*/, 48 l: [], 49 m: {}, 50 n: null /*err*/}; 51 52 var cloned_object = {a:undefined, b:null, c:false, d:true, e:1, f:NaN, g:Infinity, h:'foo', i: date, j: /foo/, k:null, l: [], m: {}, n:null}; 53 54 var tests = [undefined, null, 55 false, true, 56 1, NaN, Infinity, 57 'foo', 58 date, 59 /foo/, 60 /* ImageData, File, FileData, FileList, */ 61 null /*self*/, 62 test_array, 63 test_object, 64 null /*err*/]; 65 66 for (var i = 0; i < tests.length; ++i) { 67 postMessage(tests[i], '*'); 68 } 69 70 var test_undefined = async_test('undefined'); 71 var test_null = async_test('null'); 72 var test_false = async_test('false'); 73 var test_true = async_test('true'); 74 var test_1 = async_test('1'); 75 var test_NaN = async_test('NaN'); 76 var test_Infinity = async_test('Infinity'); 77 var test_string = async_test('string'); 78 var test_date = async_test('date'); 79 var test_regex = async_test('regex'); 80 var test_self = async_test('self'); 81 var test_array = async_test('array'); 82 var test_object = async_test('object'); 83 var test_error = async_test('error'); 84 var test_unreached = async_test('unreached'); 85 86 var j = 0; 87 onmessage = function(e) { 88 switch (j) { 89 case 0: test_undefined.step(function() { assert_equals(e.data, undefined); this.done(); }); break; 90 case 1: test_null.step(function() { assert_equals(e.data, null); this.done(); }); break; 91 case 2: test_false.step(function() { assert_false(e.data); this.done(); }); break; 92 case 3: test_true.step(function() { assert_true(e.data); this.done(); }); break; 93 case 4: test_1.step(function() { assert_equals(e.data, 1); this.done(); }); break; 94 case 5: test_NaN.step(function() { assert_equals(e.data, NaN); this.done(); }); break; 95 case 6: test_Infinity.step(function() { assert_equals(e.data, Infinity); this.done(); }); break; 96 case 7: test_string.step(function() { assert_equals(e.data, 'foo'); this.done(); }); break; 97 case 8: test_date.step(function() { assert_true(sameDate(e.data, date)); this.done(); }); break; 98 case 9: test_regex.step(function() { assert_equals('' + e.data, '/foo/'); assert_equals(e.data instanceof RegExp, true, 'e.data instanceof RegExp'); this.done(); }); break; 99 // not testing it any more, as cloning host objects will now raise exceptions. TODO: add (exceptional) tests for these. 100 case 10: test_self.step(function() { assert_equals(e.data, null); this.done(); }); break; 101 case 11: test_array.step(function() { assert_array_equals_(e.data, cloned_array, 'array'); this.done(); }); break; 102 case 12: test_object.step(function() { assert_object_equals_(e.data, cloned_object, 'object'); this.done(); }); break; 103 case 13: 104 test_error.step(function() { assert_equals(e.data, null, 'new Error()'); this.done(); }); 105 setTimeout(test_unreached.step_func(function() { assert_equals(j, 14); this.done(); }), 50); 106 break; 107 default: test_unreached.step(function() { assert_unreached('got an unexpected message event ('+j+')'); }); 108 }; 109 j++; 110 } 111 112 </script>