Bug 1110759 - Remove Iterator() from some tests. r=smaug
authorTom Schuster <evilpies@gmail.com>
Thu, 08 Jan 2015 19:58:45 +0100
changeset 248653 6429d270c004f34fe264ee5c7d64f4d552e89a9d
parent 248652 c3179d05230b05a39178a5dd901695f7bf3060f0
child 248654 70f64ef5569e12ebd16e206b5e067f5378bc3ada
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1110759
milestone37.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 1110759 - Remove Iterator() from some tests. r=smaug
accessible/tests/mochitest/jsat/jsatcommon.js
browser/base/content/test/social/head.js
dom/html/test/forms/test_input_number_mouse_events.html
dom/html/test/forms/test_input_untrusted_key_events.html
toolkit/components/social/test/browser/head.js
toolkit/content/tests/widgets/test_popupanchor.xul
--- a/accessible/tests/mochitest/jsat/jsatcommon.js
+++ b/accessible/tests/mochitest/jsat/jsatcommon.js
@@ -117,38 +117,38 @@ var AccessFuTest = {
     // Finish through idle callback to let AccessFu._disable complete.
     SimpleTest.executeSoon(function () {
       AccessFu.detach();
       SimpleTest.finish();
     });
   },
 
   nextTest: function AccessFuTest_nextTest() {
-    var testFunc;
-    try {
-      // Get the next test function from the iterator. If none left,
-      // StopIteration exception is thrown.
-      testFunc = gIterator.next()[1];
-    } catch (ex) {
-      // StopIteration exception.
+    var result = gIterator.next();
+    if (result.done) {
       this.finish();
       return;
     }
+    var testFunc = result.value;
     testFunc();
   },
 
   runTests: function AccessFuTest_runTests(aAdditionalPrefs) {
     if (gTestFuncs.length === 0) {
       ok(false, "No tests specified!");
       SimpleTest.finish();
       return;
     }
 
     // Create an Iterator for gTestFuncs array.
-    gIterator = Iterator(gTestFuncs); // jshint ignore:line
+    gIterator = (function*() {
+      for (var testFunc of gTestFuncs) {
+        yield testFunc;
+      }
+    })();
 
     // Start AccessFu and put it in stand-by.
     Components.utils.import("resource://gre/modules/accessibility/AccessFu.jsm");
 
     AccessFu.attach(getMainChromeWindow(window));
 
     AccessFu.readyCallback = function readyCallback() {
       // Enable logging to the console service.
--- a/browser/base/content/test/social/head.js
+++ b/browser/base/content/test/social/head.js
@@ -162,41 +162,46 @@ function runSocialTestWithProvider(manif
           callback(finishSocialTest);
         }, "providers added and enabled");
       }
     });
   });
 }
 
 function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
