Avoid unwanted CSS/JS in conformance tests
authorAryeh Gregor <AryehGregor+gitcommit@gmail.com>
Fri, 02 Sep 2011 16:34:35 -0600
changeset 561 f2acf9b8ef05
parent 560 460ece410c7e
child 562 d724083aa605
Avoid unwanted CSS/JS in conformance tests

We don't want tests.js to actually *run* any code at all, only define
some functions and variables we can use. Likewise, tests.css had a lot
more rules than we actually wanted.

Conformance tests regenerated, no changes.
conformancetest/gentest.html
conformancetest/runtest.html
css/reset.css
tests.css
tests.js
--- a/conformancetest/gentest.html	Fri Sep 02 16:12:07 2011 -0600
+++ b/conformancetest/gentest.html	Fri Sep 02 16:34:35 2011 -0600
@@ -1,10 +1,6 @@
 <!doctype html>
 <meta charset=utf-8>
-<link rel=stylesheet href=../tests.css>
-<style>
-body { margin-top: 0 }
-#toolbar { display: none !important }
-</style>
+<link rel=stylesheet href=../css/reset.css>
 <title>Generator for editing conformance tests</title>
 <p>See the <a href=editing.html#tests>Tests</a> section of the specification
 for documentation.
@@ -20,12 +16,11 @@
 <div id=test-container></div>
 
 <script src=../implementation.js></script>
+<script>var testsJsLibraryOnly = true</script>
 <script src=../tests.js></script>
 <script>
 "use strict";
 
-document.getElementById("toolbar").parentNode.removeChild(document.getElementById("toolbar"));
-
 function generateTests() {
 	var startTime = Date.now();
 	document.getElementById("test-container").innerHTML = "<div contenteditable></div><p>test";
--- a/conformancetest/runtest.html	Fri Sep 02 16:12:07 2011 -0600
+++ b/conformancetest/runtest.html	Fri Sep 02 16:34:35 2011 -0600
@@ -1,10 +1,6 @@
 <!doctype html>
 <meta charset=utf-8>
-<link rel=stylesheet href=../tests.css>
-<style>
-body { margin-top: 0 }
-#toolbar { display: none !important }
-</style>
+<link rel=stylesheet href=../css/reset.css>
 <title>HTML editing conformance tests</title>
 <p>See the <a href=editing.html#tests>Tests</a> section of the specification
 for documentation.
@@ -16,11 +12,8 @@
 <div id=test-container></div>
 
 <script src=../implementation.js></script>
+<script>var testsJsLibraryOnly = true</script>
 <script src=../tests.js></script>
-<script>
-document.getElementById("toolbar").parentNode.removeChild(
-	document.getElementById("toolbar"));
-</script>
 <script src=data.js></script>
 <script src=http://dvcs.w3.org/hg/html/raw-file/tip/tests/resources/testharness.js></script>
 <script src=http://dvcs.w3.org/hg/html/raw-file/tip/tests/resources/testharnessreport.js></script>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/css/reset.css	Fri Sep 02 16:34:35 2011 -0600
@@ -0,0 +1,24 @@
+/* Make sure various CSS values are what are expected, so that tests work
+ * right. */
+body { font-family: serif }
+/* http://www.w3.org/Bugs/Public/show_bug.cgi?id=12154
+ * https://bugzilla.mozilla.org/show_bug.cgi?id=589124
+ * https://bugs.webkit.org/show_bug.cgi?id=56400 */
+b, strong { font-weight: bold }
+.bold { font-weight: bold }
+.notbold { font-weight: normal }
+.underline { text-decoration: underline }
+.line-through { text-decoration: line-through }
+.underline-and-line-through { text-decoration: underline line-through }
+#purple { color: purple }
+/* https://bugs.webkit.org/show_bug.cgi?id=56670 */
+dfn { font-style: italic }
+/* Opera has weird default blockquote style */
+blockquote { margin: 1em 40px }
+/* Some tests assume links are blue, for the sake of argument, but they aren't
+ * blue in any browser.  And :visited definitely isn't blue, except in engines
+ * like Gecko that lie.
+ *
+ * This should really be #00e, probably.  See:
+ * http://www.w3.org/Bugs/Public/show_bug.cgi?id=13330 */
+:link, :visited { color: blue }
--- a/tests.css	Fri Sep 02 16:12:07 2011 -0600
+++ b/tests.css	Fri Sep 02 16:34:35 2011 -0600
@@ -1,4 +1,4 @@
-body { font-family: serif }
[email protected] "css/reset.css";
 .yes { color: green }
 .no { color: red }
 .maybe { color: orange }
@@ -18,16 +18,6 @@
 .extra-results { font-size: small }
 .good-result { color: green }
 .bad-result { color: red }
-/* http://www.w3.org/Bugs/Public/show_bug.cgi?id=12154
- * https://bugzilla.mozilla.org/show_bug.cgi?id=589124
- * https://bugs.webkit.org/show_bug.cgi?id=56400 */
-b, strong { font-weight: bold }
-.bold { font-weight: bold }
-.notbold { font-weight: normal }
-.underline { text-decoration: underline }
-.line-through { text-decoration: line-through }
-.underline-and-line-through { text-decoration: underline line-through }
-#purple { color: purple }
 body > div > table > tbody > tr > td > div:first-child {
 	padding-bottom: 0.2em;
 }
@@ -43,10 +33,6 @@
 body > div > table > tbody > tr > td > div:last-child {
 	white-space: pre-wrap;
 }
-/* https://bugs.webkit.org/show_bug.cgi?id=56670 */
-dfn { font-style: italic }
-/* Opera has weird default blockquote style */
-blockquote { margin: 1em 40px }
 /* Let the rendered HTML line up so it's easier to compare whitespace */
 body > div > table > tbody > tr > td { vertical-align: top }
 /* We don't want test cells to not wrap */
@@ -96,7 +82,3 @@
 	text-align: center;
 	padding: 2em;
 }
