Bug 1272425 Fix downloads misc tests r?kmag draft
authorAndrew Swan <aswan@mozilla.com>
Thu, 26 May 2016 20:31:05 -0700
changeset 371944 a0deb1329030416fbd68f41ea47d2d1d7d1c6501
parent 371943 3b549b841b2d356b5d5ef4be433fa4fb199cc433
child 522057 4bb152a9fddd9645011eee6ffc2ee926bc8136ed
push id19395
push useraswan@mozilla.com
push dateFri, 27 May 2016 03:31:33 +0000
reviewerskmag
bugs1272425
milestone49.0a1
Bug 1272425 Fix downloads misc tests r?kmag See the bug for extended discussion, trying to fix this with re-used URLs doesn't seem practical so just use unique URLs for partial downloads. MozReview-Commit-ID: FdS4XroVUqj
toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_misc.html
--- a/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_misc.html
+++ b/toolkit/components/extensions/test/mochitest/test_chrome_ext_downloads_misc.html
@@ -20,22 +20,26 @@ const {
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Downloads.jsm");
 
 const BASE = "http://mochi.test:8888/chrome/toolkit/components/extensions/test/mochitest";
 const TXT_FILE = "file_download.txt";
 const TXT_URL = BASE + "/" + TXT_FILE;
-/* bug 1272425
-const INTERRUPTIBLE_URL = BASE + "/interruptible.sjs";
+
 // Keep these in sync with code in interruptible.sjs
 const INT_PARTIAL_LEN = 15;
 const INT_TOTAL_LEN = 31;
-*/
+
+let interruptibleCount = 0;
+function getInterruptibleUrl() {
+  let n = interruptibleCount++;
+  return `${BASE}/interruptible.sjs?count=${n}`;
+}
 
 function backgroundScript() {
   let events = new Set();
   let eventWaiter = null;
 
   browser.downloads.onCreated.addListener(data => {
     events.add({type: "onCreated", data});
     if (eventWaiter) {
@@ -170,18 +174,16 @@ function clearDownloads(callback) {
   });
 }
 
 function runInExtension(what, ...args) {
   extension.sendMessage(`${what}.request`, ...args);
   return extension.awaitMessage(`${what}.done`);
 }
 
-/*
- * bug 1272425
 // This is pretty simplistic, it looks for a progress update for a
 // download of the given url in which the total bytes are exactly equal
 // to the given value.  Unless you know exactly how data will arrive from
 // the server (eg see interruptible.sjs), it probably isn't very useful.
 function waitForProgress(url, bytes) {
   return Downloads.getList(Downloads.ALL)
                   .then(list => new Promise(resolve => {
                     const view = {
@@ -190,17 +192,16 @@ function waitForProgress(url, bytes) {
                           list.removeView(view);
                           resolve();
                         }
                       },
                     };
                     list.addView(view);
                   }));
 }
-*/
 
 add_task(function* setup() {
   const nsIFile = Ci.nsIFile;
   downloadDir = FileUtils.getDir("TmpD", ["downloads"]);
   downloadDir.createUnique(nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
   info(`downloadDir ${downloadDir.path}`);
 
   Services.prefs.setIntPref("browser.download.folderList", 2);
@@ -245,24 +246,23 @@ add_task(function* test_events() {
           current: "complete",
         },
       },
     },
   ]);
   is(msg.status, "success", "got onCreated and onChanged events");
 });
 
-/*
- * Disabled for bug 1272425
 add_task(function* test_cancel() {
-  let msg = yield runInExtension("download", {url: INTERRUPTIBLE_URL});
+  let url = getInterruptibleUrl();
+  let msg = yield runInExtension("download", {url});
   is(msg.status, "success", "download() succeeded");
   const id = msg.result;
 
-  let progressPromise = waitForProgress(INTERRUPTIBLE_URL, INT_PARTIAL_LEN);
+  let progressPromise = waitForProgress(url, INT_PARTIAL_LEN);
 
   msg = yield runInExtension("waitForEvents", [
     {type: "onCreated", data: {id}},
   ]);
   is(msg.status, "success", "got created and changed events");
 
   yield progressPromise;
   info(`download reached ${INT_PARTIAL_LEN} bytes`);
@@ -320,21 +320,22 @@ add_task(function* test_cancel() {
   msg = yield runInExtension("pause", id);
   is(msg.status, "error", "cannot pause a canceled download");
 
   msg = yield runInExtension("resume", id);
   is(msg.status, "error", "cannot resume a canceled download");
 });
 
 add_task(function* test_pauseresume() {
-  let msg = yield runInExtension("download", {url: INTERRUPTIBLE_URL});
+  let url = getInterruptibleUrl();
+  let msg = yield runInExtension("download", {url});
   is(msg.status, "success", "download() succeeded");
   const id = msg.result;
 
-  let progressPromise = waitForProgress(INTERRUPTIBLE_URL, INT_PARTIAL_LEN);
+  let progressPromise = waitForProgress(url, INT_PARTIAL_LEN);
 
   msg = yield runInExtension("waitForEvents", [
     {type: "onCreated", data: {id}},
   ]);
   is(msg.status, "success", "got created and changed events");
 
   yield progressPromise;
   info(`download reached ${INT_PARTIAL_LEN} bytes`);
@@ -445,21 +446,22 @@ add_task(function* test_pauseresume() {
   msg = yield runInExtension("pause", id);
   is(msg.status, "error", "cannot pause a completed download");
 
   msg = yield runInExtension("resume", id);
   is(msg.status, "error", "cannot resume a completed download");
 });
 
 add_task(function* test_pausecancel() {
-  let msg = yield runInExtension("download", {url: INTERRUPTIBLE_URL});
+  let url = getInterruptibleUrl();
+  let msg = yield runInExtension("download", {url});
   is(msg.status, "success", "download() succeeded");
   const id = msg.result;
 
-  let progressPromise = waitForProgress(INTERRUPTIBLE_URL, INT_PARTIAL_LEN);
+  let progressPromise = waitForProgress(url, INT_PARTIAL_LEN);
 
   msg = yield runInExtension("waitForEvents", [
     {type: "onCreated", data: {id}},
   ]);
   is(msg.status, "success", "got created and changed events");
 
   yield progressPromise;
   info(`download reached ${INT_PARTIAL_LEN} bytes`);
@@ -591,21 +593,22 @@ add_task(function* test_file_removal() {
   is(msg.status, "error", "removeFile() fails since the file was already removed.");
   ok(/file doesn't exist/.test(msg.errmsg), "removeFile() failed on removed file.");
 
   msg = yield runInExtension("removeFile", 1000);
   ok(/Invalid download id/.test(msg.errmsg), "removeFile() failed due to non-existent id");
 });
 
 add_task(function* test_removal_of_incomplete_download() {
-  let msg = yield runInExtension("download", {url: INTERRUPTIBLE_URL});
+  let url = getInterruptibleUrl();
+  let msg = yield runInExtension("download", {url});
   is(msg.status, "success", "download() succeeded");
   const id = msg.result;
 
-  let progressPromise = waitForProgress(INTERRUPTIBLE_URL, INT_PARTIAL_LEN);
+  let progressPromise = waitForProgress(url, INT_PARTIAL_LEN);
 
   msg = yield runInExtension("waitForEvents", [
     {type: "onCreated", data: {id}},
   ]);
   is(msg.status, "success", "got created and changed events");
 
   yield progressPromise;
   info(`download reached ${INT_PARTIAL_LEN} bytes`);
@@ -685,17 +688,16 @@ add_task(function* test_removal_of_incom
       },
     },
   ]);
   is(msg.status, "success", "got onChanged events for resume and complete");
 
   msg = yield runInExtension("removeFile", id);
   is(msg.status, "success", "removeFile() succeeded following completion of resumed download.");
 });
-*/
 
 // Test erase().  We don't do elaborate testing of the query handling
 // since it uses the exact same engine as search() which is tested
 // more thoroughly in test_chrome_ext_downloads_search.html
 add_task(function* test_erase() {
   yield clearDownloads();
 
   yield runInExtension("clearEvents");