Wordpress/tests/qunit/editor/tinymce/util/Quirks_remove.html

271 lines
8.9 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html>
<head>
<title>Removing content tests</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<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="../../js/qunit/reporter.js"></script>
<script src="../../js/utils.js"></script>
<script src="../../js/tinymce_loader.js"></script>
<script src="../../js/jsrobot/robot.js"></script>
<script>
var editor;
QUnit.config.autostart = false;
QUnit.config.reorder = false;
module("Remove Content", {
autostart: false
});
asyncTest('Backspace with indented text', function() {
var c, originalContent = '<p>Line1</p>\n<p style="margin-left: 30px;">Line2</p>';
expect(2);
editor.setContent(originalContent);
editor.focus();
setSelection('p:nth-child(1)', 4, 'p:nth-child(2)', 4);
robot.type('\b', false, function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), "<p>Line2</p>", 'Delete content');
editor.execCommand('undo', false, null);
equal(editor.getContent(), originalContent, 'Undo deletion');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
// oncut is not supported by FireFox 2.0 so this is impossible to fix there.
if (!tinymce.isGecko || !/Firefox\/[12].[0-9]/.test(navigator.userAgent)) {
asyncTest('Cut with indented text', function() {
var c, originalContent = '<p>Line1</p>\n<p style="margin-left: 30px;">Line2</p>';
expect(3);
editor.setContent(originalContent);
editor.focus();
setSelection('p:nth-child(1)', 4, 'p:nth-child(2)', 4);
robot.cut(function() {
// The fix for this bug happens in a timeout after cut so we need to make sure that happens first by adding an additional delay.
setTimeout(function() {
equal(editor.getContent(), "<p>Line2</p>", 'Cut text');
editor.execCommand('undo', false, null);
equal(editor.getContent(), originalContent, 'Undo cut');
editor.execCommand('SelectAll');
robot.paste(function() {
ok(/Line/.test(editor.getContent()), 'Content should have been on clipboard. Got: ' + editor.getContent());
QUnit.start();
}, editor.selection.getNode());
}, 100);
}, editor.selection.getNode());
});
} else {
test('Skipped on FireFox 2.x: Cut with indented text', function() {});
}
asyncTest('Forward delete with indented text', function() {
var c, originalContent = '<p>Line1</p>\n<p style="margin-left: 30px;">Line2</p>';
expect(2);
editor.setContent(originalContent);
editor.focus();
setSelection('p:nth-child(1)', 4, 'p:nth-child(2)', 4);
robot.forwardDelete(function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), "<p>Line2</p>", 'Delete content');
editor.execCommand('undo', false, null);
equal(editor.getContent(), originalContent, 'Undo deletion');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Forward delete with first paragraph indented', function() {
var c, originalContent = '<p style="margin-left: 30px;">Line1</p>\n<p>Line2</p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
setSelection('p:nth-child(1)', 4, 'p:nth-child(2)', 4);
robot.forwardDelete(function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<p style="margin-left: 30px;">Line2</p>', 'Delete content');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Backward delete from paragraph to heading', function () {
var c, originalContent = '<h1>Heading</h1><p>text</p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
setSelection('p', 0);
robot.type('\b', false, function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<h1>Headingtext</h1>', 'Delete content');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Forward delete from heading to paragraph', function () {
var c, originalContent = '<h1>Heading</h1><p>text</p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
setSelection('h1', 7);
robot.forwardDelete(function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<h1>Headingtext</h1>', 'Delete content');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Forward delete from heading to paragraph with span', function () {
var c, originalContent = '<h1>Heading</h1><p><span style="color: #ff0000;">text</span></p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
setSelection('h1', 7);
robot.forwardDelete(function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<h1>Heading<span style="color: #ff0000;">text</span></h1>', 'Delete content');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Backward delete from paragraph with span to heading', function () {
var c, originalContent = '<h1>Heading</h1><p><span style="color: #ff0000;">text</span></p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
setSelection('p', 0);
robot.type('\b', false, function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<h1>Heading<span style="color: #ff0000;">text</span></h1>', 'Delete content');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Backward delete all contents', function () {
var c, originalContent = '<h1>Heading</h1><p><span style="color: #ff0000;">text</span></p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
editor.execCommand('SelectAll');
robot.type('\b', false, function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<p>&nbsp;</p>', 'Empty contents');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Forward delete all contents', function () {
var c, originalContent = '<h1>Heading</h1><p><span style="color: #ff0000;">text</span></p>';
expect(1);
editor.setContent(originalContent);
editor.focus();
editor.execCommand('SelectAll');
robot.forwardDelete(function() {
// The content is fixed up after a small timeout to let the browser default behaviour kick in.
// As such we need to defer our checks as well.
setTimeout(function() {
equal(editor.getContent(), '<p>&nbsp;</p>', 'Empty contents');
QUnit.start();
}, 100);
}, editor.selection.getNode());
});
asyncTest('Backward delete blockquote contents', function () {
expect(1);
editor.setContent('<blockquote><p>some text here</p></blockquote>');
var textNode = editor.dom.select('p')[0].firstChild;
setSelection(textNode, 0, textNode, 5);
editor.focus();
robot.type('\b', false, function() {
equal(cleanHtml(editor.getContent()), '<blockquote><p>text here</p></blockquote>');
QUnit.start();
}, editor.selection.getNode());
});
asyncTest('Forward delete after empty paragraphs does not delete all content', function () {
expect(1);
editor.setContent('<p></p><p></p><p></p>');
setSelection('p:nth-child(3)', 0);
editor.focus();
robot.forwardDelete(function() {
QUnit.notEqual(editor.getContent(), '<p>&nbsp;</p>', 'Editor contents should not be empty');
QUnit.start();
}, editor.selection.getNode());
});
var initTinyFunction = function(){
tinymce.init({
mode : "exact",
elements : "elm1",
add_unload_trigger : false,
theme_advanced_styles : 'test1=test1;test2=test2',
valid_styles : {
'*' : 'text-align,padding-left,color,font-size,font-family,background-color,font-weight,font-style,text-decoration,float,margin,margin-top,margin-right,margin-bottom,margin-left,display'
},
init_instance_callback : function(ed) {
editor = ed;
}
});
};
</script>
</head>
<body>
<h1 id="qunit-header">Removing content 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"></textarea>
</div>
<script>
initWhenTinyAndRobotAreReady(initTinyFunction);
</script>
</body>
</html>