4 <title>Test for nsITableEditor.getTableSize()
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
11 <div id=
"content" contenteditable
></div>
15 <script class=
"testbody" type=
"application/javascript">
17 SimpleTest.waitForExplicitFinish();
18 SimpleTest.waitForFocus(function() {
19 let editor = document.getElementById(
"content");
20 let selection = document.getSelection();
21 let rowCount = {}, columnCount = {};
24 getTableEditor().getTableSize(undefined, rowCount, columnCount);
25 ok(false,
"nsITableEditor.getTableSize(undefined) should cause throwing an exception");
27 ok(true,
"nsITableEditor.getTableSize(undefined) should cause throwing an exception");
31 getTableEditor().getTableSize(null, rowCount, columnCount);
32 ok(false,
"nsITableEditor.getTableSize(null) should cause throwing an exception");
34 ok(true,
"nsITableEditor.getTableSize(null) should cause throwing an exception");
38 getTableEditor().getTableSize(editor, rowCount, columnCount);
39 ok(false,
"nsITableEditor.getTableSize() should cause throwing an exception if given node is not in a <table>");
41 ok(true,
"nsITableEditor.getTableSize() should cause throwing an exception if given node is not in a <table>");
44 // Set id to
"test" for the argument for getTableSize().
45 // Set data-rows and data-cols to expected count of them.
47 '
<table><tr><td id=
"test" data-rows=
"2" data-cols=
"3">cell1-
1</td><td>cell1-
2</td><td>cell1-
3</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td><td>cell2-
3</td></tr></table>',
48 '
<table><tr id=
"test" data-rows=
"2" data-cols=
"3"><td>cell1-
1</td><td>cell1-
2</td><td>cell1-
3</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td><td>cell2-
3</td></tr></table>',
49 '
<table id=
"test" data-rows=
"2" data-cols=
"3"><tr><td>cell1-
1</td><td>cell1-
2</td><td>cell1-
3</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td><td>cell2-
3</td></tr></table>',
50 '
<table><tr><td>cell1-
1</td><td>cell1-
2</td><td>cell1-
3</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td><td><p id=
"test" data-rows=
"2" data-cols=
"3">cell2-
3</p></td></tr></table>',
51 '
<table><caption id=
"test" data-rows=
"2" data-cols=
"3">caption
</caption><tr><td>cell1-
1</td><td>cell1-
2</td><td>cell1-
3</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td><td>cell2-
3</td></tr></table>',
52 '
<table id=
"test" data-rows=
"0" data-cols=
"0"></table>',
53 '
<table id=
"test" data-rows=
"0" data-cols=
"0"><caption>caption
</caption></table>',
54 '
<table id=
"test" data-rows=
"1" data-cols=
"1"><td>cell1-
1</td></table>',
55 // rowspan does not affect, but colspan affects...
56 '
<table id=
"test" data-rows=
"1" data-cols=
"12"><tr><td rowspan=
"8" colspan=
"12">cell1-
1</td></tr></table>',
57 '
<table id=
"test" data-rows=
"1" data-cols=
"1"><tr><td><table><tr><td>cell1-
1</td><td>cell1-
2</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td></tr><tr><td>cell3-
1</td><td>cell3-
2</td></tr></table></td></tr></table>',
58 '
<table><tr><td id=
"test" data-rows=
"1" data-cols=
"1"><table><tr><td>cell1-
1</td><td>cell1-
2</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td></tr><tr><td>cell3-
1</td><td>cell3-
2</td></tr></table></td></tr></table>',
59 '
<table><tr><td><table id=
"test" data-rows=
"3" data-cols=
"2"><tr><td>cell1-
1</td><td>cell1-
2</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td></tr><tr><td>cell3-
1</td><td>cell3-
2</td></tr></table></td></tr></table>',
60 '
<table><tr><td><table><tr><td id=
"test" data-rows=
"3" data-cols=
"2">cell1-
1</td><td>cell1-
2</td></tr><tr><td>cell2-
1</td><td>cell2-
2</td></tr><tr><td>cell3-
1</td><td>cell3-
2</td></tr></table></td></tr></table>',
61 '
<table><tr><td><table><tr><td>cell1-
1</td><td>cell1-
2</td></tr><tr><td>cell2-
1</td><td><p id=
"test" data-rows=
"3" data-cols=
"2">cell2-
2</p></td></tr><tr><td>cell3-
1</td><td>cell3-
2</td></tr></table></td></tr></table>',
64 for (const kTest of kTests) {
65 editor.innerHTML = kTest;
66 let element = document.getElementById(
"test");
67 getTableEditor().getTableSize(element, rowCount, columnCount);
68 is(rowCount.value.toString(
10), element.getAttribute(
"data-rows"),
69 `Specified an element in a
<table> directly, its parent table row count should be retrieved: ${kTest}`);
70 is(columnCount.value.toString(
10), element.getAttribute(
"data-cols"),
71 `Specified an element in a
<table> directly, its parent table column count should be retrieved: ${kTest}`);
72 if (element.firstChild && element.firstChild.nodeType == Node.TEXT_NODE) {
73 selection.collapse(element.firstChild,
0);
74 getTableEditor().getTableSize(null, rowCount, columnCount);
75 is(rowCount.value.toString(
10), element.getAttribute(
"data-rows"),
76 `Selection is collapsed in a cell element, its parent table row count should be retrieved: ${kTest}`);
77 is(columnCount.value.toString(
10), element.getAttribute(
"data-cols"),
78 `Selection is collapsed in a cell element, its parent table column count should be retrieved: ${kTest}`);
85 function getTableEditor() {
86 var Ci = SpecialPowers.Ci;
87 var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
88 return editingSession.getEditorForWindow(window).QueryInterface(Ci.nsITableEditor);