Skip to content
Permalink
Browse files

Merge branch 't/12071'

  • Loading branch information
Reinmar committed Jun 11, 2014
2 parents d4bf2f9 + 0504a72 commit 6775bbee6f47a38eb205e659aeb823693be5bb00
@@ -85,6 +85,15 @@ var config = {
'tickets/',
'!/_'
]
},

'Utils': {
applications: [ 'ckeditor' ],
basePath: 'tests/',
paths: [
'utils/',
'!/_'
]
}
}
};
@@ -0,0 +1,52 @@
/* bender-tags: editor,unit,utils */

( function() {
'use strict';

bender.test( {
'test assert.isMatching': function() {
assert.isMatching( /abc/, 'abc' );
assert.isMatching( /ab?c/i, 'AC' );

var error = null;
try {
assert.isMatching( /ab?c/i, 'def', 'should fail' );
} catch ( e ) {
error = e;
}

assert.isNotNull( error );
assert.areEqual( 'def', error.actual );
assert.areEqual( '/ab?c/i', error.expected );
assert.areEqual( 'should fail', error.message );

error = null;
try {
assert.isMatching( /ab?c/i, undefined, 'should fail' );
} catch ( e ) {
error = e;
}

assert.isNotNull( error );
assert.isUndefined( error.actual );
assert.areEqual( '/ab?c/i', error.expected );
assert.areEqual( 'should fail', error.message );
},

'test synchronous wait/resume': function() {
var tc = this;

function onTestResume( cb ) {
cb.call( tc );
}

onTestResume( function() {
this.resume( function() {
assert.isTrue( true );
} );
} );

this.wait();
}
} );
} )();
@@ -0,0 +1 @@
<div id="playground" contentEditable="true"></div>
@@ -0,0 +1,117 @@
/* bender-tags: editor,unit,utils */

