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: function test() michael@0: { michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Tests (defined locally for scope's sake) michael@0: michael@0: function test_checkedAndDisabledAtStart(aWin) michael@0: { michael@0: let doc = aWin.document; michael@0: let downloads = doc.getElementById("downloads-checkbox"); michael@0: let history = doc.getElementById("history-checkbox"); michael@0: michael@0: ok(history.checked, "history checkbox is checked"); michael@0: ok(downloads.disabled, "downloads checkbox is disabled"); michael@0: ok(downloads.checked, "downloads checkbox is checked"); michael@0: } michael@0: michael@0: function test_checkedAndDisabledOnHistoryToggle(aWin) michael@0: { michael@0: let doc = aWin.document; michael@0: let downloads = doc.getElementById("downloads-checkbox"); michael@0: let history = doc.getElementById("history-checkbox"); michael@0: michael@0: EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); michael@0: ok(!history.checked, "history checkbox is not checked"); michael@0: ok(downloads.disabled, "downloads checkbox is disabled"); michael@0: ok(downloads.checked, "downloads checkbox is checked"); michael@0: } michael@0: michael@0: function test_checkedAfterAddingDownload(aWin) michael@0: { michael@0: let doc = aWin.document; michael@0: let downloads = doc.getElementById("downloads-checkbox"); michael@0: let history = doc.getElementById("history-checkbox"); michael@0: michael@0: // Add download to DB michael@0: let file = Cc["@mozilla.org/file/directory_service;1"]. michael@0: getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); michael@0: file.append("sanitize-dm-test.file"); michael@0: file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: let testPath = Services.io.newFileURI(file).spec; michael@0: let data = { michael@0: name: "381603.patch", michael@0: source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", michael@0: target: testPath, michael@0: startTime: 1180493839859230, michael@0: endTime: 1180493839859239, michael@0: state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, michael@0: currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0, michael@0: guid: "a1bcD23eF4g5" michael@0: }; michael@0: let db = Cc["@mozilla.org/download-manager;1"]. michael@0: getService(Ci.nsIDownloadManager).DBConnection; michael@0: let stmt = db.createStatement( michael@0: "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + michael@0: "state, currBytes, maxBytes, preferredAction, autoResume, guid) " + michael@0: "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + michael@0: ":currBytes, :maxBytes, :preferredAction, :autoResume, :guid)"); michael@0: try { michael@0: for (let prop in data) michael@0: stmt.params[prop] = data[prop]; michael@0: stmt.execute(); michael@0: } michael@0: finally { michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: // Toggle history to get everything to update michael@0: EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); michael@0: EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); michael@0: michael@0: ok(!history.checked, "history checkbox is not checked"); michael@0: ok(!downloads.disabled, "downloads checkbox is not disabled"); michael@0: ok(downloads.checked, "downloads checkbox is checked"); michael@0: } michael@0: michael@0: function test_checkedAndDisabledWithHistoryChecked(aWin) michael@0: { michael@0: let doc = aWin.document; michael@0: let downloads = doc.getElementById("downloads-checkbox"); michael@0: let history = doc.getElementById("history-checkbox"); michael@0: michael@0: EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); michael@0: ok(history.checked, "history checkbox is checked"); michael@0: ok(downloads.disabled, "downloads checkbox is disabled"); michael@0: ok(downloads.checked, "downloads checkbox is checked"); michael@0: } michael@0: michael@0: let tests = [ michael@0: test_checkedAndDisabledAtStart, michael@0: test_checkedAndDisabledOnHistoryToggle, michael@0: test_checkedAfterAddingDownload, michael@0: test_checkedAndDisabledWithHistoryChecked, michael@0: ]; michael@0: michael@0: ////////////////////////////////////////////////////////////////////////////// michael@0: //// Run the tests michael@0: michael@0: let dm = Cc["@mozilla.org/download-manager;1"]. michael@0: getService(Ci.nsIDownloadManager); michael@0: let db = dm.DBConnection; michael@0: michael@0: // Empty any old downloads michael@0: db.executeSimpleSQL("DELETE FROM moz_downloads"); michael@0: michael@0: // Close the UI if necessary michael@0: let win = Services.ww.getWindowByName("Sanitize", null); michael@0: if (win && (win instanceof Ci.nsIDOMWindow)) michael@0: win.close(); michael@0: michael@0: // Start the test when the sanitize window loads michael@0: Services.ww.registerNotification(function (aSubject, aTopic, aData) { michael@0: Services.ww.unregisterNotification(arguments.callee); michael@0: aSubject.QueryInterface(Ci.nsIDOMEventTarget) michael@0: .addEventListener("DOMContentLoaded", doTest, false); michael@0: }); michael@0: michael@0: // Let the methods that run onload finish before we test michael@0: let doTest = function() setTimeout(function() { michael@0: let win = Services.ww.getWindowByName("Sanitize", null) michael@0: .QueryInterface(Ci.nsIDOMWindow); michael@0: michael@0: for (let i = 0; i < tests.length; i++) michael@0: tests[i](win); michael@0: michael@0: win.close(); michael@0: finish(); michael@0: }, 0); michael@0: michael@0: // Show the UI michael@0: Services.ww.openWindow(window, michael@0: "chrome://browser/content/sanitize.xul", michael@0: "Sanitize", michael@0: "chrome,titlebar,centerscreen", michael@0: null); michael@0: michael@0: waitForExplicitFinish(); michael@0: }