Bug 1338262 - Remove legacy generator from netwerk/test/. r=mayhemer
authorTooru Fujisawa <arai_a@mac.com>
Wed, 22 Feb 2017 16:11:34 +0900
changeset 344204 4a24f274ec59f962bbe1bce06b41a537205abf34
parent 344203 7c0ec55b44dc159a6eb0c9ff65b922952e6e4f11
child 344205 9ad27050d4fcad8733022113ac8e53ef16dbaacb
push id31402
push usercbook@mozilla.com
push dateWed, 22 Feb 2017 13:33:50 +0000
treeherdermozilla-central@f5372cb6c3c7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1338262
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1338262 - Remove legacy generator from netwerk/test/. r=mayhemer
netwerk/test/httpserver/test/head_utils.js
netwerk/test/httpserver/test/test_host.js
netwerk/test/httpserver/test/test_request_line_split_in_two_packets.js
netwerk/test/httpserver/test/test_seizepower.js
netwerk/test/unit/test_backgroundfilesaver.js
netwerk/test/unit/test_bug826063.js
netwerk/test/unit/test_cache_jar.js
--- a/netwerk/test/httpserver/test/head_utils.js
+++ b/netwerk/test/httpserver/test/head_utils.js
@@ -72,17 +72,17 @@ function fileContents(file)
  * without the trailing line separator.
  *
  * @param data : string
  *   a string consisting of lines of data separated by CRLFs
  * @returns Iterator
  *   an Iterator which returns each line from data in turn; note that this
  *   includes a final empty line if data ended with a CRLF
  */
