⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 118881 in webkit


Ignore:
Timestamp:
May 29, 2012, 7:13:30 PM (14 years ago)
Author:
hayato@chromium.org
Message:

Refactor shadow-dom-event-dispatching.html.
https://bugs.webkit.org/show_bug.cgi?id=87626

Reviewed by Dimitri Glazkov.

There are badly named functions in shadow-dom-event-dispatching.html.
e.g. prepareDOMTree1, prepareDOMTree2 and so on.
That should have better namings which make the intention of each test clear.

  • fast/dom/shadow/shadow-dom-event-dispatching.html:
Location:
trunk/LayoutTests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r118871 r118881  
     12012-05-29  Hayato Ito  <hayato@chromium.org>
     2
     3        Refactor shadow-dom-event-dispatching.html.
     4        https://bugs.webkit.org/show_bug.cgi?id=87626
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        There are badly named functions in shadow-dom-event-dispatching.html.
     9        e.g. prepareDOMTree1, prepareDOMTree2 and so on.
     10        That should have better namings which make the intention of each test clear.
     11
     12        * fast/dom/shadow/shadow-dom-event-dispatching.html:
     13
    1142012-05-29  Raphael Kubo da Costa  <rakuco@webkit.org>
    215
  • trunk/LayoutTests/fast/dom/shadow/shadow-dom-event-dispatching.html

    r118645 r118881  
    9595}
    9696
    97 // FIXME: More meaningful function names instead of sequence numbers.
    98 function prepareDOMTree1(parent)
    99 {
    100     parent.appendChild(
     97function debugDispatchedEvent(eventType)
     98{
     99    debug('\n  ' + eventType);
     100    var events = dispatchedEvent(eventType);
     101    for (var i = 0; i < events.length; ++i)
     102        debug('    ' + events[i])
     103}
     104
     105function moveMouse(oldElementId, newElementId)
     106{
     107    clearEventRecords();
     108    debug('\n' + 'Moving mouse from ' + oldElementId + ' to ' + newElementId);
     109    moveMouseOver(getNodeInShadowTreeStack(oldElementId));
     110
     111    clearEventRecords();
     112    moveMouseOver(getNodeInShadowTreeStack(newElementId));
     113
     114    debugDispatchedEvent('mouseout');
     115    debugDispatchedEvent('mouseover');
     116}
     117
     118var sandbox = document.getElementById('sandbox');
     119
     120function showSandboxTree()
     121{
     122    var sandbox = document.getElementById('sandbox');
     123    sandbox.offsetLeft;
     124    debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(sandbox));
     125}
     126
     127function testEventsOnDistributedChild()
     128{
     129    sandbox.innerHTML = '';
     130    sandbox.appendChild(
    101131        createDOM('div', {'id': 'top'},
    102132                  createDOM('div', {'id': 'shadow-host'},
     
    110140                       'distributed-light-child', 'non-distributed-light-child']);
    111141    getNodeInShadowTreeStack('shadow-host/').id = 'shadow-root';
    112     parent.offsetLeft;
    113     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    114 }
    115 
    116 function prepareDOMTree2(parent)
    117 {
    118     parent.appendChild(
     142    showSandboxTree();
     143
     144    moveMouse('shadow-host', 'shadow-host/shadow-root-child');
     145    moveMouse('shadow-host/shadow-root-child', 'shadow-host');
     146
     147    moveMouse('shadow-host', 'distributed-light-child');
     148    moveMouse('distributed-light-child', 'shadow-host');
     149
     150    moveMouse('shadow-host/shadow-root-child', 'distributed-light-child');
     151    moveMouse('distributed-light-child', 'shadow-host/shadow-root-child');
     152}
     153
     154function testEventsOnDetailsSummary()
     155{
     156    sandbox.innerHTML = '';
     157    sandbox.appendChild(
    119158        createDOM('div', {'id': 'top'},
    120159                  // 'details/summary' elements use Shadow DOM in its implementation.
     
    123162
    124163    addEventListeners(['top', 'details', 'summary']);
    125     parent.offsetLeft;
    126     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    127 }
    128 
    129 function prepareDOMTree3(parent)
    130 {
    131     parent.appendChild(
     164    showSandboxTree();
     165
     166    moveMouse('details', 'summary');
     167    moveMouse('summary', 'details');
     168}
     169
     170function testEventsOnNestedShadowRoots()
     171{
     172    sandbox.innerHTML = '';
     173    sandbox.appendChild(
    132174        createDOM('div', {'id': 'top'},
    133175                  createDOM('div', {'id': 'A'},
     
    157199    getNodeInShadowTreeStack('B/G/J/').id = 'shadow-root-J';
    158200    getNodeInShadowTreeStack('B/G/L/').id = 'shadow-root-L';
    159     parent.offsetLeft;
    160     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    161 }
    162 
    163 function prepareDOMTree4(parent)
     201    showSandboxTree();
     202
     203    moveMouse('F', 'D');
     204    moveMouse('B/G/L', 'D');
     205    moveMouse('B/G/L', 'B/G/J');
     206    moveMouse('A', 'D');
     207    moveMouse('D', 'A');
     208}
     209
     210function testEventsOnSVGInShadowSubtree()
    164211{
    165212    // Makes sure that <svg> in shadow DOM subtree, which is not supported at this time, does not crash.
    166     parent.appendChild(
     213    sandbox.innerHTML = '';
     214    sandbox.appendChild(
    167215        createDOM('div', {'id': 'top'},
    168216                  createDOM('div', {'id': 'shadow-host'},
     
    174222    addEventListeners(['top', 'shadow-host/', 'shadow-host/svg-in-shadow-tree']);
    175223    getNodeInShadowTreeStack('shadow-host/').id = 'shadow-root';
    176     parent.offsetLeft;
    177     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    178 }
    179 
    180 function prepareDOMTree5(parent)
    181 {
    182     parent.appendChild(
     224    showSandboxTree();
     225
     226    moveMouse('shadow-host/svg-in-shadow-tree', 'top');
     227}
     228
     229function testEventsOnTextNodeOfShadowRoot()
     230{
     231    sandbox.innerHTML = '';
     232    sandbox.appendChild(
    183233        createDOM('div', {'id': 'top'},
    184234                  createDOM('div', {'id': 'shadow-host'},
     
    188238    shadowRoot.innerHTML = 'Text Nodes';
    189239    addEventListeners(['top', 'shadow-host', 'shadow-host/']);
    190     parent.offsetLeft;
    191     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    192 }
    193 
    194 function prepareDOMTree6(parent)
    195 {
    196     // Makes sure an insertion point can receive a event when a distributed text node is clicked.
    197     parent.appendChild(
    198         createDOM('div', {'id': 'top'},
    199                   createDOM('div', {'id': 'shadow-host'},
    200                             createShadowRoot(
    201                                 createDOM('content', {'id': 'content'})),
    202                             document.createTextNode('Text Node'))));
    203     var shadowRoot = getNodeInShadowTreeStack('shadow-host/').id = 'shadow-root';
    204     addEventListeners(['top', 'shadow-host', 'shadow-host/', 'shadow-host/content']);
    205     parent.offsetLeft;
    206     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    207 }
    208 
    209 function prepareDOMTree7(parent)
    210 {
    211     parent.appendChild(
    212         createDOM('div', {'id': 'top'},
    213                   createDOM('div', {'id': 'A'}),
    214                   createDOM('div', {'id': 'B'},
    215                             createShadowRoot(
    216                                 createDOM('content', {'id': 'active-content', 'select': '#parent-of-inactive-content'})),
    217                             createDOM('div', {'id': 'parent-of-inactive-content'},
    218                                       createDOM('content', {'id': 'inactive-content'},
    219                                                 createDOM('div', {'id': 'child-of-inactive-content'}))))));
    220 
    221     addEventListeners(['top', 'A', 'B', 'B/', 'B/active-content',
    222                        'parent-of-inactive-content', 'inactive-content', 'child-of-inactive-content']);
    223     getNodeInShadowTreeStack('B/').id = 'shadow-root-B';
    224     parent.offsetLeft;
    225     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    226 }
    227 
    228 // Hosting multiple shadow roots
    229 function prepareDOMTree8(parent)
    230 {
    231     parent.appendChild(
    232         createDOM('div', {'id': 'top'},
    233                   createDOM('div', {'id': 'A'},
    234                             createShadowRoot(
    235                                 createDOM('content', {'id': 'C'}),
    236                                 createDOM('div', {'id': 'D'})),
    237                             createShadowRoot(
    238                                 createDOM('shadow', {'id': 'E'}),
    239                                 createDOM('div', {'id': 'F'})),
    240                             createDOM('div', {'id': 'B'}))));
    241 
    242     addEventListeners(['top', 'A', 'B', 'A/', 'A/C', 'A/D', 'A//', 'A//E', 'A//F']);
    243     getNodeInShadowTreeStack('A/').id = 'older-shadow-root';
    244     getNodeInShadowTreeStack('A//').id = 'younger-shadow-root';
    245     parent.offsetLeft;
    246     debug('\n\nComposed Shadow Tree will be:\n' + dumpComposedShadowTree(parent));
    247 }
    248 
    249 function debugDispatchedEvent(eventType)
    250 {
    251     debug('\n  ' + eventType);
    252     var events = dispatchedEvent(eventType);
    253     for (var i = 0; i < events.length; ++i)
    254         debug('    ' + events[i])
    255 }
    256 
    257 function moveMouse(oldElementId, newElementId)
    258 {
    259     clearEventRecords();
    260     debug('\n' + 'Moving mouse from ' + oldElementId + ' to ' + newElementId);
    261     moveMouseOver(getNodeInShadowTreeStack(oldElementId));
    262 
    263     clearEventRecords();
    264     moveMouseOver(getNodeInShadowTreeStack(newElementId));
    265 
    266     debugDispatchedEvent('mouseout');
    267     debugDispatchedEvent('mouseover');
    268 }
    269 
    270 function test()
    271 {
    272     if (window.layoutTestController)
    273         layoutTestController.dumpAsText();
    274 
    275     var sandbox = document.getElementById('sandbox');
    276     prepareDOMTree1(sandbox);
    277 
    278     moveMouse('shadow-host', 'shadow-host/shadow-root-child');
    279     moveMouse('shadow-host/shadow-root-child', 'shadow-host');
    280 
    281     moveMouse('shadow-host', 'distributed-light-child');
    282     moveMouse('distributed-light-child', 'shadow-host');
    283 
    284     moveMouse('shadow-host/shadow-root-child', 'distributed-light-child');
    285     moveMouse('distributed-light-child', 'shadow-host/shadow-root-child');
    286 
    287     sandbox.innerHTML = '';
    288     prepareDOMTree2(sandbox);
    289 
    290     moveMouse('details', 'summary');
    291     moveMouse('summary', 'details');
    292 
    293     sandbox.innerHTML = '';
    294     prepareDOMTree3(sandbox);
    295 
    296     moveMouse('F', 'D');
    297     moveMouse('B/G/L', 'D');
    298     moveMouse('B/G/L', 'B/G/J');
    299     moveMouse('A', 'D');
    300     moveMouse('D', 'A');
    301 
    302     sandbox.innerHTML = '';
    303     prepareDOMTree4(sandbox);
    304 
    305     moveMouse('shadow-host/svg-in-shadow-tree', 'top');
    306 
    307     sandbox.innerHTML = '';
    308     prepareDOMTree5(sandbox);
     240    showSandboxTree();
    309241
    310242    // Calculates the position of the text node in the shadow root.
     
    318250    debugDispatchedEvent('mouseout');
    319251    debugDispatchedEvent('mouseover');
    320 
    321     sandbox.innerHTML = '';
    322     prepareDOMTree6(sandbox);
     252}
     253
     254function testEventsOnDistributedTextNode()
     255{
     256    // Makes sure an insertion point can receive a event when a distributed text node is clicked.
     257    sandbox.innerHTML = '';
     258    sandbox.appendChild(
     259        createDOM('div', {'id': 'top'},
     260                  createDOM('div', {'id': 'shadow-host'},
     261                            createShadowRoot(
     262                                createDOM('content', {'id': 'content'})),
     263                            document.createTextNode('Text Node'))));
     264    var shadowRoot = getNodeInShadowTreeStack('shadow-host/').id = 'shadow-root';
     265    addEventListeners(['top', 'shadow-host', 'shadow-host/', 'shadow-host/content']);
     266    showSandboxTree();
    323267
    324268    // Calculates the position of the text node.
     
    332276    debugDispatchedEvent('mouseout');
    333277    debugDispatchedEvent('mouseover');
    334 
    335     sandbox.innerHTML = '';
    336     prepareDOMTree7(sandbox);
    337 
     278}
     279
     280function testEventsOnChildOfInactiveContent()
     281{
     282    sandbox.innerHTML = '';
     283    sandbox.appendChild(
     284        createDOM('div', {'id': 'top'},
     285                  createDOM('div', {'id': 'A'}),
     286                  createDOM('div', {'id': 'B'},
     287                            createShadowRoot(
     288                                createDOM('content', {'id': 'active-content', 'select': '#parent-of-inactive-content'})),
     289                            createDOM('div', {'id': 'parent-of-inactive-content'},
     290                                      createDOM('content', {'id': 'inactive-content'},
     291                                                createDOM('div', {'id': 'child-of-inactive-content'}))))));
     292
     293    addEventListeners(['top', 'A', 'B', 'B/', 'B/active-content',
     294                       'parent-of-inactive-content', 'inactive-content', 'child-of-inactive-content']);
     295    getNodeInShadowTreeStack('B/').id = 'shadow-root-B';
     296    showSandboxTree();
    338297    moveMouse('A', 'child-of-inactive-content');
    339 
    340     sandbox.innerHTML = '';
    341     prepareDOMTree8(sandbox);
     298}
     299
     300function testEventsOnMultipleShadowRoots()
     301{
     302    sandbox.innerHTML = '';
     303    sandbox.appendChild(
     304        createDOM('div', {'id': 'top'},
     305                  createDOM('div', {'id': 'A'},
     306                            createShadowRoot(
     307                                createDOM('content', {'id': 'C'}),
     308                                createDOM('div', {'id': 'D'})),
     309                            createShadowRoot(
     310                                createDOM('shadow', {'id': 'E'}),
     311                                createDOM('div', {'id': 'F'})),
     312                            createDOM('div', {'id': 'B'}))));
     313
     314    addEventListeners(['top', 'A', 'B', 'A/', 'A/C', 'A/D', 'A//', 'A//E', 'A//F']);
     315    getNodeInShadowTreeStack('A/').id = 'older-shadow-root';
     316    getNodeInShadowTreeStack('A//').id = 'younger-shadow-root';
     317    showSandboxTree();
    342318
    343319    moveMouse('B', 'A');
    344320    moveMouse('A/D', 'A//F');
    345321    moveMouse('B', 'A//F');
     322}
     323
     324function test()
     325{
     326    if (window.layoutTestController)
     327        layoutTestController.dumpAsText();
     328
     329    testEventsOnDistributedChild();
     330    testEventsOnDetailsSummary();
     331    testEventsOnNestedShadowRoots();
     332    testEventsOnSVGInShadowSubtree();
     333    testEventsOnTextNodeOfShadowRoot();
     334    testEventsOnDistributedTextNode();
     335    testEventsOnChildOfInactiveContent();
     336    testEventsOnMultipleShadowRoots();
    346337}
    347338
Note: See TracChangeset for help on using the changeset viewer.