Best JavaScript code snippet using wpt
datatransfer.js
Source:datatransfer.js
...25 },26 'test id': function() {27 var nativeData1 = bender.tools.mockNativeDataTransfer(),28 nativeData2 = bender.tools.mockNativeDataTransfer(),29 dataTransfer1a = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData1 ),30 dataTransfer1b = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData1 ),31 dataTransfer2 = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData2 );32 assert.areSame( dataTransfer1a.id, dataTransfer1b.id, 'Ids for object based on the same event should be the same.' );33 // In IE we can not use any data type besides text, so id is fixed.34 if ( CKEDITOR.plugins.clipboard.isCustomDataTypesSupported )35 assert.areNotSame( dataTransfer1a.id, dataTransfer2.id, 'Ids for object based on different events should be different.' );36 },37 'test internal drag drop': function() {38 var bot = this.editorBots.editor1,39 editor = this.editors.editor1,40 nativeData, dataTransfer;41 bot.setHtmlWithSelection( '<p>x[x<b>foo</b>x]x</p>' );42 nativeData = bender.tools.mockNativeDataTransfer();43 nativeData.setData( 'Text', 'bar' );44 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData, editor );45 this.assertDataTransfer( {46 transferType: CKEDITOR.DATA_TRANSFER_INTERNAL,47 sourceEditor: editor,48 targetEditor: editor,49 text: 'bar',50 html: 'x<b>foo</b>x' },51 dataTransfer );52 },53 'test internal drag drop, no event': function() {54 var isCustomDataTypesSupported = CKEDITOR.plugins.clipboard.isCustomDataTypesSupported,55 bot = this.editorBots.editor1,56 editor = this.editors.editor1,57 dataTransfer;58 bot.setHtmlWithSelection( '<p>x[x<b>foo</b>x]x</p>' );59 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( null, editor );60 this.assertDataTransfer( {61 transferType: CKEDITOR.DATA_TRANSFER_INTERNAL,62 sourceEditor: editor,63 targetEditor: editor,64 text: isCustomDataTypesSupported ? 'xfoox' : '',65 html: 'x<b>foo</b>x' },66 dataTransfer );67 },68 'test drop text from external source': function() {69 var editor = this.editors.editor1,70 nativeData, dataTransfer;71 nativeData = bender.tools.mockNativeDataTransfer();72 nativeData.setData( 'Text', 'x<b>foo</b>x' );73 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );74 this.assertDataTransfer( {75 transferType: CKEDITOR.DATA_TRANSFER_EXTERNAL,76 sourceEditor: undefined,77 targetEditor: editor,78 text: 'x<b>foo</b>x',79 html: '' },80 dataTransfer );81 },82 'test drop html from external source': function() {83 var isCustomDataTypesSupported = CKEDITOR.plugins.clipboard.isCustomDataTypesSupported,84 editor = this.editors.editor1,85 nativeData, dataTransfer;86 nativeData = bender.tools.mockNativeDataTransfer();87 nativeData.setData( 'Text', 'bar' );88 if ( isCustomDataTypesSupported ) {89 nativeData.setData( 'text/html', 'x<b>foo</b>x' );90 }91 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );92 this.assertDataTransfer( {93 transferType: CKEDITOR.DATA_TRANSFER_EXTERNAL,94 sourceEditor: undefined,95 targetEditor: editor,96 text: 'bar',97 html: isCustomDataTypesSupported ? 'x<b>foo</b>x' : '' },98 dataTransfer );99 },100 'test drag drop between editors': function() {101 var bot1 = this.editorBots.editor1,102 editor1 = this.editors.editor1,103 editor2 = this.editors.editor2,104 nativeData, dataTransfer;105 bot1.setHtmlWithSelection( '<p>x[x<b>foo</b>x]x</p>' );106 nativeData = bender.tools.mockNativeDataTransfer();107 nativeData.setData( 'Text', 'bar' );108 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData, editor1 );109 this.assertDataTransfer( {110 transferType: CKEDITOR.DATA_TRANSFER_CROSS_EDITORS,111 sourceEditor: editor1,112 targetEditor: editor2,113 text: 'bar',114 html: 'x<b>foo</b>x' },115 dataTransfer );116 },117 'test drag drop between editors, no event': function() {118 var isCustomDataTypesSupported = CKEDITOR.plugins.clipboard.isCustomDataTypesSupported,119 bot1 = this.editorBots.editor1,120 editor1 = this.editors.editor1,121 editor2 = this.editors.editor2,122 dataTransfer;123 bot1.setHtmlWithSelection( '<p>x[x<b>foo</b>x]x</p>' );124 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( null, editor1 );125 this.assertDataTransfer( {126 transferType: CKEDITOR.DATA_TRANSFER_CROSS_EDITORS,127 sourceEditor: editor1,128 targetEditor: editor2,129 text: isCustomDataTypesSupported ? 'xfoox' : '',130 html: 'x<b>foo</b>x' },131 dataTransfer );132 },133 'test set-get data, data type: Text, dataTransfer with event': function() {134 var nativeData = bender.tools.mockNativeDataTransfer(),135 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );136 dataTransfer.setData( 'Text', 'foo' );137 assert.areSame( 'foo', dataTransfer.getData( 'Text' ), 'Text - Text' );138 assert.areSame( 'foo', dataTransfer.getData( 'text/plain' ), 'Text - text/plain' );139 assert.areSame( 'foo', dataTransfer.getData( 'text' ), 'Text - text' );140 },141 'test set-get data, data type: text/plain, dataTransfer with event': function() {142 var nativeData = bender.tools.mockNativeDataTransfer(),143 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );144 dataTransfer.setData( 'text/plain', 'foo2' );145 assert.areSame( 'foo2', dataTransfer.getData( 'Text' ), 'text/plain - text' );146 assert.areSame( 'foo2', dataTransfer.getData( 'text/plain' ), 'text/plain - text/plain' );147 assert.areSame( 'foo2', dataTransfer.getData( 'text' ), 'text/plain - text' );148 },149 'test set-get data, data type: text, dataTransfer with event': function() {150 var nativeData = bender.tools.mockNativeDataTransfer(),151 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );152 dataTransfer.setData( 'text', 'foo3' );153 assert.areSame( 'foo3', dataTransfer.getData( 'Text' ), 'text - Text' );154 assert.areSame( 'foo3', dataTransfer.getData( 'text/plain' ), 'text - text/plain' );155 assert.areSame( 'foo3', dataTransfer.getData( 'text' ), 'text - text' );156 },157 'test set-get data, data type: CKE/custom, dataTransfer with event': function() {158 var nativeData = bender.tools.mockNativeDataTransfer(),159 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );160 dataTransfer.setData( 'CKE/custom', 'bar' );161 assert.areSame( 'bar', dataTransfer.getData( 'cke/custom' ), 'CKE/custom - cke/custom' );162 assert.areSame( 'bar', dataTransfer.getData( 'CKE/Custom' ), 'CKE/custom - CKE/Custom' );163 },164 'test set-get data, data type: text/html, dataTransfer with event': function() {165 var nativeData = bender.tools.mockNativeDataTransfer(),166 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );167 dataTransfer.setData( 'text/html', 'html' );168 assert.areSame( 'html', dataTransfer.getData( 'text/html' ), 'text/html - text/html' );169 },170 'test set-get data, undefined data, dataTransfer with event': function() {171 var nativeData = bender.tools.mockNativeDataTransfer(),172 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );173 assert.areSame( '', dataTransfer.getData( 'cke/undefined' ), 'undefined' );174 },175 'test set-get data, data type: Text, dataTransfer without event': function() {176 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();177 dataTransfer.setData( 'Text', 'foo' );178 assert.areSame( 'foo', dataTransfer.getData( 'Text' ), 'Text - Text' );179 assert.areSame( 'foo', dataTransfer.getData( 'text/plain' ), 'Text - text/plain' );180 assert.areSame( 'foo', dataTransfer.getData( 'text' ), 'Text - text' );181 },182 'test set-get data, data type: text/plain, dataTransfer without event': function() {183 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();184 dataTransfer.setData( 'text/plain', 'foo2' );185 assert.areSame( 'foo2', dataTransfer.getData( 'Text' ), 'text/plain - text' );186 assert.areSame( 'foo2', dataTransfer.getData( 'text/plain' ), 'text/plain - text/plain' );187 assert.areSame( 'foo2', dataTransfer.getData( 'text' ), 'text/plain - text' );188 },189 'test set-get data, data type: text, dataTransfer without event': function() {190 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();191 dataTransfer.setData( 'text', 'foo3' );192 assert.areSame( 'foo3', dataTransfer.getData( 'Text' ), 'text - Text' );193 assert.areSame( 'foo3', dataTransfer.getData( 'text/plain' ), 'text - text/plain' );194 assert.areSame( 'foo3', dataTransfer.getData( 'text' ), 'text - text' );195 },196 'test set-get data, data type: CKE/custom, dataTransfer without event': function() {197 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();198 dataTransfer.setData( 'CKE/custom', 'bar' );199 assert.areSame( 'bar', dataTransfer.getData( 'cke/custom' ), 'CKE/custom - cke/custom' );200 assert.areSame( 'bar', dataTransfer.getData( 'CKE/Custom' ), 'CKE/custom - CKE/Custom' );201 },202 'test set-get data, data type: text/html, dataTransfer without event': function() {203 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();204 dataTransfer.setData( 'text/html', 'html' );205 assert.areSame( 'html', dataTransfer.getData( 'text/html' ), 'text/html - text/html' );206 },207 'test set-get data, data type: undefined data, dataTransfer without event': function() {208 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();209 assert.areSame( '', dataTransfer.getData( 'cke/undefined' ), 'undefined' );210 },211 'test getData meta filter': function() {212 if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {213 assert.ignore();214 }215 var nativeData = bender.tools.mockNativeDataTransfer();216 nativeData.setData( 'text/html', '<meta http-equiv="content-type" content="text/html; charset=utf-8">foo<b>bom</b>x\nbar' );217 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );218 assert.areSame( 'foo<b>bom</b>x\nbar', dataTransfer.getData( 'text/html' ) );219 },220 'test getData body filter': function() {221 if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {222 assert.ignore();223 }224 var nativeData = bender.tools.mockNativeDataTransfer();225 nativeData.setData( 'text/html',226 '<html>' +227 '<body foo="bar" bar=foo bom=\'bim\'>' +228 '<!--StartFragment-->foo<b>bom</b>x' +229 'bar<!--EndFragment-->' +230 '</body>' +231 '</html>' );232 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );233 assert.areSame( 'foo<b>bom</b>xbar', dataTransfer.getData( 'text/html' ) );234 },235 'test getData body filter uppercase tags': function() {236 if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {237 assert.ignore();238 }239 var nativeData = bender.tools.mockNativeDataTransfer();240 nativeData.setData( 'text/html',241 '<HTML>' +242 '<BODY foo="bar" bar=foo bom=\'bim\'>' +243 '<!--StartFragment-->foo<B>bom</B>x' +244 'bar<!--EndFragment-->' +245 '</BODY>' +246 '</HTML>' );247 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );248 assert.areSame( 'foo<B>bom</B>xbar', dataTransfer.getData( 'text/html' ) );249 },250 'test getData body filter for tables': function() {251 if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {252 assert.ignore();253 }254 var nativeData = bender.tools.mockNativeDataTransfer();255 nativeData.setData( 'text/html',256 '<html>' +257 '<body>' +258 '<table>' +259 '<!--StartFragment-->' +260 '<tr><td>foo</td><td>bar</td></tr>' +261 '<!--EndFragment-->' +262 '</table>' +263 '</body>' +264 '</html>' );265 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );266 assert.areSame(267 '<table>' +268 '<tr><td>foo</td><td>bar</td></tr>' +269 '</table>',270 dataTransfer.getData( 'text/html' ) );271 },272 'test getData Firefox fix': function() {273 if ( !CKEDITOR.env.gecko ) {274 assert.ignore();275 }276 var nativeData = bender.tools.mockNativeDataTransfer();277 nativeData.setData( 'text/plain', 'file://foo/bar.txt' );278 nativeData.files = [ 'bar.txt' ];279 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );280 assert.areSame( '', dataTransfer.getData( 'Text' ) );281 },282 'test cacheData': function() {283 var isCustomDataTypesSupported = CKEDITOR.plugins.clipboard.isCustomDataTypesSupported,284 // Emulate native clipboard.285 nativeData = bender.tools.mockNativeDataTransfer();286 if ( isCustomDataTypesSupported ) {287 nativeData.setData( 'text/html', 'foo' );288 nativeData.setData( 'text/plain', 'bom' );289 nativeData.setData( 'cke/custom', 'bar' );290 } else {291 nativeData.setData( 'Text', 'foo' );292 }293 // CacheData.294 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );295 dataTransfer.cacheData();296 // Emulate permission denied to native clipboard.297 var throwPermissionDenied = function() {298 throw 'Permission denied.';299 };300 nativeData.setData = throwPermissionDenied;301 nativeData.getData = throwPermissionDenied;302 // Assert303 if ( isCustomDataTypesSupported ) {304 assert.areSame( 'foo', dataTransfer.getData( 'text/html' ) );305 assert.areSame( 'bom', dataTransfer.getData( 'text/plain' ) );306 assert.areSame( 'bar', dataTransfer.getData( 'cke/custom' ) );307 assert.areSame( '', dataTransfer.getData( 'cke/undefined' ) );308 } else {309 assert.areSame( 'foo', dataTransfer.getData( 'Text' ) );310 assert.areSame( '', dataTransfer.getData( 'cke/undefined' ) );311 }312 },313 'test cacheData with no native event should not crash': function() {314 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();315 dataTransfer.setData( 'cke/custom', 'foo' );316 dataTransfer.cacheData();317 assert.areSame( 'foo', dataTransfer.getData( 'cke/custom' ) );318 assert.areSame( '', dataTransfer.getData( 'cke/undefined' ) );319 },320 'test files empty': function() {321 var nativeData = bender.tools.mockNativeDataTransfer(),322 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );323 dataTransfer.cacheData();324 assert.areSame( 0, dataTransfer.getFilesCount() );325 assert.isFalse( !!dataTransfer.getFile( 0 ) );326 },327 'test files': function() {328 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {329 assert.ignore();330 }331 var nativeData = bender.tools.mockNativeDataTransfer(),332 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );333 nativeData.files.push( 'foo' );334 nativeData.files.push( 'bar' );335 assert.areSame( 2, dataTransfer.getFilesCount() );336 assert.areSame( 'foo', dataTransfer.getFile( 0 ) );337 assert.areSame( 'bar', dataTransfer.getFile( 1 ) );338 assert.isUndefined( dataTransfer.getFile( 2 ) );339 },340 // #12961341 'test file in items': function() {342 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {343 assert.ignore();344 }345 var nativeData = bender.tools.mockNativeDataTransfer(),346 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData ),347 file = { type: 'type' };348 nativeData.items = [ {349 getAsFile: function() {350 return file;351 }352 } ];353 assert.areSame( 1, dataTransfer.getFilesCount() );354 assert.areSame( file, dataTransfer.getFile( 0 ) );355 assert.isUndefined( dataTransfer.getFile( 1 ) );356 },357 // #12961358 'test file in items with error': function() {359 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {360 assert.ignore();361 }362 var nativeData = bender.tools.mockNativeDataTransfer(),363 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );364 nativeData.items = [ {365 getAsFile: function() {366 return {}; // no 'type', so not file.367 }368 } ];369 assert.areSame( 0, dataTransfer.getFilesCount() );370 assert.isUndefined( dataTransfer.getFile( 0 ) );371 },372 // #12961373 'test file in items and files': function() {374 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {375 assert.ignore();376 }377 var nativeData = bender.tools.mockNativeDataTransfer(),378 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData ),379 file = { type: 'type' };380 nativeData.items = [ {381 getAsFile: function() {382 return file;383 }384 } ];385 nativeData.files.push( 'foo' );386 assert.areSame( 1, dataTransfer.getFilesCount() );387 assert.areSame( 'foo', dataTransfer.getFile( 0 ) );388 assert.isUndefined( dataTransfer.getFile( 1 ) );389 },390 'test files with cache': function() {391 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {392 assert.ignore();393 }394 var nativeData = bender.tools.mockNativeDataTransfer(),395 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );396 nativeData.files.push( 'foo' );397 nativeData.files.push( 'bar' );398 dataTransfer.cacheData();399 assert.areSame( 2, dataTransfer.getFilesCount() );400 assert.areSame( 'foo', dataTransfer.getFile( 0 ) );401 assert.areSame( 'bar', dataTransfer.getFile( 1 ) );402 assert.isFalse( !!dataTransfer.getFile( 2 ) );403 nativeData.files = [];404 assert.areSame( 2, dataTransfer.getFilesCount() );405 assert.areSame( 'foo', dataTransfer.getFile( 0 ) );406 assert.areSame( 'bar', dataTransfer.getFile( 1 ) );407 assert.isFalse( !!dataTransfer.getFile( 2 ) );408 },409 // #12961410 'test file in items with cache': function() {411 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {412 assert.ignore();413 }414 var nativeData = bender.tools.mockNativeDataTransfer(),415 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData ),416 file = { type: 'type' };417 nativeData.items = [ {418 getAsFile: function() {419 return file;420 }421 } ];422 dataTransfer.cacheData();423 assert.areSame( 1, dataTransfer.getFilesCount() );424 assert.areSame( file, dataTransfer.getFile( 0 ) );425 assert.isUndefined( dataTransfer.getFile( 1 ) );426 nativeData.files = [];427 nativeData.items = [];428 assert.areSame( 1, dataTransfer.getFilesCount() );429 assert.areSame( file, dataTransfer.getFile( 0 ) );430 assert.isUndefined( dataTransfer.getFile( 1 ) );431 },432 // #12961433 'test file in items and files with cache': function() {434 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {435 assert.ignore();436 }437 var nativeData = bender.tools.mockNativeDataTransfer(),438 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData ),439 file = { type: 'type' };440 nativeData.items = [ {441 getAsFile: function() {442 return file;443 }444 } ];445 nativeData.files.push( 'foo' );446 // debugger;447 dataTransfer.cacheData();448 assert.areSame( 1, dataTransfer.getFilesCount() );449 assert.areSame( 'foo', dataTransfer.getFile( 0 ) );450 assert.isUndefined( dataTransfer.getFile( 1 ) );451 },452 'test isEmpty 1': function() {453 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();454 assert.isTrue( dataTransfer.isEmpty() );455 },456 'test isEmpty 2': function() {457 var nativeData = bender.tools.mockNativeDataTransfer(),458 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );459 assert.isTrue( dataTransfer.isEmpty() );460 },461 'test isEmpty 3': function() {462 var nativeData = bender.tools.mockNativeDataTransfer(),463 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );464 nativeData.setData( 'Text', '' );465 assert.isTrue( dataTransfer.isEmpty() );466 },467 'test isEmpty 4': function() {468 var nativeData = bender.tools.mockNativeDataTransfer(),469 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );470 dataTransfer.setData( 'Text', '' );471 assert.isTrue( dataTransfer.isEmpty() );472 },473 'test isEmpty 5': function() {474 var nativeData = bender.tools.mockNativeDataTransfer(),475 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );476 nativeData.setData( 'Text', 'foo' );477 assert.isFalse( dataTransfer.isEmpty() );478 },479 'test isEmpty 6': function() {480 var nativeData = bender.tools.mockNativeDataTransfer(),481 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );482 dataTransfer.setData( 'Text', 'foo' );483 assert.isFalse( dataTransfer.isEmpty() );484 },485 'test isEmpty 7': function() {486 var nativeData = bender.tools.mockNativeDataTransfer(),487 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );488 dataTransfer.setData( 'cke/custom', 'foo' );489 assert.isFalse( dataTransfer.isEmpty() );490 },491 'test isEmpty 8': function() {492 var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer();493 dataTransfer.setData( 'cke/custom', 'foo' );494 assert.isFalse( dataTransfer.isEmpty() );495 },496 'test isEmpty 9': function() {497 var nativeData = bender.tools.mockNativeDataTransfer(),498 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );499 dataTransfer.setData( 'Text', 'foo' );500 dataTransfer.setData( 'Text', '' );501 assert.isTrue( dataTransfer.isEmpty() );502 },503 'test isEmpty 10': function() {504 var nativeData = bender.tools.mockNativeDataTransfer(),505 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );506 nativeData.setData( 'Text', 'foo' );507 dataTransfer.setData( 'cke/custom', 'foo' );508 assert.isFalse( dataTransfer.isEmpty() );509 },510 'test isEmpty 11': function() {511 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {512 assert.ignore();513 }514 var nativeData = bender.tools.mockNativeDataTransfer(),515 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );516 nativeData.files.push( 'foo' );517 assert.isFalse( dataTransfer.isEmpty() );518 },519 'test isEmpty 12': function() {520 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {521 assert.ignore();522 }523 var nativeData = bender.tools.mockNativeDataTransfer(),524 dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );525 nativeData.files.push( 'foo' );526 dataTransfer.cacheData();527 nativeData.files = [];528 assert.isFalse( dataTransfer.isEmpty() );529 },530 'test initDragDataTransfer binding': function() {531 var nativeData1 = bender.tools.mockNativeDataTransfer(),532 nativeData2 = bender.tools.mockNativeDataTransfer(),533 evt1a = { data: { $: { dataTransfer: nativeData1 } } },534 evt1b = { data: { $: { dataTransfer: nativeData1 } } },535 evt2 = { data: { $: { dataTransfer: nativeData2 } } };536 CKEDITOR.plugins.clipboard.initDragDataTransfer( evt1a );537 CKEDITOR.plugins.clipboard.initDragDataTransfer( evt1b );538 assert.areSame( evt1a.data.dataTransfer, evt1b.data.dataTransfer, 'If we init dataTransfer object twice on the same event this should be the same object.' );...
ClipboardTest.ts
Source:ClipboardTest.ts
1import { Assert, UnitTest } from '@ephox/bedrock-client';2import { DataTransfer, navigator } from '@ephox/dom-globals';3import { Cell, Option } from '@ephox/katamari';4import { Body, DomEvent, Element, Insert, Remove } from '@ephox/sugar';5import { cCopy, cCut, sPasteDataTransfer, sPasteFiles, sPasteItems } from 'ephox/agar/api/Clipboard';6import { createFileFromString } from 'ephox/agar/api/Files';7import { Chain, Logger, Step, ChainSequence, StepSequence } from 'ephox/agar/api/Main';8import { Pipeline } from 'ephox/agar/api/Pipeline';9if (! /phantom/i.test(navigator.userAgent)) {10 UnitTest.asynctest('ClipboardTest', (success, failure) => {11 const pastebin = Element.fromHtml('<div class="pastebin"></div>');12 const pasteState = Cell(Option.none<DataTransfer>());13 Insert.append(Body.body(), pastebin);14 const cutUnbinder = DomEvent.bind(pastebin, 'cut', (evt) => {15 const dataTransfer = evt.raw().clipboardData;16 dataTransfer.setData('text/plain', 'cut-data');17 });18 const copyUnbinder = DomEvent.bind(pastebin, 'copy', (evt) => {19 const dataTransfer = evt.raw().clipboardData;20 dataTransfer.setData('text/plain', 'copy-data');21 });22 const pasteUnbinder = DomEvent.bind(pastebin, 'paste', (evt) => {23 const dataTransfer = evt.raw().clipboardData;24 pasteState.set(Option.some(dataTransfer));25 });26 Pipeline.runStep({}, StepSequence.sequenceSame([27 Logger.t('Paste text and html items', StepSequence.sequenceSame([28 sPasteItems({29 'text/plain': 'Hello world!',30 'text/html': '<b>Hello world!</b>'31 }, '.pastebin'),32 Step.sync(() => {33 const dataTransfer = pasteState.get().getOrDie('Could not get dataTransfer from state');34 Assert.eq('Should be expected plain text', 'Hello world!', dataTransfer.getData('text/plain'));35 Assert.eq('Should be expected html', '<b>Hello world!</b>', dataTransfer.getData('text/html'));36 })37 ])),38 Logger.t('Paste text and html files', StepSequence.sequenceSame([39 sPasteFiles([40 createFileFromString('a.txt', 123, 'Hello world!', 'text/plain'),41 createFileFromString('a.html', 123, '<b>Hello world!</b>', 'text/html')42 ], '.pastebin'),43 Step.sync(() => {44 const dataTransfer = pasteState.get().getOrDie('Could not get dataTransfer from state');45 Assert.eq('Should be expected mime type', 'text/plain', dataTransfer.items[0].type);46 Assert.eq('Should be expected mime type', 'text/plain', dataTransfer.files[0].type);47 Assert.eq('Should be expected mime type', 'text/html', dataTransfer.items[1].type);48 Assert.eq('Should be expected mime type', 'text/html', dataTransfer.files[1].type);49 })50 ])),51 Logger.t('Paste using dataTransfer mutator', StepSequence.sequenceSame([52 sPasteDataTransfer((dataTransfer) => {53 dataTransfer.items.add(createFileFromString('a.txt', 123, 'Hello world!', 'text/plain'));54 dataTransfer.items.add('<b>Hello world!</b>', 'text/html');55 }, '.pastebin'),56 Step.sync(() => {57 const dataTransfer = pasteState.get().getOrDie('Could not get dataTransfer from state');58 Assert.eq('Should be expected mime type', 'text/plain', dataTransfer.items[0].type);59 Assert.eq('Should be expected mime type', 'file', dataTransfer.items[0].kind);60 Assert.eq('Should be expected mime type', 'text/html', dataTransfer.items[1].type);61 Assert.eq('Should be expected mime type', 'string', dataTransfer.items[1].kind);62 })63 ])),64 Logger.t('Cut', Chain.isolate(pastebin, ChainSequence.sequence([65 cCut,66 Chain.op((dataTransfer: DataTransfer) => {67 Assert.eq('Should be extected cut data', 'cut-data', dataTransfer.getData('text/plain'));68 })69 ]))),70 Logger.t('Copy', Chain.isolate(pastebin, ChainSequence.sequence([71 cCopy,72 Chain.op((dataTransfer: DataTransfer) => {73 Assert.eq('Should be extected copy data', 'copy-data', dataTransfer.getData('text/plain'));74 })75 ])))76 ]), () => {77 cutUnbinder.unbind();78 copyUnbinder.unbind();79 pasteUnbinder.unbind();80 Remove.remove(pastebin);81 success();82 }, failure);83 });...
Clipboard.ts
Source:Clipboard.ts
1import { File, DataTransfer } from '@ephox/dom-globals';2import { Chain } from './Chain';3import { cFindIn } from './UiFinder';4import { Body, Element } from '@ephox/sugar';5import { getWindowFromElement } from '../dragndrop/DndEvents';6import { createDataTransfer } from '../datatransfer/DataTransfer';7import { Arr, Obj } from '@ephox/katamari';8import { createPasteEvent, createCopyEvent, createCutEvent } from '../clipboard/ClipboardEvents';9import { Step } from './Step';10import * as ChainSequence from './ChainSequence';11const cPasteDataTransfer = (mutator: (dataTransfer: DataTransfer) => void): Chain<Element<any>, Element<any>> =>12 Chain.op<Element<any>>((target) => {13 const win = getWindowFromElement(target);14 const dataTransfer = createDataTransfer();15 const event = createPasteEvent(win, 0, 0, dataTransfer);16 mutator(dataTransfer);17 target.dom().dispatchEvent(event);18 });19const cPasteItems = (items: Record<string, string>): Chain<Element<any>, Element<any>> =>20 cPasteDataTransfer((dataTransfer) => {21 Obj.each(items, (data, mime) => {22 dataTransfer.setData(mime, data);23 });24 });25const cPasteFiles = (files: File[]): Chain<Element<any>, Element<any>> =>26 cPasteDataTransfer((dataTransfer) => {27 Arr.each(files, (file) => {28 dataTransfer.items.add(file);29 });30 });31const sPasteDataTransfer = <T>(mutator: (dataTransfer: DataTransfer) => void, selector: string): Step<T, T> =>32 Chain.isolate({}, ChainSequence.sequence([33 Chain.injectThunked(Body.body),34 cFindIn(selector),35 cPasteDataTransfer(mutator)36 ]));37const sPasteItems = <T>(items: Record<string, string>, selector: string): Step<T, T> =>38 Chain.isolate({}, ChainSequence.sequence([39 Chain.injectThunked(Body.body),40 cFindIn(selector),41 cPasteItems(items)42 ]));43const sPasteFiles = <T>(files: File[], selector: string): Step<T, T> =>44 Chain.isolate({}, ChainSequence.sequence([45 Chain.injectThunked(Body.body),46 cFindIn(selector),47 cPasteFiles(files)48 ]));49const cCut: Chain<Element<any>, DataTransfer> =50 Chain.mapper<Element<any>, DataTransfer>((target) => {51 const win = getWindowFromElement(target);52 const dataTransfer = createDataTransfer();53 const event = createCutEvent(win, 0, 0, dataTransfer);54 target.dom().dispatchEvent(event);55 return dataTransfer;56 });57const cCopy: Chain<Element<any>, DataTransfer> =58 Chain.mapper<Element, DataTransfer>((target) => {59 const win = getWindowFromElement(target);60 const dataTransfer = createDataTransfer();61 const event = createCopyEvent(win, 0, 0, dataTransfer);62 target.dom().dispatchEvent(event);63 return dataTransfer;64 });65export {66 cPasteDataTransfer,67 cPasteItems,68 cPasteFiles,69 sPasteDataTransfer,70 sPasteItems,71 sPasteFiles,72 cCut,73 cCopy...
Using AI Code Generation
1var wpt = require('webpagetest');2var fs = require('fs');3var wpt = new WebPageTest('www.webpagetest.org');4var options = {5};6 if (err) return console.log(err);7 console.log('Test ID: ' + data.data.testId);8 wpt.getTestResults(data.data.testId, function (err, data) {9 if (err) return console.log(err);10 console.log(data.data.testUrl);11 console.log(data.data.median.firstView.SpeedIndex);12 console.log(data.data.median.firstView.TTFB);13 console.log(data.data.median.firstView.render);14 console.log(data.data.median.firstView.fullyLoaded);15 console.log(data.data.median.firstView.loadTime);16 console.log(data.data.median.firstView.docTime);17 console.log(data.data.median.firstView.domTime);18 console.log(data.data.median.firstView.domContentLoadedEventStart);19 console.log(data.data.median.firstView.domContentLoadedEventEnd);20 console.log(data.data.median.firstView.domInteractive);21 console.log(data.data.median.firstView.domLoading);22 console.log(data.data.median.firstView.domElements);23 console.log(data.data.median.firstView.lastVisualChange);24 console.log(data.data.median.firstView.visualComplete85);25 console.log(data.data.median.firstView.visualComplete95);26 console.log(data.data.median.firstView.visualComplete99);27 console.log(data.data.median.firstView.visualComplete);28 console.log(data.data.median.firstView.SpeedIndex);29 console.log(data.data.median.firstView.requests);30 console.log(data.data.median.firstView.bytesIn);31 console.log(data.data.median.firstView.bytesOut);32 console.log(data.data.median.firstView.bytesInDoc);33 console.log(data.data.median.firstView.bytesOutDoc);34 console.log(data.data.median.firstView.connections);35 console.log(data.data.median.firstView.requestsDoc);36 console.log(data.data.median.firstView.requestsFull);37 console.log(data.data.median
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org', 'A.2b4a4d4e4b4c4d4a4a4a4a4a4a4a4a4a4a4a4a4a4');2wpt.runTest(url, function(err, data) {3 if (err) return console.error(err);4 console.log('Test submitted to WebPageTest for %s', url);5 console.log('View your test at: %s', data.data.userUrl);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org', 'A.2b4a4d4e4b4c4d4a4a4a4a4a4a4a4a4a4a4a4a4a4');9wpt.runTest(url, {location: 'Dulles:Chrome'}, function(err, data) {
Using AI Code Generation
1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Albert_Einstein');4page.get(function(err, page) {5 var data = page.data;6 fs.writeFile('data.json', JSON.stringify(data, null, 4), function(err) {7 console.log('File successfully written! - Check your project directory for the data.json file');8 });9});10{11 "extract": "Albert Einstein (14 March 1879 \u2013 18 April 1955) was a German-born theoretical physicist who developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). Einstein's work is also known for its influence on the philosophy of science. He is best known in popular culture for his mass\u2013energy equivalence formula E = mc2 (which has been dubbed \u2018the world's most famous equation\u2019). He received the 1921 Nobel Prize in Physics \"for his services to theoretical physics, and especially for his discovery of the law of the photoelectric effect\", a pivotal step in the evolution of quantum theory.",12 "coordinates": {13 },14 "image": {15 },16 "infobox": {
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var data = wptoolkit.dataTransfer;3data.set('test', 'test data');4data.get('test');5data.remove('test');6data.get('test');7data.set('test', 'test data');8data.clear();9data.get('test');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!