Changeset 106619 in webkit


Ignore:
Timestamp:
Feb 2, 2012 7:33:10 PM (12 years ago)
Author:
commit-queue@webkit.org
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 <shinyak@google.com> 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:
Location:
trunk/LayoutTests
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r106613 r106619  
     12012-02-02  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Refactoring: Share test drivers of shadow content tests.
     4        https://bugs.webkit.org/show_bug.cgi?id=77584
     5
     6        Extracts shared test code from content-element-move.html and content-element-select-dynamic.html.
     7        This test framework will be used a few more times.
     8
     9        Reviewed by Hajime Morita.
     10
     11        * fast/dom/resources/shadow-test-driver.js: Added.
     12        (log):
     13        (cleanUp):
     14        (removeContainerLines):
     15        (check):
     16        (createSpanWithText):
     17        (createContentWithSelect):
     18        (appendShadow):
     19        (appendShadowDeep):
     20        (doTestIfLeft.callIfDone):
     21        (doneTest):
     22        (doTest):
     23        * fast/dom/shadow/content-element-move.html:
     24        * fast/dom/shadow/content-element-select-dynamic.html:
     25
    1262012-02-02  Shinya Kawanaka  <shinyak@google.com>
    227
  • trunk/LayoutTests/fast/dom/shadow/content-element-move.html

    r106465 r106619  
    1414}
    1515</style>
     16<script src="../resources/shadow-test-driver.js"></script>
    1617<script>
    17 function log(message) {
    18     document.getElementById('console').innerHTML += (message + "\n");
    19 }
    20 
    21 function removeAllChildren(elem) {
    22     while (elem.firstChild)
    23         elem.removeChild(elem.firstChild);
    24 }
    25 
    26 function cleanUp() {
    27     removeAllChildren(document.getElementById('actual-container'));
    28     removeAllChildren(document.getElementById('expect-container'));
    29 }
    30 
    31 function removeContainerLines(text) {
    32     var lines = text.split('\n');
    33     lines.splice(0, 2);
    34     return lines.join('\n');
    35 }
    36 
    37 function check() {
    38     var refContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('expect-container'));
    39     var refRenderTree = removeContainerLines(refContainerRenderTree);
    40 
    41     var targetContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('actual-container'));
    42     var targetRenderTree = removeContainerLines(targetContainerRenderTree);
    43 
    44     if (targetRenderTree == refRenderTree)
    45         log("PASS");
    46     else {
    47         log("FAIL");
    48         log("Expected: ");
    49         log(refRenderTree);
    50         log("Actual: ");
    51         log(targetRenderTree);
    52     }
    53 }
    54 
    55 function createSpanWithText(text) {
    56     var span = document.createElement('span');
    57     span.appendChild(document.createTextNode(text));
    58     return span;
    59 }
    60 
    61 function createContentWithSelect(select, fallback) {
    62     var content = internals.createContentElement(document);
    63     content.setAttribute('select', select);
    64     if (!fallback)
    65         content.appendChild(createSpanWithText("FALLBACK"));
    66 
    67     return content;
    68 }
    69 
    70 function appendShadow(target, select) {
    71     var root = internals.ensureShadowRoot(target);
    72 
    73     var content = internals.createContentElement(document);
    74     content.setAttribute('select', select);
    75     content.appendChild(createSpanWithText("FALLBACK"));
    76 
    77     root.appendChild(document.createTextNode("{SHADOW: "));
    78     root.appendChild(content);
    79     root.appendChild(document.createTextNode("}"));
    80 }
    81 
    82 function appendShadowDeep(target, select) {
    83     var root = internals.ensureShadowRoot(target);
    84 
    85     var child = document.createElement("span");
    86     {
    87         var content = internals.createContentElement(document);
    88         content.setAttribute('select', select);
    89         content.appendChild(createSpanWithText("FALLBACK"));
    90 
    91         child.appendChild(document.createTextNode("{INNER: "));
    92         child.appendChild(content);
    93         child.appendChild(document.createTextNode("}"));
    94     }
    95 
    96     root.appendChild(document.createTextNode("{SHADOW: "));
    97     root.appendChild(child);
    98     root.appendChild(document.createTextNode("}"));
    99 }
    100 
    101 // ----------------------------------------------------------------------
    102 // Test Functions.
    103 
    10418function testRemoveContent(callIfDone) {
    10519    var root = document.createElement('div');
     
    444358    setTimeout(f, 0);
    445359}
    446 
    447 // ----------------------------------------------------------------------
    448 // Test Drivers.
    449360
    450361var testFuncs = [
     
    462373];
    463374
    464 function doTestIfLeft() {
    465     var test = testFuncs.shift();
    466     if (test == null)
    467         return doneTest();
    468 
    469     var callIfDone = function() {
    470         setTimeout(function() {
    471             check();
    472             cleanUp();
    473             doTestIfLeft();
    474         }, 0);
    475     };
    476 
    477     log(test.name);
    478     test(callIfDone);
    479 }
    480 
    481 function doneTest() {
    482     log("TEST COMPLETED");
    483     layoutTestController.notifyDone();
    484 }
    485 
    486 function doTest() {
    487     if (window.layoutTestController) {
    488         layoutTestController.waitUntilDone();
    489         layoutTestController.dumpAsText();
    490     }
    491 
    492     cleanUp();
    493     doTestIfLeft();
    494 }
    495375</script>
    496376</head>
    497 <body onload="doTest()">
     377<body onload="doTest(testFuncs)">
    498378
    499379<div id="actual-container" class="container"></div>
  • trunk/LayoutTests/fast/dom/shadow/content-element-select-dynamic.html

    r106527 r106619  
    1414}
    1515</style>
     16<script src="../resources/shadow-test-driver.js"></script>
    1617<script>
    17 function log(message) {
    18     document.getElementById('console').innerHTML += (message + "\n");
    19 }
    20 
    21 function removeAllChildren(elem) {
    22     while (elem.firstChild)
    23         elem.removeChild(elem.firstChild);
    24 }
    25 
    26 function cleanUp() {
    27     removeAllChildren(document.getElementById('actual-container'));
    28     removeAllChildren(document.getElementById('expect-container'));
    29 }
    30 
    31 function removeContainerLines(text) {
    32     var lines = text.split('\n');
    33     lines.splice(0, 2);
    34     return lines.join('\n');
    35 }
    36 
    37 function check() {
    38     var refContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('expect-container'));
    39     var refRenderTree = removeContainerLines(refContainerRenderTree);
    40 
    41     var targetContainerRenderTree = internals.elementRenderTreeAsText(document.getElementById('actual-container'));
    42     var targetRenderTree = removeContainerLines(targetContainerRenderTree);
    43 
    44     if (targetRenderTree == refRenderTree)
    45         log("PASS");
    46     else {
    47         log("FAIL");
    48         log("Expected: ");
    49         log(refRenderTree);
    50         log("Actual: ");
    51         log(targetRenderTree);
    52     }
    53 }
    54 
    55 function createSpanWithText(text) {
    56     var span = document.createElement('span');
    57     span.appendChild(document.createTextNode(text));
    58     return span;
    59 }
    60 
    61 function createContentWithSelect(select, fallback) {
    62     var content = internals.createContentElement(document);
    63     content.setAttribute('select', select);
    64     if (!fallback)
    65         content.appendChild(createSpanWithText("FALLBACK"));
    66 
    67     return content;
    68 }
    69 
    70 function appendShadow(target, select) {
    71     var root = internals.ensureShadowRoot(target);
    72 
    73     var content = internals.createContentElement(document);
    74     content.setAttribute('select', select);
    75     content.appendChild(createSpanWithText("FALLBACK"));
    76 
    77     root.appendChild(document.createTextNode("{SHADOW: "));
    78     root.appendChild(content);
    79     root.appendChild(document.createTextNode("}"));
    80 }
    81 
    82 function appendShadowDeep(target, select) {
    83     var root = internals.ensureShadowRoot(target);
    84 
    85     var child = document.createElement("span");
    86     {
    87         var content = internals.createContentElement(document);
    88         content.setAttribute('select', select);
    89         content.appendChild(createSpanWithText("FALLBACK"));
    90 
    91         child.appendChild(document.createTextNode("{INNER: "));
    92         child.appendChild(content);
    93         child.appendChild(document.createTextNode("}"));
    94     }
    95 
    96     root.appendChild(document.createTextNode("{SHADOW: "));
    97     root.appendChild(child);
    98     root.appendChild(document.createTextNode("}"));
    99 }
    100 
    101 // ----------------------------------------------------------------------
    102 // Test Functions.
    103 
    10418function testChangeSelect1(callIfDone) {
    10519    document.getElementById('expect-container').innerHTML =
     
    246160}
    247161
    248 // ----------------------------------------------------------------------
    249 // Test Drivers.
    250 
    251162var testFuncs = [
    252163    testChangeSelect1,
     
    257168];
    258169
    259 function doTestIfLeft() {
    260     var test = testFuncs.shift();
    261     if (test == null)
    262         return doneTest();
    263 
    264     var callIfDone = function() {
    265         setTimeout(function() {
    266             check();
    267             cleanUp();
    268             doTestIfLeft();
    269         }, 0);
    270     };
    271 
    272     log(test.name);
    273     test(callIfDone);
    274 }
    275 
    276 function doneTest() {
    277     log("TEST COMPLETED");
    278     layoutTestController.notifyDone();
    279 }
    280 
    281 function doTest() {
    282     if (window.layoutTestController) {
    283         layoutTestController.waitUntilDone();
    284         layoutTestController.dumpAsText();
    285     }
    286 
    287     cleanUp();
    288     doTestIfLeft();
    289 }
    290170</script>
    291171</head>
    292 <body onload="doTest()">
     172<body onload="doTest(testFuncs)">
    293173
    294174<div id="actual-container" class="container"></div>
Note: See TracChangeset for help on using the changeset viewer.