-  let testIter = Iterator(tests);
+  let testIter = (function*() {
+    for (let name in tests) {
+      if (tests.hasOwnProperty(name)) {
+        yield [name, tests[name]];
+      }
+    }
+  })();
   let providersAtStart = Social.providers.length;
   info("runSocialTests: start test run with " + providersAtStart + " providers");
   window.focus();
 
   PopupNotifications.transitionsEnabled = false;
 
   if (cbPreTest === undefined) {
     cbPreTest = function(cb) {cb()};
   }
   if (cbPostTest === undefined) {
     cbPostTest = function(cb) {cb()};
   }
 
   function runNextTest() {
-    let name, func;
-    try {
-      [name, func] = testIter.next();
-    } catch (err if err instanceof StopIteration) {
+    let result = testIter.next();
+    if (result.done) {
       // out of items:
       (cbFinish || defaultFinishChecks)();
       is(providersAtStart, Social.providers.length,
          "runSocialTests: finish test run with " + Social.providers.length + " providers");
       return;
     }
+    let [name, func] = result.value;
     // We run on a timeout as the frameworker also makes use of timeouts, so
     // this helps keep the debug messages sane.
     executeSoon(function() {
       function cleanupAndRunNextTest() {
         info("sub-test " + name + " complete");
         cbPostTest(runNextTest);
       }
       cbPreTest(function() {
--- a/dom/html/test/forms/test_input_number_mouse_events.html
+++ b/dom/html/test/forms/test_input_number_mouse_events.html
@@ -89,31 +89,27 @@ function test() {
   is(input.value, 1, "Test that preventDefault() works for click on spin-down button");
   input.removeEventListener("mousedown", preventDefault, false);
 
   // Run the spin tests:
   runNextSpinTest();
 }
 
 function runNextSpinTest() {
-  try {
-    var [index, test] = spinTests.next();
-    test();
-  } catch(e) {
-    if (e == StopIteration) {
-      SimpleTest.finish();
-      return; // We're all done
-    }
-    throw e;
+  var test = spinTests.shift();
+  if (!test) {
+    SimpleTest.finish();
+    return;
   }
+  test();
 }
 
 const SETTIMEOUT_DELAY = 500;
 
-var spinTests = Iterator([
+var spinTests = [
   // Test spining when the mouse button is kept depressed on the spin-up
   // button, then moved over the spin-down button:
   function() {
     var inputEventCount = 0;
     input.value = 0;
     input.addEventListener("input", function(evt) {
       ++inputEventCount;
       if (inputEventCount == 3) {
@@ -187,14 +183,14 @@ var spinTests = Iterator([
           synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mouseup" });
           input.type = "number"; // restore
           runNextSpinTest();
         }, SETTIMEOUT_DELAY);
       }
     }, false);
     synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mousedown" });
   }
-]);
+];
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/html/test/forms/test_input_untrusted_key_events.html
+++ b/dom/html/test/forms/test_input_untrusted_key_events.html
@@ -12,22 +12,22 @@
   <input id="input">
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(runNextTest, window);
 
-const kTests = Iterator([
+const kTests = [
   { type: "text", value: "foo", key: "b", expectedNewValue: "foo" },
   { type: "number", value: "123", key: "4", expectedNewValue: "123" },
   { type: "number", value: "123", key: KeyEvent.DOM_VK_UP, expectedNewValue: "123" },
   { type: "number", value: "123", key: KeyEvent.DOM_VK_DOWN, expectedNewValue: "123" },
-]);
+];
 
 function sendUntrustedKeyEvent(eventType, keyCode, target) {
   var evt = document.createEvent("KeyboardEvent");
   var canBubbleArg = true;
   var cancelableArg = true;
   var viewArg = document.defaultView;
   var ctrlKeyArg = false;
   var altKeyArg = false;
@@ -65,24 +65,21 @@ function runNextTest() {
          " after being sent '" + previousTest.key + "' key events");
   }
 
   // reset flags
   gotEvents.keydown = false;
   gotEvents.keyup = false;
   gotEvents.keypress = false;
 
-  try {
-    var [index, test] = kTests.next();
-  } catch(e) {
-    if (e == StopIteration) {
-      SimpleTest.finish();
-      return; // We're all done
-    }
-    throw e;
+
+  var test = kTests.shift();
+  if (!test) {
+    SimpleTest.finish();
+    return; // We're all done
   }
 
   input.type = test.type;
   input.focus(); // make sure we still have focus after type change
   input.value = test.value;
 
   sendUntrustedKeyEvent("keydown", test.key, input);
   sendUntrustedKeyEvent("keyup", test.key, input);
--- a/toolkit/components/social/test/browser/head.js
+++ b/toolkit/components/social/test/browser/head.js
@@ -8,34 +8,39 @@ let SocialService = Components.utils.imp
 // The "test object" should be an object with function names as keys and a
 // function as the value.  The functions will be called with a "cbnext" param
 // which should be called when the test is complete.
 // eg:
 // test = {
 //   foo: function(cbnext) {... cbnext();}
 // }
 function runTests(tests, cbPreTest, cbPostTest, cbFinish) {
-  let testIter = Iterator(tests);
+  let testIter = (function*() {
+    for (let name in tests) {
+      if (tests.hasOwnProperty(name)) {
+        yield [name, tests[name]];
+      }
+    }
+  })();
 
   if (cbPreTest === undefined) {
     cbPreTest = function(cb) {cb()};
   }
   if (cbPostTest === undefined) {
     cbPostTest = function(cb) {cb()};
   }
 
   function runNextTest() {
-    let name, func;
-    try {
-      [name, func] = testIter.next();
-    } catch (err if err instanceof StopIteration) {
+    let result = testIter.next();
+    if (result.done) {
       // out of items:
       (cbFinish || finish)();
       return;
     }
+    let [name, func] = result.value;
     // We run on a timeout as the frameworker also makes use of timeouts, so
     // this helps keep the debug messages sane.
     executeSoon(function() {
       function cleanupAndRunNextTest() {
         info("sub-test " + name + " complete");
         cbPostTest(runNextTest);
       }
       cbPreTest(function() {
--- a/toolkit/content/tests/widgets/test_popupanchor.xul
+++ b/toolkit/content/tests/widgets/test_popupanchor.xul
@@ -324,28 +324,25 @@ var tests = [
       // we just don't check the offset.
       isArrowPositionedOn("left", null);
       next();
     });
   }],
 ]
 
 function runTests() {
-  var testIter = Iterator(tests);
   function runNextTest() {
-    let name, anchorPos, test;
-    try {
-      let index;
-      [index, [name, anchorPos, test]] = testIter.next();
-    } catch (err if err instanceof StopIteration) {
+    let result = tests.shift();
+    if (!result) {
       // out of tests
       panel.hidePopup();
       SimpleTest.finish();
       return;
     }
+    let [name, anchorPos, test] = result;
     SimpleTest.info("sub-test " + anchorPos + "." + name + " starting");
     // first arrange for the anchor to be where the test requires it.
     panel.hidePopup();
     panel.sizeTo(100, 50);
     // hide all the anchors here, then later we make one of them visible.
     document.getElementById("anchor-left-wrapper").style.display = "none";
     document.getElementById("anchor-middle-wrapper").style.display = "none";
     document.getElementById("anchor-right-wrapper").style.display = "none";