From a01759ff9b014b9f9b88231a15f5d60ae7899192 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Mon, 17 Dec 2012 20:38:57 +0900 Subject: [PATCH] Bug 822173 - bunch of editable tests is never invoked, r=marcoz --- .../mochitest/editabletext/editabletext.js | 95 +++++++++++-------- .../tests/mochitest/editabletext/test_1.html | 14 +-- .../tests/mochitest/editabletext/test_2.html | 14 +-- 3 files changed, 72 insertions(+), 51 deletions(-) diff --git a/accessible/tests/mochitest/editabletext/editabletext.js b/accessible/tests/mochitest/editabletext/editabletext.js index b3d6e3d4fb91..96ce0c33a407 100644 --- a/accessible/tests/mochitest/editabletext/editabletext.js +++ b/accessible/tests/mochitest/editabletext/editabletext.js @@ -33,6 +33,26 @@ function editableTextTestRun() */ function editableTextTest(aID) { + /** + * Schedule a test, the given function with its arguments will be executed + * when preceding test is complete. + */ + this.scheduleTest = function scheduleTest(aFunc) + { + // A data container acts like a dummy invoker, it's never invoked but + // it's used to generate real invoker when previous invoker was handled. + var dataContainer = { + func: aFunc, + funcArgs: Array.slice(arguments, 1) + }; + this.mEventQueue.push(dataContainer); + + if (!this.mEventQueueReady) { + this.unwrapNextTest(); + this.mEventQueueReady = true; + } + } + /** * setTextContents test. */ @@ -51,7 +71,7 @@ function editableTextTest(aID) var oldValue = getValue(aID); var removeTripple = oldValue ? [0, oldValue.length, oldValue] : null; - this.scheduleTest(aID, removeTripple, insertTripple, setTextContentsInvoke, + this.generateTest(aID, removeTripple, insertTripple, setTextContentsInvoke, getValueChecker(aID, aValue), testID); } @@ -70,7 +90,7 @@ function editableTextTest(aID) } var resPos = (aResPos != undefined) ? aResPos : aPos; - this.scheduleTest(aID, null, [resPos, resPos + aStr.length, aStr], + this.generateTest(aID, null, [resPos, resPos + aStr.length, aStr], insertTextInvoke, getValueChecker(aID, aResStr), testID); } @@ -88,7 +108,7 @@ function editableTextTest(aID) acc.copyText(aStartPos, aEndPos); } - this.scheduleTest(aID, null, null, copyTextInvoke, + this.generateTest(aID, null, null, copyTextInvoke, getClipboardChecker(aID, aClipboardStr), testID); } @@ -108,7 +128,7 @@ function editableTextTest(aID) acc.pasteText(aPos); } - this.scheduleTest(aID, null, [aStartPos, aEndPos, getTextFromClipboard], + this.generateTest(aID, null, [aStartPos, aEndPos, getTextFromClipboard], copyNPasteInvoke, getValueChecker(aID, aResStr), testID); } @@ -129,7 +149,7 @@ function editableTextTest(aID) var resStartPos = (aResStartPos != undefined) ? aResStartPos : aStartPos; var resEndPos = (aResEndPos != undefined) ? aResEndPos : aEndPos; - this.scheduleTest(aID, [resStartPos, resEndPos, getTextFromClipboard], null, + this.generateTest(aID, [resStartPos, resEndPos, getTextFromClipboard], null, cutTextInvoke, getValueChecker(aID, aResStr), testID); } @@ -149,7 +169,7 @@ function editableTextTest(aID) acc.pasteText(aPos); } - this.scheduleTest(aID, [aStartPos, aEndPos, getTextFromClipboard], + this.generateTest(aID, [aStartPos, aEndPos, getTextFromClipboard], [aPos, -1, getTextFromClipboard], cutNPasteTextInvoke, getValueChecker(aID, aResStr), testID); @@ -168,7 +188,7 @@ function editableTextTest(aID) acc.pasteText(aPos); } - this.scheduleTest(aID, null, [aPos, -1, getTextFromClipboard], + this.generateTest(aID, null, [aPos, -1, getTextFromClipboard], pasteTextInvoke, getValueChecker(aID, aResStr), testID); } @@ -177,35 +197,20 @@ function editableTextTest(aID) */ this.deleteText = function deleteText(aStartPos, aEndPos, aResStr) { - function getRemovedText() { return invoker.removedText; } + var testID = "deleteText from " + aStartPos + " to " + aEndPos + + " for " + prettyName(aID); - var invoker = { - eventSeq: [ - new textChangeChecker(aID, aStartPos, aEndPos, getRemovedText, false) - ], + var oldValue = getValue(aID).substring(aStartPos, aEndPos); + var removeTripple = oldValue ? [aStartPos, aEndPos, oldValue] : null; - invoke: function invoke() - { - var acc = getAccessible(aID, - [nsIAccessibleText, nsIAccessibleEditableText]); + function deleteTextInvoke() + { + var acc = getAccessible(aID, [nsIAccessibleEditableText]); + acc.deleteText(aStartPos, aEndPos); + } - this.removedText = acc.getText(aStartPos, aEndPos); - - acc.deleteText(aStartPos, aEndPos); - }, - - finalCheck: function finalCheck() - { - getValueChecker(aID, aResStr).check(); - }, - - getID: function getID() - { - return "deleteText from " + aStartPos + " to " + aEndPos + " for " + - prettyName(aID); - } - }; - this.mEventQueue.push(invoker); + this.generateTest(aID, removeTripple, null, deleteTextInvoke, + getValueChecker(aID, aResStr), testID); } ////////////////////////////////////////////////////////////////////////////// @@ -265,16 +270,31 @@ function editableTextTest(aID) } /** - * Create an invoker for the test and push it into event queue. + * Process next scheduled test. */ - this.scheduleTest = function scheduleTest(aID, aRemoveTriple, aInsertTriple, + this.unwrapNextTest = function unwrapNextTest() + { + var data = this.mEventQueue.mInvokers[this.mEventQueue.mIndex + 1]; + if (data) + data.func.apply(this, data.funcArgs); + } + + /** + * Used to generate an invoker object for the sheduled test. + */ + this.generateTest = function generateTest(aID, aRemoveTriple, aInsertTriple, aInvokeFunc, aChecker, aInvokerID) { + var et = this; var invoker = { eventSeq: [], invoke: aInvokeFunc, - finalCheck: function finalCheck() { aChecker.check(); }, + finalCheck: function finalCheck() + { + aChecker.check(); + et.unwrapNextTest(); // replace dummy invoker on real invoker object. + }, getID: function getID() { return aInvokerID; } }; @@ -292,7 +312,7 @@ function editableTextTest(aID) invoker.eventSeq.push(checker); } - this.mEventQueue.push(invoker); + this.mEventQueue.mInvokers[this.mEventQueue.mIndex + 1] = invoker; } /** @@ -318,5 +338,6 @@ function editableTextTest(aID) } this.mEventQueue = new eventQueue(); + this.mEventQueueReady = false; } diff --git a/accessible/tests/mochitest/editabletext/test_1.html b/accessible/tests/mochitest/editabletext/test_1.html index 845f6de7e80e..2927655c7d04 100644 --- a/accessible/tests/mochitest/editabletext/test_1.html +++ b/accessible/tests/mochitest/editabletext/test_1.html @@ -25,16 +25,16 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=452161 ////////////////////////////////////////////////////////////////////////// // setTextContents - et.setTextContents("hello"); - et.setTextContents("olleh", aTrailChar); // due to some reason this reports '\n' in the end - et.setTextContents(""); + et.scheduleTest(et.setTextContents, "hello"); + et.scheduleTest(et.setTextContents, "olleh", aTrailChar); // due to some reason this reports '\n' in the end + et.scheduleTest(et.setTextContents, ""); ////////////////////////////////////////////////////////////////////////// // insertText - et.insertText("hello", 0, "hello"); - et.insertText("ma ", 0, "ma hello"); - et.insertText("ma", 2, "mama hello"); - et.insertText(" hello", 10, "mama hello hello"); + et.scheduleTest(et.insertText, "hello", 0, "hello"); + et.scheduleTest(et.insertText, "ma ", 0, "ma hello"); + et.scheduleTest(et.insertText, "ma", 2, "mama hello"); + et.scheduleTest(et.insertText, " hello", 10, "mama hello hello"); // XXX: bug 452584 diff --git a/accessible/tests/mochitest/editabletext/test_2.html b/accessible/tests/mochitest/editabletext/test_2.html index 25bd5e662ab7..5d96ebf35866 100644 --- a/accessible/tests/mochitest/editabletext/test_2.html +++ b/accessible/tests/mochitest/editabletext/test_2.html @@ -22,14 +22,14 @@ // 'ee' insertion/removal at 1 or 2 offset of 'hello'/'heeello' string // reports 'ee' text was inserted/removed at 2 offset. - et.insertText("ee", 1, "heeello", 2); - et.copyText(1, 3, "ee"); - et.cutText(1, 3, "hello", 2, 4); - et.insertText("ee", 2, "heeello", 2); - et.cutText(2, 4, "hello", 2, 4); + et.scheduleTest(et.insertText, "ee", 1, "heeello", 2); + et.scheduleTest(et.copyText, 1, 3, "ee"); + et.scheduleTest(et.cutText, 1, 3, "hello", 2, 4); + et.scheduleTest(et.insertText, "ee", 2, "heeello", 2); + et.scheduleTest(et.cutText, 2, 4, "hello", 2, 4); - et.deleteText(1, 3, "hlo"); - et.pasteText(1, "heelo"); + et.scheduleTest(et.deleteText, 1, 3, "hlo"); + et.scheduleTest(et.pasteText, 1, "heelo"); var testRun = new editableTextTestRun(); testRun.add(et);