dom/tests/mochitest/whatwg/test_MessageEvent.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial