toolkit/devtools/apps/tests/unit/head_apps.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;
     7 const Cr = Components.results;
     8 const CC = Components.Constructor;
    10 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
    11 Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
    13 Cu.import("resource://gre/modules/Services.jsm");
    14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    15 Cu.import("resource://gre/modules/FileUtils.jsm");
    17 let gClient, gActor;
    19 function connect(onDone) {
    20   // Initialize a loopback remote protocol connection
    21   DebuggerServer.init(function () { return true; });
    22   // We need to register browser actors to have `listTabs` working
    23   // and also have a root actor
    24   DebuggerServer.addBrowserActors();
    26   // Setup client and actor used in all tests
    27   gClient = new DebuggerClient(DebuggerServer.connectPipe());
    28   gClient.connect(function onConnect() {
    29     gClient.listTabs(function onListTabs(aResponse) {
    30       gActor = aResponse.webappsActor;
    31       onDone();
    32     });
    33   });
    34 }
    36 function webappActorRequest(request, onResponse) {
    37   if (!gActor) {
    38     connect(webappActorRequest.bind(null, request, onResponse));
    39     return;
    40   }
    42   request.to = gActor;
    43   gClient.request(request, onResponse);
    44 }
    46 // Install a test packaged webapp from data folder
    47 function installTestApp(zipName, appId, onDone) {
    48   // Copy our package to tmp folder, where the actor retrieves it
    49   let zip = do_get_file("data/" + zipName);
    50   let appDir = FileUtils.getDir("TmpD", ["b2g", appId], true, true);
    51   zip.copyTo(appDir, "application.zip");
    53   let request = {type: "install", appId: appId};
    54   webappActorRequest(request, function (aResponse) {
    55     do_check_eq(aResponse.appId, appId);
    56     if ("error" in aResponse) {
    57       do_throw("Error: " + aResponse.error);
    58     }
    59     if ("message" in aResponse) {
    60       do_throw("Error message: " + aResponse.message);
    61     }
    62     do_check_false("error" in aResponse);
    64     onDone();
    65   });
    66 };
    68 function setup() {
    69   // We have to setup a profile, otherwise indexed db used by webapps
    70   // will throw random exception when trying to get profile folder
    71   do_get_profile();
    73   // The webapps dir isn't registered on b2g xpcshell tests,
    74   // we have to manually set it to the directory service.
    75   do_get_webappsdir();
    77   // We also need a valid nsIXulAppInfo service as Webapps.jsm is querying it
    78   Components.utils.import("resource://testing-common/AppInfo.jsm");
    79   updateAppInfo();
    81   // We have to toggle this flag in order to have apps being listed in getAll
    82   // as only launchable apps are returned
    83   Components.utils.import('resource://gre/modules/Webapps.jsm');
    84   DOMApplicationRegistry.allAppsLaunchable = true;
    85 }
    87 function do_get_webappsdir() {
    88   var webappsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
    89   webappsDir.append("test_webapps");
    90   if (!webappsDir.exists())
    91     webappsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8));
    93   var coreAppsDir = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
    94   coreAppsDir.append("test_coreapps");
    95   if (!coreAppsDir.exists())
    96     coreAppsDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("755", 8));
    98   // Register our own provider for the profile directory.
    99   // It will return our special docshell profile directory.
   100   var provider = {
   101     getFile: function(prop, persistent) {
   102       persistent.value = true;
   103       if (prop == "webappsDir") {
   104         return webappsDir.clone();
   105       }
   106       else if (prop == "coreAppsDir") {
   107         return coreAppsDir.clone();
   108       }
   109       throw Cr.NS_ERROR_FAILURE;
   110     },
   111     QueryInterface: function(iid) {
   112       if (iid.equals(Ci.nsIDirectoryServiceProvider) ||
   113           iid.equals(Ci.nsISupports)) {
   114         return this;
   115       }
   116       throw Cr.NS_ERROR_NO_INTERFACE;
   117     }
   118   };
   119   Services.dirsvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
   120 }

mercurial