From c0a1acc466f9bb8b9ef5b86882a15d22761c1b25 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Wed, 13 Aug 2014 17:43:50 +1000 Subject: [PATCH 1/5] Cope with test names containing angle brackets --- webodf/lib/core/UnitTester.js | 7 ++++++- webodf/tests/tests.js | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/webodf/lib/core/UnitTester.js b/webodf/lib/core/UnitTester.js index 8bbf394c4..234821f5e 100644 --- a/webodf/lib/core/UnitTester.js +++ b/webodf/lib/core/UnitTester.js @@ -568,8 +568,13 @@ core.UnitTester = function UnitTester() { * @return {!string} **/ function link(text, code) { + // NASTY HACK, DO NOT RE-USE. String concatenation with uncontrolled user input is a bad idea for building DOM + // fragments everyone. If you feel tempted to extract the HTML escape thing from here, please force yourself to + // visit http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/ first, and learn a better + // approach to take. + return "" - + text + ""; + + text.replace(/"; } /** * @type {function(!{description:string,suite:!Array.,success:boolean,log:!Array.<{category:string,message:string}>,time:number})} diff --git a/webodf/tests/tests.js b/webodf/tests/tests.js index e4033ff3c..94d680b04 100644 --- a/webodf/tests/tests.js +++ b/webodf/tests/tests.js @@ -188,7 +188,7 @@ function runSuite(name) { } function runTest(suite, name) { "use strict"; - runtime.getWindow().location.search = "?suite=" + suite + "&test=" + name; + runtime.getWindow().location.search = "?suite=" + suite + "&test=" + encodeURIComponent(name); } function runSelectedTests(selectedTests) { @@ -211,7 +211,7 @@ function getTestNameFromUrl(selectedTests) { return; } if (options.test) { - selectedTests.testNames = options.test.split(","); + selectedTests.testNames = options.test.split(",").map(decodeURIComponent); } } From 1cd6d61a50ab20f1e20577da1f8516525907d8e0 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Wed, 13 Aug 2014 17:17:55 +1000 Subject: [PATCH 2/5] Verify the number of steps vs. expected number of cursor positions --- webodf/tests/ops/OdtDocumentTests.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/webodf/tests/ops/OdtDocumentTests.js b/webodf/tests/ops/OdtDocumentTests.js index 99cab2728..80c88ad1f 100644 --- a/webodf/tests/ops/OdtDocumentTests.js +++ b/webodf/tests/ops/OdtDocumentTests.js @@ -160,9 +160,11 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { serializer.filter = new OdfOrCursorNodeFilter(); runtime.log("Scenario: " + documentString); t.segmentCount = segments.length; + t.expectedCursorPositionsCount = segments.length - 1; // e.g., | has two segments, but only one cursor position r.shouldBe(t, "t.segmentCount > 1", "true"); documentRoot = createOdtDocument(segments.join("")); t.documentLength = t.odtDocument.convertDomPointToCursorStep(documentRoot, documentRoot.childNodes.length, PREVIOUS); + r.shouldBe(t, "t.expectedCursorPositionsCount", "(t.documentLength+1)"); // Test iteration forward for (position = 1; position < segments.length; position += 1) { From e72e8b8b253525e7b432868080c02fb9a9b72256 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Wed, 13 Aug 2014 17:19:08 +1000 Subject: [PATCH 3/5] Fix doc length check when iterating backwards --- webodf/tests/ops/OdtDocumentTests.js | 1 + 1 file changed, 1 insertion(+) diff --git a/webodf/tests/ops/OdtDocumentTests.js b/webodf/tests/ops/OdtDocumentTests.js index 80c88ad1f..2fbefd160 100644 --- a/webodf/tests/ops/OdtDocumentTests.js +++ b/webodf/tests/ops/OdtDocumentTests.js @@ -188,6 +188,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { // Test iteration backward for (position = segments.length - 1; position > 0; position -= 1) { setCursorPosition(step); + t.currentDocLength = t.odtDocument.convertDomPointToCursorStep(documentRoot, documentRoot.childNodes.length, PREVIOUS); r.shouldBe(t, "t.currentDocLength", "t.documentLength"); t.expected = "" + segments.slice(0, position).join("") + "|" + segments.slice(position, segments.length).join("") + From 2185247868c57f6f4905a9347f0c49dfaefed888 Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Wed, 13 Aug 2014 17:34:51 +1000 Subject: [PATCH 4/5] Report one test per cursor position document fragment --- webodf/tests/ops/OdtDocumentTests.js | 165 ++++++++++++++------------- 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/webodf/tests/ops/OdtDocumentTests.js b/webodf/tests/ops/OdtDocumentTests.js index 2fbefd160..4f6f4a37d 100644 --- a/webodf/tests/ops/OdtDocumentTests.js +++ b/webodf/tests/ops/OdtDocumentTests.js @@ -158,7 +158,6 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { documentRoot; serializer.filter = new OdfOrCursorNodeFilter(); - runtime.log("Scenario: " + documentString); t.segmentCount = segments.length; t.expectedCursorPositionsCount = segments.length - 1; // e.g., | has two segments, but only one cursor position r.shouldBe(t, "t.segmentCount > 1", "true"); @@ -366,76 +365,6 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { r.shouldBe(t, "t.rootToFocus", "1"); } - function testAvailablePositions_EmptyParagraph() { - // Examples from README_cursorpositions.txt - testCursorPositions("|"); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest("|"); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest("|"); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest("|"); - testCursorPositions("| "); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest(" | "); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest(" | "); - } - function testAvailablePositions_SimpleTextNodes() { - // Examples from README_cursorpositions.txt - testCursorPositions("|A|B|C|"); - } - function testAvailablePositions_MixedSpans() { - // Examples from README_cursorpositions.txt - testCursorPositions("|A|B|C|"); - testCursorPositions("|A|B|C|"); - testCursorPositions("|A|B|C|"); - testCursorPositions("|A|B|C|"); - testCursorPositions("|A|B|C|"); - } - function testAvailablePositions_Whitespace() { - // Examples from README_cursorpositions.txt - testCursorPositions("|A| |B|C|"); - testCursorPositions(" |A| "); - testCursorPositions("|A| |B|"); - testCursorPositions(" |A| | B| "); - testCursorPositions(" |a| "); - testCursorPositions(" |a| | b| "); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest(" |a| "); - testCursorPositions(" |a| "); - testCursorPositions(" |a|"); - } - function testAvailablePositions_SpaceElements() { - // Examples from README_cursorpositions.txt - testCursorPositions("|A| |B|C|"); - // Unexpanded spaces - Not really supported, but interesting to test - testCursorPositions("|A||B|C|"); - // Slight span nesting and positioning - testCursorPositions("| |"); - // TODO behaviour is different from README_cursorpositions - // cursorPositionsTest(" |A| | | |B| "); - testCursorPositions("| | | |"); - testCursorPositions("| | | |"); - testCursorPositions("|a| | | "); - testCursorPositions("|a| | |"); - } - function testAvailablePositions_DrawElements() { - testCursorPositions("|data|"); - testCursorPositions("|data|"); - } - function testAvailablePositions_Annotations() { - testCursorPositions('|a|b|||c|d|1|2|'); - testCursorPositions('|a||b||c|1|2|'); - testCursorPositions('|a||b||1|2|'); - } - function testAvailablePositions_BetweenAnnotationAndSpan() { - testCursorPositions('|a|b|||c|d|1|2|'); - testCursorPositions('|a||b||c|1|2|'); - testCursorPositions('|a||b||1|2|'); - } - - function getTextNodeAtStep_BeginningOfTextNode() { var doc = createOdtDocument("ABCD"); t.paragraph = doc.getElementsByTagNameNS(odf.Namespaces.textns, "p")[0]; @@ -627,6 +556,89 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { r.shouldBe(t, "t.domPosition.textNode.previousSibling.localName", "'cursor'"); } + function cursorPositionTests() { + // Examples from README_cursorpositions.txt + + return [ + // *************** Empty Paragraph *************** // + // Examples from README_cursorpositions.txt + "|", + // TODO behaviour is different from README_cursorpositions + // "|", + // TODO behaviour is different from README_cursorpositions + // "|", + // TODO behaviour is different from README_cursorpositions + // "|", + "| ", + // TODO behaviour is different from README_cursorpositions + // " | ", + // TODO behaviour is different from README_cursorpositions + // " | ", + + + // *************** Simple Text Nodes *************** // + "|A|B|C|", + + + // *************** Mixed spans *************** // + "|A|B|C|", + "|A|B|C|", + "|A|B|C|", + "|A|B|C|", + "|A|B|C|", + + + // *************** Whitespace *************** // + "|A| |B|C|", + " |A| ", + "|A| |B|", + " |A| | B| ", + " |a| ", + " |a| | b| ", + // TODO behaviour is different from README_cursorpositions + // cursorPositionsTest(" |a| ", + " |a| ", + " |a|", + + + // *************** Space elements *************** // + "|A| |B|C|", + // Unexpanded spaces - Not really supported, but interesting to test + "|A||B|C|", + // Slight span nesting and positioning + "| |", + // TODO behaviour is different from README_cursorpositions + // cursorPositionsTest(" |A| | | |B| ", + "| | | |", + "| | | |", + "|a| | | ", + "|a| | |", + + + // *************** Draw elements *************** // + "|data|", + "|data|", + + + // *************** Annotations *************** // + '|a|b|||c|d|1|2|', + '|a||b||c|1|2|', + '|a||b||1|2|', + + + // *************** Annotations with highlighting *************** // + '|a|b|||c|d|1|2|', + '|a||b||c|1|2|', + '|a||b||1|2|' + + ].map(function(testInput) { + return { + name: "cursorPositions " + testInput, + f: testCursorPositions.bind(undefined, testInput) + }; + }); + } + this.setUp = function () { var doc, stylesElement; testarea = core.UnitTest.provideTestAreaDiv(); @@ -659,15 +671,6 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { testFixCursorPositions_CursorNearParagraphStart_ForwardSelection, testFixCursorPositions_CursorNearParagraphStart_ReverseSelection, - testAvailablePositions_EmptyParagraph, - testAvailablePositions_SimpleTextNodes, - testAvailablePositions_MixedSpans, - testAvailablePositions_Whitespace, - testAvailablePositions_SpaceElements, - testAvailablePositions_DrawElements, - testAvailablePositions_Annotations, - testAvailablePositions_BetweenAnnotationAndSpan, - getTextNodeAtStep_BeginningOfTextNode, getTextNodeAtStep_EndOfTextNode, getTextNodeAtStep_PositionWithNoTextNode_AddsNewNode_Front, @@ -683,7 +686,7 @@ ops.OdtDocumentTests = function OdtDocumentTests(runner) { getTextNodeAtStep_At4_PutsTargetMemberCursor_BeforeTextNode, getTextNodeAtStep_AfterNonText_PutsTargetMemberCursor_BeforeTextNode, getTextNodeAtStep_EmptyP_MovesAllCursors_BeforeTextNode - ]); + ]).concat(cursorPositionTests()); }; this.asyncTests = function () { return [ From 294542b6d2dd629412abcc33d6c7256500b66acc Mon Sep 17 00:00:00 2001 From: Philip Peitsch Date: Fri, 22 Aug 2014 09:25:53 +1000 Subject: [PATCH 5/5] Print function result rather than function.toString for test description --- webodf/lib/core/UnitTester.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webodf/lib/core/UnitTester.js b/webodf/lib/core/UnitTester.js index 234821f5e..ee0be4b57 100644 --- a/webodf/lib/core/UnitTester.js +++ b/webodf/lib/core/UnitTester.js @@ -639,7 +639,7 @@ core.UnitTester = function UnitTester() { + link(testName, "runSuite(\"" + testName + "\");") + ": " + test.description() + ""); } else { - runtime.log("Running " + testName + ": " + test.description); + runtime.log("Running " + testName + ": " + test.description()); } tests = test.tests(); for (i = 0; i < tests.length; i += 1) {