dom/tests/mochitest/whatwg/test_MessageEvent.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/whatwg/test_MessageEvent.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>MessageEvent tests</title>
    1.11 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
    1.12 +  <script type="text/javascript" src="browserFu.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +  
    1.20 +</div>
    1.21 +
    1.22 +<button id="target">target</button>
    1.23 +
    1.24 +<pre id="test">
    1.25 +<script class="testbody" type="application/javascript">
    1.26 +/** Test for Bug 387706 **/
    1.27 +
    1.28 +SimpleTest.waitForExplicitFinish();
    1.29 +
    1.30 +var data = "foobar";
    1.31 +var origin = "http://cool.example.com";
    1.32 +var bubbles = true, cancelable = true;
    1.33 +var lastEventId = "lastEventId";
    1.34 +
    1.35 +var target;
    1.36 +
    1.37 +var count = 0;
    1.38 +
    1.39 +function sendMsg()
    1.40 +{
    1.41 +  try
    1.42 +  {
    1.43 +    var evt = new MessageEvent('message', {
    1.44 +      bubbles: bubbles, cancelable: cancelable, data: data,
    1.45 +      origin: origin, lastEventId: lastEventId, source: window});
    1.46 +    ok(evt instanceof MessageEvent, "I ordered a MessageEvent!");
    1.47 +  
    1.48 +    is(evt.data, data, "unexpected data");
    1.49 +    is(evt.origin, origin, "unexpected origin");
    1.50 +    is(evt.lastEventId, lastEventId, "unexpected lastEventId");
    1.51 +  
    1.52 +    is(evt.cancelable, cancelable, "wrong cancelable property");
    1.53 +    is(evt.bubbles, bubbles, "wrong bubbling property");
    1.54 +    is(evt.source, window, "wrong source");
    1.55 +  
    1.56 +    return target.dispatchEvent(evt);
    1.57 +  }
    1.58 +  catch (e)
    1.59 +  {
    1.60 +    ok(false, "exception thrown: " + e);
    1.61 +    return false;
    1.62 +  }
    1.63 +}
    1.64 +
    1.65 +function recvMsg(evt)
    1.66 +{
    1.67 +  is(evt.data, data, "unexpected data");
    1.68 +  is(evt.origin, origin, "unexpected origin");
    1.69 +  is(evt.lastEventId, lastEventId, "unexpected lastEventId");
    1.70 +
    1.71 +  is(evt.cancelable, cancelable, "wrong cancelable property");
    1.72 +  is(evt.bubbles, bubbles, "wrong bubbling property");
    1.73 +  is(evt.source, window, "wrong source");
    1.74 +
    1.75 +  is(evt.target, target, "wrong target");
    1.76 +
    1.77 +  if (target == evt.currentTarget)
    1.78 +  {
    1.79 +    is(Event.AT_TARGET, evt.eventPhase, "this listener was on the target");
    1.80 +  }
    1.81 +  else
    1.82 +  {
    1.83 +    is(evt.currentTarget, document, "should have gotten this at the window");
    1.84 +    is(Event.BUBBLING_PHASE, evt.eventPhase, "wrong phase");
    1.85 +  }
    1.86 +
    1.87 +  count++;
    1.88 +}
    1.89 +
    1.90 +function setup()
    1.91 +{
    1.92 +  target = $("target");
    1.93 +  target.addEventListener("message", recvMsg, false);
    1.94 +  document.addEventListener("message", recvMsg, false);
    1.95 +  var res = sendMsg();
    1.96 +  ok(res === true, "nothing canceled this");
    1.97 +  is(count, 2, "listener not called twice");
    1.98 +  SimpleTest.finish();
    1.99 +}
   1.100 +
   1.101 +addLoadEvent(setup);
   1.102 +
   1.103 +</script>
   1.104 +</pre>
   1.105 +</body>
   1.106 +</html>

mercurial