summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webmessaging/without-ports/010.html
blob: 062316f68039e1a1d71f0b7b145b330efd7e3d5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!doctype html>
<title>message clone</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../support/compare.js"></script>
<div id=log></div>
<script>
  var err = new Error('foo');
  var date = new Date();

  var test_array = [ undefined,
                     null,
                     false,
                     true,
                     1,
                     NaN,
                     Infinity,
                     'foo',
                     date,
                     /foo/,
                     null/*self*/,
                     null/*err*/];

  var cloned_array = [ undefined,
                       null,
                       false,
                       true,
                       1,
                       NaN,
                       Infinity,
                       'foo',
                       date,
                       /foo/,
                       null/*self*/,
                       null/*err*/];

  var test_object = {a: undefined,
                     b: null,
                     c: false,
                     d: true,
                     e: 1,
                     f: NaN,
                     g: Infinity,
                     h: 'foo',
                     i: date,
                     j: /foo/,
                     k: null/*self*/,
                     l: [],
                     m: {},
                     n: null /*err*/};

  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};

  var tests = [undefined, null,
               false, true,
               1, NaN, Infinity,
               'foo',
               date,
               /foo/,
               /* ImageData, File, FileData, FileList, */
               null /*self*/,
               test_array,
               test_object,
               null /*err*/];

  for (var i = 0; i < tests.length; ++i) {
    postMessage(tests[i], '*');
  }

  var test_undefined = async_test('undefined');
  var test_null = async_test('null');
  var test_false = async_test('false');
  var test_true = async_test('true');
  var test_1 = async_test('1');
  var test_NaN = async_test('NaN');
  var test_Infinity = async_test('Infinity');
  var test_string = async_test('string');
  var test_date = async_test('date');
  var test_regex = async_test('regex');
  var test_self = async_test('self');
  var test_array = async_test('array');
  var test_object = async_test('object');
  var test_error = async_test('error');
  var test_unreached = async_test('unreached');

  var j = 0;
  onmessage = function(e) {
    switch (j) {
      case 0: test_undefined.step(function() { assert_equals(e.data, undefined); this.done(); }); break;
      case 1: test_null.step(function() { assert_equals(e.data, null); this.done(); }); break;
      case 2: test_false.step(function() { assert_false(e.data); this.done(); }); break;
      case 3: test_true.step(function() { assert_true(e.data); this.done(); }); break;
      case 4: test_1.step(function() { assert_equals(e.data, 1); this.done(); }); break;
      case 5: test_NaN.step(function() { assert_equals(e.data, NaN); this.done(); }); break;
      case 6: test_Infinity.step(function() { assert_equals(e.data, Infinity); this.done(); }); break;
      case 7: test_string.step(function() { assert_equals(e.data, 'foo'); this.done(); }); break;
      case 8: test_date.step(function() { assert_true(sameDate(e.data, date)); this.done(); }); break;
      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;
      // not testing it any more, as cloning host objects will now raise exceptions. TODO: add (exceptional) tests for these.
      case 10: test_self.step(function() { assert_equals(e.data, null); this.done(); }); break;
      case 11: test_array.step(function() { assert_array_equals_(e.data, cloned_array, 'array'); this.done(); }); break;
      case 12: test_object.step(function() { assert_object_equals_(e.data, cloned_object, 'object'); this.done(); }); break;
      case 13:
        test_error.step(function() { assert_equals(e.data, null, 'new Error()'); this.done(); });
        setTimeout(test_unreached.step_func(function() { assert_equals(j, 14); this.done(); }), 50);
        break;
      default: test_unreached.step(function() { assert_unreached('got an unexpected message event ('+j+')'); });
    };
    j++;
  }

</script>