dom/events/test/test_messageEvent.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_messageEvent.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=848294
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 848294</title>
    1.12 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
    1.14 +  <script type="application/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script>
    1.15 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.16 +</head>
    1.17 +<body>
    1.18 +  <script type="application/javascript">
    1.19 +  function runTest() {
    1.20 +    var channel = new MessageChannel();
    1.21 +
    1.22 +    var tests = [
    1.23 +      {},
    1.24 +      { data: 42 },
    1.25 +      { data: {} },
    1.26 +      { data: true, origin: 'wow' },
    1.27 +      { data: [], lastEventId: 'wow2'  },
    1.28 +      { data: null, source: null },
    1.29 +      { data: window, source: window },
    1.30 +      { data: window, source: channel.port1 },
    1.31 +      { data: window, source: channel.port1, ports: [ channel.port1, channel.port2 ] },
    1.32 +      { data: null, ports: null },
    1.33 +    ];
    1.34 +
    1.35 +    while (tests.length) {
    1.36 +      var test = tests.shift();
    1.37 +
    1.38 +      var e = new MessageEvent('message', test);
    1.39 +      ok(e, "MessageEvent created");
    1.40 +      is(e.type, 'message', 'MessageEvent.type is right');
    1.41 +
    1.42 +      is(e.data, 'data' in test ? test.data : undefined, 'MessageEvent.data is ok');
    1.43 +      is(e.origin, 'origin' in test ? test.origin : '', 'MessageEvent.origin is ok');
    1.44 +      is(e.lastEventId, 'lastEventId' in test ? test.lastEventId : '', 'MessageEvent.lastEventId is ok');
    1.45 +      is(e.source, 'source' in test ? test.source : undefined, 'MessageEvent.source is ok');
    1.46 +
    1.47 +      if (test.ports != undefined) {
    1.48 +        is(e.ports.length, test.ports.length, 'MessageEvent.ports is ok');
    1.49 +        is(e.ports, e.ports, 'MessageEvent.ports is ok');
    1.50 +      } else {
    1.51 +        ok(!('ports' in test) || test.ports == null, 'MessageEvent.ports is ok');
    1.52 +      }
    1.53 +    }
    1.54 +
    1.55 +    try {
    1.56 +      var e = new MessageEvent('foobar', { source: 42 });
    1.57 +      ok(false, "Source has to be a window or a port");
    1.58 +    } catch(e) {
    1.59 +      ok(true, "Source has to be a window or a port");
    1.60 +    }
    1.61 +
    1.62 +    SimpleTest.finish();
    1.63 +  }
    1.64 +
    1.65 +  SimpleTest.waitForExplicitFinish();
    1.66 +  SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTest);
    1.67 +  </script>
    1.68 +</body>
    1.69 +</html>

mercurial