Title: [106619] trunk/LayoutTests
Revision
106619
Author
[email protected]
Date
2012-02-02 19:33:10 -0800 (Thu, 02 Feb 2012)

Log Message

Refactoring: Share test drivers of shadow content tests.
https://bugs.webkit.org/show_bug.cgi?id=77584

Extracts shared test code from content-element-move.html and content-element-select-dynamic.html.
This test framework will be used a few more times.

Patch by Shinya Kawanaka <[email protected]> on 2012-02-02
Reviewed by Hajime Morita.

* fast/dom/resources/shadow-test-driver.js: Added.
(log):
(cleanUp):
(removeContainerLines):
(check):
(createSpanWithText):
(createContentWithSelect):
(appendShadow):
(appendShadowDeep):
(doTestIfLeft.callIfDone):
(doneTest):
(doTest):
* fast/dom/shadow/content-element-move.html:
* fast/dom/shadow/content-element-select-dynamic.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (106618 => 106619)


--- trunk/LayoutTests/ChangeLog	2012-02-03 03:23:45 UTC (rev 106618)
+++ trunk/LayoutTests/ChangeLog	2012-02-03 03:33:10 UTC (rev 106619)
@@ -1,5 +1,30 @@
 2012-02-02  Shinya Kawanaka  <[email protected]>
 
+        Refactoring: Share test drivers of shadow content tests.
+        https://bugs.webkit.org/show_bug.cgi?id=77584
+
+        Extracts shared test code from content-element-move.html and content-element-select-dynamic.html.
+        This test framework will be used a few more times.
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/resources/shadow-test-driver.js: Added.
+        (log):
+        (cleanUp):
+        (removeContainerLines):
+        (check):
+        (createSpanWithText):
+        (createContentWithSelect):
+        (appendShadow):
+        (appendShadowDeep):
+        (doTestIfLeft.callIfDone):
+        (doneTest):
+        (doTest):
+        * fast/dom/shadow/content-element-move.html:
+        * fast/dom/shadow/content-element-select-dynamic.html:
+
+2012-02-02  Shinya Kawanaka  <[email protected]>
+
         StyleRecalc should occur when shadow root exists and light children are changed.
         https://bugs.webkit.org/show_bug.cgi?id=76262
 

Added: trunk/LayoutTests/fast/dom/resources/shadow-test-driver.js (0 => 106619)


--- trunk/LayoutTests/fast/dom/resources/shadow-test-driver.js	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/resources/shadow-test-driver.js	2012-02-03 03:33:10 UTC (rev 106619)
@@ -0,0 +1,133 @@
+//
+// shadow-test-driver.js
+//
+// To use shadow-test-driver.js, you should have
+//   <div id="actual-container"></div>
+//   <div id="expect-container"></div>
+//   <pre id="console"></pre>
+// in your body.
+//
+// Then, define test functions having one argument 'callIfDone'.
+// callIfDone should be called when your test function finished.
+//
+// In body.onload, call doTest(testFuncs) where testFuncs is an array of test functions.
+//
+// See content-element-move.html as an example.
+//
+
+function log(message) {
+    document.getElementById('console').innerHTML += (message + "\n");
+}
+
+function removeAllChildren(elem) {
+    while (elem.firstChild)
+        elem.removeChild(elem.firstChild);
+}
+
+function cleanUp() {
+    removeAllChildren(document.getElementById('actual-container'));
+    removeAllChildren(document.getElementById('expect-container'));
+}
+
+function removeContainerLines(text) {
+    var lines = text.split('\n');
+    lines.splice(0, 2);
+    return lines.join('\n');
+}
+
+function check() {
+    var refContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('expect-container'));
+    var refRenderTree = removeContainerLines(refContainerRenderTree);
+
+    var targetContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('actual-container'));
+    var targetRenderTree = removeContainerLines(targetContainerRenderTree);
+
+    if (targetRenderTree == refRenderTree)
+        log("PASS");
+    else {
+        log("FAIL");
+        log("Expected: ");
+        log(refRenderTree);
+        log("Actual: ");
+        log(targetRenderTree);
+    }
+}
+
+function createSpanWithText(text) {
+    var span = document.createElement('span');
+    span.appendChild(document.createTextNode(text));
+    return span;
+}
+
+function createContentWithSelect(select, fallback) {
+    var content = internals.createContentElement(document);
+    content.setAttribute('select', select);
+    if (!fallback)
+        content.appendChild(createSpanWithText("FALLBACK"));
+
+    return content;
+}
+
+function appendShadow(target, select) {
+    var root = internals.ensureShadowRoot(target);
+
+    var content = internals.createContentElement(document);
+    content.setAttribute('select', select);
+    content.appendChild(createSpanWithText("FALLBACK"));
+
+    root.appendChild(document.createTextNode("{SHADOW: "));
+    root.appendChild(content);
+    root.appendChild(document.createTextNode("}"));
+}
+
+function appendShadowDeep(target, select) {
+    var root = internals.ensureShadowRoot(target);
+
+    var child = document.createElement("span");
+    {
+        var content = internals.createContentElement(document);
+        content.setAttribute('select', select);
+        content.appendChild(createSpanWithText("FALLBACK"));
+
+        child.appendChild(document.createTextNode("{INNER: "));
+        child.appendChild(content);
+        child.appendChild(document.createTextNode("}"));
+    }
+
+    root.appendChild(document.createTextNode("{SHADOW: "));
+    root.appendChild(child);
+    root.appendChild(document.createTextNode("}"));
+}
+
+function doTestIfLeft(restTests) {
+    var test = restTests.shift();
+    if (test == null)
+        return doneTest();
+
+    var callIfDone = function() {
+        setTimeout(function() {
+            check();
+            cleanUp();
+            doTestIfLeft(restTests);
+        }, 0);
+    };
+
+    log(test.name);
+    test(callIfDone);
+}
+
+function doneTest() {
+    log("TEST COMPLETED");
+    layoutTestController.notifyDone();
+}
+
+// A test driver. Call this body.onload.
+function doTest(tests) {
+    if (window.layoutTestController) {
+        layoutTestController.waitUntilDone();
+        layoutTestController.dumpAsText();
+    }
+
+    cleanUp();
+    doTestIfLeft(tests);
+}

