toolkit/components/places/tests/unit/test_null_interfaces.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2 * License, v. 2.0. If a copy of the MPL was not distributed with this
     3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /**
     6  * Test bug 489872 to make sure passing nulls to nsNavHistory doesn't crash.
     7  */
     9 let Cr = Components.results;
    11 /**
    12  * Print some debug message to the console. All arguments will be printed,
    13  * separated by spaces.
    14  *
    15  * @param [arg0, arg1, arg2, ...]
    16  *        Any number of arguments to print out
    17  * @usage _("Hello World") -> prints "Hello World"
    18  * @usage _(1, 2, 3) -> prints "1 2 3"
    19  */
    20 let _ = function(some, debug, text, to) print(Array.slice(arguments).join(" "));
    22 _("Make an array of services to test, each specifying a class id, interface,",
    23   "and an array of function names that don't throw when passed nulls");
    24 let testServices = [
    25   ["browser/nav-history-service;1", "nsINavHistoryService",
    26     ["queryStringToQueries", "removePagesByTimeframe", "removePagesFromHost",
    27      "removeVisitsByTimeframe"]],
    28   ["browser/nav-bookmarks-service;1","nsINavBookmarksService",
    29     ["createFolder"]],
    30   ["browser/livemark-service;2","mozIAsyncLivemarks", ["reloadLivemarks"]],
    31   ["browser/annotation-service;1","nsIAnnotationService", []],
    32   ["browser/favicon-service;1","nsIFaviconService", []],
    33   ["browser/tagging-service;1","nsITaggingService", []],
    34 ];
    35 _(testServices.join("\n"));
    37 function run_test()
    38 {
    39   testServices.forEach(function([cid, iface, nothrow]) {
    40     _("Running test with", cid, iface, nothrow);
    41     let s = Cc["@mozilla.org/" + cid].getService(Ci[iface]);
    43     let okName = function(name) {
    44       _("Checking if function is okay to test:", name);
    45       let func = s[name];
    47       let mesg = "";
    48       if (typeof func != "function")
    49         mesg = "Not a function!";
    50       else if (func.length == 0)
    51         mesg = "No args needed!";
    52       else if (name == "QueryInterface")
    53         mesg = "Ignore QI!";
    55       if (mesg == "")
    56         return true;
    58       _(mesg, "Skipping:", name);
    59       return false;
    60     }
    62     _("Generating an array of functions to test service:", s);
    63     [i for (i in s) if (okName(i))].sort().forEach(function(n) {
    64       _();
    65       _("Testing " + iface + " function with null args:", n);
    67       let func = s[n];
    68       let num = func.length;
    69       _("Generating array of nulls for #args:", num);
    70       let args = [];
    71       for (let i = num; --i >= 0; )
    72         args.push(null);
    74       let tryAgain = true;
    75       while (tryAgain == true) {
    76         try {
    77           _("Calling with args:", JSON.stringify(args));
    78           func.apply(s, args);
    80           _("The function didn't throw! Is it one of the nothrow?", nothrow);
    81           do_check_neq(nothrow.indexOf(n), -1);
    83           _("Must have been an expected nothrow, so no need to try again");
    84           tryAgain = false;
    85         }
    86         catch(ex if ex.result == Cr.NS_ERROR_ILLEGAL_VALUE) {
    87           _("Caught an expected exception:", ex.name);
    89           _("Moving on to the next test..");
    90           tryAgain = false;
    91         }
    92         catch(ex if ex.result == Cr.NS_ERROR_XPC_NEED_OUT_OBJECT) {
    93           let pos = Number(ex.message.match(/object arg (\d+)/)[1]);
    94           _("Function call expects an out object at", pos);
    95           args[pos] = {};
    96         }
    97         catch(ex if ex.result == Cr.NS_ERROR_NOT_IMPLEMENTED) {
    98           _("Method not implemented exception:", ex.name);
   100           _("Moving on to the next test..");
   101           tryAgain = false;
   102         }
   103         catch(ex) {
   104           _("Caught some unexpected exception.. dumping");
   105           _([[i, ex[i]] for (i in ex)].join("\n"));
   106           do_check_true(false);
   107         }
   108       }
   109     });
   110   });
   111 }

mercurial