Don't fail everything if execCommand() throws
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Mon, 19 Sep 2011 14:32:01 -0600
changeset 597 4a58a50f456c
parent 596 035a0c1a4ca1
child 598 7dc85d546add
Don't fail everything if execCommand() throws

Previously, just about everything would fail in IE, because it would
throw for styleWithCSS. Of course, that was run as part of every test
except multitests. As part of this change, I need to ignore changes to
the log div, because tests will be run in the interim and so the numbers
in the log div will naturally change.

Now IE notices all the tests and actually passes some, before they all
start failing with weird exceptions.
tests.js
--- a/tests.js	Mon Sep 19 14:29:55 2011 -0600
+++ b/tests.js	Mon Sep 19 14:32:01 2011 -0600
@@ -4693,6 +4693,8 @@
 		var originalRootElement = document.documentElement.cloneNode(true);
 		originalRootElement.querySelector("[contenteditable]").parentNode
 			.removeChild(originalRootElement.querySelector("[contenteditable]"));
+		originalRootElement.querySelector("#log").parentNode
+			.removeChild(originalRootElement.querySelector("#log"));
 
 		for (var command in expectedQueryResults) {
 			var results = [];
@@ -4706,33 +4708,45 @@
 			actualQueryResults[command] = results;
 			actualQueryExceptions[command] = exceptions;
 		}
-
-		for (var i = 0; i < browserTest[1].length; i++) {
-			document.execCommand(browserTest[1][i][0], false, browserTest[1][i][1]);
-		}
-
-		for (var command in expectedQueryResults) {
-			var results = actualQueryResults[command];
-			var exceptions = actualQueryExceptions[command];
-			try { results[3] = document.queryCommandIndeterm(command) }
-			catch(e) { exceptions[3] = e }
-			try { results[4] = document.queryCommandState(command) }
-			catch(e) { exceptions[4] = e }
-			try { results[5] = document.queryCommandValue(command) }
-			catch(e) { exceptions[5] = e }
-		}
-
-		var newRootElement = document.documentElement.cloneNode(true);
-		newRootElement.querySelector("[contenteditable]").parentNode
-			.removeChild(newRootElement.querySelector("[contenteditable]"));
-
-		normalizeSerializedStyle(testDiv);
 	} catch(e) {
 		exception = e;
 	}
 
+	for (var i = 0; i < browserTest[1].length; i++) {
+		test(function() {
+			assert_equals(exception, null, "Setup must not throw an exception");
+
+			document.execCommand(browserTest[1][i][0], false, browserTest[1][i][1]);
+		}, testName + ": execCommand(" + format_value(browserTest[1][i][0]) + ", false, " + format_value(browserTest[1][i][1]) + ") must not throw an exception");
+	}
+
+	if (exception === null) {
+		try {
+			for (var command in expectedQueryResults) {
+				var results = actualQueryResults[command];
+				var exceptions = actualQueryExceptions[command];
+				try { results[3] = document.queryCommandIndeterm(command) }
+				catch(e) { exceptions[3] = e }
+				try { results[4] = document.queryCommandState(command) }
+				catch(e) { exceptions[4] = e }
+				try { results[5] = document.queryCommandValue(command) }
+				catch(e) { exceptions[5] = e }
+			}
+
+			var newRootElement = document.documentElement.cloneNode(true);
+			newRootElement.querySelector("[contenteditable]").parentNode
+				.removeChild(newRootElement.querySelector("[contenteditable]"));
+			newRootElement.querySelector("#log").parentNode
+				.removeChild(newRootElement.querySelector("#log"));
+
+			normalizeSerializedStyle(testDiv);
+		} catch(e) {
+			exception = e;
+		}
+	}
+
 	test(function() {
-		assert_equals(exception, null, "Setup and execCommand() must not throw an exception");
+		assert_equals(exception, null, "Setup must not throw an exception");
 
 		// Now test for modifications to non-editable content.  First just
 		// count children:
@@ -4756,7 +4770,7 @@
 	}, testName + " checks for modifications to non-editable content");
 
 	test(function() {
-		assert_equals(exception, null, "Setup and execCommand() must not throw an exception");
+		assert_equals(exception, null, "Setup must not throw an exception");
 
 		assert_equals(testDiv.innerHTML,
 			browserTest[2].replace(/[\[\]{}]/g, ""),
@@ -4774,7 +4788,7 @@
 		];
 		for (var i = 0; i < 6; i++) {
 			test(function() {
-				assert_equals(exception, null, "Setup and execCommand() must not throw an exception");
+				assert_equals(exception, null, "Setup must not throw an exception");
 
 				if (expectedQueryResults[command][i] === null) {
 					// Some ad hoc tests to verify that we have a real