Sfoglia il codice sorgente

Tests: SelectionObserver infinite loop removed unstable unit tests and added manual test.

Szymon Cofalik 9 anni fa
parent
commit
6cf89bdce2

+ 7 - 0
packages/ckeditor5-engine/tests/tickets/629/1.html

@@ -0,0 +1,7 @@
+<head>
+	<link rel="stylesheet" href="%APPS_DIR%ckeditor/build/modules/amd/theme/ckeditor.css">
+</head>
+
+<div id="editor">
+	<p>Lorem ipsum dolor sit amet.</p>
+</div>

+ 23 - 0
packages/ckeditor5-engine/tests/tickets/629/1.js

@@ -0,0 +1,23 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '/ckeditor5/editor-classic/classic.js';
+import Enter from '/ckeditor5/enter/enter.js';
+import Typing from '/ckeditor5/typing/typing.js';
+import Paragraph from '/ckeditor5/paragraph/paragraph.js';
+import Bold from '/ckeditor5/basic-styles/bold.js';
+
+ClassicEditor.create( document.querySelector( '#editor' ), {
+	features: [ Enter, Typing, Paragraph, Bold ],
+	toolbar: [ 'bold' ]
+} )
+.then( editor => {
+	window.editor = editor;
+} )
+.catch( err => {
+	console.error( err.stack );
+} );

+ 16 - 0
packages/ckeditor5-engine/tests/tickets/629/1.md

@@ -0,0 +1,16 @@
+@bender-ui: collapsed
+@bender-tags: ticket, 629, iteration4
+
+### Selection infinite loop [#629](https://github.com/ckeditor/ckeditor5-engine/issues/629)
+
+Before testing open console.
+
+1. Select part of text.
+2. Click bold or press <kbd>ctrl + b</kbd>.
+3. There should be no errors or warnings in console.
+
+
+1. Put caret somewhere in text.
+2. Press <kbd>left arrow</kbd>, then <kbd>right arrow</kbd>.
+3. Repeat fast more than 20 times.
+4. There should be no errors or warnings in console.

+ 10 - 79
packages/ckeditor5-engine/tests/view/observer/selectionobserver.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* globals setTimeout, Range, document, KeyboardEvent, MouseEvent */
+/* globals setTimeout, Range, document */
 /* bender-tags: view, browser-only */
 
 import ViewRange from '/ckeditor5/engine/view/range.js';
@@ -130,7 +130,10 @@ describe( 'SelectionObserver', () => {
 	} );
 
 	it( 'should warn and not enter infinite loop', ( done ) => {
-		let counter = 30;
+		// Reset infinite loop counters so other tests won't mess up with this test.
+		selectionObserver._clearInfiniteLoop();
+
+		let counter = 100;
 
 		const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
 		viewDocument.selection.addRange( ViewRange.createFromParentsAndOffsets( viewFoo, 0, viewFoo, 0 ) );
@@ -161,99 +164,27 @@ describe( 'SelectionObserver', () => {
 		changeDomSelection();
 	} );
 
-	it( 'should not be treated as an infinite loop if the position is different', ( done ) => {
+	it( 'should not be treated as an infinite loop if selection is changed only few times', ( done ) => {
 		const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
-		viewDocument.selection.addRange( ViewRange.createFromParentsAndOffsets( viewFoo, 0, viewFoo, 0 ) );
-
-		let counter = 0;
-
-		const spy = testUtils.sinon.spy( log, 'warn' );
-
-		listenter.listenTo( viewDocument, 'selectionChange', () => {
-			counter++;
 
-			if ( counter < 15 ) {
-				setTimeout( changeCollapsedDomSelection, 100 );
-			}
-		} );
+		// Reset infinite loop counters so other tests won't mess up with this test.
+		selectionObserver._clearInfiniteLoop();
 
-		changeCollapsedDomSelection();
-
-		setTimeout( () => {
-			expect( spy.called ).to.be.false;
-			done();
-		}, 1500 );
-	} );
-
-	it( 'should not be treated as an infinite loop if selection is changed only few times', ( done ) => {
-		const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
 		viewDocument.selection.addRange( ViewRange.createFromParentsAndOffsets( viewFoo, 0, viewFoo, 0 ) );
 
 		const spy = testUtils.sinon.spy( log, 'warn' );
 
-		for ( let i = 0; i < 4; i++ ) {
+		for ( let i = 0; i < 10; i++ ) {
 			changeDomSelection();
 		}
 
 		setTimeout( () => {
 			expect( spy.called ).to.be.false;
 			done();
-		}, 1500 );
+		}, 400 );
 	} );
-
-	const events = {
-		keydown: KeyboardEvent,
-		mousedown: MouseEvent,
-		mousemove: MouseEvent
-	};
-
-	for ( let event in events ) {
-		it( 'should not be treated as an infinite loop if change is triggered by ' + event + ' event', ( done ) => {
-			let counter = 0;
-
-			const viewFoo = viewDocument.getRoot().getChild( 0 ).getChild( 0 );
-			viewDocument.selection.addRange( ViewRange.createFromParentsAndOffsets( viewFoo, 0, viewFoo, 0 ) );
-
-			const spy = testUtils.sinon.spy( log, 'warn' );
-
-			listenter.listenTo( viewDocument, 'selectionChange', () => {
-				counter++;
-
-				if ( counter < 15 ) {
-					setTimeout( () => {
-						document.dispatchEvent( new events[ event ]( event ) );
-						changeDomSelection();
-					}, 100 );
-				}
-			} );
-
-			setTimeout( () => {
-				expect( spy.called ).to.be.false;
-				done();
-			}, 1000 );
-
-			document.dispatchEvent( new events[ event ]( event ) );
-			changeDomSelection();
-		} );
-	}
 } );
 
-function changeCollapsedDomSelection() {
-	const domSelection = document.getSelection();
-	const pos = domSelection.anchorOffset + 1;
-
-	if ( pos > 20 ) {
-		return;
-	}
-
-	domSelection.removeAllRanges();
-	const domFoo = document.getElementById( 'main' ).childNodes[ 0 ].childNodes[ 0 ];
-	const domRange = new Range();
-	domRange.setStart( domFoo, pos );
-	domRange.setEnd( domFoo, pos );
-	domSelection.addRange( domRange );
-}
-
 function changeDomSelection() {
 	const domSelection = document.getSelection();
 	domSelection.removeAllRanges();