Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/scripts/user-extensions.js
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/scripts/user-extensions.js	(revision 999)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/scripts/user-extensions.js	(revision 1000)
@@ -37,10 +37,22 @@
 			else if ( curNode.nodeType == 3 )
 			{
+				// usual spaces in HTML can always be compressed to a single space and not affect 
+				// the visual appearence... except for things inside a <pre>
 				if ( curNode.parentNode && curNode.parentNode.nodeName.toLowerCase() != 'pre' )
 				{
 					curNode.nodeValue = curNode.nodeValue.replace( /[ \t\r\n]+/g, ' ' ) ;
-					if ( curNode.nodeValue == ' ' )
-						nodesToDelete.push( curNode ) ;
 				}
+
+				// spaces just after or just before a block node or <br> are useless
+				var prevNode = curNode.previousSibling ;
+				var nextNode = curNode.nextSibling ;
+				var prevNodeName = prevNode ? prevNode.nodeName.toLowerCase() : "" ;
+				var nextNodeName = nextNode ? nextNode.nodeName.toLowerCase() : "" ;
+				if ( editor.FCKListsLib.BlockBoundaries[ prevNodeName ] || prevNodeName == 'br' )
+					curNode.nodeValue = curNode.nodeValue.replace( /^[ \t\r\n]+/g, '' ) ;
+				if ( editor.FCKListsLib.BlockBoundaries[ nextNodeName ] || nextNodeName == 'br' )
+					curNode.nodeValue = curNode.nodeValue.replace( /[ \t\r\n]+$/g, '' ) ;
+				if ( curNode.nodeValue == '' )
+					nodesToDelete.push( curNode ) ;
 			}
 			curNode = editor.FCKDomTools.GetNextSourceNode( curNode ) ;
