| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | |
| 2 | |
| 3 /* | |
| 4 Distributed under both the W3C Test Suite License [1] and the W3C | |
| 5 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the | |
| 6 policies and contribution forms [3]. | |
| 7 | |
| 8 [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license | |
| 9 [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license | |
| 10 [3] http://www.w3.org/2004/10/27-testcases | |
| 11 */ | |
| 12 | |
| 13 "use strict"; | |
| 14 | |
| 15 // custom element is also allowed. | |
| 16 var ATTACHSHADOW_SAFELISTED_ELEMENTS = [ | |
| 17 'article', | |
| 18 'aside', | |
| 19 'blockquote', | |
| 20 'body', | |
| 21 'div', | |
| 22 'footer', | |
| 23 'h1', | |
| 24 'h2', | |
| 25 'h3', | |
| 26 'h4', | |
| 27 'h5', | |
| 28 'h6', | |
| 29 'header', | |
| 30 'nav', | |
| 31 'p', | |
| 32 'section', | |
| 33 'span' | |
| 34 ]; | |
| 35 | |
| 36 var HTML5_ELEMENT_NAMES = [ | |
| 37 'a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', | |
| 38 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', | |
| 39 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'command', | |
| 40 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', | |
| 41 'em', 'embed', | |
| 42 'fieldset', 'figcaption', 'figure', 'footer', 'form', | |
| 43 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', | |
| 44 'html', | |
| 45 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', | |
| 46 'label', 'legend', 'li', 'link', | |
| 47 'map', 'mark', 'menu', 'meta', 'meter', | |
| 48 'nav', 'noscript', | |
| 49 'object', 'ol', 'optgroup', 'option', 'output', | |
| 50 'p', 'param', 'pre', 'progress', | |
| 51 'q', | |
| 52 'rp', 'rt', 'ruby', | |
| 53 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', | |
| 54 'strong', 'style', 'sub', | |
| 55 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', | |
| 56 'title', 'tr', 'track', | |
| 57 'u', 'ul', | |
| 58 'var', 'video', | |
| 59 'wbr' | |
| 60 ]; | |
| 61 | |
| 62 function unit(f) { | |
| 63 return function () { | |
| 64 var ctx = newContext(); | |
| 65 try { | |
| 66 f(ctx); | |
| 67 } finally { | |
| 68 cleanContext(ctx); | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 function step_unit(f, ctx, t) { | |
| 74 return function () { | |
| 75 var done = false; | |
| 76 try { | |
| 77 f(); | |
| 78 done = true; | |
| 79 } finally { | |
| 80 if (done) { | |
| 81 t.done(); | |
| 82 } | |
| 83 cleanContext(ctx); | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 function assert_nodelist_contents_equal_noorder(actual, expected, message) { | |
| 89 assert_equals(actual.length, expected.length, message); | |
| 90 var used = []; | |
| 91 for (var i = 0; i < expected.length; i++) { | |
| 92 used.push(false); | |
| 93 } | |
| 94 for (i = 0; i < expected.length; i++) { | |
| 95 var found = false; | |
| 96 for (var j = 0; j < actual.length; j++) { | |
| 97 if (used[j] == false && expected[i] == actual[j]) { | |
| 98 used[j] = true; | |
| 99 found = true; | |
| 100 break; | |
| 101 } | |
| 102 } | |
| 103 if (!found) { | |
| 104 assert_unreached(message + ". Fail reason: element not found: " + e
xpected[i]); | |
| 105 } | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 //Example taken from http://www.w3.org/TR/shadow-dom/#event-retargeting-example | |
| 110 function createTestMediaPlayer(d) { | |
| 111 d.body.innerHTML = '' + | |
| 112 '<div id="player">' + | |
| 113 '<input type="checkbox" id="outside-control">' + | |
| 114 '<div id="player-shadow-host">' + | |
| 115 '</div>' + | |
| 116 '</div>'; | |
| 117 | |
| 118 var playerShadowRoot = d.querySelector('#player-shadow-host').attachShadow({
mode: 'open'}); | |
| 119 playerShadowRoot.innerHTML = '' + | |
| 120 '<div id="controls">' + | |
| 121 '<button class="play-button">PLAY</button>' + | |
| 122 '<div tabindex="0" id="timeline">' + | |
| 123 '<div id="timeline-shadow-host">' + | |
| 124 '</div>' + | |
| 125 '</div>' + | |
| 126 '<div class="volume-slider-container" id="volume-slider-container">'
+ | |
| 127 '<div tabindex="0" class="volume-slider" id="volume-slider">' + | |
| 128 '<div id="volume-shadow-host">' + | |
| 129 '</div>' + | |
| 130 '</div>' + | |
| 131 '</div>' + | |
| 132 '</div>'; | |
| 133 | |
| 134 var timeLineShadowRoot = playerShadowRoot.querySelector('#timeline-shadow-ho
st').attachShadow({mode: 'open'}); | |
| 135 timeLineShadowRoot.innerHTML = '<div class="slider-thumb" id="timeline-slid
er-thumb"></div>'; | |
| 136 | |
| 137 var volumeShadowRoot = playerShadowRoot.querySelector('#volume-shadow-host')
.attachShadow({mode: 'open'}); | |
| 138 volumeShadowRoot.innerHTML = '<div class="slider-thumb" id="volume-slider-th
umb"></div>'; | |
| 139 | |
| 140 return { | |
| 141 'playerShadowRoot': playerShadowRoot, | |
| 142 'timeLineShadowRoot': timeLineShadowRoot, | |
| 143 'volumeShadowRoot': volumeShadowRoot | |
| 144 }; | |
| 145 } | |
| 146 | |
| 147 //FIXME This call of initKeyboardEvent works for WebKit-only. | |
| 148 //See https://bugs.webkit.org/show_bug.cgi?id=16735 | |
| 149 // and https://bugs.webkit.org/show_bug.cgi?id=13368. Add check for browser here | |
| 150 function fireKeyboardEvent(doc, element, key) { | |
| 151 var event = doc.createEvent('KeyboardEvent'); | |
| 152 event.initKeyboardEvent("keydown", true, true, doc.defaultView, key, 0, fals
e, false, false, false); | |
| 153 element.dispatchEvent(event); | |
| 154 } | |
| OLD | NEW |