-function LineIterator(data)
+function* LineIterator(data)
 {
   var start = 0, index = 0;
   do
   {
     index = data.indexOf("\r\n");
     if (index >= 0)
       yield data.substring(0, index);
     else
@@ -102,17 +102,17 @@ function LineIterator(data)
  * @param expectedLines : [string]
  *   an array of the expected lines of text
  * @throws string
  *   an error message if iter doesn't agree with expectedLines
  */
 function expectLines(iter, expectedLines)
 {
   var index = 0;
-  for (var line in iter)
+  for (var line of iter)
   {
     if (expectedLines.length == index)
       throw "Error: got more than " + expectedLines.length + " expected lines!";
 
     var expected = expectedLines[index++];
     if (expected !== line)
       throw "Error on line " + index + "!\n" +
             "  actual: '" + line + "',\n" +
@@ -150,19 +150,19 @@ function writeDetails(request, response)
  * point the body of the response will be returned next from the iterator.
  *
  * @param iter : Iterator
  *   an iterator over the CRLF-delimited lines in an HTTP response, currently
  *   just after the Request-Line
  */
 function skipHeaders(iter)
 {
-  var line = iter.next();
+  var line = iter.next().value;
   while (line !== "")
-    line = iter.next();
+    line = iter.next().value;
 }
 
 /**
  * Checks that the exception e (which may be an XPConnect-created exception
  * object or a raw nsresult number) is the given nsresult.
  *
  * @param e : Exception or nsresult
  *   the actual exception
--- a/netwerk/test/httpserver/test/test_host.js
+++ b/netwerk/test/httpserver/test/test_host.js
@@ -262,17 +262,17 @@ function checkPrimariesThrow(id)
 /**
  * Utility function to check for a 400 response.
  */
 function check400(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  var firstLine = iter.next();
+  var { value: firstLine } = iter.next();
   do_check_eq(firstLine.substring(0, HTTP_400_LEADER_LENGTH), HTTP_400_LEADER);
 }
 
 
 /***************
  * BEGIN TESTS *
  ***************/
 
@@ -291,17 +291,17 @@ function http10Request(request, response
 }
 data = "GET /http/1.0-request HTTP/1.0\r\n" +
        "\r\n";
 function check10(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.0 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.0 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /http/1.0-request",
@@ -390,17 +390,17 @@ function http11goodHost(request, respons
 data = "GET /http/1.1-good-host HTTP/1.1\r\n" +
        "Host: localhost:4444\r\n" +
        "\r\n";
 function check11goodHost(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /http/1.1-good-host",
@@ -427,17 +427,17 @@ function http11ipHost(request, response)
 data = "GET /http/1.1-ip-host HTTP/1.1\r\n" +
        "Host: 127.0.0.1:4444\r\n" +
        "\r\n";
 function check11ipHost(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /http/1.1-ip-host",
@@ -512,17 +512,17 @@ tests.push(test);
 data = "GET /http/1.0-request HTTP/1.0\r\n" +
        "Host: not-localhost:4444\r\n" +
        "\r\n";
 function check10ip(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.0 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.0 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /http/1.0-request",
@@ -549,17 +549,17 @@ function http11goodHostWackyPort(request
 data = "GET /http/1.1-good-host-wacky-port HTTP/1.1\r\n" +
        "Host: localhost\r\n" +
        "\r\n";
 function check11goodHostWackyPort(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /http/1.1-good-host-wacky-port",
--- a/netwerk/test/httpserver/test/test_request_line_split_in_two_packets.js
+++ b/netwerk/test/httpserver/test/test_request_line_split_in_two_packets.js
@@ -60,17 +60,17 @@ for (var i = 0; i < str.length; i += 163
 function checkVeryLongRequestLine(data)
 {
   var iter = LineIterator(data);
 
   print("data length: " + data.length);
   print("iter object: " + iter);
 
   // Status-Line
-  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /very-long-request-line",
@@ -107,17 +107,17 @@ for (var i = 0; i < str.length; i += 100
 function checkLotsOfLeadingBlankLines(data)
 {
   var iter = LineIterator(data);
 
   // Status-Line
   print("data length: " + data.length);
   print("iter object: " + iter);
 
-  do_check_eq(iter.next(), "HTTP/1.1 200 TEST PASSED");
+  do_check_eq(iter.next().value, "HTTP/1.1 200 TEST PASSED");
 
   skipHeaders(iter);
 
   // Okay, next line must be the data we expected to be written
   var body =
     [
      "Method:  GET",
      "Path:    /lots-of-leading-blank-lines",
--- a/netwerk/test/httpserver/test/test_seizepower.js
+++ b/netwerk/test/httpserver/test/test_seizepower.js
@@ -152,17 +152,17 @@ function checkRawData(data)
 {
   do_check_eq(data, "Raw data!");
 }
 
 var data1 = "GET /called-too-late HTTP/1.0\r\n" +
        "\r\n";
 function checkTooLate(data)
 {
-  do_check_eq(LineIterator(data).next(), "too-late passed");
+  do_check_eq(LineIterator(data).next().value, "too-late passed");
 }
 
 var data2 = "GET /exceptions HTTP/1.0\r\n" +
        "\r\n";
 function checkExceptions(data)
 {
   do_check_eq("exceptions test passed", data);
 }
@@ -173,10 +173,10 @@ function checkAsyncSeizure(data)
 {
   do_check_eq(data, "async seizure passed");
 }
 
 var data4 = "GET /seize-after-async HTTP/1.0\r\n" +
        "\r\n";
 function checkSeizeAfterAsync(data)
 {
-  do_check_eq(LineIterator(data).next(), "HTTP/1.0 200 async seizure pass");
+  do_check_eq(LineIterator(data).next().value, "HTTP/1.0 200 async seizure pass");
 }
--- a/netwerk/test/unit/test_backgroundfilesaver.js
+++ b/netwerk/test/unit/test_backgroundfilesaver.js
@@ -257,17 +257,17 @@ add_task(function test_setup()
   // Wait 10 minutes, that is half of the external xpcshell timeout.
   do_timeout(10 * 60 * 1000, function() {
     if (gStillRunning) {
       do_throw("Test timed out.");
     }
   })
 });
 
-add_task(function test_normal()
+add_task(function* test_normal()
 {
   // This test demonstrates the most basic use case.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   // Create the object implementing the output stream.
   let saver = new BackgroundFileSaverOutputStream();
 
   // Set up callbacks for completion and target file name change.
@@ -291,17 +291,17 @@ add_task(function test_normal()
   // Only after we receive the completion notification, we can also be sure that
   // we've received the target file name change notification before it.
   do_check_true(receivedOnTargetChange);
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_combinations()
+add_task(function* test_combinations()
 {
   let initialFile = getTempFile(TEST_FILE_NAME_1);
   let renamedFile = getTempFile(TEST_FILE_NAME_2);
 
   // Keep track of the current file.
   let currentFile = null;
   function onTargetChange(aTarget) {
     currentFile = null;
@@ -398,17 +398,17 @@ add_task(function test_combinations()
         renamedFile.remove(false);
       }
     }
 
     do_print("Test case completed in " + (Date.now() - startTime) + " ms.");
   }
 });
 
-add_task(function test_setTarget_after_close_stream()
+add_task(function* test_setTarget_after_close_stream()
 {
   // This test checks the case where we close the output stream before we call
   // the setTarget method.  All the data should be buffered and written anyway.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   // Test the case where the file does not already exists first, then the case
   // where the file already exists.
   for (let i = 0; i < 2; i++) {
@@ -432,17 +432,17 @@ add_task(function test_setTarget_after_c
     do_check_eq(EXPECTED_HASHES[TEST_DATA_SHORT.length],
                 toHex(saver.sha256Hash));
   }
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_setTarget_fast()
+add_task(function* test_setTarget_fast()
 {
   // This test checks a fast rename of the target file.
   let destFile1 = getTempFile(TEST_FILE_NAME_1);
   let destFile2 = getTempFile(TEST_FILE_NAME_2);
   let saver = new BackgroundFileSaverOutputStream();
   let completionPromise = promiseSaverComplete(saver);
 
   // Set the initial name after the stream is closed, then rename immediately.
@@ -455,17 +455,17 @@ add_task(function test_setTarget_fast()
   yield completionPromise;
 
   // Verify results and clean up.
   do_check_false(destFile1.exists());
   yield promiseVerifyContents(destFile2, TEST_DATA_SHORT);
   destFile2.remove(false);
 });
 
-add_task(function test_setTarget_multiple()
+add_task(function* test_setTarget_multiple()
 {
   // This test checks multiple renames of the target file.
   let destFile = getTempFile(TEST_FILE_NAME_1);
   let saver = new BackgroundFileSaverOutputStream();
   let completionPromise = promiseSaverComplete(saver);
 
   // Rename both before and after the stream is closed.
   saver.setTarget(getTempFile(TEST_FILE_NAME_2), false);
@@ -480,17 +480,17 @@ add_task(function test_setTarget_multipl
 
   // Verify results and clean up.
   do_check_false(getTempFile(TEST_FILE_NAME_2).exists());
   do_check_false(getTempFile(TEST_FILE_NAME_3).exists());
   yield promiseVerifyContents(destFile, TEST_DATA_SHORT);
   destFile.remove(false);
 });
 
-add_task(function test_enableAppend()
+add_task(function* test_enableAppend()
 {
   // This test checks append mode with hashing disabled.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   // Test the case where the file does not already exists first, then the case
   // where the file already exists.
   for (let i = 0; i < 2; i++) {
     let saver = new BackgroundFileSaverOutputStream();
@@ -508,17 +508,17 @@ add_task(function test_enableAppend()
                                    : TEST_DATA_LONG + TEST_DATA_LONG);
     yield promiseVerifyContents(destFile, expectedContents);
   }
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_enableAppend_setTarget_fast()
+add_task(function* test_enableAppend_setTarget_fast()
 {
   // This test checks a fast rename of the target file in append mode.
   let destFile1 = getTempFile(TEST_FILE_NAME_1);
   let destFile2 = getTempFile(TEST_FILE_NAME_2);
 
   // Test the case where the file does not already exists first, then the case
   // where the file already exists.
   for (let i = 0; i < 2; i++) {
@@ -545,17 +545,17 @@ add_task(function test_enableAppend_setT
                                    : TEST_DATA_SHORT + TEST_DATA_SHORT);
     yield promiseVerifyContents(secondFile, expectedContents);
   }
 
   // Clean up.
   destFile1.remove(false);
 });
 
-add_task(function test_enableAppend_hash()
+add_task(function* test_enableAppend_hash()
 {
   // This test checks append mode, also verifying that the computed hash
   // includes the contents of the existing data.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   // Test the case where the file does not already exists first, then the case
   // where the file already exists.
   for (let i = 0; i < 2; i++) {
@@ -577,30 +577,30 @@ add_task(function test_enableAppend_hash
     do_check_eq(EXPECTED_HASHES[expectedContents.length],
                 toHex(saver.sha256Hash));
   }
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_finish_only()
+add_task(function* test_finish_only()
 {
   // This test checks creating the object and doing nothing.
   let destFile = getTempFile(TEST_FILE_NAME_1);
   let saver = new BackgroundFileSaverOutputStream();
   function onTargetChange(aTarget) {
     do_throw("Should not receive the onTargetChange notification.");
   }
   let completionPromise = promiseSaverComplete(saver, onTargetChange);
   saver.finish(Cr.NS_OK);
   yield completionPromise;
 });
 
-add_task(function test_empty()
+add_task(function* test_empty()
 {
   // This test checks we still create an empty file when no data is fed.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   let saver = new BackgroundFileSaverOutputStream();
   let completionPromise = promiseSaverComplete(saver);
 
   saver.setTarget(destFile, false);
@@ -612,17 +612,17 @@ add_task(function test_empty()
   // Verify results.
   do_check_true(destFile.exists());
   do_check_eq(destFile.fileSize, 0);
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_empty_hash()
+add_task(function* test_empty_hash()
 {
   // This test checks the hash of an empty file, both in normal and append mode.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   // Test normal mode first, then append mode.
   for (let i = 0; i < 2; i++) {
     let saver = new BackgroundFileSaverOutputStream();
     if (i == 1) {
@@ -641,17 +641,17 @@ add_task(function test_empty_hash()
     do_check_eq(destFile.fileSize, 0);
     do_check_eq(EXPECTED_HASHES[0], toHex(saver.sha256Hash));
   }
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_invalid_hash()
+add_task(function* test_invalid_hash()
 {
   let saver = new BackgroundFileSaverStreamListener();
   let completionPromise = promiseSaverComplete(saver);
   // We shouldn't be able to get the hash if hashing hasn't been enabled
   try {
     let hash = saver.sha256Hash;
     do_throw("Shouldn't be able to get hash if hashing not enabled");
   } catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) { }
@@ -671,17 +671,17 @@ add_task(function test_invalid_hash()
   // Wait for completion so that the worker thread finishes dealing with the
   // target file. We expect it to fail.
   try {
     yield completionPromise;
     do_throw("completionPromise should throw");
   } catch (ex if ex.result == Cr.NS_ERROR_FAILURE) { }
 });
 
-add_task(function test_signature()
+add_task(function* test_signature()
 {
   // Check that we get a signature if the saver is finished.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   let saver = new BackgroundFileSaverOutputStream();
   let completionPromise = promiseSaverComplete(saver);
 
   try {
@@ -699,17 +699,17 @@ add_task(function test_signature()
 
   // signatureInfo is an empty nsIArray
   do_check_eq(0, saver.signatureInfo.length);
 
   // Clean up.
   destFile.remove(false);
 });
 
-add_task(function test_signature_not_enabled()
+add_task(function* test_signature_not_enabled()
 {
   // Check that we get a signature if the saver is finished on Windows.
   let destFile = getTempFile(TEST_FILE_NAME_1);
 
   let saver = new BackgroundFileSaverOutputStream();
   let completionPromise = promiseSaverComplete(saver);
   saver.setTarget(destFile, false);
   yield promiseCopyToSaver(TEST_DATA_SHORT, saver, true);
--- a/netwerk/test/unit/test_bug826063.js
+++ b/netwerk/test/unit/test_bug826063.js
@@ -20,17 +20,17 @@ function LoadContext(usePrivateBrowsing)
   this.usePrivateBrowsing = usePrivateBrowsing;
 }
 LoadContext.prototype = {
   originAttributes: {},
   QueryInterface: XPCOMUtils.generateQI([Ci.nsILoadContext, Ci.nsIInterfaceRequestor]),
   getInterface: XPCOMUtils.generateQI([Ci.nsILoadContext])
 };
 
-function getChannels() {
+function* getChannels() {
   for (let u of URIs) {
     yield NetUtil.newChannel({
       uri: u,
       loadUsingSystemPrincipal: true
     });
   }
 }
 
--- a/netwerk/test/unit/test_cache_jar.js
+++ b/netwerk/test/unit/test_cache_jar.js
@@ -42,85 +42,80 @@ var thirdTests = [
   [0, false, 0, 0], [0, true, 0, 0], [1, false, 0, 1], [1, true, 0, 1],
   [0, false, 1, 0], [0, true, 1, 0], [1, false, 1, 0], [1, true, 1, 0]
 ];
 var fourthTests = [
   [0, false, 0, 0], [0, true, 0, 0], [1, false, 0, 0], [1, true, 0, 0],
   [0, false, 1, 1], [0, true, 1, 0], [1, false, 1, 0], [1, true, 1, 0]
 ];
 
-function run_all_tests() {
+async function run_all_tests() {
   for (let test of firstTests) {
     handlers_called = 0;
-    var chan = makeChan(URL, test[0], test[1], test[2]);
-    chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
-    yield undefined;
+    await test_channel(...test);
   }
 
   // We can't easily cause webapp data to be cleared from the child process, so skip
   // the rest of these tests.
   let procType = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime).processType;
   if (procType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)
     return;
 
   let attrs_inBrowser = JSON.stringify({ appId:1, inIsolatedMozBrowser:true });
   let attrs_notInBrowser = JSON.stringify({ appId:1 });
 
   Services.obs.notifyObservers(null, "clear-origin-attributes-data", attrs_inBrowser);
 
   for (let test of secondTests) {
     handlers_called = 0;
-    var chan = makeChan(URL, test[0], test[1], test[2]);
-    chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
-    yield undefined;
+    await test_channel(...test);
   }
 
   Services.obs.notifyObservers(null, "clear-origin-attributes-data", attrs_notInBrowser);
   Services.obs.notifyObservers(null, "clear-origin-attributes-data", attrs_inBrowser);
 
   for (let test of thirdTests) {
     handlers_called = 0;
-    var chan = makeChan(URL, test[0], test[1], test[2]);
-    chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
-    yield undefined;
+    await test_channel(...test);
   }
 
   let attrs_userContextId = JSON.stringify({ userContextId: 1 });
   Services.obs.notifyObservers(null, "clear-origin-attributes-data", attrs_userContextId);
 
   for (let test of fourthTests) {
     handlers_called = 0;
-    var chan = makeChan(URL, test[0], test[1], test[2]);
-    chan.asyncOpen2(new ChannelListener(doneFirstLoad, test[3]));
-    yield undefined;
+    await test_channel(...test);
   }
 }
 
-var gTests;
 function run_test() {
   do_get_profile();
   if (!newCacheBackEndUsed()) {
     do_check_true(true, "This test checks only cache2 specific behavior.");
     return;
   }
   do_test_pending();
   httpserv = new HttpServer();
   httpserv.registerPathHandler("/cached", cached_handler);
   httpserv.start(-1);
-  gTests = run_all_tests();
-  gTests.next();
+  run_all_tests().then(() => {
+    do_test_finished();
+  });
 }
 
-function doneFirstLoad(req, buffer, expected) {
+function test_channel(appId, inIsolatedMozBrowser, userContextId, expected) {
+  return new Promise(resolve => {
+    var chan = makeChan(URL, appId, inIsolatedMozBrowser, userContextId);
+    chan.asyncOpen2(new ChannelListener(doneFirstLoad.bind(null, resolve), expected));
+  });
+}
+
+function doneFirstLoad(resolve, req, buffer, expected) {
   // Load it again, make sure it hits the cache
   var oa = req.loadInfo.originAttributes;
   var chan = makeChan(URL, oa.appId, oa.isInIsolatedMozBrowserElement, oa.userContextId);
-  chan.asyncOpen2(new ChannelListener(doneSecondLoad, expected));
+  chan.asyncOpen2(new ChannelListener(doneSecondLoad.bind(null, resolve), expected));
 }
 
-function doneSecondLoad(req, buffer, expected) {
+function doneSecondLoad(resolve, req, buffer, expected) {
   do_check_eq(handlers_called, expected);
-  try {
-    gTests.next();
-  } catch (x) {
-    do_test_finished();
-  }
+  resolve();
 }