Explorar el Código

Merge pull request #6103 from ckeditor/i/5880

Internal: Added editor setData manual performance test. Part of #5880.
Maciej hace 5 años
padre
commit
6d5a2b22fe

+ 1 - 0
tests/manual/performance/_utils/large.txt

@@ -0,0 +1 @@
+<h1>large data placeholder</h1>

+ 1 - 0
tests/manual/performance/_utils/medium.txt

@@ -0,0 +1 @@
+<h1>Medium data placeholder</h1>

+ 3 - 0
tests/manual/performance/_utils/small.txt

@@ -0,0 +1,3 @@
+<h1>Hello world</h1>
+
+<p>This is rather short text with <em>very little</em> text <strong>formatting</strong>.</p>

+ 11 - 0
tests/manual/performance/setdata.html

@@ -0,0 +1,11 @@
+<div id="test-controls">
+	Call <code>editor.setData()</code> with:
+	<button id="small-content" data-file-name="small" disabled>small</button>
+	<button id="medium-content" data-file-name="medium" disabled>medium</button>
+	<button id="large-content" data-file-name="large" disabled>large</button>
+	HTML payload.
+</div>
+
+<hr>
+
+<div id="editor"></div>

+ 68 - 0
tests/manual/performance/setdata.js

@@ -0,0 +1,68 @@
+/**
+ * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/* globals console, window, document */
+
+import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
+import ArticlePluginSet from '@ckeditor/ckeditor5-core/tests/_utils/articlepluginset';
+
+ClassicEditor
+	.create( document.querySelector( '#editor' ), {
+		plugins: [ ArticlePluginSet ],
+		toolbar: [
+			'heading',
+			'|',
+			'bold',
+			'italic',
+			'link',
+			'bulletedList',
+			'numberedList',
+			'|',
+			'outdent',
+			'indent',
+			'|',
+			'blockQuote',
+			'insertTable',
+			'mediaEmbed',
+			'undo',
+			'redo'
+		]
+	} )
+	.then( editor => {
+		window.editor = editor;
+	} )
+	.catch( err => {
+		console.error( err.stack );
+	} );
+
+preloadData()
+	.then( fixtures => {
+		const buttons = document.querySelectorAll( '#test-controls button' );
+
+		for ( const button of buttons ) {
+			button.addEventListener( 'click', function() {
+				const content = fixtures[ this.getAttribute( 'data-file-name' ) ];
+
+				window.editor.setData( content );
+			} );
+			button.disabled = false;
+		}
+	} );
+
+function preloadData() {
+	return Promise.all( [ getFileContents( 'small' ), getFileContents( 'medium' ), getFileContents( 'large' ) ] )
+		.then( responses => {
+			return {
+				small: responses[ 0 ],
+				medium: responses[ 1 ],
+				large: responses[ 2 ]
+			};
+		} );
+
+	function getFileContents( fileName ) {
+		return window.fetch( `_utils/${ fileName }.txt` )
+			.then( resp => resp.text() );
+	}
+}

+ 5 - 0
tests/manual/performance/setdata.md

@@ -0,0 +1,5 @@
+# Performance: `editor.setData()`
+
+1. Begin performance recording in devtools.
+1. Use any button to call `editor.setData()` with chosen data size.
+1. Stop performance recording.