tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_MessageEvent.html (2481B)


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