test_paragraphboundary.html (5594B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Paragraph boundary getText* functions tests</title> 5 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 6 7 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 8 <script type="application/javascript" 9 src="../common.js"></script> 10 <script type="application/javascript" 11 src="../text.js"></script> 12 <script type="application/javascript"> 13 function doTest() { 14 // First, test the contentEditable. 15 testTextAtOffset("ce", BOUNDARY_PARAGRAPH, 16 [[0, 0, kEmbedChar, 0, 1], 17 [1, 2, kEmbedChar, 1, 2]]); 18 19 // Now, test each paragraph. 20 var ID = getNode("ce").firstElementChild; 21 testTextAtOffset(ID, BOUNDARY_PARAGRAPH, 22 [[0, 15, "hello my friend", 0, 15]]); 23 ID = getNode("ce").lastElementChild; 24 testTextAtOffset(ID, BOUNDARY_PARAGRAPH, 25 [[0, 11, "hello again", 0, 11]]); 26 27 // Test a paragraph whose line forcefully wraps. 28 testTextAtOffset("forced_wrap", BOUNDARY_PARAGRAPH, 29 [[0, 2, "ab", 0, 2]]); 30 31 // Test paragraphs with a few line breaks. 32 testTextAtOffset("forced_br", BOUNDARY_PARAGRAPH, 33 [[0, 1, "a\n", 0, 2], // a and br treated as a paragraph 34 [2, 3, "b\n", 2, 4], // b treated as a paragraph, excl 2nd line break 35 [4, 4, "\n", 4, 5], // second br treated as a separate paragraph 36 [5, 6, "c", 5, 6]]); // Last paragraph treated as usual 37 testTextAtOffset("br_at_beginning", BOUNDARY_PARAGRAPH, 38 [[0, 0, "\n", 0, 1], // br treated as a separate paragraph 39 [1, 2, "a\n", 1, 3], // a and br treated as a paragraph 40 [3, 4, "b", 3, 4]]); // b treated as last paragraph 41 42 // Test a paragraph with an embedded link. 43 testTextAtOffset("pWithLink", BOUNDARY_PARAGRAPH, 44 [[0, 3, "a" + kEmbedChar + "d", 0, 3]]); 45 testTextAtOffset("link", BOUNDARY_PARAGRAPH, 46 [[0, 2, "bc", 0, 2]]); 47 48 // Paragraph with link that contains a line break. 49 testTextAtOffset("pWithLinkWithBr", BOUNDARY_PARAGRAPH, 50 [[0, 0, "a" + kEmbedChar, 0, 2], 51 [1, 1, "a" + kEmbedChar + "d", 0, 3], 52 [2, 3, kEmbedChar + "d", 1, 3]]); 53 54 // Test a list and list item 55 testTextAtOffset("ul", BOUNDARY_PARAGRAPH, 56 [[0, 0, kEmbedChar, 0, 1], 57 [1, 2, kEmbedChar, 1, 2]]); 58 testTextAtOffset("li1", BOUNDARY_PARAGRAPH, 59 [[0, 3, "• a", 0, 3]]); 60 testTextAtOffset("li2", BOUNDARY_PARAGRAPH, 61 [[0, 3, "• a", 0, 3]]); 62 // Test a list item containing multiple text leaf nodes. 63 testTextAtOffset("liMultiLeaf", BOUNDARY_PARAGRAPH, 64 [[0, 4, "• ab", 0, 4]]); 65 66 // Test line breaks in a textarea. 67 testTextAtOffset("textarea", BOUNDARY_PARAGRAPH, 68 [[0, 1, "a\n", 0, 2], 69 [2, 3, "b\n", 2, 4], 70 [4, 4, "\n", 4, 5], 71 [5, 6, "c", 5, 6]]); 72 73 // Test that a textarea has a blank paragraph at the end if it contains 74 // a line break as its last character. 75 testTextAtOffset("textarea_with_trailing_br", BOUNDARY_PARAGRAPH, 76 [[0, 15, "This is a test.\n", 0, 16], 77 [16, 16, "", 16, 16]]); 78 79 // Paragraph with a presentational line break. 80 testTextAtOffset("presentational_br", BOUNDARY_PARAGRAPH, 81 [[0, 3, "a b", 0, 3]]); 82 83 // Two paragraphs in a div, non-editable case. 84 testTextAtOffset("two_paragraphs", BOUNDARY_PARAGRAPH, 85 [[0, 0, kEmbedChar, 0, 1], 86 [1, 2, kEmbedChar, 1, 2]]); 87 88 // Div containing a paragraph containing a link 89 testTextAtOffset("divWithParaWithLink", BOUNDARY_PARAGRAPH, 90 [[0, 0, kEmbedChar, 0, 1], 91 [1, 2, "b", 1, 2]]); 92 93 // Two text nodes and a br 94 testTextAtOffset("twoTextNodesAndBr", BOUNDARY_PARAGRAPH, 95 [[0, 2, "ab\n", 0, 3], 96 [3, 3, "", 3, 3]]); 97 98 // Link followed by a paragraph. 99 testTextAtOffset("linkThenPara", BOUNDARY_PARAGRAPH, 100 [[0, 0, kEmbedChar, 0, 1], 101 [1, 2, kEmbedChar, 1, 2]]); 102 103 SimpleTest.finish(); 104 } 105 106 SimpleTest.waitForExplicitFinish(); 107 addA11yLoadEvent(doTest); 108 </script> 109 </head> 110 <body> 111 112 <a target="_blank" 113 title="getTextAtOffset for paragraph boundaries" 114 href="https://bugzilla.mozilla.org/show_bug.cgi?id=1520779"> 115 Bug 1520779 116 </a> 117 118 <p id="display"></p> 119 <div id="content" style="display: none"></div> 120 <pre id="test"> 121 </pre> 122 123 <div id="ce" contenteditable="true"> 124 <p>hello my friend</p> 125 <p>hello again</p> 126 </div> 127 <p id="forced_wrap" style="width: 1px; word-break: break-all;">ab</p> 128 <p id="forced_br">a<br>b<br><br>c</p> 129 <p id="br_at_beginning"><br>a<br>b</p> 130 <p id="pWithLink">a<a id="link" href="https://example.com/">bc</a>d</p> 131 <p id="pWithLinkWithBr">a<a href="#">b<br>c</a>d</p> 132 <ul id="ul"><li id="li1">a</li><li>b</li></ul> 133 <style>#li2::marker { content:'\2022\0020'; }</style> 134 <ul id="ul"><li id="li2">a</li><li>b</li></ul> 135 <ul><li id="liMultiLeaf">a<span>b</span></li></ul> 136 <textarea id="textarea">a 137 b 138 139 c</textarea> <!-- This must be outdented for a correct test case --> 140 <textarea id="textarea_with_trailing_br">This is a test. 141 </textarea> <!-- This must be outdented for a correct test case --> 142 <p id="presentational_br" style="white-space: pre-wrap;">a<span> <br role="presentation"></span>b</p> 143 <div id="two_paragraphs"><p>a</p><p>b</p></div> 144 <div id ="divWithParaWithLink"><p><a href="#">a</a></p>b</div> 145 <p id="twoTextNodesAndBr">a<span>b</span><br></p> 146 <div id="linkThenPara"><a href="#">a</a><p>b</p></div> 147 </body> 148 </html>