OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file | 3 // BSD-style license that can be found in the LICENSE file |
4 | 4 |
5 library postmessage_js_test; | 5 library postmessage_js_test; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'package:unittest/html_individual_config.dart'; | 7 import 'package:unittest/html_individual_config.dart'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:collection'; // SplayTreeMap | 9 import 'dart:collection'; // SplayTreeMap |
10 import 'dart:typed_data'; | 10 import 'dart:typed_data'; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 if (data is String) return; // Messages from unit test protocol. | 71 if (data is String) return; // Messages from unit test protocol. |
72 completed = true; | 72 completed = true; |
73 subscription.cancel(); | 73 subscription.cancel(); |
74 expect(data, isMap); | 74 expect(data, isMap); |
75 expect(data['eggs'], equals(3)); | 75 expect(data['eggs'], equals(3)); |
76 }, | 76 }, |
77 () => completed)); | 77 () => completed)); |
78 injectSource(JS_CODE); | 78 injectSource(JS_CODE); |
79 }); | 79 }); |
80 | 80 |
81 test('js-to-dart--null-prototype-eventdata', () { | |
82 // Pass an object with a null prototype from JavaScript. | |
83 // It should be seen as a Dart Map. | |
84 final JS_CODE = """ | |
85 // Call anonymous function to create a local scope. | |
86 (function() { | |
87 var o = Object.create(null); | |
88 o.eggs = 3; | |
89 var foo = new MessageEvent('stuff', {data: o}); | |
90 window.dispatchEvent(foo); | |
91 })(); | |
92 """; | |
93 var completed = false; | |
94 var subscription = null; | |
95 subscription = window.on['stuff'].listen(expectAsyncUntil( | |
96 (MessageEvent e) { | |
97 var data = e.data; | |
98 if (data is String) return; // Messages from unit test protocol. | |
99 completed = true; | |
100 subscription.cancel(); | |
101 expect(data, isMap); | |
102 expect(data['eggs'], equals(3)); | |
103 }, | |
104 () => completed)); | |
105 injectSource(JS_CODE); | |
106 }); | |
107 | |
108 test('dart-to-js-to-dart-postmessage', () { | 81 test('dart-to-js-to-dart-postmessage', () { |
109 // Pass dictionaries between Dart and JavaScript. | 82 // Pass dictionaries between Dart and JavaScript. |
110 | 83 |
111 final JS_CODE = """ | 84 final JS_CODE = """ |
112 window.addEventListener('message', handler); | 85 window.addEventListener('message', handler); |
113 function handler(e) { | 86 function handler(e) { |
114 var data = e.data; | 87 var data = e.data; |
115 if (typeof data == 'string') return; | 88 if (typeof data == 'string') return; |
116 if (data.recipient != 'JS') return; | 89 if (data.recipient != 'JS') return; |
117 var response = {recipient: 'DART'}; | 90 var response = {recipient: 'DART'}; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 go('test_DAG', obj2); | 129 go('test_DAG', obj2); |
157 go('test_cycle', obj3); | 130 go('test_cycle', obj3); |
158 go('test_simple_splay', obj4); | 131 go('test_simple_splay', obj4); |
159 go('const_array_1', const [const [1], const [2]]); | 132 go('const_array_1', const [const [1], const [2]]); |
160 go('const_array_dag', const [const [1], const [1]]); | 133 go('const_array_dag', const [const [1], const [1]]); |
161 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]); | 134 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]); |
162 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]); | 135 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]); |
163 go('cyclic_list', cyclic_list); | 136 go('cyclic_list', cyclic_list); |
164 }); | 137 }); |
165 | 138 |
| 139 group('more_primitives', () { |
| 140 test('js-to-dart-null-prototype-eventdata', () { |
| 141 // Pass an object with a null prototype from JavaScript. |
| 142 // It should be seen as a Dart Map. |
| 143 final JS_CODE = """ |
| 144 // Call anonymous function to create a local scope. |
| 145 (function() { |
| 146 var o = Object.create(null); |
| 147 o.eggs = 3; |
| 148 var foo = new MessageEvent('stuff', {data: o}); |
| 149 window.dispatchEvent(foo); |
| 150 })(); |
| 151 """; |
| 152 var completed = false; |
| 153 var subscription = null; |
| 154 subscription = window.on['stuff'].listen(expectAsyncUntil( |
| 155 (MessageEvent e) { |
| 156 var data = e.data; |
| 157 if (data is String) return; // Messages from unit test protocol. |
| 158 completed = true; |
| 159 subscription.cancel(); |
| 160 expect(data, isMap); |
| 161 expect(data['eggs'], equals(3)); |
| 162 }, |
| 163 () => completed)); |
| 164 injectSource(JS_CODE); |
| 165 }); |
| 166 }); |
| 167 |
166 group('typed_arrays', () { | 168 group('typed_arrays', () { |
167 var array_buffer = new Uint8List(16).buffer; | 169 var array_buffer = new Uint8List(16).buffer; |
168 var view_a = new Float32List.view(array_buffer, 0, 4); | 170 var view_a = new Float32List.view(array_buffer, 0, 4); |
169 var view_b = new Uint8List.view(array_buffer, 1, 13); | 171 var view_b = new Uint8List.view(array_buffer, 1, 13); |
170 var typed_arrays_list = [view_a, array_buffer, view_b]; | 172 var typed_arrays_list = [view_a, array_buffer, view_b]; |
171 | 173 |
172 // Note that FF is failing this test because in the sent message: | 174 // Note that FF is failing this test because in the sent message: |
173 // view_a.buffer == array_buffer | 175 // view_a.buffer == array_buffer |
174 // But in the response: | 176 // But in the response: |
175 // view_a.buffer != array_buffer | 177 // view_a.buffer != array_buffer |
176 go('typed_arrays_list', typed_arrays_list); | 178 go('typed_arrays_list', typed_arrays_list); |
177 }); | 179 }); |
178 | 180 |
179 group('iframe', () { | 181 group('iframe', () { |
180 test('postMessage clones data', () { | 182 test('postMessage clones data', () { |
181 var iframe = new IFrameElement(); | 183 var iframe = new IFrameElement(); |
182 var future = iframe.onLoad.first.then((_) { | 184 var future = iframe.onLoad.first.then((_) { |
183 iframe.contentWindow.postMessage(new HashMap<String,num>(), '*'); | 185 iframe.contentWindow.postMessage(new HashMap<String,num>(), '*'); |
184 }); | 186 }); |
185 iframe.src = 'about:blank'; | 187 iframe.src = 'about:blank'; |
186 document.body.append(iframe); | 188 document.body.append(iframe); |
187 | 189 |
188 return future; | 190 return future; |
189 }); | 191 }); |
190 }); | 192 }); |
191 | 193 |
192 } | 194 } |
OLD | NEW |