table.action.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  1. /**
  2. * Created with JetBrains PhpStorm.
  3. * User: taoqili
  4. * Date: 13-2-25
  5. * Time: 下午4:40
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. //test('', function () {
  9. // stop()
  10. //});
  11. test('框选', function () {
  12. var editor = te.obj[0];
  13. var range = te.obj[1];
  14. editor.setContent('<p></p>');
  15. setTimeout(function () {
  16. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  17. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  18. var tds = editor.body.getElementsByTagName('td');
  19. ua.mousedown(tds[0]);
  20. ua.mouseover(tds[4]);
  21. ua.mouseup(tds[4]);
  22. setTimeout(function () {
  23. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  24. var tds = editor.body.getElementsByTagName('td');
  25. equal(selectedTds.length, 4, '框选');
  26. if ( ua.browser.ie >8 && ua.browser.ie<11)
  27. ua.checkResult(editor.selection.getRange(), tds[0].firstChild, tds[0].firstChild, 1, 1, true, '检查选中的range')
  28. else
  29. ua.checkResult(editor.selection.getRange(), tds[0], tds[0], 0, 0, true, '检查选中的range');
  30. range.setStart(tds[4], 0).collapse(true).select();
  31. ua.mousedown(tds[4], {button: 2});
  32. setTimeout(function () {
  33. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  34. var tds = editor.body.getElementsByTagName('td');
  35. equal(selectedTds.length, 4, '右键框选不变');
  36. if ( ua.browser.ie >8 && ua.browser.ie<11)
  37. ua.checkResult(editor.selection.getRange(), tds[0].firstChild, tds[0].firstChild, 1, 1, true, '检查选中的range')
  38. else
  39. ua.checkResult(editor.selection.getRange(), tds[0], tds[0], 0, 0, true, '检查选中的range');
  40. start();
  41. }, 50);
  42. }, 50);
  43. }, 80);
  44. stop();
  45. });
  46. test('tableDragable-显示和消失', function () {
  47. if (browser.ie && browser.version < 8) return;
  48. var div = document.body.appendChild(document.createElement('div'));
  49. div.id = 'ue';
  50. var editor = UE.getEditor('ue', {tableDragable: true});
  51. editor.ready(function () {
  52. var range = new baidu.editor.dom.Range(editor.document);
  53. editor.setContent('<p></p>');
  54. setTimeout(function () {
  55. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  56. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  57. var tds = editor.body.getElementsByTagName('td');
  58. ua.mousemove(editor.body.firstChild);
  59. var pos = domUtils.getXY(editor.body.firstChild);
  60. var select = ua.browser.webkit ? '-webkit-user-select: none;' : ua.browser.gecko ? '-moz-user-select: none;' : ua.browser.ie >8?'-ms-user-select: none':'';//-ms-user-select: none
  61. var html = '<div contenteditable=\"false\" style=\"width:15px;height:15px;background-image:url(' + editor.options.UEDITOR_HOME_URL + 'dialogs/table/dragicon.png);position: absolute;cursor:move;top:' + (pos.y - 15) + 'px;left:' + pos.x + 'px; ' + select + '\"' + (ua.browser.ie && ua.browser.ie<9 ? 'unselectable=\"on\"' : '') + '></div>';
  62. setTimeout(function () {
  63. var button = editor.body.lastChild;
  64. ua.checkSameHtml(button.outerHTML.replace('&quot;', ''), html, 'DragButton显示');
  65. ua.mouseout(button);
  66. ua.mousemove(editor.body);
  67. setTimeout(function () {
  68. equal(editor.body.getElementsByTagName('div').length, 0, '按钮没有了');
  69. UE.delEditor('ue');
  70. te.dom.push(document.getElementById('ue'));
  71. te.dom.push(document.getElementById('edui_fixedlayer'));
  72. start();
  73. }, 2100);
  74. }, 20);
  75. }, 50);
  76. });
  77. stop();
  78. });
  79. test('tableDragable-单击', function () {//tableClicked
  80. if (browser.ie && browser.version < 8) return;
  81. var div = document.body.appendChild(document.createElement('div'));
  82. div.id = 'ue';
  83. var editor = UE.getEditor('ue', {tableDragable: true});
  84. expect(1);
  85. editor.ready(function () {
  86. var range = new baidu.editor.dom.Range(editor.document);
  87. editor.setContent('<p></p>');
  88. setTimeout(function () {
  89. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  90. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  91. var tds = editor.body.getElementsByTagName('td');
  92. ua.mousemove(editor.body.firstChild);
  93. setTimeout(function () {
  94. var button = editor.body.lastChild;
  95. editor.addListener("tableClicked", function (type, table, buttonOn) {
  96. same(table, editor.body.getElementsByTagName('table')[0], 'tableClicked事件,传入的参数正确');
  97. setTimeout(function () {
  98. UE.delEditor('ue');
  99. te.dom.push(document.getElementById('ue'));
  100. te.dom.push(document.getElementById('edui_fixedlayer'));
  101. start();
  102. }, 500);
  103. });
  104. ua.click(button);
  105. }, 20);
  106. }, 50);
  107. });
  108. stop();
  109. });
  110. test('tableDragable-双击', function () {//tableClicked
  111. if (browser.ie && browser.version < 8) return;
  112. var div = document.body.appendChild(document.createElement('div'));
  113. div.id = 'ue';
  114. var editor = UE.getEditor('ue', {tableDragable: true});
  115. editor.ready(function () {
  116. var range = new baidu.editor.dom.Range(editor.document);
  117. editor.setContent('<p></p>');
  118. setTimeout(function () {
  119. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  120. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  121. var tds = editor.body.getElementsByTagName('td');
  122. ua.mousemove(editor.body.firstChild);
  123. setTimeout(function () {
  124. var button = editor.body.lastChild;
  125. ua.dblclick(button);
  126. setTimeout(function () {
  127. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  128. var tds = editor.body.getElementsByTagName('td');
  129. equal(selectedTds.length, 9, '全选');
  130. if (ua.browser.ie > 8 && ua.browser.ie<11)
  131. ua.checkResult(editor.selection.getRange(), tds[0].firstChild, tds[0].firstChild, 1, 1, true, '检查选中的range');
  132. else
  133. ua.checkResult(editor.selection.getRange(), tds[0], tds[0], 0, 0, true, '检查选中的range');
  134. setTimeout(function () {
  135. UE.delEditor('ue');
  136. te.dom.push(document.getElementById('ue'));
  137. te.dom.push(document.getElementById('edui_fixedlayer'));
  138. start();
  139. }, 500);
  140. }, 100);
  141. }, 100);
  142. }, 100);
  143. });
  144. stop();
  145. });
  146. test('从外面粘贴表格', function () {
  147. var editor = te.obj[0];
  148. var range = te.obj[1];
  149. editor.setContent('<p></p>');
  150. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  151. var html = {html: '<table style="width:992px"><tbody><tr><td style="border-color: rgb(247, 150, 70);width:198px" >hello1</td><td style="background-color: rgb(255, 0, 0); border-color: rgb(247, 150, 70);width:198px" ></td></tr><tr><td >hello2</td><td ></td></tr></tbody></table><p>hello2</p>'};
  152. editor.fireEvent('beforepaste', html);
  153. //**//*粘贴*//**//*
  154. stop();
  155. setTimeout(function () {
  156. var space = ua.browser.ie ? '' : '<br/>';
  157. var border = (ua.browser.ie && ua.browser.ie < 9) ? 'border-bottom-color: rgb(247,150,70); border-top-color: rgb(247,150,70); border-right-color: rgb(247,150,70); border-left-color: rgb(247,150,70)' : 'border-color: rgb(247, 150, 70)';
  158. var resultHtml = '<table width="992"><tbody><tr><td style="' + border + ';" width="198">hello1</td><td style="background-color: rgb(255, 0, 0); ' + border + ';" width="198">' + space + '</td></tr><tr><td>hello2</td><td>' + space + '</td></tr></tbody></table><p>hello2</p>';
  159. ua.checkSameHtml(html.html.toLowerCase(), resultHtml.toLowerCase(), '粘贴的表格规范格式');
  160. start();
  161. }, 50);
  162. });
  163. test('从外面粘贴表格到表格-表格中不能粘完整的表格', function () {
  164. var editor = te.obj[0];
  165. var range = te.obj[1];
  166. editor.setContent('');
  167. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  168. //**//*插入表格*//**//*
  169. var tds = editor.body.getElementsByTagName('td');
  170. range.setStart(tds[0], 0).collapse(true).select();
  171. var html = {html: '<table><tbody><tr><td>hello1</td><td ></td></tr><tr><td >hello2</td><td ></td></tr></tbody></table><p>hello2</p>'};
  172. editor.fireEvent('beforepaste', html);
  173. //**//*粘贴*//**//*
  174. stop();
  175. setTimeout(function () {
  176. equal(html.html, '<p>hello2</p>', '表格中不能粘完整的表格');
  177. start();
  178. }, 50);
  179. });
  180. test(' trace 3729 从外面粘贴表格到表格-在caption中粘贴,只粘贴文本内容', function () {
  181. var editor = te.obj[0];
  182. var range = te.obj[1];
  183. editor.setContent('');
  184. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  185. //**//*插入表格*//**//*
  186. var tds = editor.body.getElementsByTagName('td');
  187. range.setStart(tds[0], 0).collapse(true).select();
  188. editor.execCommand('insertcaption');
  189. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  190. var html = {html: '<table><tbody><tr><td>hello1</td><td ></td></tr></tbody></table>'};
  191. editor.fireEvent('beforepaste', html);
  192. //**//*粘贴*//**//*
  193. stop();
  194. setTimeout(function () {
  195. //todo ie9 使用 div[browser.ie ? 'innerText' : 'textContent'] 会多一个换行,用textContent没有 trace 3729
  196. equal(html.html, 'hello1', '在caption中粘贴,只粘贴文本内容');
  197. start();
  198. }, 50);
  199. });
  200. test('getText,取表格内的文本', function () {
  201. var editor = te.obj[0];
  202. var range = te.obj[1];
  203. editor.setContent('<table><tbody><tr><td> hello1</td><td ></td></tr><tr><td >hello2</td><td ></td></tr></tbody></table>');
  204. stop();
  205. setTimeout(function () {
  206. var trs = editor.body.firstChild.getElementsByTagName('tr');
  207. range.setStart(trs[0].cells[0],0).collapse(true).select();
  208. var ut = editor.getUETable(editor.body.firstChild);
  209. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  210. ut.setSelected(cellsRange);
  211. setTimeout(function () {
  212. ua.manualDeleteFillData(editor.body);
  213. equal(editor.selection.getText(), 'hello1hello2');
  214. start();
  215. }, 50);
  216. }, 50);
  217. });
  218. test('在第一个单元格里最前面回车,且表格前面没有内容', function () {
  219. var editor = te.obj[0];
  220. var range = te.obj[1];
  221. editor.setContent('<p></p>');
  222. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  223. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  224. var trs = editor.body.firstChild.getElementsByTagName('tr');
  225. var ut = editor.getUETable(editor.body.firstChild);
  226. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  227. ut.setSelected(cellsRange);
  228. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  229. ua.keydown(editor.body, {'keyCode': 13});
  230. stop();
  231. setTimeout(function () {
  232. ua.manualDeleteFillData(editor.body);
  233. equal(editor.body.firstChild.innerHTML, ua.browser.ie ? '&nbsp;' : '<br>', '表格前插入空行');
  234. equal(editor.body.firstChild.tagName.toLowerCase(), 'p', '表格前插入空行');
  235. equal(editor.body.childNodes[1].tagName.toLowerCase(), 'table', '表格在空行后面');
  236. start();
  237. }, 50);
  238. });
  239. test('delete 事件', function () {
  240. var editor = te.obj[0];
  241. var range = te.obj[1];
  242. editor.setContent('<p></p>');
  243. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  244. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  245. expect(4);
  246. editor.addListener('saveScene', function () {
  247. ok(true);
  248. });
  249. var trs = editor.body.firstChild.getElementsByTagName('tr');
  250. trs[0].cells[0].innerHTML = 'hello';
  251. trs[1].cells[0].innerHTML = 'hello';
  252. var ut = editor.getUETable(editor.body.firstChild);
  253. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[1].cells[0]);
  254. ut.setSelected(cellsRange);
  255. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  256. ua.keydown(editor.body, {'keyCode': 46});
  257. stop();
  258. setTimeout(function () {
  259. ua.manualDeleteFillData(editor.body);
  260. trs = editor.body.firstChild.getElementsByTagName('tr');
  261. equal(trs[0].cells[0].innerHTML, ua.browser.ie ? '' : '<br>', '内容');
  262. equal(trs[1].cells[0].innerHTML, ua.browser.ie ? '' : '<br>', '内容');
  263. start();
  264. }, 20);
  265. });
  266. //**//*trace 3047,3545*//**//*
  267. test('trace 3047 ,3545 全屏插入表格', function () {
  268. if (ua.browser.gecko)return;//TODO 1.2.6
  269. if (ua.browser.ie && ua.browser.ie < 9)return;//TODO 1.2.6
  270. var div = document.body.appendChild(document.createElement('div'));
  271. $(div).css('width', '500px').css('height', '500px').css('border', '1px solid #ccc');
  272. var editor = te.obj[2];
  273. editor.render(div);
  274. stop();
  275. editor.ready(function () {
  276. editor.setContent('<p></p>');
  277. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  278. editor.execCommand('inserttable');
  279. var width1 = editor.body.getElementsByTagName('td')[0].width;
  280. setTimeout(function () {
  281. editor.ui.setFullScreen(!editor.ui.isFullScreen());
  282. setTimeout(function () {
  283. var width2 = editor.body.getElementsByTagName('td')[0].width;
  284. ok((width1 - width2) > 10, '页面宽度自适应');
  285. div.parentNode.removeChild(div);
  286. start();
  287. }, 500);
  288. }, 500);
  289. });
  290. });
  291. test('backspace事件:删除caption', function () {
  292. if(ua.browser.ie&&ua.browser.ie>8)return ;//todo 1.3.0
  293. var editor = te.obj[0];
  294. var range = te.obj[1];
  295. editor.setContent('<p></p>');
  296. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  297. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  298. stop();
  299. setTimeout(function () {
  300. var trs = editor.body.firstChild.getElementsByTagName('tr');
  301. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  302. editor.execCommand('insertcaption');
  303. ua.keydown(editor.body, {'keyCode': 8});
  304. setTimeout(function () {
  305. equal(editor.body.getElementsByTagName('caption').length, 0, '删除caption');
  306. equal(editor.selection.getRange().collapsed, true, '检查光标');
  307. equal(editor.selection.getRange().startContainer, editor.body.getElementsByTagName('td')[0], '检查光标');
  308. start();
  309. }, 500);
  310. }, 50);
  311. });
  312. test('backspace事件:deleterow', function () {
  313. var editor = te.obj[0];
  314. var range = te.obj[1];
  315. editor.setContent('<p></p>');
  316. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  317. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  318. stop();
  319. setTimeout(function () {
  320. var trs = editor.body.firstChild.getElementsByTagName('tr');
  321. var ut = editor.getUETable(editor.body.firstChild);
  322. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[0].cells[2]);
  323. ut.setSelected(cellsRange);
  324. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  325. ua.keydown(editor.body, {'keyCode': 8});
  326. setTimeout(function () {
  327. equal(editor.body.getElementsByTagName('tr').length, 2, '删除整行');
  328. if(!ua.browser.ie||ua.browser.ie<9){//todo
  329. equal(editor.selection.getRange().collapsed, true, '检查光标');
  330. equal(editor.selection.getRange().startContainer, editor.body.getElementsByTagName('td')[0], '检查光标');
  331. }
  332. start();
  333. }, 100);
  334. }, 50);
  335. });
  336. test('backspace事件:deletecol', function () {
  337. var editor = te.obj[0];
  338. var range = te.obj[1];
  339. editor.setContent('<p></p>');
  340. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  341. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  342. stop();
  343. setTimeout(function () {
  344. var trs = editor.body.firstChild.getElementsByTagName('tr');
  345. var ut = editor.getUETable(editor.body.firstChild);
  346. var cellsRange = ut.getCellsRange(trs[0].cells[0], trs[2].cells[0]);
  347. ut.setSelected(cellsRange);
  348. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  349. setTimeout(function () {
  350. ua.keydown(trs[0].cells[0], {'keyCode': 8});
  351. setTimeout(function () {
  352. equal(editor.body.getElementsByTagName('tr')[0].getElementsByTagName('td').length, 2, '删除整列');
  353. if(!ua.browser.ie||ua.browser.ie<9){//todo
  354. equal(editor.selection.getRange().collapsed, true, '检查光标');
  355. equal(editor.selection.getRange().startContainer, editor.body.getElementsByTagName('td')[0], '检查光标');
  356. }
  357. start();
  358. }, 100);
  359. }, 50);
  360. }, 100);
  361. });
  362. //test('backspace事件:delcells', function () {
  363. // //TODO
  364. //});
  365. test('表格名称中backspace键', function () {
  366. var editor = te.obj[0];
  367. var range = te.obj[1];
  368. editor.setContent('<p></p>');
  369. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  370. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  371. stop();
  372. setTimeout(function () {
  373. var trs = editor.body.firstChild.getElementsByTagName('tr');
  374. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  375. editor.execCommand('insertcaption');
  376. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  377. ua.keydown(editor.body, {'keyCode': 8});
  378. setTimeout(function () {
  379. equal(editor.body.getElementsByTagName('caption').length, 0, '删除caption');
  380. equal(editor.body.getElementsByTagName('table').length, 1, '不会增加表格数量');
  381. equal(editor.body.getElementsByTagName('tr').length, 3, '不会增加表格行数量');
  382. equal(editor.body.getElementsByTagName('tr')[0].cells.length, 3, '不会增加表格列数量');
  383. if(!ua.browser.ie||ua.browser.ie<9){//todo
  384. equal(editor.selection.getRange().collapsed, true, '检查光标');
  385. equal(editor.selection.getRange().startContainer, editor.body.getElementsByTagName('td')[0], '检查光标');
  386. }
  387. start();
  388. }, 100);
  389. }, 200);
  390. });
  391. test('trace 3097 标题行中backspace键', function () {
  392. var editor = te.obj[0];
  393. var range = te.obj[1];
  394. editor.setContent('<p></p>');
  395. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  396. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  397. var trs = editor.body.firstChild.getElementsByTagName('tr');
  398. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  399. editor.execCommand('insertcaption');
  400. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  401. var x = range.cloneRange();
  402. editor.execCommand('inserttitle');
  403. range.setStart(editor.body.getElementsByTagName('th')[0], 0).collapse(true).select();
  404. ua.keydown(editor.body, {'keyCode': 8});
  405. stop();
  406. setTimeout(function () {
  407. editor = te.obj[0];
  408. equal(editor.body.getElementsByTagName('caption').length, 1, '不会删除caption');
  409. equal(editor.body.getElementsByTagName('th').length, 3, '不会误删除标题行');
  410. equal(editor.body.getElementsByTagName('table').length, 1, '不会增加表格数量');
  411. equal(editor.body.getElementsByTagName('tr').length, 4, '不会增加表格行数量');
  412. equal(editor.body.getElementsByTagName('tr')[0].cells.length, 3, '不会增加表格列数量');
  413. equal(editor.selection.getRange().collapsed, true, '检查光标');
  414. trs[0].cells[0].innerHTML = 'hello';
  415. // equal(editor.selection.getRange().startContainer, te.obj[0].body.getElementsByTagName('th')[0], '检查光标');
  416. equal(trs[0].cells[0].innerHTML,'hello', '检查光标');
  417. start();
  418. }, 50);
  419. });
  420. test('拖拽', function () {
  421. if (ua.browser.ie && ua.browser.ie < 8) return;
  422. var editor = te.obj[0];
  423. var range = te.obj[1];
  424. editor.setContent('<p></p>');
  425. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  426. editor.execCommand('inserttable');
  427. ua.manualDeleteFillData(editor.body);
  428. var tds = te.obj[0].body.getElementsByTagName('td');
  429. var width1 = tds[1].width;
  430. ua.mousemove(tds[1], {clientX: 199, clientY: 100});
  431. equal(editor.body.style.cursor, 'col-resize', '检查鼠标显示');
  432. ua.mousedown(tds[1], {clientX: 199, clientY: 100});
  433. setTimeout(function () {
  434. ua.mousemove(tds[1], {clientX: 299, clientY: 100});
  435. ua.mouseup(tds[1], {clientX: 299, clientY: 100});
  436. var p = ua.getMousePosition;
  437. setTimeout(function () {
  438. var width2 = tds[1].width;
  439. ok(width2 - width1 > 50, '拖拽后单元格宽度改变');
  440. start();
  441. }, 50);
  442. }, 400);
  443. stop();
  444. });
  445. test('拖拽_row-resize鼠标显示', function () {
  446. if (ua.browser.ie && ua.browser.ie < 8) return;
  447. var editor = te.obj[0];
  448. var range = te.obj[1];
  449. editor.setContent('<p></p>');
  450. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  451. editor.execCommand('inserttable');
  452. ua.manualDeleteFillData(editor.body);
  453. var tds = te.obj[0].body.getElementsByTagName('td');
  454. var width1 = tds[1].width;
  455. ua.mousemove(tds[4], {clientX: 450, clientY: 39});
  456. equal(editor.body.style.cursor, 'row-resize', 'row-resize鼠标显示');
  457. expect(3);
  458. setTimeout(function () {
  459. editor.addListener("tablemouseout", function (type, table, buttonOn) {
  460. same(table, editor.body.getElementsByTagName('table')[0], 'tablemouseout事件,传入的参数正确');
  461. });
  462. ua.mouseout(tds[1], {clientX: 299, clientY: 35});
  463. setTimeout(function () {
  464. equal(editor.body.style.cursor, 'text', '焦点转移,row-resize不显示');
  465. start();
  466. }, 50);
  467. }, 20);
  468. stop();
  469. });
  470. test('拖拽-最右边的单元格', function () {
  471. if (ua.browser.ie && ua.browser.ie < 8) return;
  472. var editor = te.obj[0];
  473. var range = te.obj[1];
  474. editor.setContent('<p></p>');
  475. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  476. editor.execCommand('inserttable');
  477. ua.manualDeleteFillData(editor.body);
  478. var tds = te.obj[0].body.getElementsByTagName('td');
  479. var width1 = tds[4].width;
  480. ua.mousemove(tds[4], {clientX: 492, clientY: 21});
  481. equal(editor.body.style.cursor, 'col-resize', '检查鼠标显示');
  482. ua.mousedown(tds[4], {clientX: 492, clientY: 21});
  483. setTimeout(function () {
  484. ua.mousemove(tds[4], {clientX: 481, clientY: 21});
  485. ua.mouseup(tds[4], {clientX: 481, clientY: 21});
  486. setTimeout(function () {
  487. var width2 = te.obj[0].body.getElementsByTagName('td')[4].width;
  488. ok(width1 != width2 , '拖拽后单元格宽度改变');
  489. start();
  490. }, 50);
  491. }, 400);
  492. stop();
  493. });
  494. test('拖拽-最下边的单元格', function () {
  495. // if (ua.browser.ie ) return;//todo 1.3.0
  496. var editor = te.obj[0];
  497. var range = te.obj[1];
  498. editor.setContent('<p></p>');
  499. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  500. editor.execCommand('inserttable');
  501. var tds = te.obj[0].body.getElementsByTagName('td');
  502. var height1 = tds[20].height;
  503. ua.mousemove(tds[24], {clientX: 439, clientY: 512});
  504. ua.mousedown(tds[24], {clientX: 439, clientY: 512});
  505. equal(editor.body.style.cursor, 'row-resize', '检查鼠标显示');
  506. setTimeout(function () {
  507. ua.mousemove(tds[24], {clientX: 439, clientY: 562});
  508. ua.mouseup(tds[24], {clientX: 439, clientY: 562});
  509. setTimeout(function () {
  510. var height2 = te.obj[0].body.getElementsByTagName('td')[20].height;
  511. ok(height2 - height1 > 10, '拖拽后单元格宽度改变');
  512. start();
  513. }, 50);
  514. }, 400);
  515. stop();
  516. });
  517. test('trace 3022 表格名称中backspace、ctrl+z、enter', function () {
  518. var editor = te.obj[0];
  519. var range = te.obj[1];
  520. editor.setContent('<p></p>');
  521. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  522. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  523. // expect(9);
  524. editor.addListener('saveScene', function () {
  525. ok(true);
  526. });
  527. stop();
  528. setTimeout(function () {
  529. var trs = editor.body.firstChild.getElementsByTagName('tr');
  530. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  531. editor.execCommand('insertcaption');
  532. ua.keydown(editor.body, {'keyCode': 8});
  533. setTimeout(function () {
  534. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  535. ua.keydown(editor.body, {'keyCode': 90, 'ctrlKey': true});
  536. setTimeout(function () {
  537. ua.keydown(editor.body, {'keyCode': 13});
  538. equal(te.obj[0].body.getElementsByTagName('caption').length, 1, '撤销删除caption');
  539. equal(te.obj[0].body.getElementsByTagName('th').length, 0, '不会误插入标题行');
  540. equal(te.obj[0].body.getElementsByTagName('table').length, 1, '不会增加表格数量');
  541. equal(te.obj[0].body.getElementsByTagName('tr').length, 3, '不会增加表格行数量');
  542. equal(te.obj[0].body.getElementsByTagName('tr')[0].cells.length, 3, '不会增加表格列数量');
  543. equal(te.obj[0].selection.getRange().collapsed, true, '检查光标');
  544. if(!ua.browser.gecko && !ua.browser.webkit)//todo 1.3.6 ff 回退后光标找不好
  545. equal(te.obj[0].selection.getRange().startContainer.parentNode, te.obj[0].body.getElementsByTagName('td')[0], '检查光标');
  546. start();
  547. }, 20);
  548. }, 20);
  549. }, 50);
  550. });
  551. /*trace 3067*/
  552. test('trace 3067 向右合并--tab键', function () {
  553. var editor = te.obj[0];
  554. var range = te.obj[1];
  555. editor.setContent('<p></p>');
  556. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  557. editor.execCommand('inserttable', {numCols: 2, numRows: 2});
  558. ua.manualDeleteFillData(editor.body);
  559. var tds = editor.body.getElementsByTagName('td');
  560. range.setStart(tds[0], 0).collapse(true).select();
  561. editor.execCommand('mergeright');
  562. range.setStart(tds[0], 0).collapse(true).select();
  563. range = editor.selection.getRange();
  564. var common = range.getCommonAncestor(true, true);
  565. equal(common.colSpan, 2, 'tab键前光标位于合并后的单元格中');
  566. ua.keydown(editor.body, {'keyCode': 9});
  567. setTimeout(function () {
  568. range = editor.selection.getRange();
  569. common = range.getCommonAncestor(true, true);
  570. equal(common.colSpan, 1, 'tab键前光标跳到合并后单元格的下一个单元格中');
  571. start();
  572. }, 20);
  573. stop();
  574. });
  575. /*trace 3100*/
  576. test('trace 3100 表格名称中tab键', function () {
  577. var editor = te.obj[0];
  578. var range = te.obj[1];
  579. editor.setContent('<p></p>');
  580. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  581. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  582. var trs = editor.body.firstChild.getElementsByTagName('tr');
  583. range.setStart(trs[0].cells[0], 0).collapse(true).select();
  584. editor.execCommand('insertcaption');
  585. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  586. ua.keydown(editor.body, {'keyCode': 9});
  587. stop();
  588. setTimeout(function () {
  589. editor = te.obj[0];
  590. equal(editor.body.getElementsByTagName('caption').length, 1, '不会删除caption');
  591. equal(editor.body.getElementsByTagName('th').length, 0, '不会误插入标题行');
  592. equal(editor.body.getElementsByTagName('table').length, 1, '不会增加表格数量');
  593. equal(editor.body.getElementsByTagName('tr').length, 3, '不会增加表格行数量');
  594. equal(editor.body.getElementsByTagName('tr')[0].cells.length, 3, '不会增加表格列数量');
  595. equal(editor.selection.getRange().collapsed, true, '检查光标');
  596. if (!ua.browser.ie) //ie8下会导致堆栈溢出,奇葩的bug,以后不溢出再检查ie8
  597. equal(editor.selection.getRange().startContainer, te.obj[0].body.getElementsByTagName('td')[0], '检查光标');
  598. start();
  599. }, 50);
  600. });
  601. /*trace 3059*/
  602. test('trace 3059 表格右浮动', function () {
  603. if (ua.browser.ie)return;//TODO 1.2.6
  604. var editor = te.obj[0];
  605. var range = te.obj[1];
  606. editor.setContent('<p></p>');
  607. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  608. editor.execCommand('inserttable');
  609. ua.manualDeleteFillData(editor.body);
  610. var tds = te.obj[0].body.getElementsByTagName('td');
  611. var oldWidth = tds[0].offsetWidth;
  612. ua.mousemove(tds[0], {clientX: 105, clientY: 20});
  613. ua.mousedown(tds[0], {clientX: 105, clientY: 20});
  614. ua.mouseup(tds[0], {clientX: 105, clientY: 20});
  615. setTimeout(function () {
  616. ua.mousedown(tds[0], {clientX: 105, clientY: 20});
  617. ua.mouseup(tds[0], {clientX: 105, clientY: 20});
  618. setTimeout(function () {
  619. tds = editor.body.firstChild.getElementsByTagName('td');
  620. ok(tds[0].offsetWidth < oldWidth, '第一列宽度变小');
  621. range.setStart(tds[0], 0).collapse(true).select();
  622. editor.execCommand('tablealignment', 'right');
  623. var table = te.obj[0].body.getElementsByTagName('table')[0];
  624. equal(table.align, 'right', '表格右浮动');
  625. start();
  626. }, 500);
  627. }, 50);
  628. stop();
  629. });
  630. test('trace 3378:拖拽后tab,不影响表格样式', function () {
  631. if (ua.browser.ie && ua.browser.ie < 8) return;
  632. var editor = te.obj[0];
  633. var range = te.obj[1];
  634. editor.setContent('<p></p>');
  635. range.setStart(editor.body.firstChild, 0).collapse(true).select();
  636. editor.execCommand('inserttable');
  637. ua.manualDeleteFillData(editor.body);
  638. var tds = te.obj[0].body.getElementsByTagName('td');
  639. var width1 = tds[1].width;
  640. ua.mousemove(tds[1], {clientX: 199, clientY: 100});
  641. ua.mousedown(tds[1], {clientX: 199, clientY: 100});
  642. setTimeout(function () {
  643. ua.mousemove(tds[1], {clientX: 299, clientY: 100});
  644. ua.mouseup(tds[1], {clientX: 299, clientY: 100});
  645. var width2 = tds[1].width;
  646. ok(width2 - width1 > 50, '拖拽后单元格宽度改变');
  647. range.setStart(tds[24], 0).collapse(true).select();
  648. ua.keydown(editor.body, {'keyCode': 9});
  649. setTimeout(function () {
  650. equal(tds[1].width, width2, 'tab键不影响单元格宽度');
  651. start();
  652. }, 20);
  653. }, 400);
  654. stop();
  655. });
  656. //超时,暂时注掉
  657. test('表格粘贴', function () {
  658. var div = document.body.appendChild(document.createElement('div'));
  659. var editor = te.obj[0];
  660. var range = te.obj[1];
  661. editor.setContent('');
  662. editor.execCommand('inserttable');
  663. /*插入表格*/
  664. var tds = editor.body.getElementsByTagName('td');
  665. var ut = editor.getUETable(editor.body.firstChild);
  666. var cellsRange = ut.getCellsRange(tds[0], tds[24]);
  667. ut.setSelected(cellsRange);
  668. /*确定选区*/
  669. range.setStart(tds[0], 0).collapse(true).select();
  670. /*定光标*/
  671. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  672. /*ctrl+c*/
  673. var html = {html: editor.body.innerHTML};
  674. range.setStart(editor.body.lastChild, 0).collapse(true).select();
  675. equal(editor.body.getElementsByTagName('table').length, '1', '触发粘贴事件前有1个table');
  676. editor.fireEvent('beforepaste', html);
  677. /*粘贴*/
  678. editor.fireEvent("afterpaste");
  679. equal(editor.body.getElementsByTagName('table').length, '2', '触发粘贴事件后有2个table');
  680. });
  681. //
  682. //test('trace 3104 粘贴后合并单元格',function(){
  683. // var div = document.body.appendChild(document.createElement('div'));
  684. // var editor = te.obj[0];
  685. // var range = te.obj[1];
  686. // editor.setContent('');
  687. // editor.execCommand('inserttable');
  688. // var trs = editor.body.getElementsByTagName('tr');
  689. // var ut = editor.getUETable(editor.body.firstChild);
  690. // var cellsRange = ut.getCellsRange(trs[0].cells[0],trs[4].cells[0]);
  691. // ut.setSelected(cellsRange);
  692. // range.setStart( trs[0].cells[0], 0 ).collapse( true ).select();
  693. // ua.keydown(editor.body,{'keyCode':67,'ctrlKey':true});
  694. // ut.clearSelected();
  695. // var html ={html:editor.body.innerHTML};
  696. // range.setStart(editor.body.lastChild,0).collapse(true).select();
  697. // editor.fireEvent('beforepaste',html);
  698. // editor.fireEvent("afterpaste");
  699. // var table = editor.body.getElementsByTagName('table');
  700. // equal(table.length,'2','触发粘贴事件后有2个table');
  701. // equal(table[1].firstChild.childNodes.length,'5','5行');
  702. // equal(table[1].firstChild.firstChild.childNodes.length,'1','1列');
  703. //
  704. // var tds = editor.body.getElementsByTagName('td');
  705. // ut = editor.getUETable(editor.body.firstChild.nextSibling);
  706. // cellsRange = ut.getCellsRange(tds[25],tds[29]);
  707. // ut.setSelected(cellsRange);
  708. // range.setStart(tds[25], 0 ).collapse( true ).select();
  709. // editor.execCommand('mergecells');
  710. // table = editor.body.getElementsByTagName('table');
  711. // equal(table[1].firstChild.childNodes.length,'1','1行');
  712. // equal(table[1].firstChild.firstChild.childNodes.length,'1','1列');
  713. //});
  714. //
  715. test('trace 3105 在表格名称中粘贴', function () {
  716. var div = document.body.appendChild(document.createElement('div'));
  717. var editor = te.obj[0];
  718. var range = te.obj[1];
  719. editor.setContent('');
  720. editor.execCommand('inserttable', {numCols: 2, numRows: 2});
  721. range.setStart(editor.body.getElementsByTagName('td')[0], 0).collapse(true).select();
  722. editor.execCommand('insertcaption');
  723. var str = ua.getChildHTML(editor.body);
  724. var ut = editor.getUETable(editor.body.firstChild);
  725. var tds = editor.body.getElementsByTagName('td');
  726. var cellsRange = ut.getCellsRange(tds[0], tds[1]);
  727. ut.setSelected(cellsRange);
  728. range.setStart(tds[0], 0).collapse(true).select();
  729. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  730. var html = {html: editor.body.innerHTML};
  731. range.setStart(editor.body.getElementsByTagName('caption')[0], 0).collapse(true).select();
  732. editor.fireEvent('beforepaste', html);
  733. editor.fireEvent("afterpaste");
  734. ut.clearSelected();
  735. equal(editor.body.getElementsByTagName('table').length, '1', '触发粘贴事件后有1个table');
  736. equal(ua.getChildHTML(editor.body), str, '粘贴无效');
  737. });
  738. test('trace 3106 粘贴标题行', function () {
  739. var div = document.body.appendChild(document.createElement('div'));
  740. var editor = te.obj[0];
  741. var range = te.obj[1];
  742. editor.setContent('');
  743. editor.execCommand('inserttable');
  744. var tds = editor.body.getElementsByTagName('td');
  745. range.setStart(tds[0], 0).collapse(true).select();
  746. editor.execCommand('inserttitle');
  747. var ut = editor.getUETable(editor.body.firstChild);
  748. var ths = editor.body.getElementsByTagName('th');
  749. var cellsRange = ut.getCellsRange(ths[0], ths[4]);
  750. ut.setSelected(cellsRange);
  751. range.setStart(ths[0], 0).collapse(true).select();
  752. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  753. var html = {html: editor.body.innerHTML};
  754. range.setStart(editor.body.lastChild, 0).collapse(true).select();
  755. editor.fireEvent('beforepaste', html);
  756. editor.fireEvent("afterpaste");
  757. equal(editor.body.getElementsByTagName('table').length, '2', '触发粘贴事件后有2个table');
  758. if (ua.browser.gecko) {
  759. //这个比较没意义
  760. // equal(editor.body.firstChild.firstChild.firstChild.firstChild.tagName.toLowerCase(),'td','不是th,是td');
  761. range.setStart(editor.body.firstChild.firstChild.firstChild.firstChild, 0).collapse(true).select();
  762. equal(editor.queryCommandState('inserttable'), -1, '应当不可以插入表格');
  763. equal(editor.queryCommandState('mergeright'), 0, '应当可以右合并单元格');
  764. }
  765. else {
  766. // equal(editor.body.firstChild.nextSibling.firstChild.firstChild.firstChild.tagName.toLowerCase(),'td','不是th,是td');
  767. range.setStart(editor.body.firstChild.nextSibling.firstChild.firstChild.firstChild, 0).collapse(true).select();
  768. equal(editor.queryCommandState('inserttable'), -1, '应当不可以插入表格');
  769. equal(editor.queryCommandState('mergeright'), 0, '应当可以右合并单元格');
  770. }
  771. });
  772. test('trace 3114 在单元格内粘贴行', function () {
  773. var div = document.body.appendChild(document.createElement('div'));
  774. var editor = te.obj[0];
  775. var range = te.obj[1];
  776. editor.setContent('');
  777. editor.execCommand('inserttable');
  778. var tds = editor.body.getElementsByTagName('td');
  779. var ut = editor.getUETable(editor.body.firstChild);
  780. var cellsRange = ut.getCellsRange(tds[0], tds[9]);
  781. ut.setSelected(cellsRange);
  782. range.setStart(tds[0], 0).collapse(true).select();
  783. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  784. var html = {html: editor.body.innerHTML};
  785. range.setStart(tds[0], 0).collapse(true).select();
  786. editor.fireEvent('beforepaste', html);
  787. editor.fireEvent("afterpaste");
  788. equal(editor.body.getElementsByTagName('table').length, '1', '触发粘贴事件后有1个table');
  789. stop();
  790. setTimeout(function () {
  791. editor.execCommand('source');
  792. setTimeout(function () {
  793. editor.execCommand('source');
  794. equal(editor.body.getElementsByTagName('tr').length, '7', '触发粘贴事件后有7个tr');
  795. start();
  796. }, 50);
  797. }, 50);
  798. });
  799. test('在单元格中粘贴_粘到最后', function () {
  800. var editor = te.obj[0];
  801. var range = te.obj[1];
  802. editor.setContent('');
  803. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  804. /*插入表格*/
  805. var tds = editor.body.getElementsByTagName('td');
  806. var ut = editor.getUETable(editor.body.firstChild);
  807. var cellsRange = ut.getCellsRange(tds[0], tds[4]);
  808. ut.setSelected(cellsRange);
  809. /*确定选区*/
  810. range.setStart(tds[0], 0).collapse(true).select();
  811. /*定光标*/
  812. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  813. /*ctrl+c*/
  814. var html = {html: editor.body.innerHTML};
  815. range.setStart(tds[8], 0).collapse(true).select();
  816. equal(editor.body.getElementsByTagName('tr').length, 3, '触发粘贴事件前有3个tr');
  817. equal(editor.body.getElementsByTagName('td').length, 9, '触发粘贴事件前有9个td');
  818. editor.fireEvent('beforepaste', html);
  819. /*粘贴*/
  820. editor.fireEvent("afterpaste");
  821. equal(editor.body.getElementsByTagName('tr').length, 4, '触发粘贴事件后有4个tr');
  822. equal(editor.body.getElementsByTagName('td').length, 16, '触发粘贴事件后有12个td');
  823. });
  824. test('在单元格中粘贴_整列', function () {
  825. var editor = te.obj[0];
  826. var range = te.obj[1];
  827. editor.setContent('');
  828. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  829. /*插入表格*/
  830. var tds = editor.body.getElementsByTagName('td');
  831. range.setStart(tds[0], 0).collapse(true).select();
  832. editor.execCommand('inserttitle');
  833. var ut = editor.getUETable(editor.body.firstChild);
  834. var cellsRange = ut.getCellsRange(tds[0], tds[6]);
  835. ut.setSelected(cellsRange);
  836. /*确定选区*/
  837. range.setStart(tds[0], 0).collapse(true).select();
  838. /*定光标*/
  839. ua.keydown(editor.body, {'keyCode': 67, 'ctrlKey': true});
  840. /*ctrl+c*/
  841. var html = {html: editor.body.innerHTML};
  842. range.setStart(tds[6], 0).collapse(true).select();
  843. equal(editor.body.getElementsByTagName('tr').length, 4, '触发粘贴事件前有4个tr');
  844. equal(editor.body.getElementsByTagName('th').length, 3, '触发粘贴事件前有3个th');
  845. equal(editor.body.getElementsByTagName('td').length, 9, '触发粘贴事件前有9个td');
  846. editor.fireEvent('beforepaste', html);
  847. /*粘贴*/
  848. editor.fireEvent("afterpaste");
  849. equal(editor.body.getElementsByTagName('tr').length, 4, '触发粘贴事件后有4个tr');
  850. equal(editor.body.getElementsByTagName('th').length, 4, '触发粘贴事件前有4个th');
  851. equal(editor.body.getElementsByTagName('td').length, 12, '触发粘贴事件后有12个td');
  852. });
  853. test('点击一行的最左边,选中一行', function () {
  854. if (ua.browser.ie && ua.browser.ie < 9)return;//todo click事件模拟有问题
  855. var editor = te.obj[0];
  856. var range = te.obj[1];
  857. editor.setContent('');
  858. editor.execCommand('inserttable', {numCols: 2, numRows: 3});
  859. /*插入表格*/
  860. setTimeout(function () {
  861. var tds = editor.body.getElementsByTagName('td');
  862. tds[0].innerHTML = 'hello1';
  863. tds[1].innerHTML = 'hello2';
  864. ua.mousemove(tds[0], {clientX: 8, clientY: 24});
  865. ua.click(tds[0], {clientX: 8, clientY: 24});
  866. setTimeout(function () {
  867. var space = ua.browser.ie ? '' : ' ';
  868. var quot = ua.browser.gecko ? '\"' : '';
  869. equal(editor.body.style.cursor, 'url(' + quot + editor.options.cursorpath + 'v.png' + quot + '),' + space + 'pointer');
  870. // //me.body.style.cursor
  871. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  872. equal(selectedTds.length, 2, '选中一行');
  873. equal(selectedTds[0].className, 'selectTdClass', '检查样式');
  874. equal(selectedTds[1].className, 'selectTdClass', '检查样式');
  875. equal(selectedTds[0].innerHTML, 'hello1', '检查内容');
  876. equal(selectedTds[1].innerHTML, 'hello2', '检查内容');
  877. //todo trace 3571
  878. // ua.click(tds[2],{clientX:12,clientY:24,shiftKey:true});
  879. // equal(editor.getUETable(editor.body.firstChild).selectedTds.length,6,'');
  880. start();
  881. }, 50);
  882. }, 50);
  883. stop();
  884. });
  885. test('点击一行的最左边,但是每行只有一列,这时选中单元格中的内容', function () {
  886. if (ua.browser.ie && ua.browser.ie < 9)return;//todo click事件模拟有问题
  887. var editor = te.obj[0];
  888. editor.setContent('');
  889. editor.execCommand('inserttable', {numCols: 1, numRows: 1});
  890. /*插入表格*/
  891. var tds = editor.body.getElementsByTagName('td');
  892. tds[0].innerHTML = 'hello';
  893. setTimeout(function () {
  894. window.scrollTo(0,0);//保证位置准确
  895. ua.click(tds[0], {clientX: 10, clientY: 23});
  896. setTimeout(function () {
  897. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  898. equal(selectedTds.length, 0, '不选中行');
  899. if (ua.browser.ie>8) {
  900. ua.checkResult(editor.selection.getRange(), tds[0].firstChild, tds[0].firstChild, 0, 5, false, '检查选中的range');
  901. } else {
  902. ua.checkResult(editor.selection.getRange(), tds[0], tds[0], 0, 1, false, '检查选中的range');
  903. }
  904. start();
  905. }, 500);
  906. }, 500);
  907. stop();
  908. });
  909. test('点击一列的最上边,但是每列只有一行,这时选中单元格中的内容', function () {
  910. if (ua.browser.ie && ua.browser.ie < 9)return;//todo click事件模拟有问题
  911. var editor = te.obj[0];
  912. var range = te.obj[1];
  913. editor.setContent('');
  914. editor.execCommand('inserttable', {numCols: 1, numRows: 1});
  915. /*插入表格*/
  916. stop();
  917. setTimeout(function () {
  918. var tds = editor.body.getElementsByTagName('td');
  919. tds[0].innerHTML = 'hello';
  920. window.scrollTo(0,0);//保证位置准确
  921. ua.click(tds[0], {clientX: 81, clientY: 9,pageX: 81, pageY: 9});
  922. setTimeout(function () {
  923. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  924. equal(selectedTds.length, 0, '不选中列');
  925. if (ua.browser.ie>8) {
  926. ua.checkResult(editor.selection.getRange(), tds[0].firstChild, tds[0].firstChild, 0, 5, false, '检查选中的range');
  927. } else {
  928. ua.checkResult(editor.selection.getRange(), tds[0], tds[0], 0, 1, false, '检查选中的range');
  929. }
  930. start();
  931. },10);
  932. }, 50);
  933. });
  934. test('点击一列的最上边,选中一列', function () {
  935. if (ua.browser.ie && ua.browser.ie < 9)return;//todo click事件模拟有问题
  936. var editor = te.obj[0];
  937. var range = te.obj[1];
  938. editor.setContent('');
  939. editor.execCommand('inserttable', {numCols: 3, numRows: 3});
  940. /*插入表格*/
  941. stop();
  942. setTimeout(function () {
  943. var tds = editor.body.getElementsByTagName('td');
  944. tds[0].innerHTML = 'hello';
  945. window.scrollTo(0,0);
  946. ua.mousemove(tds[0], {clientX: 81, clientY: 9});
  947. var space = ua.browser.ie ? '' : ' ';
  948. var quot = ua.browser.gecko ? '\"' : '';
  949. equal(editor.body.style.cursor, 'url(' + quot + editor.options.cursorpath + 'h.png' + quot + '),' + space + 'pointer');
  950. ua.click(tds[0], {clientX: 81, clientY: 9});
  951. setTimeout(function () {
  952. var selectedTds = editor.getUETable(editor.body.firstChild).selectedTds;
  953. equal(selectedTds.length, 3, '选中一列');
  954. equal(selectedTds[0].innerHTML, 'hello', '检查内容');
  955. equal(selectedTds[0].className, 'selectTdClass', '检查样式');
  956. equal(selectedTds[1].className, 'selectTdClass', '检查样式');
  957. equal(selectedTds[2].className, 'selectTdClass', '检查样式');
  958. //todo trace 3571
  959. // ua.click(tds[2],{clientX:370,clientY:9,shiftKey:true});
  960. // equal(editor.getUETable(editor.body.firstChild).selectedTds.length,9,'');
  961. start();
  962. }, 500);
  963. }, 50);
  964. });