( function() {
'use strict';

var doc = CKEDITOR.document,
playground = doc.getById( 'playground' ),
setRange = bender.tools.range.setWithHtml,
getRange = bender.tools.range.getWithHtml,
playgroundAddress = playground.getAddress(),

failIE11 = CKEDITOR.env.ie && CKEDITOR.env.version > 10,
failIE8 = CKEDITOR.env.ie && CKEDITOR.env.version < 9;

// Asserts setRange and getRange.
function s( html, collapsed, startAddress, startOffset, endAddress, endOffset, htmlWithRange ) {
return function() {
var range = setRange( playground, html ),
startContainer, endContainer, range;

// Get startContainer by address.
if ( startAddress && startOffset != undefined )
startContainer = doc.getByAddress( playgroundAddress.concat( startAddress ) );

// Get endContainer by address.
if ( collapsed === true ) {
endContainer = startContainer;
endOffset = startOffset;
} else if ( collapsed === false )
endContainer = doc.getByAddress( playgroundAddress.concat( endAddress ) );

if ( startContainer && endContainer ) {
assert.isTrue( startContainer.equals( range.startContainer ), 'startContainer' );
assert.isTrue( endContainer.equals( range.endContainer ), 'endContainer' );
assert.areSame( startOffset, range.startOffset, 'startOffset' );
assert.areSame( endOffset, range.endOffset, 'endOffset' );
assert.areSame( collapsed, range.collapsed, 'collapsed' );
} else {
assert.isNull( range, 'No ranges returned' );
}

assert.areSame( html.replace( /[\{\}\[\]]/g, '' ), bender.tools.fixHtml( playground.getHtml(), 1, 1 ), 'Markers cleaned - setRange' );
assert.areSame( htmlWithRange == undefined ? html : htmlWithRange, bender.tools.fixHtml( getRange( playground, range ), 1, 1 ), 'getRange' );
};
}

bender.test( {
_should: {
ignore: {
// IE11 inserts extra <br>.
'test text #0': failIE11,

// IE8 normalizes double spaces, etc.
'test text #16': failIE8,
'test text #18': failIE8,
'test text #19': failIE8,
'test element #13': failIE8,
'test element #14': failIE8,
'test element #15': failIE8,
'test element #16': failIE8,
'test element #17': failIE8,
'test mixed #8': failIE8
}
},

// Collapsed Start Address Start Offset End Address End offset HtmlWithRange
'test text #0': s( '' ),
'test text #1': s( '{}', null, null, null, null, null, '' ),
'test text #2': s( '<p>x</p>' ),
'test text #3': s( '<p>x{}x</p>', true, [ 0, 0 ], 1 ),
'test text #4': s( '<p>{}x</p>', true, [ 0, 0 ], 0 ),
'test text #5': s( '<p>x{}</p>', true, [ 0, 0 ], 1 ),
'test text #6': s( '<p>{x}</p>', false, [ 0, 0 ], 0, [ 0, 0 ], 1 ),
'test text #7': s( '<p>{x</p><p>y}</p>', false, [ 0, 0 ], 0, [ 1, 0 ], 1 ),
'test text #8': s( '<p>x{</p><p>y}</p>', false, [ 0, 0 ], 1, [ 1, 0 ], 1 ),
'test text #9': s( '<p>x{</p><p>}y</p>', false, [ 0, 0 ], 1, [ 1, 0 ], 0 ),
'test text #10': s( '<ul><li>x{x</li><li>}y</li></ul>', false, [ 0, 0, 0 ], 1, [ 0, 1, 0 ], 0 ),
'test text #11': s( '<ol><li>x{}<ul><li>y</li></ul></li></ol>', true, [ 0, 0, 0 ], 1 ),
'test text #12': s( '<p>{}<span>x</span></p>', null, null, null, null, null, '<p><span>x</span></p>' ),
'test text #13': s( '<p>{<span>x</span>}</p>', null, null, null, null, null, '<p><span>x</span></p>' ),
'test text #14': s( '<p>x {}</p>', true, [ 0, 0 ], 2 ),
'test text #15': s( '<p>{} x</p>', true, [ 0, 0 ], 0 ),
'test text #16': s( '<p> {} </p>', true, [ 0, 0 ], 1 ),
'test text #17': s( '<p>{ }</p>', false, [ 0, 0 ], 0, [ 0, 0 ], 1 ),
'test text #18': s( '<p>{ }</p>', false, [ 0, 0 ], 0, [ 0, 0 ], 2 ),
'test text #19': s( '<div>{ <p> }</p></div>', false, [ 0, 0 ], 0, [ 0, 1, 0 ], 1 ),
'test text #20': s( '<p>{<span>x</span> }</p>', false, null, null, null, null, '<p><span>x</span> </p>' ),

'test element #0': s( '[]', true, [], 0 ),
'test element #1': s( '<p>x[]x</p>', true, [ 0 ], 1 ),
'test element #2': s( '<p>[]x</p>', true, [ 0 ], 0 ),
'test element #3': s( '<p>x[]</p>', true, [ 0 ], 1 ),
'test element #4': s( '<p>[x]</p>', false, [ 0 ], 0, [ 0 ], 1 ),
'test element #5': s( '<ul>[<li>x</li><li>y</li>]</ul>', false, [ 0 ], 0, [ 0 ], 2 ),
'test element #6': s( '<ul><li>x[x</li><li>]y</li></ul>', false, [ 0, 0 ], 1, [ 0, 1 ], 0 ),
'test element #7': s( '<p>x[<span>y</span>]</p>', false, [ 0 ], 1, [ 0 ], 2 ),
'test element #8': s( '<p>[]<span>x</span></p>', true, [ 0 ], 0 ),
'test element #9': s( '<table><tbody><tr>[<td>x</td>]<td>x</td></tr></tbody></table>', false, [ 0, 0, 0 ], 0, [ 0, 0, 0 ], 1 ),
'test element #10': s( '<ol><li>x[]<ul><li>y</li></ul></li></ol>', true, [ 0, 0 ], 1 ),
'test element #11': s( '<ol>[<li>x</li><li>y<ul><li>z</li>]<li>a</li></ul></li></ol>', false, [ 0 ], 0, [ 0, 1, 1 ], 1 ),
'test element #12': s( '<p>x []</p>', true, [ 0 ], 1 ),
'test element #13': s( '<p>[] x</p>', true, [ 0 ], 0 ),
'test element #14': s( '<p> [] </p>', true, [ 0 ], 1 ),
'test element #15': s( '<p>[ ]</p>', false, [ 0 ], 0, [ 0 ], 1 ),
'test element #16': s( '<p>[ ]</p>', false, [ 0 ], 0, [ 0 ], 1 ),
'test element #17': s( '<div>[ <p> ]</p></div>', false, [ 0 ], 0, [ 0, 1 ], 1 ),

'test mixed #1': s( '<p>x{x]</p>', false, [ 0, 0 ], 1, [ 0 ], 1 ),
'test mixed #2': s( '<p>{x]</p>', false, [ 0, 0 ], 0, [ 0 ], 1 ),
'test mixed #3': s( '<p>[x}</p>', false, [ 0 ], 0, [ 0, 0 ], 1 ),
'test mixed #4': s( '<p>[}x</p>', false, [ 0 ], 0, [ 0, 0 ], 0 ),
'test mixed #5': s( '<p>x{]</p>', false, [ 0, 0 ], 1, [ 0 ], 1 ),
'test mixed #6': s( '<p>[x</p><p>y}</p>', false, [ 0 ], 0, [ 1, 0 ], 1 ),
'test mixed #7': s( '<p>{ ]</p>', false, [ 0, 0 ], 0, [ 0 ], 1 ),
'test mixed #8': s( '<p> { ] </p>', false, [ 0, 0 ], 1, [ 0 ], 1 )
} );
} )();
@@ -0,0 +1,141 @@
/* bender-tags: editor,unit,utils */

