michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: /** michael@0: * Provides infrastructure for automated download components tests. michael@0: * (adapted from browser/component/downloads test's head.js) michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Globals michael@0: michael@0: XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", michael@0: "resource://gre/modules/FileUtils.jsm"); michael@0: michael@0: const nsIDM = Ci.nsIDownloadManager; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Test Helpers michael@0: michael@0: var { spawn } = Task; michael@0: michael@0: function equalStrings(){ michael@0: let ref = ""+arguments[0]; michael@0: for (let i=1; i= 0; i--) { michael@0: let dataRow = aDataRows[i]; michael@0: let download = yield addDownloadRow(dataRow); michael@0: michael@0: // At each iteration, ensure that the start and end time in the global michael@0: // template is distinct, as these column are used to sort each download michael@0: // in its category. michael@0: gDownloadRowTemplate.startTime++; michael@0: gDownloadRowTemplate.endTime++; michael@0: } michael@0: } finally { michael@0: info("gen_addDownloadRows, finally"); michael@0: } michael@0: } michael@0: michael@0: ///////////////////////////////////// michael@0: // Test implementations michael@0: michael@0: gTests.push({ michael@0: desc: "zero downloads", michael@0: run: function () { michael@0: yield resetDownloads(); michael@0: todo(false, "Test there are no visible notifications with an empty db."); michael@0: } michael@0: }); michael@0: michael@0: /** michael@0: * Make sure the downloads panel can display items in the right order and michael@0: * contains the expected data. michael@0: */ michael@0: gTests.push({ michael@0: desc: "Show downloads", michael@0: run: function(){ michael@0: // Display one of each download state. michael@0: let DownloadData = [ michael@0: { endTime: 1180493839859239, state: nsIDM.DOWNLOAD_NOTSTARTED }, michael@0: { endTime: 1180493839859238, state: nsIDM.DOWNLOAD_DOWNLOADING }, michael@0: { endTime: 1180493839859237, state: nsIDM.DOWNLOAD_PAUSED }, michael@0: { endTime: 1180493839859236, state: nsIDM.DOWNLOAD_SCANNING }, michael@0: { endTime: 1180493839859235, state: nsIDM.DOWNLOAD_QUEUED }, michael@0: { endTime: 1180493839859234, state: nsIDM.DOWNLOAD_FINISHED }, michael@0: { endTime: 1180493839859233, state: nsIDM.DOWNLOAD_FAILED }, michael@0: { endTime: 1180493839859232, state: nsIDM.DOWNLOAD_CANCELED }, michael@0: { endTime: 1180493839859231, state: nsIDM.DOWNLOAD_BLOCKED_PARENTAL }, michael@0: { endTime: 1180493839859230, state: nsIDM.DOWNLOAD_DIRTY }, michael@0: { endTime: 1180493839859229, state: nsIDM.DOWNLOAD_BLOCKED_POLICY } michael@0: ]; michael@0: michael@0: yield resetDownloads(); michael@0: michael@0: try { michael@0: // Populate the downloads database with the data required by this test. michael@0: // we're going to add stuff to the downloads db. michael@0: yield spawn( gen_addDownloadRows( DownloadData ) ); michael@0: michael@0: todo( false, "Check that MetroDownloadsView._progressNotificationInfo and MetroDownloadsView._downloadCount \ michael@0: have the correct length (DownloadData.length) \ michael@0: May also test that the correct notifications show up for various states."); michael@0: michael@0: todo(false, "Iterate through download objects in MetroDownloadsView._progressNotificationInfo \ michael@0: and confirm that the downloads they refer to are the same as those in \ michael@0: DownloadData."); michael@0: } catch(e) { michael@0: info("Show downloads, some error: " + e); michael@0: } michael@0: finally { michael@0: // Clean up when the test finishes. michael@0: yield resetDownloads(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: /** michael@0: * Make sure the downloads can be removed with the expected result on the notifications michael@0: */ michael@0: gTests.push({ michael@0: desc: "Remove downloads", michael@0: run: function(){ michael@0: // Push a few items into the downloads db. michael@0: let DownloadData = [ michael@0: { endTime: 1180493839859239, state: nsIDM.DOWNLOAD_FINISHED }, michael@0: { endTime: 1180493839859238, state: nsIDM.DOWNLOAD_FINISHED }, michael@0: { endTime: 1180493839859237, state: nsIDM.DOWNLOAD_FINISHED } michael@0: ]; michael@0: michael@0: yield resetDownloads(); michael@0: michael@0: try { michael@0: // Populate the downloads database with the data required by this test. michael@0: yield spawn( gen_addDownloadRows( DownloadData ) ); michael@0: michael@0: let downloadRows = null, michael@0: promisedDownloads; michael@0: // get all the downloads from the db michael@0: promisedDownloads = getPromisedDbResult( michael@0: "SELECT guid " michael@0: + "FROM moz_downloads " michael@0: + "ORDER BY startTime DESC" michael@0: ).then(function(aRows){ michael@0: downloadRows = aRows; michael@0: }, function(aError){ michael@0: throw aError; michael@0: }); michael@0: yield promisedDownloads; michael@0: michael@0: is(downloadRows.length, 3, "Correct number of downloads in the db before removal"); michael@0: michael@0: todo(false, "Get some download from MetroDownloadsView._progressNotificationInfo, \ michael@0: confirm that its file exists, then remove it."); michael@0: michael@0: // remove is async(?), wait a bit michael@0: yield waitForMs(0); michael@0: michael@0: // get all the downloads from the db michael@0: downloadRows = null; michael@0: promisedDownloads = getPromisedDbResult( michael@0: "SELECT guid " michael@0: + "FROM moz_downloads " michael@0: + "ORDER BY startTime DESC" michael@0: ).then(function(aRows){ michael@0: downloadRows = aRows; michael@0: }, function(aError){ michael@0: throw aError; michael@0: }); michael@0: yield promisedDownloads; michael@0: michael@0: todo(false, "confirm that the removed download is no longer in the database \ michael@0: and its file no longer exists."); michael@0: michael@0: } catch(e) { michael@0: info("Remove downloads, some error: " + e); michael@0: } michael@0: finally { michael@0: // Clean up when the test finishes. michael@0: yield resetDownloads(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: /** michael@0: * Make sure the cancelled/aborted downloads are handled correctly. michael@0: */ michael@0: gTests.push({ michael@0: desc: "Cancel/Abort Downloads", michael@0: run: function(){ michael@0: todo(false, "Ensure that a cancelled/aborted download is in the correct state \ michael@0: including correct values for state variables (e.g. _downloadCount, _downloadsInProgress) \ michael@0: and the existence of the downloaded file."); michael@0: } michael@0: }); michael@0: michael@0: /** michael@0: * Make sure download notifications are moved when we close tabs. michael@0: */ michael@0: gTests.push({ michael@0: desc: "Download notifications in closed tabs", michael@0: setUp: function() { michael@0: // put up a couple notifications on the initial tab michael@0: let notificationBox = Browser.getNotificationBox(); michael@0: notificationBox.appendNotification("not important", "low-priority-thing", "", notificationBox.PRIORITY_INFO_LOW, []); michael@0: notificationBox.appendNotification("so important", "high-priority-thing", "", notificationBox.PRIORITY_CRITICAL_HIGH, []); michael@0: michael@0: // open a new tab where we'll conduct the test michael@0: yield addTab("about:mozilla"); michael@0: }, michael@0: run: function(){ michael@0: let notificationBox = Browser.getNotificationBox(); michael@0: let notn = MetroDownloadsView.showNotification("download-progress", "test message", [], michael@0: notificationBox.PRIORITY_WARNING_LOW); michael@0: Browser.closeTab(Browser.selectedTab); michael@0: michael@0: yield waitForEvent(Elements.tabList, "TabRemove"); michael@0: michael@0: // expected behavior when a tab is closed while a download notification is showing: michael@0: // * the notification remains visible as long as a next tab/browser exists michael@0: // * normal rules about priority apply michael@0: // * notifications - including any pre-existing ones - display in expected order michael@0: let nextBox = Browser.getNotificationBox(); michael@0: let currentNotification; michael@0: michael@0: ok(nextBox.getNotificationWithValue("download-progress"), "notification was moved to next tab"); michael@0: michael@0: currentNotification = nextBox.currentNotification; michael@0: is(currentNotification.value, "high-priority-thing", "high priority notification is current"); michael@0: currentNotification.close(); michael@0: michael@0: currentNotification = nextBox.currentNotification; michael@0: is(currentNotification.value, "download-progress", "download notification is next"); michael@0: currentNotification.close(); michael@0: michael@0: currentNotification = nextBox.currentNotification; michael@0: is(currentNotification.value, "low-priority-thing", "low priority notification is next"); michael@0: currentNotification.close(); michael@0: } michael@0: });