@@ -101,8 +113,18 @@
 		while ( editorNode || verifyNode )
 		{
+			if ( ! editorNode )
+				throw new SeleniumError( "DOM structure mismatch: missing DOM node in editor document - "
+					       + verifyNode.nodeName + " expected." ) ;
+			if ( ! verifyNode )
+				throw new SeleniumError( "DOM structure mismatch: missing DOM node in verification document - "
+					       + editorNode.nodeName + " expected." ) ;
 			if ( editorNode.nodeType == 1 && editorNode.nodeName != verifyNode.nodeName )
-				throw new SeleniumError( "DOM structure mismatch: element tags are different." ) ;
+				throw new SeleniumError( "DOM structure mismatch: element tags are different - "
+					       + editorNode.nodeName + " encountered in editor document while "
+					       + verifyNode.nodeName + " is expected by verification document." ) ;
 			if ( editorNode.nodeType == 3 && editorNode.nodeValue != verifyNode.nodeValue )
-				throw new SeleniumError( "DOM structure mismatch: text node values are different." ) ;
+				throw new SeleniumError( "DOM structure mismatch: text node values are different - "
+						+ "'" + editorNode.nodeValue + "' is different "
+						+ " to '" + verifyNode.nodeValue + "'." ) ;
 			editorNode = win.FCKDomTools.GetNextSourceNode( editorNode ) ;
 			verifyNode = win.FCKDomTools.GetNextSourceNode( verifyNode ) ;
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/FCKTestSuite.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/FCKTestSuite.html	(revision 999)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/FCKTestSuite.html	(revision 1000)
@@ -6,7 +6,7 @@
 		<table cellpadding="1" cellspacing="1" border="1">
 			<tbody>
-				<tr><td><b>Load FCKeditor</b></td></tr>
+				<tr><td><b>FCKeditor Test Suite</b></td></tr>
 				<tr><td><a href="./TestLoadFCKeditor.html">Test Load FCKeditor</a></td></tr>
-				<tr><td><a href="./TestCreateList.html">Test Create Lists</a></td></tr>
+				<tr><td><a href="./TestCreateList.html">Test List Creation and Removal</a></td></tr>
 			</tbody>
 		</table>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/TestCreateList.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/TestCreateList.html	(revision 999)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/TestCreateList.html	(revision 1000)
@@ -11,5 +11,5 @@
 	-->
 	<head>
-		<title>Test Create Lists</title>
+		<title>Test List Creation and Removal</title>
 	</head>
 	<body>
@@ -17,6 +17,5 @@
 			<tbody>
 				<tr>
-					<td rowspan="1" colspan="3">Test Create Lists<br>
-					</td>
+					<td rowspan="1" colspan="3">Test List Creation and Removal</td>
 				</tr>
 				<tr>
@@ -25,4 +24,6 @@
 					<td></td>
 				</tr>
+				<!-- Tests 1 to 4 correspond to bugs #67, #646, #647, #654, #663, #675, #1178. -->
+				<!-- Test 1: Converting mixed <p> <div> <br> paragraphs to ordered list. -->
 				<tr>
 					<td>fckLoadContents</td>
@@ -37,5 +38,169 @@
 				<tr>
 					<td>fckCheckSimilarTo</td>
-					<td>tests/html/test_list_input1_results.html</td>
+					<td>tests/html/test_list_input1_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 2: Converting ordered list back to paragraphs in P mode. -->
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertOrderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input1_results2.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 3: Covnerting <p> paragraphs to unordered list. -->
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input1_results3.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 4: Converting unordered list back to paragraphs in BR mode. -->
+				<tr>
+					<td>waitForCondition</td>
+					<td>
+						win=selenium.browserbot.getCurrentWindow() ;
+						win.FCKConfig.EnterMode = 'br' ;
+						true ;
+					</td>
+					<td>500</td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>waitForCondition</td>
+					<!-- this is needed because we might still have a <p> padding node
+						and fckCheckSimilar to depends on EnterMode to remove padding nodes. -->
+					<td>
+						win.FCKConfig.EnterMode = 'p' ;
+						true ;
+					</td>
+					<td>500</td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input1_results4.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 5: Removing indented list items (#1267). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input2.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input2_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 6: Creating a list in an empty document in P mode (#1287). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input3.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertOrderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input3_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 7: Create a list across three empty <P> paragraphs (#1291). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input4.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input4_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 8: Remove a list item containing a block node (#1292). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input5.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input5_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 9: Merging paragraphs to an existing list in the middle (#1309). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input6.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input6_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 10: Creating a list from a hyperlink paragraph, with the caret at the end of paragraph (#1346). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input7.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertUnorderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input7_results1.html</td>
+					<td></td>
+				</tr>
+				<!-- Test 11: Creating a list from a paragraph consisting of bold text only (#1352). -->
+				<tr>
+					<td>fckLoadContents</td>
+					<td>tests/html/test_list_input8.html</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckExecuteCommand</td>
+					<td>InsertOrderedList</td>
+					<td></td>
+				</tr>
+				<tr>
+					<td>fckCheckSimilarTo</td>
+					<td>tests/html/test_list_input8_results1.html</td>
 					<td></td>
 				</tr>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results1.html	(revision 1000)
@@ -0,0 +1,9 @@
+<p>line 1 is not part of the list</p>
+<ol>
+	<li>this is point 1</li>
+	<li>this is point 2</li>
+	<li>this <b>is poi</b>nt 3</li>
+	<li>this is point 4</li>
+	<li>this is point 5</li>
+</ol>
+<div>line 6 is not part of the list</div>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results2.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results2.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results2.html	(revision 1000)
@@ -0,0 +1,7 @@
+<p>line 1 is not part of the list</p>
+<p>this is point 1</p>
+<p>this is point 2</p>
+<p>this <b>is poi</b>nt 3</p>
+<p>this is point 4</p>
+<p>this is point 5</p>
+<div>line 6 is not part of the list</div>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results3.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results3.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results3.html	(revision 1000)
@@ -0,0 +1,9 @@
+<p>line 1 is not part of the list</p>
+<ul>
+	<li>this is point 1</li>
+	<li>this is point 2</li>
+	<li>this <b>is poi</b>nt 3</li>
+	<li>this is point 4</li>
+	<li>this is point 5</li>
+</ul>
+<div>line 6 is not part of the list</div>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results4.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results4.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input1_results4.html	(revision 1000)
@@ -0,0 +1,7 @@
+<p>line 1 is not part of the list</p>
+this is point 1<br />
+this is point 2<br />
+this <b>is poi</b>nt 3<br />
+this is point 4<br />
+this is point 5<br />
+<div>line 6 is not part of the list</div>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2.html	(revision 1000)
@@ -0,0 +1,13 @@
+<ul>
+	<li>list item 1
+	<ul>
+		<li>list <span id="SelStart" _fck_bookmark="true"></span><span id="SelEnd" _fck_bookmark="true"></span>item 2<br />
+		<ul>
+			<li>list item 3</li>
+			<li>list item 4</li>
+		</ul>
+		</li>
+	</ul>
+	</li>
+	<li>list item 5</li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input2_results1.html	(revision 1000)
@@ -0,0 +1,9 @@
+<ul>
+	<li>list item 1</li>
+</ul>
+<p>list item 2</p>
+<ul>
+	<li>list item 3</li>
+	<li>list item 4</li>
+	<li>list item 5</li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3.html	(revision 1000)
@@ -0,0 +1,1 @@
+<p><span id="SelStart" _fck_bookmark="true"></span><span id="SelEnd" _fck_bookmark="true"></span></p>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input3_results1.html	(revision 1000)
@@ -0,0 +1,3 @@
+<ol>
+	<li></li>
+</ol>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4.html	(revision 1000)
@@ -0,0 +1,3 @@
+<p><span id="SelStart" _fck_bookmark="true"></span></p>
+<p></p>
+<p><span id="SelEnd" _fck_bookmark="true"></span></p>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input4_results1.html	(revision 1000)
@@ -0,0 +1,5 @@
+<ul>
+	<li></li>
+	<li></li>
+	<li></li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5.html	(revision 1000)
@@ -0,0 +1,7 @@
+<ul>
+	<li>Line 1</li>
+	<li>
+	<h1>Line 2<span id="SelStart" _fck_bookmark="true"></span><span id="SelEnd" _fck_bookmark="true"></span></h1>
+	</li>
+	<li>Line 3</li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input5_results1.html	(revision 1000)
@@ -0,0 +1,7 @@
+<ul>
+	<li>Line 1</li>
+</ul>
+<h1>Line 2</h1>
+<ul>
+	<li>Line 3</li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6.html	(revision 1000)
@@ -0,0 +1,5 @@
+<p>Line<span id="SelStart" _fck_bookmark="true"></span> 1</p>
+<ul>
+	<li>Line 2</li>
+</ul>
+<p>L<span id="SelEnd" _fck_bookmark="true"></span>ine 3</p>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input6_results1.html	(revision 1000)
@@ -0,0 +1,5 @@
+<ul>
+	<li>Line 1</li>
+	<li>Line 2</li>
+	<li>Line 3</li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7.html	(revision 1000)
@@ -0,0 +1,1 @@
+<p><a href="http://www.example.com">Test</a><span id="SelStart" _fck_bookmark="true"></span><span id="SelEnd" _fck_bookmark="true"></span></p>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input7_results1.html	(revision 1000)
@@ -0,0 +1,3 @@
+<ul>
+	<li><a href="http://www.example.com">Test</a></li>
+</ul>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8.html	(revision 1000)
@@ -0,0 +1,1 @@
+<p><b>Test<span id="SelStart" _fck_bookmark="true"></span><span id="SelEnd" _fck_bookmark="true"></span></b></p>
Index: /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8_results1.html
===================================================================
--- /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8_results1.html	(revision 1000)
+++ /FCKeditor/branches/features/selenium-tests/_test/selenium/tests/html/test_list_input8_results1.html	(revision 1000)
@@ -0,0 +1,3 @@
+<ol>
+	<li><b>Test</b></li>
+</ol>
Index: /FCKeditor/branches/features/selenium-tests/editor/_source/internals/fckdomtools.js
===================================================================
--- /FCKeditor/branches/features/selenium-tests/editor/_source/internals/fckdomtools.js	(revision 999)
+++ /FCKeditor/branches/features/selenium-tests/editor/_source/internals/fckdomtools.js	(revision 1000)
@@ -758,5 +758,11 @@
 					currentListItem.appendChild( item.contents[i].cloneNode( true ) ) ;
 				if ( currentListItem.nodeType == 11 )
+				{
+					if ( currentListItem.lastChild && 
+							currentListItem.lastChild.getAttribute &&
+							currentListItem.lastChild.getAttribute( 'type' ) == '_moz' )
+						currentListItem.removeChild( currentListItem.lastChild );
 					currentListItem.appendChild( doc.createElement( 'br' ) ) ;
+				}
 				if ( currentListItem.nodeName.IEquals( FCKConfig.EnterMode ) && currentListItem.firstChild )
 				{
