paste.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. module( 'plugins.paste' );
  2. //不能模拟出真实的粘贴效果,此用例用于检查中间值
  3. test( '粘贴', function() {
  4. if(ua.browser.ie || ua.browser.opera)return;
  5. var div = document.body.appendChild( document.createElement( 'div' ) );
  6. $( div ).css( 'width', '500px' ).css( 'height', '500px' ).css( 'border', '1px solid #ccc' );
  7. var me = te.obj[2];
  8. me.render(div);
  9. stop();
  10. me.ready(function(){
  11. var range = new baidu.editor.dom.Range( te.obj[2].document );
  12. me.focus();
  13. me.setContent('<p>hello</p>');
  14. range.setStart(me.body.firstChild,0).collapse(true).select();
  15. ua.keydown(me.body,{'keyCode':65,'ctrlKey':true});
  16. ua.keydown(me.body,{'keyCode':67,'ctrlKey':true});
  17. setTimeout(function(){
  18. me.focus();
  19. range.setStart(me.body.firstChild,0).collapse(true).select();
  20. ua.paste(me.body,{'keyCode':86,'ctrlKey':true});
  21. equal(me.body.lastChild.id,'baidu_pastebin','检查id');
  22. equal(me.body.lastChild.style.position,'absolute','检查style');
  23. div.parentNode.removeChild(div);
  24. start();
  25. },50);
  26. stop();
  27. });
  28. } );
  29. //me.fireEvent('pasteTransfer','paste');//todo
  30. test( 'getClipboardData--ctrl+v', function() {
  31. // var editor = new baidu.editor.Editor( {'plugins':['paste']} )
  32. // var div = te.dom[0];
  33. // editor.render( div );
  34. // editor.focus();
  35. // editor.setContent( '<p>你好</p>' )
  36. // var doc = editor.document;
  37. // var r = new baidu.editor.dom.Range( doc );
  38. // /*从word中粘贴的未经过滤的列表*/
  39. // var html = '<p><span lang="EN-US" style="text-indent: -28px; font-family: Wingdings; ">l<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span>列表<span lang="EN-US" style="text-indent: -28px; ">1</span><br></p><p class="MsoListParagraph" style="margin-left:21.0pt;text-indent:-21.0pt;'
  40. // + 'mso-char-indent-count:0;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span lang="EN-US" style="font-family:Wingdings;mso-fareast-font-family:Wingdings;mso-bidi-font-family:Wingdings">l<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp; </span></span><!--[endif]-->列表<span lang="EN-US">2<o:p></o:p></span></p>';
  41. // te.setClipData( html );
  42. // r.setStart( editor.body.firstChild, 1 ).collapse( 1 ).select();
  43. // editor.focus();
  44. // te.presskey( 'ctrl', 'v' );
  45. // editor.focus();
  46. // setTimeout( function() {
  47. // equal( editor.body.firstChild.innerHTML, html );
  48. // start();
  49. // } );
  50. // stop();
  51. equal('','','');
  52. } );
  53. //需要点击授权弹出框,暂时去除
  54. //test('检查IE下粘贴命令是否执行正常', function () {
  55. //
  56. // if (browser.ie) {
  57. // var editor = te.obj[0];
  58. // editor.setContent('<p>hello</p>');
  59. // editor.focus();
  60. //
  61. // editor.execCommand('selectall');
  62. // editor.body.document.execCommand('copy');
  63. // editor.setContent('<p>test</p>');
  64. // editor.execCommand('selectall');
  65. // editor.execCommand('paste');
  66. //
  67. // setTimeout(function(){
  68. // equal(utils.trim(editor.getContent().replace('<p></p>', '').replace('<p>&nbsp;</p>', '')), '<p>hello</p>', '检查html内容,IE下成功粘贴内容');
  69. // equal(utils.trim(editor.getContentTxt()), 'hello', '检查text内容,IE下成功粘贴内容');
  70. // start();
  71. // },100);
  72. //
  73. // stop();
  74. // }
  75. //
  76. //});