<commit_before><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Editor/EnterKeyHandling Plugin Test</title>

		<style>
			@import "../../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../../dojo/dojo.js"
			djConfig="isDebug: true, parseOnLoad: true"></script>

		<!-- functions to help test -->
		<script type="text/javascript" src="../../helpers.js"></script>

		<script type="text/javascript">
			dojo.require("dojo.DeferredList");
			dojo.require("dijit.robotx");

			function dom2string(root){
				// summary:
				//		Simple dump of the HTML inside an editor, skipping
				//		attributes altogether.   Similar to `dijit._editor.getNodeHtml`
				//		(maybe want to switch to using that).
				var out = [];

				function recurse(children){
					var i=0, node = children[i++];
					while(node){
						switch(node.nodeType){
						case 1:	// normal node
							if(node.childNodes.length){
								out.push("<" + node.tagName.toLowerCase() + ">");
								recurse(node.childNodes);
								out.push("</" + node.tagName.toLowerCase() + ">");
							}else{
								out.push("<" + node.tagName.toLowerCase() + "/>");
							}
							break;
						case 3:	// text
							var text = dojo.trim(node.textContent || node.data).
										replace('\u00a0', "&nbsp;");
							if(text){
								out.push(text);
							}
							break;
						}
						node = children[i++];
					}
				}

				recurse(root.childNodes);
				return out.join("");
			}

			dojo.addOnLoad(function(){
				doh.robot.initRobot('../EnterKeyHandling.html');

				var metaKey = {ctrl: true}
				
				// Tests for BR mode
				doh.register("blockNodeForEnter=BR", [
					{
						name: "wait for editors to load",
						timeout: 5000,
						runTest: function(){
						    return new dojo.DeferredList(
						        dijit.registry.filter(function(w){ return w.onLoadDeferred; }).map(function(w){ return w.onLoadDeferred; })
						    );
						}
					},
					{
						name: "type in some text",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
							
							// tab to the MenuBar... then focus should automatically shift to "File" menu,
							for(var i=0; i<4; i++){
								doh.robot.typeKeys("ab345", 500);
								doh.robot.keyPress(dojo.keys.ENTER, 500, {});
							}

							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/&nbsp;/g, "");
								value = value.replace(/ /g, "");
								value = value.replace(/\xA0/g, "");
								doh.is('ab345<br/>ab345<br/>ab345<br/>ab345<br/>',
										value,
										"get('value')");
							}), 1000);

							return d;
						}
					},
					{
						name: "copy and paste",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
								
							doh.robot.typeKeys("testingCopyAndPaste", 500);
							doh.robot.keyPress("a", 500, metaKey);	// select all
							doh.robot.keyPress("c", 500, metaKey);	// copy
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress(dojo.keys.ENTER, 500, {shift: false});
							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/ /g, "");
								value = value.replace(/\xA0/g, "");
								
								doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste<br/>',
										value,
										"get('value')");
							}), 1000);
							return d;
						}
					},
					{
						name: "copy and paste split",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
								
							doh.robot.typeKeys("testingCopyAndPaste", 500);
							doh.robot.keyPress("a", 500, metaKey);	// select all
							doh.robot.keyPress("c", 500, metaKey);	// copy
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.ENTER, 500, {});
							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/ /g, "");
								doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndP<br/>aste',
										value,
										"get('value')");
							}), 1000);
							return d;
						}
					}
				]);
				doh.register("Split tests", [
					{
						name: "Test div line split",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();
							// The initial input was a div with a line of text with a bold tag in the middle.
							// we want to focus on the bold and enter there, splitting it.
							var editor = dijit.byId("div2");
							dojo.window.scrollIntoView(editor.iframe);
							var node = dojo.withGlobal(editor.window, function(){
								return dojo.byId("boldLine0");
							});
							
							doh.robot.mouseMoveAt(editor.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);

							doh.robot.sequence(function(){<commit_msg>ctrl-c on mac in safari converts to <h3> it doesn't copy.  Odd.  Also, safari sometimes leaves a trailing BR.   Updated testcase to acount for both and use the right meta key when on mac.  refs #12007<commit_after><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>doh.robot Editor/EnterKeyHandling Plugin Test</title>

		<style>
			@import "../../../../util/doh/robot/robot.css";
		</style>

		<!-- required: dojo.js -->
		<script type="text/javascript" src="../../../../dojo/dojo.js"
			djConfig="isDebug: true, parseOnLoad: true"></script>

		<!-- functions to help test -->
		<script type="text/javascript" src="../../helpers.js"></script>

		<script type="text/javascript">
			dojo.require("dojo.DeferredList");
			dojo.require("dijit.robotx");

			function dom2string(root){
				// summary:
				//		Simple dump of the HTML inside an editor, skipping
				//		attributes altogether.   Similar to `dijit._editor.getNodeHtml`
				//		(maybe want to switch to using that).
				var out = [];

				function recurse(children){
					var i=0, node = children[i++];
					while(node){
						switch(node.nodeType){
						case 1:	// normal node
							if(node.childNodes.length){
								out.push("<" + node.tagName.toLowerCase() + ">");
								recurse(node.childNodes);
								out.push("</" + node.tagName.toLowerCase() + ">");
							}else{
								out.push("<" + node.tagName.toLowerCase() + "/>");
							}
							break;
						case 3:	// text
							var text = dojo.trim(node.textContent || node.data).
										replace('\u00a0', "&nbsp;");
							if(text){
								out.push(text);
							}
							break;
						}
						node = children[i++];
					}
				}

				recurse(root.childNodes);
				return out.join("");
			}

			dojo.addOnLoad(function(){
				doh.robot.initRobot('../EnterKeyHandling.html');

				var metaKey = dojo.isMac? {meta: true} : {ctrl: true};
				
				// Tests for BR mode
				doh.register("blockNodeForEnter=BR", [
					{
						name: "wait for editors to load",
						timeout: 5000,
						runTest: function(){
						    return new dojo.DeferredList(
						        dijit.registry.filter(function(w){ return w.onLoadDeferred; }).map(function(w){ return w.onLoadDeferred; })
						    );
						}
					},
					{
						name: "type in some text",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
							
							// tab to the MenuBar... then focus should automatically shift to "File" menu,
							for(var i=0; i<4; i++){
								doh.robot.typeKeys("ab345", 500);
								doh.robot.keyPress(dojo.keys.ENTER, 500, {});
							}

							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/&nbsp;/g, "");
								value = value.replace(/ /g, "");
								value = value.replace(/\xA0/g, "");
								doh.is('ab345<br/>ab345<br/>ab345<br/>ab345<br/>',
										value,
										"get('value')");
							}), 1000);

							return d;
						}
					},
					{
						name: "copy and paste",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
								
							doh.robot.typeKeys("testingCopyAndPaste", 500);
							doh.robot.keyPress("a", 500, metaKey);	// select all
							doh.robot.keyPress("c", 500, metaKey);	// copy
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress(dojo.keys.ENTER, 500, {shift: false});
							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/ /g, "");
								value = value.replace(/\xA0/g, "");
								
								// Safari may end with a trailing/extra br, so we need to remove it.
								if(/<br\/><br\/>$/.test(value)){
									value = value.substring(0, value.length - 5);
								}
								doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste<br/>',
										value,
										"get('value')");
							}), 1000);
							return d;
						}
					},
					{
						name: "copy and paste split",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();

							var br = dijit.byId("br");
							br.set("value", "");
							br.focus();
							
							doh.robot.mouseMoveAt(br.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);
							doh.robot.keyPress(dojo.keys.BACKSPACE, 500, {});
								
							doh.robot.typeKeys("testingCopyAndPaste", 500);
							doh.robot.keyPress("a", 500, metaKey);	// select all
							doh.robot.keyPress("c", 500, metaKey);	// copy
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress("v", 500, metaKey);	// paste
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500, {});
							doh.robot.keyPress(dojo.keys.ENTER, 500, {});
							doh.robot.sequence(d.getTestCallback(function(){
								// get('value') should call the post-filter which recombines the separate <p> nodes into bigger
								// paragraphs.
								var value = br.get('value');
								value = value.replace(/ /g, "");

								// Safari may end with a trailing/extra br, so we need to remove it.
								if(/aste<br\/>$/.test(value)){
									value = value.substring(0, value.length - 5);
								}
								doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndP<br/>aste',
										value,
										"get('value')");
							}), 1000);
							return d;
						}
					}
				]);
				doh.register("Split tests", [
					{
						name: "Test div line split",
						timeout: 10000,
						runTest: function(){
							var d = new doh.Deferred();
							// The initial input was a div with a line of text with a bold tag in the middle.
							// we want to focus on the bold and enter there, splitting it.
							var editor = dijit.byId("div2");
							dojo.window.scrollIntoView(editor.iframe);
							var node = dojo.withGlobal(editor.window, function(){
								return dojo.byId("boldLine0");
							});
							
							doh.robot.mouseMoveAt(editor.iframe, 500);
							doh.robot.mouseClick({left:true}, 500);

							doh.robot.sequence(function(){
{'fraction_non_alphanumeric': 0.16840175953079178, 'fraction_numerical': 0.02463343108504399, 'mean_word_length': 2.166434540389972, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '1201528', 'n_tokens_mistral': 6884, 'n_tokens_neox': 4538, 'n_words': 933}