Skip to content

Commit

Permalink
Tests: Selection normalisation is needed whenever we operate on real …
Browse files Browse the repository at this point in the history
…selection. Fixes #12990.
  • Loading branch information
Reinmar committed Feb 26, 2015
1 parent 503667b commit 015c43d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
Expand Up @@ -11,9 +11,7 @@ var quirksTools = ( function() {
8: 'BACKSPACE'
};

function assertKeystroke( key, keyModifiers, handled, html, expected, normalizeSelection ) {
normalizeSelection = ( normalizeSelection === false ) ? false : true;

function assertKeystroke( key, keyModifiers, handled, html, expected ) {
function decodeBoguses( html ) {
return html.replace( /@/g, CKEDITOR.env.needsBrFiller ? '<br />' : '' );
}
Expand Down Expand Up @@ -43,7 +41,7 @@ var quirksTools = ( function() {
assert.isInnerHtmlMatching(
expected,
htmlWithSelection,
{ compareSelection: true, normalizeSelection: normalizeSelection },
{ compareSelection: true, normalizeSelection: true },
message
);

Expand All @@ -61,12 +59,22 @@ var quirksTools = ( function() {
return assertKeystroke.apply( this, [ BACKSPACE, 0, 0 ].concat( [].slice.call( arguments ) ) );
}

function bf( html ) {
return assertKeystroke.apply( this, [ BACKSPACE, 0, 1, html, html, false ] );
// We need expected param, because in some cases selection normalization will change the input
// selection markers. Therefore, in some cases we can't compare the result after with the input HTML.
function bf( html, expected ) {
if ( !expected ) {
expected = html;
}

return assertKeystroke.apply( this, [ BACKSPACE, 0, 1, html, expected ] );
}

function df( html ) {
return assertKeystroke.apply( this, [ DEL, 0, 1, html, html, false ] );
function df( html, expected ) {
if ( !expected ) {
expected = html;
}

return assertKeystroke.apply( this, [ DEL, 0, 1, html, expected ] );
}

return {
Expand Down
30 changes: 16 additions & 14 deletions tests/core/editable/keystrokes/delbackspacequirks/collapsed.js
Expand Up @@ -111,13 +111,14 @@
'test backspace, bogus #4': b( '<p><br>@</p><p>[]@</p>', '<p><br />^@!</p>' ),

// False positives. Some of them are buggy, but it's a different case e.g. not merging blocks.
'test backspace, no action #1': bf( '<p>x</p><p>y{}y</p>' ),
'test backspace, no action #2': bf( '<span>x</span><p>{}y</p>' ),
'test backspace, no action #3': bf( '<p>x</p><p><strong>y{}y</strong></p>' ),
'test backspace, no action #4': bf( '<p>x</p><blockquote><p>y{}y</p></blockquote>' ),
'test backspace, no action #5': bf( '<p>x</p><blockquote>z<p>{}y</p></blockquote>' ),
'test backspace, no action #6': bf( 'x<p>{}y</p>' ),
'test backspace, no action #7': bf( '<p>x</p>z<p>{}y</p>' ),
// Note: The second pattern is just the first but after a selection normalization.
'test backspace, no action #1': bf( '<p>x</p><p>y{}y</p>', '<p>x</p><p>y^y</p>' ),
'test backspace, no action #2': bf( '<span>x</span><p>{}y</p>', '<span>x</span><p>^y</p>' ),
'test backspace, no action #3': bf( '<p>x</p><p><strong>y{}y</strong></p>', '<p>x</p><p><strong>y^y</strong></p>' ),
'test backspace, no action #4': bf( '<p>x</p><blockquote><p>y{}y</p></blockquote>', '<p>x</p><blockquote><p>y^y</p></blockquote>' ),
'test backspace, no action #5': bf( '<p>x</p><blockquote>z<p>{}y</p></blockquote>', '<p>x</p><blockquote>z<p>^y</p></blockquote>' ),
'test backspace, no action #6': bf( 'x<p>{}y</p>', 'x<p>^y</p>' ),
'test backspace, no action #7': bf( '<p>x</p>z<p>{}y</p>', '<p>x</p>z<p>^y</p>' ),

// Handled by list or table plugin or editable, but not related to #9998.
// This is just to control whether the fix for #9998 does not break some case which it should not handle at all.
Expand Down Expand Up @@ -162,13 +163,14 @@
'test delete, bogus #4': d( '<p>[]@</p><p><br>@</p>', '<p>^<br />@!</p>' ),

// False positives. Some of them are buggy, but it's a different case e.g. not merging blocks.
'test delete, no action #1': df( '<p>x{}x</p><p>y</p>' ),
'test delete, no action #2': df( '<p>x{}</p><span>y</span>' ),
'test delete, no action #3': df( '<p><strong>x{}x</strong></p><p>y</p>' ),
'test delete, no action #4': df( '<blockquote><p>x{}x</p></blockquote><p>y</p>' ),
'test delete, no action #5': df( '<blockquote><p>x{}</p>x</blockquote><p>y</p>' ),
'test delete, no action #6': df( '<p>x{}</p>y' ),
'test delete, no action #7': df( '<p>y{}</p>y<p>z</p>' ),
// Note: The second pattern is just the first but after a selection normalization.
'test delete, no action #1': df( '<p>x{}x</p><p>y</p>', '<p>x^x</p><p>y</p>' ),
'test delete, no action #2': df( '<p>x{}</p><span>y</span>', '<p>x^</p><span>y</span>' ),
'test delete, no action #3': df( '<p><strong>x{}x</strong></p><p>y</p>', '<p><strong>x^x</strong></p><p>y</p>' ),
'test delete, no action #4': df( '<blockquote><p>x{}x</p></blockquote><p>y</p>', '<blockquote><p>x^x</p></blockquote><p>y</p>' ),
'test delete, no action #5': df( '<blockquote><p>x{}</p>x</blockquote><p>y</p>', '<blockquote><p>x^</p>x</blockquote><p>y</p>' ),
'test delete, no action #6': df( '<p>x{}</p>y', '<p>x^</p>y' ),
'test delete, no action #7': df( '<p>y{}</p>y<p>z</p>', '<p>y^</p>y<p>z</p>' ),

// Handled by list or table plugin or editable, but not related to #9998.
// This is just to control whether the fix for #9998 does not break some case which it should not handle at all.
Expand Down

0 comments on commit 015c43d

Please sign in to comment.