Bug 1110759 - Remove Iterator() from some tests. r=smaug

This commit is contained in:
Tom Schuster 2015-01-08 19:58:45 +01:00
parent 94ec2143c9
commit b7974c146f
6 changed files with 45 additions and 45 deletions

View File

@ -122,16 +122,12 @@ var AccessFuTest = {
}, },
nextTest: function AccessFuTest_nextTest() { nextTest: function AccessFuTest_nextTest() {
var testFunc; var result = gIterator.next();
try { if (result.done) {
// Get the next test function from the iterator. If none left,
// StopIteration exception is thrown.
testFunc = gIterator.next()[1];
} catch (ex) {
// StopIteration exception.
this.finish(); this.finish();
return; return;
} }
var testFunc = result.value;
testFunc(); testFunc();
}, },
@ -143,7 +139,11 @@ var AccessFuTest = {
} }
// Create an Iterator for gTestFuncs array. // 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. // Start AccessFu and put it in stand-by.
Components.utils.import("resource://gre/modules/accessibility/AccessFu.jsm"); Components.utils.import("resource://gre/modules/accessibility/AccessFu.jsm");

View File

@ -167,7 +167,13 @@ function runSocialTestWithProvider(manifest, callback, finishcallback) {
} }
function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) { 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; let providersAtStart = Social.providers.length;
info("runSocialTests: start test run with " + providersAtStart + " providers"); info("runSocialTests: start test run with " + providersAtStart + " providers");
window.focus(); window.focus();
@ -182,16 +188,15 @@ function runSocialTests(tests, cbPreTest, cbPostTest, cbFinish) {
} }
function runNextTest() { function runNextTest() {
let name, func; let result = testIter.next();
try { if (result.done) {
[name, func] = testIter.next();
} catch (err if err instanceof StopIteration) {
// out of items: // out of items:
(cbFinish || defaultFinishChecks)(); (cbFinish || defaultFinishChecks)();
is(providersAtStart, Social.providers.length, is(providersAtStart, Social.providers.length,
"runSocialTests: finish test run with " + Social.providers.length + " providers"); "runSocialTests: finish test run with " + Social.providers.length + " providers");
return; return;
} }
let [name, func] = result.value;
// We run on a timeout as the frameworker also makes use of timeouts, so // We run on a timeout as the frameworker also makes use of timeouts, so
// this helps keep the debug messages sane. // this helps keep the debug messages sane.
executeSoon(function() { executeSoon(function() {

View File

@ -94,21 +94,17 @@ function test() {
} }
function runNextSpinTest() { function runNextSpinTest() {
try { var test = spinTests.shift();
var [index, test] = spinTests.next(); if (!test) {
test(); SimpleTest.finish();
} catch(e) { return;
if (e == StopIteration) {
SimpleTest.finish();
return; // We're all done
}
throw e;
} }
test();
} }
const SETTIMEOUT_DELAY = 500; const SETTIMEOUT_DELAY = 500;
var spinTests = Iterator([ var spinTests = [
// Test spining when the mouse button is kept depressed on the spin-up // Test spining when the mouse button is kept depressed on the spin-up
// button, then moved over the spin-down button: // button, then moved over the spin-down button:
function() { function() {
@ -192,7 +188,7 @@ var spinTests = Iterator([
}, false); }, false);
synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mousedown" }); synthesizeMouse(input, SPIN_DOWN_X, SPIN_DOWN_Y, { type: "mousedown" });
} }
]); ];
</script> </script>
</pre> </pre>

View File

@ -17,12 +17,12 @@
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runNextTest, window); SimpleTest.waitForFocus(runNextTest, window);
const kTests = Iterator([ const kTests = [
{ type: "text", value: "foo", key: "b", expectedNewValue: "foo" }, { type: "text", value: "foo", key: "b", expectedNewValue: "foo" },
{ type: "number", value: "123", key: "4", expectedNewValue: "123" }, { 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_UP, expectedNewValue: "123" },
{ type: "number", value: "123", key: KeyEvent.DOM_VK_DOWN, expectedNewValue: "123" }, { type: "number", value: "123", key: KeyEvent.DOM_VK_DOWN, expectedNewValue: "123" },
]); ];
function sendUntrustedKeyEvent(eventType, keyCode, target) { function sendUntrustedKeyEvent(eventType, keyCode, target) {
var evt = document.createEvent("KeyboardEvent"); var evt = document.createEvent("KeyboardEvent");
@ -70,14 +70,11 @@ function runNextTest() {
gotEvents.keyup = false; gotEvents.keyup = false;
gotEvents.keypress = false; gotEvents.keypress = false;
try {
var [index, test] = kTests.next(); var test = kTests.shift();
} catch(e) { if (!test) {
if (e == StopIteration) { SimpleTest.finish();
SimpleTest.finish(); return; // We're all done
return; // We're all done
}
throw e;
} }
input.type = test.type; input.type = test.type;

View File

@ -13,7 +13,13 @@ let SocialService = Components.utils.import("resource://gre/modules/SocialServic
// foo: function(cbnext) {... cbnext();} // foo: function(cbnext) {... cbnext();}
// } // }
function runTests(tests, cbPreTest, cbPostTest, cbFinish) { 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) { if (cbPreTest === undefined) {
cbPreTest = function(cb) {cb()}; cbPreTest = function(cb) {cb()};
@ -23,14 +29,13 @@ function runTests(tests, cbPreTest, cbPostTest, cbFinish) {
} }
function runNextTest() { function runNextTest() {
let name, func; let result = testIter.next();
try { if (result.done) {
[name, func] = testIter.next();
} catch (err if err instanceof StopIteration) {
// out of items: // out of items:
(cbFinish || finish)(); (cbFinish || finish)();
return; return;
} }
let [name, func] = result.value;
// We run on a timeout as the frameworker also makes use of timeouts, so // We run on a timeout as the frameworker also makes use of timeouts, so
// this helps keep the debug messages sane. // this helps keep the debug messages sane.
executeSoon(function() { executeSoon(function() {

View File

@ -329,18 +329,15 @@ var tests = [
] ]
function runTests() { function runTests() {
var testIter = Iterator(tests);
function runNextTest() { function runNextTest() {
let name, anchorPos, test; let result = tests.shift();
try { if (!result) {
let index;
[index, [name, anchorPos, test]] = testIter.next();
} catch (err if err instanceof StopIteration) {
// out of tests // out of tests
panel.hidePopup(); panel.hidePopup();
SimpleTest.finish(); SimpleTest.finish();
return; return;
} }
let [name, anchorPos, test] = result;
SimpleTest.info("sub-test " + anchorPos + "." + name + " starting"); SimpleTest.info("sub-test " + anchorPos + "." + name + " starting");
// first arrange for the anchor to be where the test requires it. // first arrange for the anchor to be where the test requires it.
panel.hidePopup(); panel.hidePopup();