| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 61       // Map. | 61       // Map. | 
| 62 | 62 | 
| 63       final JS_CODE = """ | 63       final JS_CODE = """ | 
| 64         window.postMessage({eggs: 3}, '*'); | 64         window.postMessage({eggs: 3}, '*'); | 
| 65         """; | 65         """; | 
| 66       var completed = false; | 66       var completed = false; | 
| 67       var subscription = null; | 67       var subscription = null; | 
| 68       subscription = window.onMessage.listen(expectAsyncUntil( | 68       subscription = window.onMessage.listen(expectAsyncUntil( | 
| 69         (e) { | 69         (e) { | 
| 70           var data = e.data; | 70           var data = e.data; | 
| 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('dart-to-js-to-dart-postmessage', () { | 81     test('dart-to-js-to-dart-postmessage', () { | 
| 82       // Pass dictionaries between Dart and JavaScript. | 82       // Pass dictionaries between Dart and JavaScript. | 
| 83 | 83 | 
| 84       final JS_CODE = """ | 84       final JS_CODE = """ | 
| 85         window.addEventListener('message', handler); | 85         window.addEventListener('message', handler); | 
| 86         function handler(e) { | 86         function handler(e) { | 
| 87           var data = e.data; | 87           var data = e.data; | 
| 88           if (typeof data == 'string') return; | 88           if (typeof data == 'string') return; | 
| 89           if (data.recipient != 'JS') return; | 89           if (data.recipient != 'JS') return; | 
| 90           var response = {recipient: 'DART'}; | 90           var response = {recipient: 'DART'}; | 
| 91           response[data['curry']] = 50; | 91           response[data['curry']] = 50; | 
| 92           window.removeEventListener('message', handler); | 92           window.removeEventListener('message', handler); | 
| 93           window.postMessage(response, '*'); | 93           window.postMessage(response, '*'); | 
| 94         } | 94         } | 
| 95         """; | 95         """; | 
| 96       var completed = false; | 96       var completed = false; | 
| 97       var subscription = null; | 97       var subscription = null; | 
| 98       subscription = window.onMessage.listen(expectAsyncUntil( | 98       subscription = window.onMessage.listen(expectAsyncUntil( | 
| 99         (e) { | 99         (e) { | 
| 100           var data = e.data; | 100           var data = e.data; | 
| 101           if (data is String) return;    // Messages from unit test protocol. | 101           if (data is String) return; //    Messages from unit test protocol. | 
| 102           if (data['recipient'] != 'DART') return;  // Hearing the sent message. | 102           if (data['recipient'] != 'DART') return;  // Hearing the sent message. | 
| 103           completed = true; | 103           completed = true; | 
| 104           subscription.cancel(); | 104           subscription.cancel(); | 
| 105           expect(data, isMap); | 105           expect(data, isMap); | 
| 106           expect(data['peas'], equals(50)); | 106           expect(data['peas'], equals(50)); | 
| 107         }, | 107         }, | 
| 108         () => completed)); | 108         () => completed)); | 
| 109       injectSource(JS_CODE); | 109       injectSource(JS_CODE); | 
| 110       window.postMessage({'recipient': 'JS', 'curry': 'peas'}, '*'); | 110       window.postMessage({'recipient': 'JS', 'curry': 'peas'}, '*'); | 
| 111     }); | 111     }); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 147           o.eggs = 3; | 147           o.eggs = 3; | 
| 148           var foo = new MessageEvent('stuff', {data: o}); | 148           var foo = new MessageEvent('stuff', {data: o}); | 
| 149           window.dispatchEvent(foo); | 149           window.dispatchEvent(foo); | 
| 150         })(); | 150         })(); | 
| 151       """; | 151       """; | 
| 152       var completed = false; | 152       var completed = false; | 
| 153       var subscription = null; | 153       var subscription = null; | 
| 154       subscription = window.on['stuff'].listen(expectAsyncUntil( | 154       subscription = window.on['stuff'].listen(expectAsyncUntil( | 
| 155           (MessageEvent e) { | 155           (MessageEvent e) { | 
| 156             var data = e.data; | 156             var data = e.data; | 
| 157             if (data is String) return;    // Messages from unit test protocol. | 157             if (data is String) return; //    Messages from unit test protocol. | 
| 158             completed = true; | 158             completed = true; | 
| 159             subscription.cancel(); | 159             subscription.cancel(); | 
| 160             expect(data, isMap); | 160             expect(data, isMap); | 
| 161             expect(data['eggs'], equals(3)); | 161             expect(data['eggs'], equals(3)); | 
| 162           }, | 162           }, | 
| 163           () => completed)); | 163           () => completed)); | 
| 164       injectSource(JS_CODE); | 164       injectSource(JS_CODE); | 
| 165     }); | 165     }); | 
| 166   }); | 166   }); | 
| 167 | 167 | 
| (...skipping 17 matching lines...) Expand all  Loading... | 
| 185         iframe.contentWindow.postMessage(new HashMap<String,num>(), '*'); | 185         iframe.contentWindow.postMessage(new HashMap<String,num>(), '*'); | 
| 186       }); | 186       }); | 
| 187       iframe.src = 'about:blank'; | 187       iframe.src = 'about:blank'; | 
| 188       document.body.append(iframe); | 188       document.body.append(iframe); | 
| 189 | 189 | 
| 190       return future; | 190       return future; | 
| 191     }); | 191     }); | 
| 192   }); | 192   }); | 
| 193 | 193 | 
| 194 } | 194 } | 
| OLD | NEW | 
|---|