Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

132 lines (115 sloc) 3.939 kB
<!DOCTYPE html>
<html>
<head>
<title>Undo Tests</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script src="qunit/connector.js"></script>
<script type="text/javascript" src="qunit/runner.js"></script>
<script type="text/javascript" src="js/utils.js"></script>
<script type="text/javascript" src="js/tiny_mce_loader.js"></script>
<script>
QUnit.config.reorder = false;
QUnit.config.autostart = false;
var BACKSPACE = 0x8;
module('Undo', {
autostart: false
});
function isUndoEnabled() {
return !editor.controlManager.get('undo').isDisabled();
}
// The following code never made it into the main codebase -- but it might be useful one day.
// If you're seeing this in August 2011 or later, please delete.
// in webkit the iframe window needs to be given focus before selection
// will behave correctly. This code assigns focus to the tinymce window, giving it back to the
// main window if it started with it.
// if (tinymce.isWebKit) {
// var hadFocus = document.hasFocus();
// t.getWin().focus();
// if (hadFocus) {
// window.focus();
// }
// }
function assertUndoEnabledWhenTyping(c, expectedContent) {
editor.setContent('<p>Content</p>');
editor.undoManager.clear();
editor.undoManager.add();
editor.execCommand('mceRepaint');
// Need to focus the editor before setting selection in order to get the editor typing working correctly.
// All evidence points to the normal APIs not needing an editor.focus() call
editor.focus();
setSelection('p', 4);
ok(!isUndoEnabled(), 'Undo starts disabled.');
robot.type(c, false, function() {
equal(editor.getContent(), expectedContent);
ok(isUndoEnabled(), 'Undo is enabled.');
QUnit.start();
}, editor.selection.getNode());
}
asyncTest('Undo added when typing character', function() {
assertUndoEnabledWhenTyping('b', '<p>Contbent</p>');
});
asyncTest('Undo added when typing enter', function() {
assertUndoEnabledWhenTyping('\n', '<p>Cont</p><p>ent</p>');
});
asyncTest('Forward delete triggers undo in IE', function() {
editor.setContent('<p>Test1 Test2</p>');
editor.undoManager.clear();
editor.execCommand('mceRepaint');
ok(!isUndoEnabled(), 'Undo is disabled.');
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 0);
rng.setEnd(editor.dom.select('p')[0].firstChild, 6);
editor.selection.setRng(rng);
robot.forwardDelete(function() {
equal(editor.getContent(), '<p>Test2</p>', 'First word has been deleted');
ok(isUndoEnabled(), 'Undo is enabled.');
editor.undoManager.undo();
equal(editor.getContent(), '<p>Test1 Test2</p>', 'First word has been restored');
QUnit.start();
}, editor.selection.getNode());
});
asyncTest('Undo added when losing focus', function(){
editor.undoManager.clear();
editor.setContent("<p>some text</p>");
setSelection('p', 4, 'p', 9);
robot.type(0x8, false, function(){
var styleMenu = editor.controlManager.controls['elm1_styleselect'];
styleMenu.focus();
editor.execCommand('FormatBlock', false, 'h1');
editor.undoManager.undo();
equal(editor.getContent(), "<p>some</p>");
QUnit.start();
});
});
var initTinyFunction = function(){
tinyMCE.init({
mode : "exact",
elements : "elm1",
theme : "advanced",
cleanup: true,
add_unload_trigger : false,
apply_source_formatting : 0,
init_instance_callback : function(ed) {
editor = ed;
}
});
}
</script>
</head>
<body>
<h1 id="qunit-header">Undo Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="content">
<textarea id="elm1" name="elm1">Content
</textarea>
</div>
<script type="text/javascript" language="JavaScript" src="jsrobot/robot.js"></script>
<script>
initWhenTinyAndRobotAreReady(initTinyFunction);
</script>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.