| 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('../../pkg/unittest/unittest.dart'); | 6 #import('../../pkg/unittest/unittest.dart'); |
| 7 #import('../../pkg/unittest/html_config.dart'); | 7 #import('../../pkg/unittest/html_config.dart'); |
| 8 #import('dart:html'); | 8 #import('dart:html'); |
| 9 #import('dart:coreimpl'); // SplayTreeMap | 9 #import('dart:coreimpl'); // SplayTreeMap |
| 10 #import('utils.dart'); | 10 #import('utils.dart'); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 window.postMessage({eggs: 3}, '*'); | 27 window.postMessage({eggs: 3}, '*'); |
| 28 """; | 28 """; |
| 29 var callback; | 29 var callback; |
| 30 var onSuccess = expectAsync1((e) { | 30 var onSuccess = expectAsync1((e) { |
| 31 window.on.message.remove(callback); | 31 window.on.message.remove(callback); |
| 32 }); | 32 }); |
| 33 callback = (e) { | 33 callback = (e) { |
| 34 guardAsync(() { | 34 guardAsync(() { |
| 35 var data = e.data; | 35 var data = e.data; |
| 36 if (data is String) return; // Messages from unit test protocol. | 36 if (data is String) return; // Messages from unit test protocol. |
| 37 expect(data is Map); | 37 expect(data, isMap); |
| 38 expect(data['eggs'], equals(3)); | 38 expect(data['eggs'], equals(3)); |
| 39 onSuccess(e); | 39 onSuccess(e); |
| 40 }); | 40 }); |
| 41 }; | 41 }; |
| 42 window.on.message.add(callback); | 42 window.on.message.add(callback); |
| 43 injectSource(JS_CODE); | 43 injectSource(JS_CODE); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 test('dart-to-js-to-dart-postmessage', () { | 46 test('dart-to-js-to-dart-postmessage', () { |
| 47 // Pass dictionaries between Dart and JavaScript. | 47 // Pass dictionaries between Dart and JavaScript. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 59 } | 59 } |
| 60 """; | 60 """; |
| 61 var callback; | 61 var callback; |
| 62 var onSuccess = expectAsync1((e) { | 62 var onSuccess = expectAsync1((e) { |
| 63 window.on.message.remove(callback); | 63 window.on.message.remove(callback); |
| 64 }); | 64 }); |
| 65 callback = (e) { | 65 callback = (e) { |
| 66 guardAsync(() { | 66 guardAsync(() { |
| 67 var data = e.data; | 67 var data = e.data; |
| 68 if (data is String) return; // Messages from unit test protocol. | 68 if (data is String) return; // Messages from unit test protocol. |
| 69 expect(data is Map); | 69 expect(data, isMap); |
| 70 if (data['recipient'] != 'DART') return; // Hearing the sent messag
e. | 70 if (data['recipient'] != 'DART') return; // Hearing the sent messag
e. |
| 71 expect(data['peas'], equals(50)); | 71 expect(data['peas'], equals(50)); |
| 72 onSuccess(e); | 72 onSuccess(e); |
| 73 }); | 73 }); |
| 74 }; | 74 }; |
| 75 window.on.message.add(callback); | 75 window.on.message.add(callback); |
| 76 injectSource(JS_CODE); | 76 injectSource(JS_CODE); |
| 77 window.postMessage({'recipient': 'JS', 'curry': 'peas'}, '*'); | 77 window.postMessage({'recipient': 'JS', 'curry': 'peas'}, '*'); |
| 78 }); | 78 }); |
| 79 | 79 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 var response = {recipient: 'DART', data: data.data}; | 91 var response = {recipient: 'DART', data: data.data}; |
| 92 window.removeEventListener('message', handler); | 92 window.removeEventListener('message', handler); |
| 93 window.postMessage(response, '*'); | 93 window.postMessage(response, '*'); |
| 94 } | 94 } |
| 95 """; | 95 """; |
| 96 var onSuccess = expectAsync0(() {}); | 96 var onSuccess = expectAsync0(() {}); |
| 97 callback(e) { | 97 callback(e) { |
| 98 guardAsync(() { | 98 guardAsync(() { |
| 99 var data = e.data; | 99 var data = e.data; |
| 100 if (data is String) return; // Messages from unit test protoc
ol. | 100 if (data is String) return; // Messages from unit test protoc
ol. |
| 101 expect(data is Map); | 101 expect(data, isMap); |
| 102 if (data['recipient'] != 'DART') return; // Not for me. | 102 if (data['recipient'] != 'DART') return; // Not for me. |
| 103 var returnedValue = data['data']; | 103 var returnedValue = data['data']; |
| 104 | 104 |
| 105 window.on.message.remove(callback); | 105 window.on.message.remove(callback); |
| 106 expect(returnedValue, isNot(same(value))); | 106 expect(returnedValue, isNot(same(value))); |
| 107 verifyGraph(value, returnedValue); | 107 verifyGraph(value, returnedValue); |
| 108 onSuccess(); | 108 onSuccess(); |
| 109 }); | 109 }); |
| 110 }; | 110 }; |
| 111 window.on.message.add(callback); | 111 window.on.message.add(callback); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 131 go('test_map', obj1); | 131 go('test_map', obj1); |
| 132 go('test_DAG', obj2); | 132 go('test_DAG', obj2); |
| 133 go('test_cycle', obj3); | 133 go('test_cycle', obj3); |
| 134 go('test_simple_splay', obj4); | 134 go('test_simple_splay', obj4); |
| 135 go('const_array_1', const [const [1], const [2]]); | 135 go('const_array_1', const [const [1], const [2]]); |
| 136 go('const_array_dag', const [const [1], const [1]]); | 136 go('const_array_dag', const [const [1], const [1]]); |
| 137 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]); | 137 go('array_deferred_copy', [1,2,3, obj3, obj3, 6]); |
| 138 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]); | 138 go('array_deferred_copy_2', [1,2,3, [4, 5, obj3], [obj3, 6]]); |
| 139 go('cyclic_list', cyclic_list); | 139 go('cyclic_list', cyclic_list); |
| 140 } | 140 } |
| OLD | NEW |