diff -r 000000000000 -r 6474c204b198 toolkit/mozapps/downloads/tests/chrome/utils.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/toolkit/mozapps/downloads/tests/chrome/utils.js Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,160 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/** + * Provides utility functions for the download manager chrome tests. + */ + +const Cc = Components.classes; +const Ci = Components.interfaces; +const Cr = Components.results; + +Components.utils.import("resource://gre/modules/Services.jsm"); + +/** + * Returns the toolkit implementation of the download manager UI service. + * If the toolkit implementation of the service can't be found (e.g. because + * SeaMonkey doesn't package that version but an own implementation that calls + * different UI), then returns false (see bug 483781). + * + * @returns toolkit's nsIDownloadManagerUI implementation or false if not found + */ +function getDMUI() +{ + try { + // This method throws an exception if the old Download Manager is disabled. + Services.downloads.activeDownloadCount; + } catch (ex) { + return false; + } + if (Components.classesByID["{7dfdf0d1-aff6-4a34-bad1-d0fe74601642}"]) + return Components.classesByID["{7dfdf0d1-aff6-4a34-bad1-d0fe74601642}"]. + getService(Ci.nsIDownloadManagerUI); + return false; +} + +/** + * Adds a live download to the download manager. + * + * @param [optional] aName + * The name that will be assigned to the downloaded file. + * @returns an instance of nsIDownload. + */ +function addDownload(aName) { + function createURI(aObj) { + let ios = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + return (aObj instanceof Ci.nsIFile) ? ios.newFileURI(aObj) : + ios.newURI(aObj, null, null); + } + + function randomString() { + let chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; + let string_length = 8; + let randomstring = ""; + for (let i=0; i