<commit_before><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unit tests for forceblocks</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="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>
var editor, rng;

QUnit.config.reorder = false;
QUnit.config.autostart = false;

module("ForceBlocks", {
	autostart: false
});

function pressEnter(evt) {
	var dom = editor.dom, target = editor.selection.getNode();

	evt = tinymce.extend({}, evt);

	dom.fire(target, 'keydown', evt);
	dom.fire(target, 'keypress', evt);
	dom.fire(target, 'keyup', evt);
}

test('Enter at end of H1', function() {
	editor.setContent('<h1>abc</h1>');
	setSelection('h1', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>abc</h1><p>\u00a0</p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'P');
});

test('Enter in midde of H1', function() {
	editor.setContent('<h1>abcd</h1>');
	setSelection('h1', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>ab</h1><h1>cd</h1>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'H1');
});

test('Enter at end of P', function() {
	editor.setContent('<p>abc</p>');
	setSelection('p', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p>abc</p><p>\u00a0</p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'P');
});

test('Enter at end of EM inside P', function() {
	editor.setContent('<p><em>abc</em></p>');
	setSelection('em', 3);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em>abc</em></p><p><em></em></p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'EM');
});

test('Enter at middle of EM inside P', function() {
	editor.setContent('<p><em>abcd</em></p>');
	setSelection('em', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p><em>ab</em></p><p><em>cd</em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM');
});

test('Enter at beginning EM inside P', function() {
	editor.setContent('<p><em>abc</em></p>');
	setSelection('em', 0);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em></em></p><p><em>abc</em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM');
});

test('Enter at end of STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abc</strong></em></p>');
	setSelection('strong', 3);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em><strong>abc</strong></em></p><p><em><strong></strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'STRONG');
});

test('Enter at middle of STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abcd</strong></em></p>');
	setSelection('strong', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p><em><strong>ab</strong></em></p><p><em><strong>cd</strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG');
});

test('Enter at beginning STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abc</strong></em></p>');
	setSelection('strong', 0);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em><strong></strong></em></p><p><em><strong>abc</strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG');
});

test('Enter at beginning of P', function() {
	editor.setContent('<p>abc</p>');
	setSelection('p', 0);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p>\u00a0</p><p>abc</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at middle of P with style, id and class attributes', function() {
	editor.setContent('<p id="a" class="b" style="color:#000">abcd</p>');
	setSelection('p', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p id="a" class="b" style="color: #000;">ab</p><p class="b" style="color: #000;">cd</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at a range between H1 and P', function() {
	editor.setContent('<h1>abcd</h1><p>efgh</p>');
	setSelection('h1', 2, 'p', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>ab</h1><p>gh</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at end of H1 in HGROUP', function() {
	editor.setContent('<hgroup><h1>abc</h1></hgroup>');
	setSelection('h1', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<hgroup><h1>abc</h1><h1>\u00a0</h1></hgroup>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'H1');
});

test('Enter inside empty TD', function() {
	editor.setContent('<table><tr><td></td></tr></table>');
	setSelection('td', 0);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<table><tbody><tr><td><p>\u00a0</p><p>\u00a0</p></td></tr></tbody></table>');
	equal(editor.selection.getRng(true).startContainer.nodeName, '#text');
});

test('Enter inside empty P with empty P siblings', function() {
	// Tests that a workaround for an IE bug is working correctly
	editor.getBody().innerHTML = '<p></p><p></p><p>X</p>';
	setSelection('p', 0);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p>\u00a0</p><p>\u00a0</p><p>\u00a0</p><p>X</p>');
});
<commit_msg>Excluded an IE specific forceblocks test from other browsers.<commit_after><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unit tests for forceblocks</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="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>
var editor, rng;

QUnit.config.reorder = false;
QUnit.config.autostart = false;

module("ForceBlocks", {
	autostart: false
});

function pressEnter(evt) {
	var dom = editor.dom, target = editor.selection.getNode();

	evt = tinymce.extend({}, evt);

	dom.fire(target, 'keydown', evt);
	dom.fire(target, 'keypress', evt);
	dom.fire(target, 'keyup', evt);
}

test('Enter at end of H1', function() {
	editor.setContent('<h1>abc</h1>');
	setSelection('h1', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>abc</h1><p>\u00a0</p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'P');
});

test('Enter in midde of H1', function() {
	editor.setContent('<h1>abcd</h1>');
	setSelection('h1', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>ab</h1><h1>cd</h1>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'H1');
});

test('Enter at end of P', function() {
	editor.setContent('<p>abc</p>');
	setSelection('p', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p>abc</p><p>\u00a0</p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'P');
});

test('Enter at end of EM inside P', function() {
	editor.setContent('<p><em>abc</em></p>');
	setSelection('em', 3);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em>abc</em></p><p><em></em></p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'EM');
});

test('Enter at middle of EM inside P', function() {
	editor.setContent('<p><em>abcd</em></p>');
	setSelection('em', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p><em>ab</em></p><p><em>cd</em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM');
});

test('Enter at beginning EM inside P', function() {
	editor.setContent('<p><em>abc</em></p>');
	setSelection('em', 0);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em></em></p><p><em>abc</em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM');
});

test('Enter at end of STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abc</strong></em></p>');
	setSelection('strong', 3);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em><strong>abc</strong></em></p><p><em><strong></strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'STRONG');
});

