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