test_nsITableEditor_in_plaintext-only.html (20745B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <script src="/tests/SimpleTest/SimpleTest.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 8 <script> 9 "use strict"; 10 11 SimpleTest.waitForExplicitFinish(); 12 SimpleTest.waitForFocus(async () => { 13 document.body.contentEditable = "plaintext-only"; 14 document.body.focus(); 15 const tableEditor = getHTMLEditor(); 16 17 await (async function test_insertTableCell() { 18 document.body.innerHTML = "<table><td><br></td></table>"; 19 const td = document.querySelector("td"); 20 td.getBoundingClientRect(); 21 getSelection().collapse(td, 0); 22 const innerHTML = document.body.innerHTML; 23 try { 24 tableEditor.insertTableCell(1, true); 25 ok(false, "insertTableCell should fail in contenteditable=plaintext-only"); 26 } catch (e) { 27 is( 28 e.name, 29 "NS_ERROR_NOT_AVAILABLE", 30 "insertTableCell should throw NS_ERROR_NOT_AVAILABLE exception" 31 ); 32 } 33 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 34 is(document.body.innerHTML, innerHTML, "insertTableCell shouldn't change the DOM"); 35 })(); 36 37 await (async function test_insertTableColumn() { 38 document.body.innerHTML = "<table><td><br></td></table>"; 39 const td = document.querySelector("td"); 40 td.getBoundingClientRect(); 41 getSelection().collapse(td, 0); 42 const innerHTML = document.body.innerHTML; 43 try { 44 tableEditor.insertTableColumn(1, true); 45 ok(false, "insertTableColumn should fail in contenteditable=plaintext-only"); 46 } catch (e) { 47 is( 48 e.name, 49 "NS_ERROR_NOT_AVAILABLE", 50 "insertTableColumn should throw NS_ERROR_NOT_AVAILABLE exception" 51 ); 52 } 53 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 54 is(document.body.innerHTML, innerHTML, "insertTableColumn shouldn't change the DOM"); 55 })(); 56 57 await (async function test_insertTableRow() { 58 document.body.innerHTML = "<table><td><br></td></table>"; 59 const td = document.querySelector("td"); 60 td.getBoundingClientRect(); 61 getSelection().collapse(td, 0); 62 const innerHTML = document.body.innerHTML; 63 try { 64 tableEditor.insertTableRow(1, true); 65 ok(false, "insertTableRow should fail in contenteditable=plaintext-only"); 66 } catch (e) { 67 is( 68 e.name, 69 "NS_ERROR_NOT_AVAILABLE", 70 "insertTableRow should throw NS_ERROR_NOT_AVAILABLE exception" 71 ); 72 } 73 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 74 is(document.body.innerHTML, innerHTML, "insertTableRow shouldn't change the DOM"); 75 })(); 76 77 await (async function test_deleteTableCellContents() { 78 document.body.innerHTML = "<table><td>abc</td></table>"; 79 const td = document.querySelector("td"); 80 td.getBoundingClientRect(); 81 getSelection().selectAllChildren(td); 82 const innerHTML = document.body.innerHTML; 83 try { 84 tableEditor.deleteTableCellContents(); 85 ok(false, "deleteTableCellContents should fail in contenteditable=plaintext-only"); 86 } catch (e) { 87 is( 88 e.name, 89 "NS_ERROR_NOT_AVAILABLE", 90 "deleteTableCellContents should throw NS_ERROR_NOT_AVAILABLE exception" 91 ); 92 } 93 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 94 is(document.body.innerHTML, innerHTML, "deleteTableCellContents shouldn't change the DOM"); 95 })(); 96 97 await (async function test_deleteTableCell() { 98 document.body.innerHTML = "<table><td><br></td><td><br></td></table>"; 99 const td = document.querySelector("td"); 100 td.getBoundingClientRect(); 101 getSelection().collapse(td, 0); 102 const innerHTML = document.body.innerHTML; 103 try { 104 tableEditor.deleteTableCell(1); 105 ok(false, "deleteTableCell should fail in contenteditable=plaintext-only"); 106 } catch (e) { 107 is( 108 e.name, 109 "NS_ERROR_NOT_AVAILABLE", 110 "deleteTableCell should throw NS_ERROR_NOT_AVAILABLE exception" 111 ); 112 } 113 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 114 is(document.body.innerHTML, innerHTML, "deleteTableCell shouldn't change the DOM"); 115 })(); 116 117 await (async function test_deleteTableColumn() { 118 document.body.innerHTML = "<table><td><br></td><td><br></td></table>"; 119 const td = document.querySelector("td"); 120 td.getBoundingClientRect(); 121 getSelection().collapse(td, 0); 122 const innerHTML = document.body.innerHTML; 123 try { 124 tableEditor.deleteTableColumn(1); 125 ok(false, "deleteTableColumn should fail in contenteditable=plaintext-only"); 126 } catch (e) { 127 is( 128 e.name, 129 "NS_ERROR_NOT_AVAILABLE", 130 "deleteTableColumn should throw NS_ERROR_NOT_AVAILABLE exception" 131 ); 132 } 133 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 134 is(document.body.innerHTML, innerHTML, "deleteTableColumn shouldn't change the DOM"); 135 })(); 136 137 await (async function test_deleteTableRow() { 138 document.body.innerHTML = "<table><tr><td><br></td></tr><tr><td><br></td></tr></table>"; 139 const td = document.querySelector("td"); 140 td.getBoundingClientRect(); 141 getSelection().collapse(td, 0); 142 const innerHTML = document.body.innerHTML; 143 try { 144 tableEditor.deleteTableRow(1); 145 ok(false, "deleteTableRow should fail in contenteditable=plaintext-only"); 146 } catch (e) { 147 is( 148 e.name, 149 "NS_ERROR_NOT_AVAILABLE", 150 "deleteTableRow should throw NS_ERROR_NOT_AVAILABLE exception" 151 ); 152 } 153 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 154 is(document.body.innerHTML, innerHTML, "deleteTableRow shouldn't change the DOM"); 155 })(); 156 157 await (async function test_selectTableCell() { 158 document.body.innerHTML = "<table><td>abc</td></table>"; 159 const td = document.querySelector("td"); 160 td.getBoundingClientRect(); 161 getSelection().collapse(td.firstChild, 0); 162 const innerHTML = document.body.innerHTML; 163 try { 164 tableEditor.selectTableCell(); 165 ok(true, "selectTableCell should succeed even in contenteditable=plaintext-only"); 166 } catch (e) { 167 ok(false, `selectTableCell shouldn't fail in contenteditable=plaintext-only (${e.message})`); 168 } 169 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 170 is(document.body.innerHTML, innerHTML, "selectTableCell shouldn't change the DOM"); 171 })(); 172 173 await (async function test_selectTableRow() { 174 document.body.innerHTML = "<table><td>abc</td></table>"; 175 const td = document.querySelector("td"); 176 td.getBoundingClientRect(); 177 getSelection().collapse(td.firstChild, 0); 178 const innerHTML = document.body.innerHTML; 179 try { 180 tableEditor.selectTableRow(); 181 ok(true, "selectTableRow should succeed even in contenteditable=plaintext-only"); 182 } catch (e) { 183 ok(false, `selectTableRow shouldn't fail in contenteditable=plaintext-only (${e.message})`); 184 } 185 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 186 is(document.body.innerHTML, innerHTML, "selectTableRow shouldn't change the DOM"); 187 })(); 188 189 await (async function test_selectTableColumn() { 190 document.body.innerHTML = "<table><td>abc</td></table>"; 191 const td = document.querySelector("td"); 192 td.getBoundingClientRect(); 193 getSelection().collapse(td.firstChild, 0); 194 const innerHTML = document.body.innerHTML; 195 try { 196 tableEditor.selectTableColumn(); 197 ok(true, "selectTableColumn should succeed even in contenteditable=plaintext-only"); 198 } catch (e) { 199 ok(false, `selectTableColumn shouldn't fail in contenteditable=plaintext-only (${e.message})`); 200 } 201 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 202 is(document.body.innerHTML, innerHTML, "selectTableColumn shouldn't change the DOM"); 203 })(); 204 205 await (async function test_selectTable() { 206 document.body.innerHTML = "<table><td>abc</td></table>"; 207 const td = document.querySelector("td"); 208 td.getBoundingClientRect(); 209 getSelection().collapse(td.firstChild, 0); 210 const innerHTML = document.body.innerHTML; 211 try { 212 tableEditor.selectTable(); 213 ok(true, "selectTable should succeed even in contenteditable=plaintext-only"); 214 } catch (e) { 215 ok(false, `selectTable shouldn't fail in contenteditable=plaintext-only (${e.message})`); 216 } 217 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 218 is(document.body.innerHTML, innerHTML, "selectTable shouldn't change the DOM"); 219 })(); 220 221 await (async function test_selectAllTableCells() { 222 document.body.innerHTML = "<table><td>abc</td></table>"; 223 const td = document.querySelector("td"); 224 td.getBoundingClientRect(); 225 getSelection().collapse(td.firstChild, 0); 226 const innerHTML = document.body.innerHTML; 227 try { 228 tableEditor.selectAllTableCells(); 229 ok(true, "selectAllTableCells should succeed even in contenteditable=plaintext-only"); 230 } catch (e) { 231 ok(false, `selectAllTableCells shouldn't fail in contenteditable=plaintext-only (${e.message})`); 232 } 233 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 234 is(document.body.innerHTML, innerHTML, "selectAllTableCells shouldn't change the DOM"); 235 })(); 236 237 await (async function test_switchTableCellHeaderType() { 238 document.body.innerHTML = "<table><td><br></td></table>"; 239 const td = document.querySelector("td"); 240 td.getBoundingClientRect(); 241 getSelection().collapse(td, 0); 242 const innerHTML = document.body.innerHTML; 243 try { 244 tableEditor.switchTableCellHeaderType(td); 245 ok(false, "switchTableCellHeaderType should fail in contenteditable=plaintext-only"); 246 } catch (e) { 247 is( 248 e.name, 249 "NS_ERROR_NOT_AVAILABLE", 250 "switchTableCellHeaderType should throw NS_ERROR_NOT_AVAILABLE exception" 251 ); 252 } 253 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 254 is(document.body.innerHTML, innerHTML, "switchTableCellHeaderType shouldn't change the DOM"); 255 })(); 256 257 await (async function test_joinTableCells() { 258 document.body.innerHTML = "<table><td><br></td><td><br></td></table>"; 259 const td1 = document.querySelector("td"); 260 const td2 = document.querySelector("td + td"); 261 td1.getBoundingClientRect(); 262 const range1 = document.createRange(); 263 range1.selectNode(td1); 264 const range2 = document.createRange(); 265 range2.selectNode(td2); 266 getSelection().removeAllRanges(); 267 getSelection().addRange(range1); 268 getSelection().addRange(range2); 269 const innerHTML = document.body.innerHTML; 270 try { 271 tableEditor.joinTableCells(true); 272 ok(false, "joinTableCells should fail in contenteditable=plaintext-only"); 273 } catch (e) { 274 is( 275 e.name, 276 "NS_ERROR_NOT_AVAILABLE", 277 "joinTableCells should throw NS_ERROR_NOT_AVAILABLE exception" 278 ); 279 } 280 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 281 is(document.body.innerHTML, innerHTML, "joinTableCells shouldn't change the DOM"); 282 })(); 283 284 await (async function test_splitTableCell() { 285 document.body.innerHTML = "<table><tr><td colspan=\"2\" rowspan=\"2\"><br></td><td><br></td></tr><tr><td><br></td></tr></table>"; 286 const td = document.querySelector("td"); 287 td.getBoundingClientRect(); 288 getSelection().collapse(td, 0); 289 const innerHTML = document.body.innerHTML; 290 try { 291 tableEditor.splitTableCell(); 292 ok(false, "splitTableCell should fail in contenteditable=plaintext-only"); 293 } catch (e) { 294 is( 295 e.name, 296 "NS_ERROR_NOT_AVAILABLE", 297 "splitTableCell should throw NS_ERROR_NOT_AVAILABLE exception" 298 ); 299 } 300 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 301 is(document.body.innerHTML, innerHTML, "splitTableCell shouldn't change the DOM"); 302 })(); 303 304 await (async function test_normalizeTable() { 305 document.body.innerHTML = "<table><tr><td><br></td><td><br></td></tr><tr><td><br></td></tr></table>"; 306 const td = document.querySelector("td"); 307 td.getBoundingClientRect(); 308 getSelection().collapse(td, 0); 309 const innerHTML = document.body.innerHTML; 310 try { 311 tableEditor.normalizeTable(document.querySelector("table")); 312 ok(false, "normalizeTable should fail in contenteditable=plaintext-only"); 313 } catch (e) { 314 is( 315 e.name, 316 "NS_ERROR_NOT_AVAILABLE", 317 "normalizeTable should throw NS_ERROR_NOT_AVAILABLE exception" 318 ); 319 } 320 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 321 is(document.body.innerHTML, innerHTML, "normalizeTable shouldn't change the DOM"); 322 })(); 323 324 await (async function test_getCellIndexes() { 325 document.body.innerHTML = "<table><td><br></td></table>"; 326 const td = document.querySelector("td"); 327 td.getBoundingClientRect(); 328 getSelection().collapse(td, 0); 329 const innerHTML = document.body.innerHTML; 330 try { 331 const rowIndex = {}; 332 const colIndex = {}; 333 tableEditor.getCellIndexes(td, rowIndex, colIndex); 334 ok(true, "getCellIndexes should succeed even in contenteditable=plaintext-only"); 335 } catch (e) { 336 ok(false, `getCellIndexes shouldn't fail in contenteditable=plaintext-only (${e.message})`); 337 } 338 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 339 is(document.body.innerHTML, innerHTML, "getCellIndexes shouldn't change the DOM"); 340 })(); 341 342 await (async function test_getTableSize() { 343 document.body.innerHTML = "<table><td><br></td></table>"; 344 const td = document.querySelector("td"); 345 td.getBoundingClientRect(); 346 getSelection().collapse(td, 0); 347 const innerHTML = document.body.innerHTML; 348 try { 349 const rowSize = {}; 350 const colSize = {}; 351 tableEditor.getTableSize(td, rowSize, colSize); 352 ok(true, "getTableSize should succeed even in contenteditable=plaintext-only"); 353 } catch (e) { 354 ok(false, `getTableSize shouldn't fail in contenteditable=plaintext-only (${e.message})`); 355 } 356 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 357 is(document.body.innerHTML, innerHTML, "getTableSize shouldn't change the DOM"); 358 })(); 359 360 await (async function test_getCellAt() { 361 document.body.innerHTML = "<table><td><br></td></table>"; 362 const td = document.querySelector("td"); 363 td.getBoundingClientRect(); 364 getSelection().collapse(td, 0); 365 const innerHTML = document.body.innerHTML; 366 try { 367 tableEditor.getCellAt(document.querySelector("table"), 0, 0); 368 ok(true, "getCellAt should succeed even in contenteditable=plaintext-only"); 369 } catch (e) { 370 ok(false, `getCellAt shouldn't fail in contenteditable=plaintext-only (${e.message})`); 371 } 372 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 373 is(document.body.innerHTML, innerHTML, "getCellAt shouldn't change the DOM"); 374 })(); 375 376 await (async function test_getCellDataAt() { 377 document.body.innerHTML = "<table><td><br></td></table>"; 378 const td = document.querySelector("td"); 379 td.getBoundingClientRect(); 380 getSelection().collapse(td, 0); 381 const innerHTML = document.body.innerHTML; 382 try { 383 const cellElement = {}, 384 rowIndex = {}, colIndex = {}, 385 rowSpan = {}, colSpan = {}, 386 effectiveRowSpan = {}, effectiveColSpan = {}, 387 isSelected = {}; 388 tableEditor.getCellDataAt( 389 document.querySelector("table"), 390 0, 0, 391 cellElement, 392 rowIndex, colIndex, 393 rowSpan, colSpan, 394 effectiveRowSpan, effectiveColSpan, 395 isSelected 396 ); 397 ok(true, "getCellDataAt should succeed even in contenteditable=plaintext-only"); 398 } catch (e) { 399 ok(false, `getCellDataAt shouldn't fail in contenteditable=plaintext-only (${e.message})`); 400 } 401 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 402 is(document.body.innerHTML, innerHTML, "getCellDataAt shouldn't change the DOM"); 403 })(); 404 405 await (async function test_getFirstRow() { 406 document.body.innerHTML = "<table><td><br></td></table>"; 407 const td = document.querySelector("td"); 408 td.getBoundingClientRect(); 409 getSelection().collapse(td, 0); 410 const innerHTML = document.body.innerHTML; 411 try { 412 tableEditor.getFirstRow(document.querySelector("table")); 413 ok(true, "getFirstRow should succeed even in contenteditable=plaintext-only"); 414 } catch (e) { 415 ok(false, `getFirstRow shouldn't fail in contenteditable=plaintext-only (${e.message})`); 416 } 417 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 418 is(document.body.innerHTML, innerHTML, "getFirstRow shouldn't change the DOM"); 419 })(); 420 421 await (async function test_getSelectedOrParentTableElement() { 422 document.body.innerHTML = "<table><td><br></td></table>"; 423 const td = document.querySelector("td"); 424 td.getBoundingClientRect(); 425 getSelection().collapse(td, 0); 426 const innerHTML = document.body.innerHTML; 427 try { 428 const tagName = {}, count = {}; 429 tableEditor.getSelectedOrParentTableElement(document.querySelector("table"), tagName, count); 430 ok(true, "getSelectedOrParentTableElement should succeed even in contenteditable=plaintext-only"); 431 } catch (e) { 432 ok(false, `getSelectedOrParentTableElement shouldn't fail in contenteditable=plaintext-only (${e.message})`); 433 } 434 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 435 is(document.body.innerHTML, innerHTML, "getSelectedOrParentTableElement shouldn't change the DOM"); 436 })(); 437 438 await (async function test_getSelectedCellsType() { 439 document.body.innerHTML = "<table><td><br></td></table>"; 440 const td = document.querySelector("td"); 441 td.getBoundingClientRect(); 442 getSelection().collapse(td, 0); 443 const innerHTML = document.body.innerHTML; 444 try { 445 tableEditor.getSelectedCellsType(td); 446 ok(true, "getSelectedCellsType should succeed even in contenteditable=plaintext-only"); 447 } catch (e) { 448 ok(false, `getSelectedCellsType shouldn't fail in contenteditable=plaintext-only (${e.message})`); 449 } 450 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 451 is(document.body.innerHTML, innerHTML, "getSelectedCellsType shouldn't change the DOM"); 452 })(); 453 454 await (async function test_getFirstSelectedCellInTable() { 455 document.body.innerHTML = "<table><td><br></td></table>"; 456 const td = document.querySelector("td"); 457 td.getBoundingClientRect(); 458 getSelection().collapse(td, 0); 459 const innerHTML = document.body.innerHTML; 460 try { 461 const rowIndex = {}, colIndex = {}; 462 tableEditor.getFirstSelectedCellInTable(document.querySelector("table"), rowIndex, colIndex); 463 ok(true, "getFirstSelectedCellInTable should succeed even in contenteditable=plaintext-only"); 464 } catch (e) { 465 ok(false, `getFirstSelectedCellInTable shouldn't fail in contenteditable=plaintext-only (${e.message})`); 466 } 467 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 468 is(document.body.innerHTML, innerHTML, "getFirstSelectedCellInTable shouldn't change the DOM"); 469 })(); 470 471 await (async function test_getSelectedCells() { 472 document.body.innerHTML = "<table><td><br></td></table>"; 473 const td = document.querySelector("td"); 474 td.getBoundingClientRect(); 475 getSelection().collapse(td, 0); 476 const innerHTML = document.body.innerHTML; 477 try { 478 tableEditor.getSelectedCells(); 479 ok(true, "getSelectedCells should succeed even in contenteditable=plaintext-only"); 480 } catch (e) { 481 ok(false, `getSelectedCells shouldn't fail in contenteditable=plaintext-only (${e.message})`); 482 } 483 await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))); 484 is(document.body.innerHTML, innerHTML, "getSelectedCells shouldn't change the DOM"); 485 })(); 486 487 document.body.removeAttribute("contenteditable"); 488 SimpleTest.finish(); 489 }); 490 491 function getHTMLEditor() { 492 const Ci = SpecialPowers.Ci; 493 const editingSession = SpecialPowers.wrap(window).docShell.editingSession; 494 return editingSession.getEditorForWindow(window) 495 .QueryInterface(Ci.nsITableEditor); 496 } 497 </script> 498 </head> 499 <body></body> 500 </html>