test('Enter at middle of STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abcd</strong></em></p>');
	setSelection('strong', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p><em><strong>ab</strong></em></p><p><em><strong>cd</strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG');
});

test('Enter at beginning STRONG in EM inside P', function() {
	editor.setContent('<p><em><strong>abc</strong></em></p>');
	setSelection('strong', 0);
	pressEnter({keyCode: 13});
	equal(cleanHtml(editor.getBody().innerHTML).replace(/<br>|&nbsp;/g, ''), '<p><em><strong></strong></em></p><p><em><strong>abc</strong></em></p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG');
});

test('Enter at beginning of P', function() {
	editor.setContent('<p>abc</p>');
	setSelection('p', 0);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p>\u00a0</p><p>abc</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at middle of P with style, id and class attributes', function() {
	editor.setContent('<p id="a" class="b" style="color:#000">abcd</p>');
	setSelection('p', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<p id="a" class="b" style="color: #000;">ab</p><p class="b" style="color: #000;">cd</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at a range between H1 and P', function() {
	editor.setContent('<h1>abcd</h1><p>efgh</p>');
	setSelection('h1', 2, 'p', 2);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<h1>ab</h1><p>gh</p>');
	equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P');
});

test('Enter at end of H1 in HGROUP', function() {
	editor.setContent('<hgroup><h1>abc</h1></hgroup>');
	setSelection('h1', 3);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<hgroup><h1>abc</h1><h1>\u00a0</h1></hgroup>');
	equal(editor.selection.getRng(true).startContainer.nodeName, 'H1');
});

test('Enter inside empty TD', function() {
	editor.setContent('<table><tr><td></td></tr></table>');
	setSelection('td', 0);
	pressEnter({keyCode: 13});
	equal(editor.getContent(), '<table><tbody><tr><td><p>\u00a0</p><p>\u00a0</p></td></tr></tbody></table>');
	equal(editor.selection.getRng(true).startContainer.nodeName, '#text');
});

if (tinymce.isIE) {
	test('Enter inside empty P with empty P siblings', function() {
		// Tests that a workaround for an IE bug is working correctly
		editor.getBody().innerHTML = '<p></p><p></p><p>X</p>';
		setSelection('p', 0);
		pressEnter({keyCode: 13});
		equal(editor.getContent(), '<p>\u00a0</p><p>\u00a0</p><p>\u00a0</p><p>X</p>');
	});
}

{'fraction_non_alphanumeric': 0.24960267670430783, 'fraction_numerical': 0.020577164366373902, 'mean_word_length': 6.654289372599232, 'pattern_counts': {'":': 0, '<': 387, '<?xml version=': 0, '>': 387, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2935929', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4405, 'n_words': 692}