( function() {
'use strict';

bender.editor = true;

bender.test( {
'test setSelection - none': function() {
var editor = this.editor,
selectionChangeCalled = 0;

var listener = editor.on( 'selectionChange', function() {
++selectionChangeCalled;
} );

var selection = bender.tools.selection.setWithHtml( editor, '<p>x</p>' );

listener.removeListener();

assert.areSame( 0, selectionChangeCalled, 'selectionChange called' );
assert.isTrue( selection instanceof CKEDITOR.dom.selection, 'CKEDITOR.dom.selection' );
assert.areSame( '<p>x</p>', editor.getData(), 'editor data' );
},

'test setSelection - element': function() {
var editor = this.editor,
selectionChangeCalled = 0;

var listener = editor.on( 'selectionChange', function() {
++selectionChangeCalled;
} );

var selection = bender.tools.selection.setWithHtml( editor, '<p>[x]</p>' );

listener.removeListener();

assert.areSame( 1, selectionChangeCalled, 'selectionChange called' );
assert.isTrue( selection instanceof CKEDITOR.dom.selection, 'CKEDITOR.dom.selection' );
assert.areSame( '<p>x</p>', editor.getData(), 'editor data' );
},

'test setSelection - text': function() {
var editor = this.editor,
selectionChangeCalled = 0;

var listener = editor.on( 'selectionChange', function() {
++selectionChangeCalled;
} );

var selection = bender.tools.selection.setWithHtml( editor, '<p>{x}</p>' );

listener.removeListener();

assert.areSame( 1, selectionChangeCalled, 'selectionChange called' );
assert.isTrue( selection instanceof CKEDITOR.dom.selection, 'CKEDITOR.dom.selection' );
assert.areSame( '<p>x</p>', editor.getData(), 'editor data' );
},

'test setSelection - selectionChange is always fired': function() {
var editor = this.editor,
bot = this.editorBot,
selectionChangeCalled = 0;

bot.setData( '<p>x</p>', function() {
var listener = editor.on( 'selectionChange', function() {
++selectionChangeCalled;
} );

// Focus editor what may make browser preparing initial selection
// after we set editable's HTML. That selection may be placed in
// exactly the same location, so selectionChange would not be fired.
editor.focus();

selectionChangeCalled = 0;

bender.tools.selection.setWithHtml( editor, '<p>[]x</p>' );
assert.areSame( 1, selectionChangeCalled, 'selectionChange called #1a' );

bender.tools.selection.setWithHtml( editor, '<p>[]x</p>' );
assert.areSame( 2, selectionChangeCalled, 'selectionChange called #1b' );

selectionChangeCalled = 0;

bender.tools.selection.setWithHtml( editor, '<p>{}x</p>' );
assert.areSame( 1, selectionChangeCalled, 'selectionChange called #2a' );

bender.tools.selection.setWithHtml( editor, '<p>{}x</p>' );
assert.areSame( 2, selectionChangeCalled, 'selectionChange called #2b' );

selectionChangeCalled = 0;

bender.tools.selection.setWithHtml( editor, '<p>[x]</p>' );
assert.areSame( 1, selectionChangeCalled, 'selectionChange called #3a' );

bender.tools.selection.setWithHtml( editor, '<p>[x]</p>' );
assert.areSame( 2, selectionChangeCalled, 'selectionChange called #3b' );

listener.removeListener();
} );
},

'test getSelection - element': function() {
var editor = this.editor,
htmlWithRange = '<p>[x]</p>';

var selection = bender.tools.selection.setWithHtml( editor, htmlWithRange );

assert.isMatching( /<p>[\[\{]x[\]\}](<br>)?<\/p>/gi, bender.tools.selection.getWithHtml( editor ), 'getSelection' );
assert.isMatching( '<p>x(<br>)?</p>', bender.tools.fixHtml( editor.editable().getHtml(), 1, 1 ), 'editable innerHTML' );
},

'test getSelection - text': function() {
var editor = this.editor,
htmlWithRange = '<p>{x}</p>';

var selection = bender.tools.selection.setWithHtml( editor, htmlWithRange );

assert.isMatching( /<p>[\[\{]x[\]\}](<br>)?<\/p>/gi, bender.tools.selection.getWithHtml( editor ), 'getSelection' );
assert.isMatching( '<p>x(<br>)?</p>', bender.tools.fixHtml( editor.editable().getHtml(), 1, 1 ), 'editable innerHTML' );
},

'test getSelection - multiple ranges': function() {
var editor = this.editor,
revert = bender.tools.replaceMethod( CKEDITOR.dom.selection.prototype, 'getRanges', function() {
return [ 1, 2 ];
} ),
error;

try {
bender.tools.selection.getWithHtml( editor );
} catch( e ) {
error = e;
} finally {
revert();
}

assert.isNotUndefined( error, 'Error is expected to be thrown' );
}
} );
} )();
@@ -0,0 +1,45 @@
<div id="playground" contentEditable="true"></div>
<textarea id="textarea_1">
<ol id="ol_1">[<li id="li_3">leve1<ol><li id="li_4">level2</li></ol></li>]</ol>
</textarea>
<textarea id="textarea_2">
<ol><li id="li_1">[leve1]<ol><li id="li_2">[level2]</li></ol></li></ol>
</textarea>
<textarea id="textarea_3">
<p id="p_1">some[<span id="span_1">text</span>]</p>
</textarea>
<textarea id="textarea_4">
<p id="p_2">so^me<span id="span_2">text</span></p>
</textarea>
<textarea id="textarea_5">
<table>
<tr id="tr_1">
[<td>cell</td>]
<td>cell</td>
</tr>
<tr id="tr_2">
<td>cell</td>
[<td>cell</td>]
</tr>
</table>
</textarea>
<textarea id="textarea_6">
<ol id="ol_2">
[<li>foo</li>
<li>bar
<ul id="ul_1">
<li>
baz
</li>]
<li>quz</li>
</ul>
</li>
</ol>
</textarea>
<textarea id="textarea_7">
<ol>
<li id="li_5">foo^
<ul><li>bar</li></ul>
</li>
</ol>
</textarea>

0 comments on commit 6775bbe

Please sign in to comment.
You can’t perform that action at this time.