OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 // Dart test for testing isolation across multiple script tags. | |
6 #library("multiscript"); | |
7 #import("dart:dom"); | |
8 #import("dart:json"); | |
9 | |
10 class State { | |
11 static int s = 1; | |
12 static update() { s++; } | |
13 } | |
14 | |
15 checkEventDelivery(id, expect) { | |
16 addHandler('test${id}', (m) { | |
17 State.update(); | |
18 postResult(State.s, expect); | |
19 }); | |
20 postMessage('test${id}', {}); | |
21 } | |
22 | |
23 onStart(handler) { | |
24 addHandler('start', handler); | |
25 } | |
26 | |
27 addHandler(cmd, handler) { | |
28 window.addEventListener('message', (e) { | |
29 var msg = {}; | |
30 // We do this, as unit test framework also uses DOM messages to function. | |
31 try { | |
32 msg = JSON.parse(e.data); | |
33 } catch (var e) {} | |
34 if (msg['multiscript-cmd'] == cmd) { | |
35 handler(msg); | |
36 } | |
37 }, false); | |
38 } | |
39 | |
40 postMessage(cmd, params) { | |
41 params['multiscript-cmd'] = cmd; | |
42 window.postMessage(JSON.stringify(params), '*'); | |
43 } | |
44 | |
45 postResult(actual, expect) { | |
46 postMessage('done', {'actual': actual, 'expect': expect}); | |
47 } | |
OLD | NEW |