Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>nsIHyper>TextAccessible in dynamic tests</title> |
michael@0 | 5 | <link rel="stylesheet" type="text/css" |
michael@0 | 6 | href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 7 | |
michael@0 | 8 | <script type="application/javascript" |
michael@0 | 9 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | |
michael@0 | 11 | <script type="application/javascript" |
michael@0 | 12 | src="../common.js"></script> |
michael@0 | 13 | <script type="application/javascript" |
michael@0 | 14 | src="../events.js"></script> |
michael@0 | 15 | |
michael@0 | 16 | <script type="application/javascript"> |
michael@0 | 17 | const kLinksCount = 128; |
michael@0 | 18 | function addLinks(aContainerID) |
michael@0 | 19 | { |
michael@0 | 20 | this.containerNode = getNode(aContainerID); |
michael@0 | 21 | |
michael@0 | 22 | this.eventSeq = [ |
michael@0 | 23 | new invokerChecker(EVENT_REORDER, this.containerNode) |
michael@0 | 24 | ]; |
michael@0 | 25 | |
michael@0 | 26 | this.invoke = function addLinks_invoke() |
michael@0 | 27 | { |
michael@0 | 28 | for (var jdx = 0; jdx < kLinksCount; jdx++) { |
michael@0 | 29 | var a = document.createElement("a"); |
michael@0 | 30 | a.setAttribute("href", "mozilla.org"); |
michael@0 | 31 | a.textContent = "mozilla"; |
michael@0 | 32 | this.containerNode.appendChild(a); |
michael@0 | 33 | |
michael@0 | 34 | var span = document.createElement("span"); |
michael@0 | 35 | span.textContent = " text "; |
michael@0 | 36 | this.containerNode.appendChild(span); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | this.finalCheck = function addLinks_finalCheck() |
michael@0 | 41 | { |
michael@0 | 42 | // getLinkAt and getLinkIndex. |
michael@0 | 43 | var htAcc = getAccessible(this.containerNode, [nsIAccessibleHyperText]); |
michael@0 | 44 | for (var jdx = 0; jdx < kLinksCount; jdx++) { |
michael@0 | 45 | var link = htAcc.getLinkAt(jdx); |
michael@0 | 46 | ok(link, "No link at index " + jdx + " for '" + aContainerID + "'"); |
michael@0 | 47 | |
michael@0 | 48 | var linkIdx = htAcc.getLinkIndex(link); |
michael@0 | 49 | is(linkIdx, jdx, "Wrong link index for '" + aContainerID + "'!"); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | this.getID = function addLinks_getID() |
michael@0 | 54 | { |
michael@0 | 55 | return "Add links for '" + aContainerID + "'"; |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function updateText(aContainerID) |
michael@0 | 60 | { |
michael@0 | 61 | this.containerNode = getNode(aContainerID); |
michael@0 | 62 | this.container = getAccessible(this.containerNode, nsIAccessibleHyperText); |
michael@0 | 63 | this.text = this.container.firstChild; |
michael@0 | 64 | this.textNode = this.text.DOMNode; |
michael@0 | 65 | this.textLen = this.textNode.data.length; |
michael@0 | 66 | |
michael@0 | 67 | this.eventSeq = [ |
michael@0 | 68 | new invokerChecker(EVENT_TEXT_INSERTED, this.containerNode) |
michael@0 | 69 | ]; |
michael@0 | 70 | |
michael@0 | 71 | this.invoke = function updateText_invoke() |
michael@0 | 72 | { |
michael@0 | 73 | is(this.container.getLinkIndexAtOffset(this.textLen), 0, |
michael@0 | 74 | "Wrong intial text offsets!"); |
michael@0 | 75 | |
michael@0 | 76 | this.text.DOMNode.appendData(" my"); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | this.finalCheck = function updateText_finalCheck() |
michael@0 | 80 | { |
michael@0 | 81 | is(this.container.getLinkIndexAtOffset(this.textLen), -1, |
michael@0 | 82 | "Text offsets weren't updated!"); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | this.getID = function updateText_getID() |
michael@0 | 86 | { |
michael@0 | 87 | return "update text for '" + aContainerID + "'"; |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Text offsets must be updated when hypertext child is removed. |
michael@0 | 93 | */ |
michael@0 | 94 | function removeChild(aContainerID, aChildID, aInitialText, aFinalText) |
michael@0 | 95 | { |
michael@0 | 96 | this.containerNode = getNode(aContainerID); |
michael@0 | 97 | this.container = getAccessible(this.containerNode, nsIAccessibleText); |
michael@0 | 98 | this.childNode = getNode(aChildID); |
michael@0 | 99 | |
michael@0 | 100 | // Call first to getText so offsets are cached |
michael@0 | 101 | is(this.container.getText(0, -1), aInitialText, |
michael@0 | 102 | "Wrong text before child removal"); |
michael@0 | 103 | |
michael@0 | 104 | this.eventSeq = [ |
michael@0 | 105 | new invokerChecker(EVENT_REORDER, this.containerNode) |
michael@0 | 106 | ]; |
michael@0 | 107 | |
michael@0 | 108 | this.invoke = function removeChild_invoke() |
michael@0 | 109 | { |
michael@0 | 110 | this.containerNode.removeChild(this.childNode); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | this.finalCheck = function removeChild_finalCheck() |
michael@0 | 114 | { |
michael@0 | 115 | is(this.container.getText(0, -1), aFinalText, |
michael@0 | 116 | "Wrong text after child removal"); |
michael@0 | 117 | is(this.container.characterCount, aFinalText.length, |
michael@0 | 118 | "Wrong text after child removal"); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | this.getID = function removeChild_getID() |
michael@0 | 122 | { |
michael@0 | 123 | return "check text after removing child from '" + aContainerID + "'"; |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | |
michael@0 | 128 | |
michael@0 | 129 | //gA11yEventDumpToConsole = true; // debug stuff |
michael@0 | 130 | |
michael@0 | 131 | var gQueue = null; |
michael@0 | 132 | function doTest() |
michael@0 | 133 | { |
michael@0 | 134 | gQueue = new eventQueue(); |
michael@0 | 135 | gQueue.push(new addLinks("p1")); |
michael@0 | 136 | gQueue.push(new updateText("p2")); |
michael@0 | 137 | gQueue.push(new removeChild("div1","div2", |
michael@0 | 138 | "hello my good friend", "hello friend")); |
michael@0 | 139 | |
michael@0 | 140 | gQueue.invoke(); // Will call SimpleTest.finish(); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 144 | addA11yLoadEvent(doTest); |
michael@0 | 145 | </script> |
michael@0 | 146 | </head> |
michael@0 | 147 | <body> |
michael@0 | 148 | |
michael@0 | 149 | <a target="_blank" |
michael@0 | 150 | title="Cache links within hypertext accessible" |
michael@0 | 151 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=572394"> |
michael@0 | 152 | Mozilla Bug 572394 |
michael@0 | 153 | </a> |
michael@0 | 154 | <a target="_blank" |
michael@0 | 155 | title="Text offsets don't get updated when text of first child text accessible is changed" |
michael@0 | 156 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=625009"> |
michael@0 | 157 | Mozilla Bug 625009 |
michael@0 | 158 | </a> |
michael@0 | 159 | <a target="_blank" |
michael@0 | 160 | title="Crash in nsHyperTextAccessible::GetText()" |
michael@0 | 161 | href="https://bugzilla.mozilla.org/show_bug.cgi?id=630841"> |
michael@0 | 162 | Mozilla Bug 630841 |
michael@0 | 163 | </a><br> |
michael@0 | 164 | <p id="display"></p> |
michael@0 | 165 | <div id="content" style="display: none"></div> |
michael@0 | 166 | <pre id="test"> |
michael@0 | 167 | </pre> |
michael@0 | 168 | |
michael@0 | 169 | <p id="p1"></p> |
michael@0 | 170 | <p id="p2"><b>hello</b><a>friend</a></p> |
michael@0 | 171 | <div id="div1">hello<span id="div2"> my<span id="div3"> good</span></span> friend</span></div> |
michael@0 | 172 | </body> |
michael@0 | 173 | </html> |