File: plugins.js

package info (click to toggle)
ckeditor 4.4.4%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 25,632 kB
  • ctags: 2,419
  • sloc: sh: 190; python: 37; makefile: 29; php: 15; xml: 5
file content (86 lines) | stat: -rw-r--r-- 2,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* bender-tags: editor,unit */

bender.test(
{
	'test: Loading self defined external plugin file paths' : function() {
		CKEDITOR.plugins.addExternal( 'myplugin', '%TEST_DIR%_assets/myplugins/sample/', 'my_plugin.js' );

		CKEDITOR.plugins.load( 'myplugin', function() {
			this.resume( function() {
					assert.isTrue( CKEDITOR.plugins.get( 'myplugin' ).definition );
				} );
		}
		, this );

		this.wait();
	},

	'errors thrown when required plugin specified in removePlugins list' : function() {
		var originalSetTimeout = window.setTimeout,
			errors = [];

		// Override native setTimeout to catch all errors.
		window.setTimeout = function( fn, timeout ) {
			originalSetTimeout( function() {
				try
				{
					fn.apply( this, Array.prototype.slice.call( arguments ) );
				}
				catch ( err ) {
					errors.push( err );

					// Do not fail silently on other errors.
					if ( !err.message || !err.message.match( /^Plugin "\w+" cannot be removed/ ) )
						throw err;
				}
			}, timeout );
		};

		CKEDITOR.plugins.add( 'errorplugin1' , {
			requires: 'errorplugin3,errorplugin2'
		} );
		CKEDITOR.plugins.add( 'errorplugin2' , {
			requires: 'errorplugin3,errorplugin4'
		} );
		CKEDITOR.plugins.add( 'errorplugin3' , {
			init : function( editor ) {
				editor.plugin3Inited = true;
			}
		} );
		CKEDITOR.plugins.add( 'errorplugin4' , {
			init : function( editor ) {
				editor.plugin4Inited = true;
			}
		} );

		originalSetTimeout( function() {
			CKEDITOR.replace( 'errortest', {
				plugins : 'wysiwygarea,errorplugin1,errorplugin3',
				extraPlugins : 'errorplugin2',
				removePlugins : 'errorplugin3,errorplugin4',

				on : {
					instanceReady: function( evt ) {
						resume( function() {
							// Reset overriden setTimeout.
							window.setTimeout = originalSetTimeout;

							// plugin 3 reqed by plugin 1 and plugins 4 & 3 reqed by plugin 2.
							assert.areEqual( 3, errors.length );

							var err;
							while ( ( err = errors.pop() ) )
								assert.isMatching( /^Plugin "\w+" cannot be removed/, err.message );

							// Plugins are corretly inited.
							assert.isTrue( evt.editor.plugin3Inited );
							assert.isTrue( evt.editor.plugin4Inited );
						} );
					}
				}
			} );
		} );

		wait();
	}
} );