-/* Some tests assume links are blue, for the sake of argument, but they aren't
- * blue in any browser.  And :visited definitely isn't blue, except in engines
- * like Gecko that lie. */
-:link, :visited { color: blue }
--- a/tests.js	Fri Sep 02 16:12:07 2011 -0600
+++ b/tests.js	Fri Sep 02 16:34:35 2011 -0600
@@ -1,76 +1,81 @@
-// Alert the reader of egregious Opera bug that will make the specced
-// implementation horribly buggy
-//@{
-(function() {
-	var div = document.createElement("div");
-	div.appendChild(document.createElement("br"));
-	document.body.insertBefore(div, document.body.firstChild);
-	var range = document.createRange();
-	range.setStart(div, 1);
-	div.insertBefore(document.createElement("p"), div.firstChild);
-	if (range.startOffset > range.startContainer.childNodes.length) {
-		var warningDiv = document.createElement("p");
-		document.body.insertBefore(warningDiv, document.body.firstChild);
-		warningDiv.style.fontWeight = "bold";
-		warningDiv.style.fontSize = "2em";
-		warningDiv.style.color = "red";
-		warningDiv.innerHTML = 'Your browser suffers from an <a href="http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1028">egregious bug</a> in range mutation that will give incorrect results for the spec columns in many cases.  To ensure that the spec column contains the output actually required by the spec, use a different browser.';
+// For the original (development) tests, we want to make a bunch of changes to
+// the page as it loads.  We don't want this for the conformance tests, so let
+// them opt out.
+if (typeof testsJsLibraryOnly == "undefined" || !testsJsLibraryOnly) {
+	// Alert the reader of egregious Opera bug that will make the specced
+	// implementation horribly buggy
+	//@{
+	(function() {
+		var div = document.createElement("div");
+		div.appendChild(document.createElement("br"));
+		document.body.insertBefore(div, document.body.firstChild);
+		var range = document.createRange();
+		range.setStart(div, 1);
+		div.insertBefore(document.createElement("p"), div.firstChild);
+		if (range.startOffset > range.startContainer.childNodes.length) {
+			var warningDiv = document.createElement("p");
+			document.body.insertBefore(warningDiv, document.body.firstChild);
+			warningDiv.style.fontWeight = "bold";
+			warningDiv.style.fontSize = "2em";
+			warningDiv.style.color = "red";
+			warningDiv.innerHTML = 'Your browser suffers from an <a href="http://software.hixie.ch/utilities/js/live-dom-viewer/saved/1028">egregious bug</a> in range mutation that will give incorrect results for the spec columns in many cases.  To ensure that the spec column contains the output actually required by the spec, use a different browser.';
+		}
+		div.parentNode.removeChild(div);
+	})();
+	//@}
+
+	// Insert the toolbar thingie as soon as the script file is loaded
+	//@{
+	(function() {
+		var toolbarDiv = document.createElement("div");
+		toolbarDiv.id = "toolbar";
+		// Note: this is completely not a hack at all.
+		toolbarDiv.innerHTML = "<style id=alerts>/* body > div > table > tbody > tr:not(.alert):not(:first-child):not(.active) { display: none } */</style>"
+			+ "<label><input id=alert-checkbox type=checkbox accesskey=a checked onclick='updateAlertRowStyle()'> Display rows without spec <u>a</u>lerts</label>"
+			+ "<label><input id=browser-checkbox type=checkbox accesskey=b checked onclick='localStorage[\"display-browser-tests\"] = event.target.checked'> Run <u>b</u>rowser tests as well as spec tests</label>";
+
+		document.body.appendChild(toolbarDiv);
+	})();
+	//@}
+
+	// Confusingly, we're storing a string here, not a boolean.
+	document.querySelector("#alert-checkbox").checked = localStorage["display-alerts"] != "false";
+	document.querySelector("#browser-checkbox").checked = localStorage["display-browser-tests"] != "false";
+
+	function updateAlertRowStyle() {
+	//@{
+		var checked = document.querySelector("#alert-checkbox").checked;
+		var style = document.querySelector("#alerts");
+		if (checked && !/^\/\*/.test(style.textContent)) {
+			style.textContent = "/* " + style.textContent + " */";
+		} else if (!checked) {
+			style.textContent = style.textContent.replace(/(\/\* | \*\/)/g, "");
+		}
+		localStorage["display-alerts"] = checked;
 	}
-	div.parentNode.removeChild(div);
-})();
-//@}
-
-// Insert the toolbar thingie as soon as the script file is loaded
-//@{
-(function() {
-	var toolbarDiv = document.createElement("div");
-	toolbarDiv.id = "toolbar";
-	// Note: this is completely not a hack at all.
-	toolbarDiv.innerHTML = "<style id=alerts>/* body > div > table > tbody > tr:not(.alert):not(:first-child):not(.active) { display: none } */</style>"
-		+ "<label><input id=alert-checkbox type=checkbox accesskey=a checked onclick='updateAlertRowStyle()'> Display rows without spec <u>a</u>lerts</label>"
-		+ "<label><input id=browser-checkbox type=checkbox accesskey=b checked onclick='localStorage[\"display-browser-tests\"] = event.target.checked'> Run <u>b</u>rowser tests as well as spec tests</label>";
-
-	document.body.appendChild(toolbarDiv);
-})();
-//@}
-
-// Confusingly, we're storing a string here, not a boolean.
-document.querySelector("#alert-checkbox").checked = localStorage["display-alerts"] != "false";
-document.querySelector("#browser-checkbox").checked = localStorage["display-browser-tests"] != "false";
-
-function updateAlertRowStyle() {
-//@{
-	var checked = document.querySelector("#alert-checkbox").checked;
-	var style = document.querySelector("#alerts");
-	if (checked && !/^\/\*/.test(style.textContent)) {
-		style.textContent = "/* " + style.textContent + " */";
-	} else if (!checked) {
-		style.textContent = style.textContent.replace(/(\/\* | \*\/)/g, "");
-	}
-	localStorage["display-alerts"] = checked;
+	//@}
+	updateAlertRowStyle();
+
+	// Feature-test whether the browser wraps at <wbr> or not, and set word-wrap:
+	// break-word where necessary if not.  (IE and Opera don't wrap, Gecko and
+	// WebKit do.)  word-wrap: break-word will break anywhere at all, so it looks
+	// significantly uglier.
+	//@{
+	(function() {
+		var wordWrapTestDiv = document.createElement("div");
+		wordWrapTestDiv.style.width = "5em";
+		document.body.appendChild(wordWrapTestDiv);
+		wordWrapTestDiv.innerHTML = "abc";
+		var height1 = getComputedStyle(wordWrapTestDiv).height;
+		wordWrapTestDiv.innerHTML = "abc<wbr>abc<wbr>abc<wbr>abc<wbr>abc<wbr>abc";
+		var height2 = getComputedStyle(wordWrapTestDiv).height;
+		document.body.removeChild(wordWrapTestDiv);
+		if (height1 == height2) {
+			document.body.className = (document.body.className + " wbr-workaround").trim();
+		}
+	})();
+	//@}
 }
-//@}
-updateAlertRowStyle();
-
-// Feature-test whether the browser wraps at <wbr> or not, and set word-wrap:
-// break-word where necessary if not.  (IE and Opera don't wrap, Gecko and
-// WebKit do.)  word-wrap: break-word will break anywhere at all, so it looks
-// significantly uglier.
-//@{
-(function() {
-	var wordWrapTestDiv = document.createElement("div");
-	wordWrapTestDiv.style.width = "5em";
-	document.body.appendChild(wordWrapTestDiv);
-	wordWrapTestDiv.innerHTML = "abc";
-	var height1 = getComputedStyle(wordWrapTestDiv).height;
-	wordWrapTestDiv.innerHTML = "abc<wbr>abc<wbr>abc<wbr>abc<wbr>abc<wbr>abc";
-	var height2 = getComputedStyle(wordWrapTestDiv).height;
-	document.body.removeChild(wordWrapTestDiv);
-	if (height1 == height2) {
-		document.body.className = (document.body.className + " wbr-workaround").trim();
-	}
-})();
-//@}
 
 // Now for the meat of the file.
 var tests = {