dom/tests/mochitest/whatwg/test_MessageEvent.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>MessageEvent tests</title>
michael@0 8 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="text/javascript" src="browserFu.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content" style="display: none">
michael@0 16
michael@0 17 </div>
michael@0 18
michael@0 19 <button id="target">target</button>
michael@0 20
michael@0 21 <pre id="test">
michael@0 22 <script class="testbody" type="application/javascript">
michael@0 23 /** Test for Bug 387706 **/
michael@0 24
michael@0 25 SimpleTest.waitForExplicitFinish();
michael@0 26
michael@0 27 var data = "foobar";
michael@0 28 var origin = "http://cool.example.com";
michael@0 29 var bubbles = true, cancelable = true;
michael@0 30 var lastEventId = "lastEventId";
michael@0 31
michael@0 32 var target;
michael@0 33
michael@0 34 var count = 0;
michael@0 35
michael@0 36 function sendMsg()
michael@0 37 {
michael@0 38 try
michael@0 39 {
michael@0 40 var evt = new MessageEvent('message', {
michael@0 41 bubbles: bubbles, cancelable: cancelable, data: data,
michael@0 42 origin: origin, lastEventId: lastEventId, source: window});
michael@0 43 ok(evt instanceof MessageEvent, "I ordered a MessageEvent!");
michael@0 44
michael@0 45 is(evt.data, data, "unexpected data");
michael@0 46 is(evt.origin, origin, "unexpected origin");
michael@0 47 is(evt.lastEventId, lastEventId, "unexpected lastEventId");
michael@0 48
michael@0 49 is(evt.cancelable, cancelable, "wrong cancelable property");
michael@0 50 is(evt.bubbles, bubbles, "wrong bubbling property");
michael@0 51 is(evt.source, window, "wrong source");
michael@0 52
michael@0 53 return target.dispatchEvent(evt);
michael@0 54 }
michael@0 55 catch (e)
michael@0 56 {
michael@0 57 ok(false, "exception thrown: " + e);
michael@0 58 return false;
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 function recvMsg(evt)
michael@0 63 {
michael@0 64 is(evt.data, data, "unexpected data");
michael@0 65 is(evt.origin, origin, "unexpected origin");
michael@0 66 is(evt.lastEventId, lastEventId, "unexpected lastEventId");
michael@0 67
michael@0 68 is(evt.cancelable, cancelable, "wrong cancelable property");
michael@0 69 is(evt.bubbles, bubbles, "wrong bubbling property");
michael@0 70 is(evt.source, window, "wrong source");
michael@0 71
michael@0 72 is(evt.target, target, "wrong target");
michael@0 73
michael@0 74 if (target == evt.currentTarget)
michael@0 75 {
michael@0 76 is(Event.AT_TARGET, evt.eventPhase, "this listener was on the target");
michael@0 77 }
michael@0 78 else
michael@0 79 {
michael@0 80 is(evt.currentTarget, document, "should have gotten this at the window");
michael@0 81 is(Event.BUBBLING_PHASE, evt.eventPhase, "wrong phase");
michael@0 82 }
michael@0 83
michael@0 84 count++;
michael@0 85 }
michael@0 86
michael@0 87 function setup()
michael@0 88 {
michael@0 89 target = $("target");
michael@0 90 target.addEventListener("message", recvMsg, false);
michael@0 91 document.addEventListener("message", recvMsg, false);
michael@0 92 var res = sendMsg();
michael@0 93 ok(res === true, "nothing canceled this");
michael@0 94 is(count, 2, "listener not called twice");
michael@0 95 SimpleTest.finish();
michael@0 96 }
michael@0 97
michael@0 98 addLoadEvent(setup);
michael@0 99
michael@0 100 </script>
michael@0 101 </pre>
michael@0 102 </body>
michael@0 103 </html>

mercurial