Modified: trunk/LayoutTests/fast/dom/shadow/content-element-move.html (106618 => 106619)


--- trunk/LayoutTests/fast/dom/shadow/content-element-move.html	2012-02-03 03:23:45 UTC (rev 106618)
+++ trunk/LayoutTests/fast/dom/shadow/content-element-move.html	2012-02-03 03:33:10 UTC (rev 106619)
@@ -13,94 +13,8 @@
     border: solid;
 }
 </style>
+<script src=""
 <script>
-function log(message) {
-    document.getElementById('console').innerHTML += (message + "\n");
-}
-
-function removeAllChildren(elem) {
-    while (elem.firstChild)
-        elem.removeChild(elem.firstChild);
-}
-
-function cleanUp() {
-    removeAllChildren(document.getElementById('actual-container'));
-    removeAllChildren(document.getElementById('expect-container'));
-}
-
-function removeContainerLines(text) {
-    var lines = text.split('\n');
-    lines.splice(0, 2);
-    return lines.join('\n');
-}
-
-function check() {
-    var refContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('expect-container'));
-    var refRenderTree = removeContainerLines(refContainerRenderTree);
-
-    var targetContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('actual-container'));
-    var targetRenderTree = removeContainerLines(targetContainerRenderTree);
-
-    if (targetRenderTree == refRenderTree)
-        log("PASS");
-    else {
-        log("FAIL");
-        log("Expected: ");
-        log(refRenderTree);
-        log("Actual: ");
-        log(targetRenderTree);
-    }
-}
-
-function createSpanWithText(text) {
-    var span = document.createElement('span');
-    span.appendChild(document.createTextNode(text));
-    return span;
-}
-
-function createContentWithSelect(select, fallback) {
-    var content = internals.createContentElement(document);
-    content.setAttribute('select', select);
-    if (!fallback)
-        content.appendChild(createSpanWithText("FALLBACK"));
-
-    return content;
-}
-
-function appendShadow(target, select) {
-    var root = internals.ensureShadowRoot(target);
-
-    var content = internals.createContentElement(document);
-    content.setAttribute('select', select);
-    content.appendChild(createSpanWithText("FALLBACK"));
-
-    root.appendChild(document.createTextNode("{SHADOW: "));
-    root.appendChild(content);
-    root.appendChild(document.createTextNode("}"));
-}
-
-function appendShadowDeep(target, select) {
-    var root = internals.ensureShadowRoot(target);
-
-    var child = document.createElement("span");
-    {
-        var content = internals.createContentElement(document);
-        content.setAttribute('select', select);
-        content.appendChild(createSpanWithText("FALLBACK"));
-
-        child.appendChild(document.createTextNode("{INNER: "));
-        child.appendChild(content);
-        child.appendChild(document.createTextNode("}"));
-    }
-
-    root.appendChild(document.createTextNode("{SHADOW: "));
-    root.appendChild(child);
-    root.appendChild(document.createTextNode("}"));
-}
-
-// ----------------------------------------------------------------------
-// Test Functions.
-
 function testRemoveContent(callIfDone) {
     var root = document.createElement('div');
 
@@ -444,9 +358,6 @@
     setTimeout(f, 0);
 }
 
-// ----------------------------------------------------------------------
-// Test Drivers.
-
 var testFuncs = [
     testRemoveContent,
     testRemoveContentToRecalc1,
@@ -461,40 +372,9 @@
     testMoveLightChildOut
 ];
 
