module("plugins.font"); //test('stop',function(){stop();}); test('trace1583:applyInlineStyle--MergeToParent', function () { var editor = te.obj[0]; var range = te.obj[1]; stop(); setTimeout(function () { editor.setContent('
12345678910
'); range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 4).select(); editor.execCommand('fontsize', '24px'); var html = '12345678910'; ua.checkSameHtml(editor.body.firstChild.innerHTML.toLowerCase(), html, ''); start(); }, 50); }); test('trace 3337:字符边框', function () { if (ua.browser.opera)return; var editor = te.obj[0]; var range = te.obj[1]; editor.setContent(''); range.setStart(editor.body.firstChild, 0).collapse(true).select(); editor.execCommand('fontborder'); range = editor.selection.getRange(); range.insertNode(editor.document.createTextNode('hello')); ua.manualDeleteFillData(editor.body); var br = baidu.editor.browser.ie ? ' ' : '欢迎光临
'); range.setStart(editor.body.firstChild.firstChild, 0).setEnd(editor.body.firstChild.lastChild, 3).select(); editor.execCommand('fontborder'); var p1 = '欢迎光临'; var p2 = '欢迎光临'; if (ua.browser.ie && ua.browser.ie < 9) ua.checkSameHtml(editor.body.firstChild.innerHTML, p2, '查看添加了字符边框后的样式'); else ua.checkHTMLSameStyle(p1, editor.document, editor.body.firstChild, '查看添加了字符边框后的样式'); }); test('设置超链接前景色再清除颜色', function () { if (ua.browser.ie < 9)return;//TODO 1.2.6 var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('hellobaidu
'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('forecolor', 'rgb(255,0,0)'); editor.execCommand('backcolor', 'rgb(0,255,0)'); editor.execCommand('forecolor', 'default'); // var html = 'hellobaidu';todo 1.2.6.1 样式复制了一次 var html = 'hellobaidu'; ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '清除前景色'); }); test('font转span', function () { var editor = te.obj[0]; editor.setContent('hellohello'); var html = 'hellohello'; ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签'); /*size的值在sizeMap中有对应的值*/ editor.setContent('hello'); html = 'hello'; ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签'); }); test('beforegetContent', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.body.innerHTML = 'hello
'; range.selectNode(editor.body.firstChild).select(); editor.execCommand('forecolor', 'rgb(255,0,0)'); var div = document.createElement('div'); var div1 = document.createElement('div'); stop(); setTimeout(function () { /*getContent会触发beforegetcontent事件*/ div1.innerHTML = editor.getContent(); div.innerHTML = 'hello
'; // ok( ua.haveSameAllChildAttribs( div, div1 ), '查看空span是否被删除' ); // equal(ua.getChildHTML(div), ua.getChildHTML(div1)); start(); }, 50); }); /*为超链接添加删除线,超链接仍然有删除线,trace946*/ test('underline and linethrough', function () { var editor = te.obj[0]; var range = te.obj[1]; stop(); editor.setContent('hellobaidutest'); setTimeout(function () { if (!ua.browser.opera) { editor.focus(); } var body = editor.body; ua.manualDeleteFillData(editor.body); range.selectNode(body.firstChild.firstChild.nextSibling).select(); ok(/underline/.test(editor.queryCommandValue('underline')), 'query command value is underline'); ok(/underline/.test(editor.queryCommandValue('strikethrough')), 'query command value is underline'); ok(editor.queryCommandState('underline'), 'query underline state'); editor.execCommand('strikethrough'); var html = 'hellobaidutest'; ua.checkHTMLSameStyle(html, editor.document, body.firstChild, 'check results'); start(); }, 50); }); /*为不同字号的文本加背景色,trace981*/ test('background--不同字号', function () { if (!ua.browser.opera) { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('你好'); editor.focus(); var body = editor.document.body; ua.manualDeleteFillData(editor.body); range.selectNode(body.firstChild.firstChild).select(); editor.execCommand('backcolor', 'rgb(255,0,0)'); range.setStart(body.firstChild.firstChild, 1).collapse(1).select(); editor.execCommand('fontsize', '30px'); range = editor.selection.getRange(); range.insertNode(editor.document.createTextNode('hello')); stop(); setTimeout(function () { ua.manualDeleteFillData(editor.body); /*去掉空白字符*/ var color = ua.browser.ie && ua.browser.ie < 9 ? '' : ';background-color: rgb(255, 0, 0); '; var html = '你好hello'; ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '检查不同字号的文本背景色是否一致'); start(); }, 50); } }); /*trace 937,chrome,safari,maxthon有问题*/ test('trace 937:为第一个有样式的字加删除线', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('欢迎光临
'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('strikethrough'); var p1 = editor.document.createElement('p'); p1.innerHTML = '欢迎光临'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '查看添加了下划线后的样式'); }); /*trace 918*/ test('trace 918:字体的状态反射', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('欢迎你回来
'); var p = editor.body.firstChild; range.selectNode(p).select(); editor.execCommand('underline'); var p1 = document.createElement('p'); p1.innerHTML = '欢迎你回来'; if (!ua.browser.opera) { ok(ua.haveSameAllChildAttribs(p, p1), '检查是否添加了下划线'); } range.setStart(p.firstChild.firstChild, 3).setEnd(p.firstChild.firstChild, 4).select(); editor.execCommand('fontfamily', '楷体'); var txt = '楷体'; if (ua.browser.opera) txt = '\"楷体\"'; equal(editor.queryCommandValue('fontfamily'), txt, '检查字体的状态反射'); }); test(' 选中文本设置前景色为默认', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('hello'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('forecolor', 'rgb(255,0,0)'); ua.checkHTMLSameStyle('hello', editor.document, editor.body.firstChild, '文本的前景色设为红色'); editor.execCommand('forecolor', 'default'); equal(ua.getChildHTML(editor.body), 'hello
', '设置字体颜色为默认颜色'); }); /*trace 869*/ //插件相关!!!!!!!!!! //test( 'trace 869:设置前景色后清除前景色,再输入文本', function() { // var editor = te.obj[0]; // var range = te.obj[1]; // editor.setContent( '' ); // stop() //// alert(navigator.userAgent) // setTimeout( function() { // range.setStart( editor.body.firstChild, 0 ).select(); // editor.execCommand( 'forecolor', 'red' ); // editor.execCommand( 'forecolor', 'default' ); // range = editor.selection.getRange(); // editor.focus(); // setTimeout( function() { // //TODO maxthon有2种模式,句柄分为IE的和maxthon两种,需要根据userAgent区别对待,但是貌似还是有问题的 // te.presskey( '', 'e' ); // editor.focus(); // setTimeout( function() { // var br = baidu.editor.browser.ie ? '' : 'e' + br + '
' ); // start(); // }, 250 ); // }, 100 ); //// range.insertNode( document.createTextNode( 'hello' ) ); // }, 150 ); //} ); /*trace 823*/ //TODO 涉及文本输入和光标位置移动的结合 // 不好测,采取workaround,不用输入的方式 test('trace 823:设置前景色后设置删除线', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('你好hello
'); range.selectNode(editor.body.firstChild.firstChild, 0).select(); editor.execCommand('strikethrough'); var p1 = editor.document.createElement('p'); p1.innerHTML = '你好hello'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查加入删除线后的样式'); }); /*trace 819, 765*/ test('trace 819, 765:删除线和下划线互斥', function () { var editor = te.obj[0]; var range = te.obj[1]; var p1 = editor.document.createElement('p'); editor.setContent('你好
'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('underline'); p1.innerHTML = '你好'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '下划线'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('strikethrough'); p1.innerHTML = '你好'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '删除线,和下划线互斥'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('underline'); p1.innerHTML = '你好'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '下划线,和删除线互斥'); }); ///*trace 810*/ //TODO 1.2.6 //test( 'trace 810:闭合时设置删除线会改变文本前景色', function() { // if(!ua.browser.opera){ // var editor = te.obj[2]; // var div = document.body.appendChild( document.createElement( 'div' ) ); // $( div ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' ); // editor.render(div); // var range = new baidu.editor.dom.Range( editor.document ); // stop(); // setTimeout(function(){ // editor.setContent( '你好hello
' ); // range.setStart( editor.body.firstChild.firstChild.lastChild, 1 ).collapse( true ).select(); // editor.execCommand( 'strikethrough' ); // range = editor.selection.getRange(); // range.insertNode( editor.document.createTextNode( 'hey' ) ); // /*ff下会自动加一个空的设置了style的span,比较时不作考虑*/ // if ( baidu.editor.dom.domUtils.isEmptyNode( editor.body.firstChild.lastChild ) && baidu.editor.browser.gecko ) // editor.body.firstChild.removeChild( editor.body.firstChild.lastChild ); // var html = '你好hellohey'; // ua.checkHTMLSameStyle( html, editor.document, editor.body.firstChild, '检查插入的删除线前景色是否正确' ); // equal(editor.body.firstChild.innerHTML,html); // div.parentNode.removeChild(div); // start(); // },50); // } //} ); /*trace 809*/ test('trace 809:闭合时改变前景色和删除线,再输入文本', function () { if (!ua.browser.opera) { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('你好
'); var p = editor.body.firstChild; range.setStart(p.firstChild, 1).collapse(true).select(); editor.execCommand('forecolor', 'rgb(0,255,0)'); range = editor.selection.getRange(); editor.execCommand('underline'); range = editor.selection.getRange(); range.insertNode(editor.document.createTextNode('hey')); var p1 = editor.document.createElement('p'); p1.innerHTML = '你好hey'; ua.manualDeleteFillData(editor.body); /*ff下会自动加一个空的设置了style的span,比较时不作考虑*/ if (baidu.editor.dom.domUtils.isEmptyNode(editor.body.firstChild.lastChild) && baidu.editor.browser.gecko) editor.body.firstChild.removeChild(editor.body.firstChild.lastChild); ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查新输入的文本下划线和颜色是否正确'); } }); /*trace 805*/ test('trace 805:切换删除线和下划线,前景色没了', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('你好早安
'); var text = editor.body.firstChild.firstChild.firstChild; range.selectNode(text).select(); editor.execCommand('forecolor', 'rgb(255,0,0)'); range.setStart(text, 0).setEnd(text, 2).select(); editor.execCommand('underline'); range.setStart(text, 0).setEnd(text, 2).select(); editor.execCommand('strikethrough'); var p1 = editor.document.createElement('p'); p1.innerHTML = '你好早安'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '查看前景色是不是还在'); }); /*trace 802*/ test('trace 802:为设置了字体的文本添加删除线', function () { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('你好早安
'); var text = editor.body.firstChild.firstChild.firstChild; range.setStart(text, 0).setEnd(text, 2).select(); editor.execCommand('strikethrough'); var p1 = editor.document.createElement('p'); p1.innerHTML = '你好早安'; ok(ua.haveSameAllChildAttribs(editor.body.firstChild, p1), '检查删除线是否正确'); editor.execCommand('fontfamily', '隶书'); editor.execCommand('source'); var txt = '隶书'; if (ua.browser.opera) txt = '\"隶书\"'; if(!ua.browser.gecko)//todo 1.4.0 equal(editor.queryCommandValue('fontfamily'), txt); }); /*trace 744*/ test('trace 744:设置超链接背景色后切换到源码再切回来', function () { var editor = te.obj[0]; var range = te.obj[1]; stop(); editor.setContent('hellobaidu
'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('backcolor', 'rgb(255,0,0)'); var html = editor.body.firstChild.innerHTML; editor.execCommand('source'); setTimeout(function () { editor.execCommand('source'); setTimeout(function () { ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '切换后html代码不变'); /*切换源码前后代码应当相同*/ start(); }, 50); }, 50); }); test('对表格中的文本添加颜色和下划线', function () { var editor = te.obj[0]; var range = te.obj[1]; stop(); editor.setContent('hello1 | hello2 |
hello3 |
你好早安
'); range.selectNode(editor.body.firstChild).select(); editor.execCommand('forecolor', 'rgb(255,0,0)'); var text = editor.body.firstChild.firstChild.firstChild; range.setStart(text, 2).setEnd(text, 4).select(); editor.execCommand('forecolor', 'rgb(0,255,0)'); range.setStart(editor.body.firstChild, 0).setEnd(editor.body.firstChild, 1).select(); editor.execCommand('fontfamily', ' 楷体, 楷体_GB2312, SimKai; '); setTimeout(function () { var html = '你好早安'; ua.checkSameHtml(html, editor.body.firstChild.innerHTML, '查看字体和颜色是否正确'); start(); }, 50); }); /*trace 721*/ test('trace 721:预先设置下划线和字体颜色,再输入文本,查看下划线颜色', function () { if (!ua.browser.opera) { var editor = te.obj[0]; var range = te.obj[1]; editor.setContent('hello
'); range.setStart(editor.body.firstChild.firstChild, 0).setEnd(editor.body.firstChild.firstChild, 2).select(); editor.execCommand('fontborder'); range.setStart(editor.body.firstChild.lastChild, 0).setEnd(editor.body.firstChild.lastChild, 2).select(); editor.execCommand('fontborder'); // var br = baidu.editor.browser.ie ? ' ' : 'x
'; ua.checkHTMLSameStyle(html, editor.document, editor.body, '转换font标签'); editor.setContent('x'); html = 'x'; ua.checkHTMLSameStyle(html, editor.document, editor.body.firstChild, '转换font标签'); });