File: preview.js

package info (click to toggle)
ckeditor 4.19.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 290,372 kB
  • sloc: javascript: 242,409; sh: 202; makefile: 64; python: 37; php: 15; xml: 5
file content (145 lines) | stat: -rw-r--r-- 3,644 bytes parent folder | download | duplicates (2)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* bender-tags: editor */
/* bender-ckeditor-plugins: preview */

bender.editor = {
	startupData: '<p>Foo</p>'
};

bender.test( {
	// (#4026)
	'test title of preview': function() {
		var tc = this,
			editor = tc.editor;

		editor.title = 'Test title';
		editor.once( 'contentPreview', function( event ) {
			event.cancel();

			tc.resume( function() {
				assert.isMatching( '<title>' + editor.title + '</title>', event.data.dataValue,
					'Preview title is editor\'s title.' );
			} );
		}, null, null, 1 );

		editor.execCommand( 'preview' );

		tc.wait();
	},

	'test processing of data on contentPreview': function() {
		var tc = this,
			editor = tc.editor;

		editor.once( 'contentPreview', function( event ) {
			event.data.dataValue = event.data.dataValue.replace( 'Foo', 'Bar' );
		}, null, null, 1 );

		editor.once( 'contentPreview', function( event ) {
			tc.resume( function() {
				assert.isArray( event.data.dataValue.match( '<p>Bar</p>' ), 'Content has been altered.' );
			} );

			event.cancel();	// Don't open preview window.
		}, null, null, 2 );

		editor.execCommand( 'preview' );

		tc.wait();
	},

	// (#3661)
	'test createPreview returns new window': function() {
		// It's not possible to overwrite window.open in IE8.
		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
			assert.ignore();
		}

		var openStub = sinon.stub( window, 'open', function() {
				return {
					document: {
						open: function() {},
						write: function() {},
						close: function() {}
					}
				};
			} ),
			returnValue = CKEDITOR.plugins.preview.createPreview( this.editor );

		openStub.restore();

		assert.isInstanceOf( CKEDITOR.dom.window, returnValue );
	},

	// (#3661)
	'test preview command is available in inline editor': function() {
		bender.editorBot.create( {
			name: 'inline',
			creator: 'inline',
			startupData: '<p>Foo</p>',
			config: {
				plugins: 'preview'
			}
		}, function( bot ) {
			assert.isNotUndefined( bot.editor.getCommand( 'preview' ), 'Command is registered' );
		} );
	},

	// (#3661)
	'test preview command is not available in source mode': function() {
		bender.editorBot.create( {
			name: 'source-test',
			startupData: '<p>Foo</p>',
			config: {
				startupMode: 'source',
				plugins: 'preview,sourcearea'
			}
		}, function( bot ) {
			var editor = bot.editor,
				previewCommand = editor.getCommand( 'preview' );

			assert.isNotUndefined( previewCommand, 'Command is registered' );
			assert.areSame( previewCommand.state, CKEDITOR.TRISTATE_DISABLED, 'Command is disabled' );
		} );
	},

	// (#4790)
	'test callback should be called when document.readyState is complete': function() {
		// It's not possible to overwrite window.open in IE8.
		if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) {
			assert.ignore();
		}

		var documentReadyState = 'complete',
			// We need to prevent the opening of a new as browsers block it and the test will fall.
			openStub = sinon.stub( window, 'open', function() {
				return {
					document: {
						open: function() {},
						write: function() {},
						close: function() {},
						readyState: documentReadyState
					}
				};
			} );

		bender.editorBot.create( {
			name: 'callback-execute-test',
			config: {
				plugins: 'print,image'
			}
		}, function( bot ) {
			var editor = bot.editor,
				preview = CKEDITOR.plugins.preview;

			preview.createPreview( editor, function( previewWindow ) {
				resume( function() {
					assert.areSame( 'complete', previewWindow.$.document.readyState, 'callback was not called because document.readyState is other than complete' );
				} );
			} );

			openStub.restore();

			wait();
		} );
	}
} );