-function doTestIfLeft() {
-    var test = testFuncs.shift();
-    if (test == null)
-        return doneTest();
-
-    var callIfDone = function() {
-        setTimeout(function() {
-            check();
-            cleanUp();
-            doTestIfLeft();
-        }, 0);
-    };
-
-    log(test.name);
-    test(callIfDone);
-}
-
-function doneTest() {
-    log("TEST COMPLETED");
-    layoutTestController.notifyDone();
-}
-
-function doTest() {
-    if (window.layoutTestController) {
-        layoutTestController.waitUntilDone();
-        layoutTestController.dumpAsText();
-    }
-
-    cleanUp();
-    doTestIfLeft();
-}
 </script>
 </head>
-<body _onload_="doTest()">
+<body _onload_="doTest(testFuncs)">
 
 <div id="actual-container" class="container"></div>
 <div id="expect-container" class="container"></div>

Modified: trunk/LayoutTests/fast/dom/shadow/content-element-select-dynamic.html (106618 => 106619)


--- trunk/LayoutTests/fast/dom/shadow/content-element-select-dynamic.html	2012-02-03 03:23:45 UTC (rev 106618)
+++ trunk/LayoutTests/fast/dom/shadow/content-element-select-dynamic.html	2012-02-03 03:33:10 UTC (rev 106619)
@@ -13,94 +13,8 @@
     border: solid;
 }
 </style>
+<script src=""
 <script>
-function log(message) {
-    document.getElementById('console').innerHTML += (message + "\n");
-}
-
-function removeAllChildren(elem) {
-    while (elem.firstChild)
-        elem.removeChild(elem.firstChild);
-}
-
-function cleanUp() {
-    removeAllChildren(document.getElementById('actual-container'));
-    removeAllChildren(document.getElementById('expect-container'));
-}
-
-function removeContainerLines(text) {
-    var lines = text.split('\n');
-    lines.splice(0, 2);
-    return lines.join('\n');
-}
-
-function check() {
-    var refContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('expect-container'));
-    var refRenderTree = removeContainerLines(refContainerRenderTree);
-
-    var targetContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('actual-container'));
-    var targetRenderTree = removeContainerLines(targetContainerRenderTree);
-
-    if (targetRenderTree == refRenderTree)
-        log("PASS");
-    else {
-        log("FAIL");
-        log("Expected: ");
-        log(refRenderTree);
-        log("Actual: ");
-        log(targetRenderTree);
-    }
-}
-
-function createSpanWithText(text) {
-    var span = document.createElement('span');
-    span.appendChild(document.createTextNode(text));
-    return span;
-}
-
-function createContentWithSelect(select, fallback) {
-    var content = internals.createContentElement(document);
-    content.setAttribute('select', select);
-    if (!fallback)
-        content.appendChild(createSpanWithText("FALLBACK"));
-
-    return content;
-}
-
-function appendShadow(target, select) {
-    var root = internals.ensureShadowRoot(target);
-
-    var content = internals.createContentElement(document);
-    content.setAttribute('select', select);
-    content.appendChild(createSpanWithText("FALLBACK"));
-
-    root.appendChild(document.createTextNode("{SHADOW: "));
-    root.appendChild(content);
-    root.appendChild(document.createTextNode("}"));
-}
-
-function appendShadowDeep(target, select) {
-    var root = internals.ensureShadowRoot(target);
-
-    var child = document.createElement("span");
-    {
-        var content = internals.createContentElement(document);
-        content.setAttribute('select', select);
-        content.appendChild(createSpanWithText("FALLBACK"));
-
-        child.appendChild(document.createTextNode("{INNER: "));
-        child.appendChild(content);
-        child.appendChild(document.createTextNode("}"));
-    }
-
-    root.appendChild(document.createTextNode("{SHADOW: "));
-    root.appendChild(child);
-    root.appendChild(document.createTextNode("}"));
-}
-
-// ----------------------------------------------------------------------
-// Test Functions.
-
 function testChangeSelect1(callIfDone) {
     document.getElementById('expect-container').innerHTML =
         "<div><span>BEFORE</span><span>LIGHT 2</span><span>AFTER</span></div>";
@@ -245,9 +159,6 @@
     setTimeout(f, 0);
 }
 
-// ----------------------------------------------------------------------
-// Test Drivers.
-
 var testFuncs = [
     testChangeSelect1,
     testChangeSelect2,
@@ -256,40 +167,9 @@
     testChangeSelectFromFallback,
 ];
 
-function doTestIfLeft() {
-    var test = testFuncs.shift();
-    if (test == null)
-        return doneTest();
-
-    var callIfDone = function() {
-        setTimeout(function() {
-            check();
-            cleanUp();
-            doTestIfLeft();
-        }, 0);
-    };
-
-    log(test.name);
-    test(callIfDone);
-}
-
-function doneTest() {
-    log("TEST COMPLETED");
-    layoutTestController.notifyDone();
-}
-
-function doTest() {
-    if (window.layoutTestController) {
-        layoutTestController.waitUntilDone();
-        layoutTestController.dumpAsText();
-    }
-
-    cleanUp();
-    doTestIfLeft();
-}
 </script>
 </head>
-<body _onload_="doTest()">
+<body _onload_="doTest(testFuncs)">
 
 <div id="actual-container" class="container"></div>
 <div id="expect-container" class="container"></div>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to