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