toolkit/devtools/apps/tests/debugger-protocol-helper.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 const Cc = Components.classes;
     5 const Ci = Components.interfaces;
     6 const Cu = Components.utils;
     8 const { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
     9 const { DebuggerClient } = Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
    11 const { FileUtils } = Cu.import("resource://gre/modules/FileUtils.jsm");
    12 const { Services } = Cu.import("resource://gre/modules/Services.jsm");
    14 let gClient, gActor;
    16 function connect(onDone) {
    18   if (Services.appinfo.name == "B2G") {
    19     // On b2g, we try to exercice the code that launches the production debugger server
    20     let settingsService = Cc["@mozilla.org/settingsService;1"].getService(Ci.nsISettingsService);
    21     settingsService.createLock().set("devtools.debugger.remote-enabled", true, null);
    22     // We can't use `set` callback as it is fired before shell.js code listening for this setting
    23     // is actually called. Same thing applies to mozsettings-changed obs notification.
    24     // So listen to a custom event until bug 942756 lands
    25     let observer = {
    26       observe: function (subject, topic, data) {
    27         Services.obs.removeObserver(observer, "debugger-server-started");
    28         let transport = debuggerSocketConnect("127.0.0.1", 6000);
    29         startClient(transport, onDone);
    30       }
    31     };
    32     Services.obs.addObserver(observer, "debugger-server-started", false);
    33   } else {
    34     // Initialize a loopback remote protocol connection
    35     DebuggerServer.init(function () { return true; });
    36     // We need to register browser actors to have `listTabs` working
    37     // and also have a root actor
    38     DebuggerServer.addBrowserActors();
    39     let transport = DebuggerServer.connectPipe();
    40     startClient(transport, onDone);
    41   }
    42 }
    44 function startClient(transport, onDone) {
    45   // Setup client and actor used in all tests
    46   gClient = new DebuggerClient(transport);
    47   gClient.connect(function onConnect() {
    48     gClient.listTabs(function onListTabs(aResponse) {
    49       gActor = aResponse.webappsActor;
    50       if (gActor)
    51         webappActorRequest({type: "watchApps"}, onDone);
    52     });
    53   });
    55   gClient.addListener("appInstall", function (aState, aType, aPacket) {
    56     sendAsyncMessage("installed-event", { manifestURL: aType.manifestURL });
    57   });
    59   gClient.addListener("appUninstall", function (aState, aType, aPacket) {
    60     sendAsyncMessage("uninstalled-event", { manifestURL: aType.manifestURL });
    61   });
    63   addMessageListener("appActorRequest", request => {
    64     webappActorRequest(request, response => {
    65       sendAsyncMessage("appActorResponse", response);
    66     });
    67   });
    68 }
    70 function webappActorRequest(request, onResponse) {
    71   if (!gActor) {
    72     connect(webappActorRequest.bind(null, request, onResponse));
    73     return;
    74   }
    76   request.to = gActor;
    77   gClient.request(request, onResponse);
    78 }
    81 function downloadURL(url, file) {
    82   let channel = Services.io.newChannel(url, null, null);
    83   let istream = channel.open();
    84   let bstream = Cc["@mozilla.org/binaryinputstream;1"]
    85                   .createInstance(Ci.nsIBinaryInputStream);
    86   bstream.setInputStream(istream);
    87   let data = bstream.readBytes(bstream.available());
    89   let ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"]
    90                   .createInstance(Ci.nsIFileOutputStream);
    91   ostream.init(file, 0x04 | 0x08 | 0x20, 0600, 0);
    92   ostream.write(data, data.length);
    93   ostream.QueryInterface(Ci.nsISafeOutputStream).finish();
    94 }
    96 // Install a test packaged webapp from data folder
    97 addMessageListener("install", function (aMessage) {
    98   let url = aMessage.url;
    99   let appId = aMessage.appId;
   101   try {
   102     // Download its content from mochitest http server
   103     // Copy our package to tmp folder, where the actor retrieves it
   104     let zip = FileUtils.getDir("TmpD", ["b2g", appId], true, true);
   105     zip.append("application.zip");
   106     downloadURL(url, zip);
   108     let request = {type: "install", appId: appId};
   109     webappActorRequest(request, function (aResponse) {
   110       sendAsyncMessage("installed", aResponse);
   111     });
   112   } catch(e) {
   113     dump("installTestApp exception: " + e + "\n");
   114   }
   115 });
   117 addMessageListener("cleanup", function () {
   118   webappActorRequest({type: "unwatchApps"}, function () {
   119     gClient.close();
   120   });
   121 });

mercurial