tor-browser

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

test_eventsourceservice_worker.html (2147B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4    <title>EventSource event service worker test</title>
      5    <meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
      6    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
      7    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 var service = SpecialPowers.Cc["@mozilla.org/eventsourceevent/service;1"]
     14                .getService(SpecialPowers.Ci.nsIEventSourceEventService);
     15 ok(!!service, "We have the nsIEventSourceEventService");
     16 
     17 var innerId = SpecialPowers.wrap(window).windowGlobalChild.innerWindowId;
     18 ok(innerId, "We have a valid innerWindowID: " + innerId);
     19 
     20 var channelId = null;
     21 var listener = {
     22    QueryInterface(aIID) {
     23      if (
     24        SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
     25        SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIEventSourceEventListener)
     26      ) {
     27        return this;
     28      }
     29      throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
     30    },
     31    eventSourceConnectionOpened(httpChannelId) {
     32        info("eventSourceConnectionOpened");
     33        ok(httpChannelId > 0, "Channel ID received");
     34        channelId = httpChannelId;
     35    },
     36    eventSourceConnectionClosed(httpChannelId) {
     37        info("eventSourceConnectionClosed");
     38        ok(httpChannelId === channelId, "Channel ID matched");
     39        SimpleTest.finish();
     40    },
     41    eventReceived(httpChannelId, eventName, lastEventId, data, retry, timeStamp) {
     42        info("eventReceived");
     43        is(eventName, "message", "Event name is 'message'");
     44        is(lastEventId, "1", "Last event id is '1'");
     45        is(data, "msg 1", "Data is 'msg 1'");
     46        ok(retry > 0, "Reconnection time received");
     47        ok(httpChannelId === channelId, "Channel ID matched");
     48        ok(timeStamp > 0, "TimeStamp received");
     49    }
     50 }
     51 
     52 service.addListener(innerId, listener);
     53 ok(true, "Listener added");
     54 addLoadEvent(function () {
     55    const worker = new Worker("eventsource_worker.js");
     56 });
     57 SimpleTest.waitForExplicitFinish();
     58 </script>
     59 </pre>
     60 </body>
     61 </html>