How to use Dom method in apickli

Best JavaScript code snippet using apickli

DomUtilsTest.js

Source:DomUtilsTest.js Github

copy

Full Screen

1asynctest(2 'browser.tinymce.core.dom.DomUtilsTest',3 [4 'ephox.agar.api.Pipeline',5 'ephox.mcagar.api.LegacyUnit',6 'global!document',7 'global!window',8 'tinymce.core.dom.Dimensions',9 'tinymce.core.dom.DOMUtils',10 'tinymce.core.Env',11 'tinymce.core.html.Schema',12 'tinymce.core.test.HtmlUtils',13 'tinymce.core.test.ViewBlock',14 'tinymce.core.util.Arr',15 'tinymce.core.util.Tools'16 ],17 function (Pipeline, LegacyUnit, document, window, Dimensions, DOMUtils, Env, Schema, HtmlUtils, ViewBlock, Arr, Tools) {18 var DOM = new DOMUtils(document, { keep_values : true, schema : new Schema() });19 var success = arguments[arguments.length - 2];20 var failure = arguments[arguments.length - 1];21 var suite = LegacyUnit.createSuite();22 suite.test('parseStyle', function () {23 var dom;24 DOM.add(document.body, 'div', { id : 'test' });25 dom = new DOMUtils(document, { hex_colors : true, keep_values : true, url_converter : function (u) {26 return 'X' + u + 'Y';27 } });28 LegacyUnit.equal(29 dom.serializeStyle(dom.parseStyle('border: 1px solid red; color: green')),30 'border: 1px solid red; color: green;'31 );32 LegacyUnit.equal(33 dom.serializeStyle(dom.parseStyle('border: 1px solid rgb(0, 255, 255); color: green')),34 'border: 1px solid #00ffff; color: green;'35 );36 LegacyUnit.equal(37 dom.serializeStyle(38 dom.parseStyle('border-top: 1px solid red; border-left: 1px solid red; border-bottom: 1px solid red; border-right: 1px solid red;')39 ),40 'border: 1px solid red;'41 );42 LegacyUnit.equal(43 dom.serializeStyle(44 dom.parseStyle('border-width: 1pt 1pt 1pt 1pt; border-style: none none none none; border-color: black black black black;')45 ),46 'border: 1pt none black;'47 );48 LegacyUnit.equal(49 dom.serializeStyle(50 dom.parseStyle('border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;')51 ),52 'border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;'53 );54 LegacyUnit.equal(55 dom.serializeStyle(dom.parseStyle('background: transparent url(test.gif);')),56 'background: transparent url(\'Xtest.gifY\');'57 );58 LegacyUnit.equal(59 dom.serializeStyle(dom.parseStyle('background: transparent url(http://www.site.com/test.gif?a=1&b=2);')),60 'background: transparent url(\'Xhttp://www.site.com/test.gif?a=1&b=2Y\');'61 );62 dom.setHTML('test', '<span id="test2" style=" margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px "></span>');63 LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'margin: 1px;');64 dom.setHTML('test', '<span id="test2" style="background-image: url(test.gif);"></span>');65 LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xtest.gifY\');');66 // dom.get('test').innerHTML = '<span id="test2" style="border: 1px solid #00ff00"></span>';67 // LegacyUnit.equal(dom.getAttrib('test2', 'style'), Env.ue && !window.getSelection ?68 // 'border: #00ff00 1px solid;' : 'border: 1px solid #00ff00;'); // IE has a separate output69 dom.get('test').innerHTML = '<span id="test2" style="background-image: url(http://www.site.com/test.gif);"></span>';70 LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xhttp://www.site.com/test.gifY\');');71 DOM.remove('test');72 });73 suite.test('addClass', function () {74 DOM.add(document.body, 'div', { id : 'test' });75 DOM.get('test').className = '';76 DOM.addClass('test', 'abc');77 LegacyUnit.equal(DOM.get('test').className, 'abc');78 DOM.addClass('test', '123');79 LegacyUnit.equal(DOM.get('test').className, 'abc 123');80 DOM.get('test').innerHTML = '<span id="test2"></span><span id="test3"></span><span id="test4"></span>';81 DOM.addClass(DOM.select('span', 'test'), 'abc');82 LegacyUnit.equal(DOM.get('test2').className, 'abc');83 LegacyUnit.equal(DOM.get('test3').className, 'abc');84 LegacyUnit.equal(DOM.get('test4').className, 'abc');85 DOM.get('test').innerHTML = '';86 DOM.remove('test');87 });88 suite.test('removeClass', function () {89 DOM.add(document.body, 'div', { id : 'test' });90 DOM.get('test').className = 'abc 123 xyz';91 DOM.removeClass('test', '123');92 LegacyUnit.equal(DOM.get('test').className, 'abc xyz');93 DOM.get('test').innerHTML = (94 '<span id="test2" class="test1"></span><span id="test3" class="test test1 test"></span><span id="test4" class="test1 test"></span>'95 );96 DOM.removeClass(DOM.select('span', 'test'), 'test1');97 LegacyUnit.equal(DOM.get('test2').className, '');98 LegacyUnit.equal(DOM.get('test3').className, 'test test');99 LegacyUnit.equal(DOM.get('test4').className, 'test');100 DOM.get('test').innerHTML = '<span id="test2" class="test"></span>';101 DOM.removeClass('test2', 'test');102 LegacyUnit.equal(HtmlUtils.normalizeHtml(DOM.get('test').innerHTML), '<span id="test2"></span>');103 DOM.remove('test');104 });105 suite.test('hasClass', function () {106 DOM.add(document.body, 'div', { id : 'test' });107 DOM.get('test').className = 'abc 123 xyz';108 LegacyUnit.equal(DOM.hasClass('test', 'abc'), true);109 LegacyUnit.equal(DOM.hasClass('test', '123'), true);110 LegacyUnit.equal(DOM.hasClass('test', 'xyz'), true);111 LegacyUnit.equal(DOM.hasClass('test', 'aaa'), false);112 DOM.get('test').className = 'abc';113 LegacyUnit.equal(DOM.hasClass('test', 'abc'), true);114 DOM.get('test').className = 'aaa abc';115 LegacyUnit.equal(DOM.hasClass('test', 'abc'), true);116 DOM.get('test').className = 'abc aaa';117 LegacyUnit.equal(DOM.hasClass('test', 'abc'), true);118 DOM.remove('test');119 });120 suite.test('add', function () {121 var e;122 DOM.add(document.body, 'div', { id : 'test' });123 DOM.add('test', 'span', { 'class' : 'abc 123' }, 'content <b>abc</b>');124 e = DOM.get('test').getElementsByTagName('span')[0];125 LegacyUnit.equal(e.className, 'abc 123');126 LegacyUnit.equal(e.innerHTML.toLowerCase(), 'content <b>abc</b>');127 DOM.remove(e);128 DOM.add('test', 'span', { 'class' : 'abc 123' });129 e = DOM.get('test').getElementsByTagName('span')[0];130 LegacyUnit.equal(e.className, 'abc 123');131 DOM.remove(e);132 DOM.add('test', 'span');133 e = DOM.get('test').getElementsByTagName('span')[0];134 LegacyUnit.equal(e.nodeName, 'SPAN');135 DOM.remove(e);136 DOM.get('test').innerHTML = '<span id="test2"></span><span id="test3"></span><span id="test4"></span>';137 DOM.add(['test2', 'test3', 'test4'], 'span', { 'class' : 'abc 123' });138 LegacyUnit.equal(DOM.select('span', 'test').length, 6);139 DOM.remove('test');140 });141 suite.test('create', function () {142 var e;143 e = DOM.create('span', { 'class' : 'abc 123' }, 'content <b>abc</b>');144 LegacyUnit.equal(e.nodeName, 'SPAN');145 LegacyUnit.equal(e.className, 'abc 123');146 LegacyUnit.equal(e.innerHTML.toLowerCase(), 'content <b>abc</b>');147 });148 suite.test('createHTML', function () {149 LegacyUnit.equal(150 DOM.createHTML('span', { 'id': 'id1', 'class': 'abc 123' }, 'content <b>abc</b>'),151 '<span id="id1" class="abc 123">content <b>abc</b></span>'152 );153 LegacyUnit.equal(DOM.createHTML('span', { 'id': 'id1', 'class': 'abc 123' }), '<span id="id1" class="abc 123" />');154 LegacyUnit.equal(DOM.createHTML('span', { 'id': null, 'class': undefined }), '<span />');155 LegacyUnit.equal(DOM.createHTML('span'), '<span />');156 LegacyUnit.equal(DOM.createHTML('span', null, 'content <b>abc</b>'), '<span>content <b>abc</b></span>');157 });158 suite.test('uniqueId', function () {159 DOM.counter = 0;160 LegacyUnit.equal(DOM.uniqueId(), 'mce_0');161 LegacyUnit.equal(DOM.uniqueId(), 'mce_1');162 LegacyUnit.equal(DOM.uniqueId(), 'mce_2');163 });164 suite.test('showHide', function () {165 DOM.add(document.body, 'div', { id : 'test' });166 DOM.show('test');167 LegacyUnit.equal(DOM.get('test').style.display, '');168 LegacyUnit.equal(DOM.isHidden('test'), false);169 DOM.hide('test');170 LegacyUnit.equal(DOM.get('test').style.display, 'none');171 LegacyUnit.equal(DOM.isHidden('test'), true);172 // Cleanup173 DOM.setAttrib('test', 'style', '');174 DOM.remove('test');175 });176 suite.test('select', function () {177 DOM.add(document.body, 'div', { id : 'test' });178 DOM.setHTML('test', '<div>test 1</div><div>test 2 <div>test 3</div></div><div>test 4</div>');179 LegacyUnit.equal(DOM.select('div', 'test').length, 4);180 LegacyUnit.equal(DOM.select('div', 'test').reverse !== undefined, true);181 DOM.setHTML('test', '<div class="test1 test2 test3">test 1</div><div class="test2">test 2 <div>test 3</div></div><div>test 4</div>');182 LegacyUnit.equal(DOM.select('div.test2', 'test').length, 2);183 DOM.setHTML('test', '<div class="test1 test2 test3">test 1</div><div class="test2">test 2 <div>test 3</div></div><div>test 4</div>');184 LegacyUnit.equal(DOM.select('div div', 'test').length, 1, null, Env.webkit); // Issue: http://bugs.webkit.org/show_bug.cgi?id=17461185 //alert(DOM.select('div div', 'test').length +","+DOM.get('test').querySelectorAll('div div').length);186 DOM.remove('test');187 });188 suite.test('is', function () {189 DOM.add(document.body, 'div', { id : 'test' });190 DOM.setHTML('test', '<div id="textX" class="test">test 1</div>');191 LegacyUnit.equal(DOM.is(DOM.get('textX'), 'div'), true);192 LegacyUnit.equal(DOM.is(DOM.get('textX'), 'div#textX.test'), true);193 LegacyUnit.equal(DOM.is(DOM.get('textX'), 'div#textX2'), false);194 LegacyUnit.equal(DOM.is(null, 'div#textX2'), false);195 DOM.remove('test');196 });197 suite.test('encode', function () {198 LegacyUnit.equal(DOM.encode('abc<>"&\'\u00e5\u00e4\u00f6'), 'abc&lt;&gt;&quot;&amp;&#39;\u00e5\u00e4\u00f6');199 });200 suite.test('setGetAttrib', function () {201 var dom;202 DOM.add(document.body, 'div', { id : 'test' });203 DOM.setAttrib('test', 'class', 'test 123');204 LegacyUnit.equal(DOM.getAttrib('test', 'class'), 'test 123');205 DOM.setAttrib('test', 'src', 'url');206 LegacyUnit.equal(DOM.getAttrib('test', 'src'), 'url');207 LegacyUnit.equal(DOM.getAttrib('test', 'data-mce-src'), 'url');208 LegacyUnit.equal(DOM.getAttrib('test', 'abc'), '');209 DOM.setAttribs('test', { 'class' : '123', title : 'abc' });210 LegacyUnit.equal(DOM.getAttrib('test', 'class'), '123');211 LegacyUnit.equal(DOM.getAttrib('test', 'title'), 'abc');212 DOM.setAttribs('test');213 LegacyUnit.equal(DOM.getAttrib('test', 'class'), '123');214 LegacyUnit.equal(DOM.getAttrib('test', 'title'), 'abc');215 dom = new DOMUtils(document, { keep_values : true, url_converter : function (u, n) {216 return '&<>"' + u + '&<>"' + n;217 } });218 dom.setAttribs('test', { src : '123', href : 'abc' });219 LegacyUnit.equal(DOM.getAttrib('test', 'src'), '&<>"123&<>"src');220 LegacyUnit.equal(DOM.getAttrib('test', 'href'), '&<>"abc&<>"href');221 LegacyUnit.equal(DOM.getAttrib(document, 'test'), '');222 LegacyUnit.equal(DOM.getAttrib(document, 'test', ''), '');223 LegacyUnit.equal(DOM.getAttrib(document, 'test', 'x'), 'x');224 DOM.remove('test');225 });226 suite.test('setGetAttrib on null', function () {227 LegacyUnit.equal(DOM.getAttrib(null, 'test'), '');228 DOM.setAttrib(null, 'test');229 });230 suite.test('getAttribs', function () {231 var check = function (obj, val) {232 var count = 0;233 val = val.split(',');234 Tools.each(obj, function (o) {235 if (Tools.inArray(val, o.nodeName.toLowerCase()) !== -1 && o.specified) {236 count++;237 }238 });239 return count === obj.length;240 };241 DOM.add(document.body, 'div', { id : 'test' });242 DOM.get('test').innerHTML = '<span id="test2" class="test"></span>';243 LegacyUnit.equal(check(DOM.getAttribs('test2'), 'id,class'), true);244 DOM.get('test').innerHTML = '<input id="test2" type="checkbox" name="test" value="1" disabled readonly checked></span>';245 LegacyUnit.equal(246 check(DOM.getAttribs('test2'), 'id,type,name,value,disabled,readonly,checked'),247 true,248 'Expected attributed: type,name,disabled,readonly,checked'249 );250 DOM.remove('test');251 });252 suite.test('setGetStyles', function () {253 DOM.add(document.body, 'div', { id : 'test' });254 DOM.setStyle('test', 'font-size', '20px');255 LegacyUnit.equal(DOM.getStyle('test', 'font-size'), '20px');256 DOM.setStyle('test', 'fontSize', '21px');257 LegacyUnit.equal(DOM.getStyle('test', 'fontSize'), '21px');258 DOM.setStyles('test', { fontSize : '22px', display : 'inline' });259 LegacyUnit.equal(DOM.getStyle('test', 'fontSize'), '22px');260 LegacyUnit.equal(DOM.getStyle('test', 'display'), 'inline');261 DOM.setStyle('test', 'fontSize', 23);262 LegacyUnit.equal(DOM.getStyle('test', 'fontSize'), '23px');263 DOM.setStyle('test', 'fontSize', 23);264 DOM.setStyle('test', 'fontSize', '');265 LegacyUnit.equal(DOM.getStyle('test', 'fontSize'), '');266 DOM.setStyle('test', 'fontSize', 23);267 DOM.setStyle('test', 'fontSize', null);268 LegacyUnit.equal(DOM.getStyle('test', 'fontSize'), '');269 DOM.setAttrib('test', 'style', '');270 LegacyUnit.equal(typeof DOM.getStyle(null, 'fontSize'), 'undefined');271 DOM.remove('test');272 });273 suite.test('getPos', function () {274 DOM.add(document.body, 'div', { id : 'test' });275 DOM.setStyles('test', { position : 'absolute', left : 100, top : 110 });276 LegacyUnit.equal(DOM.getPos('test').x, 100);277 LegacyUnit.equal(DOM.getPos('test').y, 110);278 DOM.setAttrib('test', 'style', '');279 DOM.remove('test');280 });281 var eqNodeName = function (name) {282 return function (n) {283 return n.nodeName === name;284 };285 };286 suite.test('getParent', function () {287 DOM.add(document.body, 'div', { id : 'test' });288 DOM.get('test').innerHTML = '<div><span>ab<a id="test2" href="">abc</a>c</span></div>';289 LegacyUnit.equal(DOM.getParent('test2', eqNodeName('SPAN')).nodeName, 'SPAN');290 LegacyUnit.equal(DOM.getParent('test2', eqNodeName('BODY')).nodeName, 'BODY');291 LegacyUnit.equal(DOM.getParent('test2', eqNodeName('BODY'), document.body), null);292 LegacyUnit.equal(DOM.getParent('test2', eqNodeName('X')), null);293 LegacyUnit.equal(DOM.getParent('test2', 'SPAN').nodeName, 'SPAN');294 LegacyUnit.equal(DOM.getParent('test2', 'body', DOM.get('test')), null);295 DOM.get('test').innerHTML = '';296 DOM.remove('test');297 });298 suite.test('getParents', function () {299 DOM.add(document.body, 'div', { id : 'test' });300 DOM.get('test').innerHTML = '<div><span class="test">ab<span><a id="test2" href="">abc</a>c</span></span></div>';301 LegacyUnit.equal(DOM.getParents('test2', eqNodeName('SPAN')).length, 2);302 LegacyUnit.equal(DOM.getParents('test2', 'span').length, 2);303 LegacyUnit.equal(DOM.getParents('test2', 'span.test').length, 1);304 LegacyUnit.equal(DOM.getParents('test2', 'body', DOM.get('test')).length, 0);305 DOM.remove('test');306 });307 suite.test('is', function () {308 DOM.add(document.body, 'div', { id : 'test' });309 DOM.get('test').innerHTML = '<div><span class="test">ab<span><a id="test2" href="">abc</a>c</span></span></div>';310 LegacyUnit.equal(DOM.is(DOM.select('span', 'test'), 'span'), true);311 LegacyUnit.equal(DOM.is(DOM.select('#test2', 'test'), '#test2'), true);312 DOM.remove('test');313 });314 suite.test('getViewPort', function () {315 var wp;316 wp = DOM.getViewPort();317 LegacyUnit.equal(wp.x, 0);318 LegacyUnit.equal(wp.y, 0);319 LegacyUnit.equal(wp.w > 0, true);320 LegacyUnit.equal(wp.h > 0, true);321 });322 suite.test('getRect', function () {323 var r;324 DOM.add(document.body, 'div', { id : 'test' });325 DOM.setStyles('test', { position : 'absolute', left : 100, top : 110, width : 320, height : 240 });326 r = DOM.getRect('test');327 LegacyUnit.equal(r.x, 100);328 LegacyUnit.equal(r.y, 110);329 LegacyUnit.equal(r.w, 320);330 LegacyUnit.equal(r.h, 240);331 DOM.setAttrib('test', 'style', '');332 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:50%;height:240px"></div></div>';333 r = DOM.getRect('test2');334 LegacyUnit.equal(r.w, 160);335 DOM.remove('test');336 });337 suite.test('getSize', function () {338 var r;339 DOM.add(document.body, 'div', { id : 'test' });340 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:50%;height:240px"></div></div>';341 r = DOM.getSize('test2');342 LegacyUnit.equal(r.w, 160);343 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:100px;height:240px"></div></div>';344 r = DOM.getSize('test2');345 LegacyUnit.equal(r.w, 100);346 DOM.remove('test');347 });348 suite.test('getNext', function () {349 DOM.add(document.body, 'div', { id : 'test' });350 DOM.get('test').innerHTML = '<strong>A</strong><span>B</span><em>C</em>';351 LegacyUnit.equal(DOM.getNext(DOM.get('test').firstChild, '*').nodeName, 'SPAN');352 LegacyUnit.equal(DOM.getNext(DOM.get('test').firstChild, 'em').nodeName, 'EM');353 LegacyUnit.equal(DOM.getNext(DOM.get('test').firstChild, 'div'), null);354 LegacyUnit.equal(DOM.getNext(null, 'div'), null);355 LegacyUnit.equal(DOM.getNext(DOM.get('test').firstChild, eqNodeName('EM')).nodeName, 'EM');356 DOM.remove('test');357 });358 suite.test('getPrev', function () {359 DOM.add(document.body, 'div', { id : 'test' });360 DOM.get('test').innerHTML = '<strong>A</strong><span>B</span><em>C</em>';361 LegacyUnit.equal(DOM.getPrev(DOM.get('test').lastChild, '*').nodeName, 'SPAN');362 LegacyUnit.equal(DOM.getPrev(DOM.get('test').lastChild, 'strong').nodeName, 'STRONG');363 LegacyUnit.equal(DOM.getPrev(DOM.get('test').lastChild, 'div'), null);364 LegacyUnit.equal(DOM.getPrev(null, 'div'), null);365 LegacyUnit.equal(DOM.getPrev(DOM.get('test').lastChild, eqNodeName('STRONG')).nodeName, 'STRONG');366 DOM.remove('test');367 });368 suite.test('loadCSS', function () {369 var c = 0;370 DOM.loadCSS('tinymce/dom/test.css?a=1,tinymce/dom/test.css?a=2,tinymce/dom/test.css?a=3');371 Tools.each(document.getElementsByTagName('link'), function (n) {372 if (n.href.indexOf('test.css?a=') !== -1) {373 c++;374 }375 });376 LegacyUnit.equal(c, 3);377 });378 suite.test('insertAfter', function () {379 DOM.add(document.body, 'div', { id : 'test' });380 DOM.setHTML('test', '<span id="test2"></span>');381 DOM.insertAfter(DOM.create('br'), 'test2');382 LegacyUnit.equal(DOM.get('test2').nextSibling.nodeName, 'BR');383 DOM.setHTML('test', '<span>test</span><span id="test2"></span><span>test</span>');384 DOM.insertAfter(DOM.create('br'), 'test2');385 LegacyUnit.equal(DOM.get('test2').nextSibling.nodeName, 'BR');386 DOM.remove('test');387 });388 suite.test('isBlock', function () {389 LegacyUnit.equal(DOM.isBlock(DOM.create('div')), true);390 LegacyUnit.equal(DOM.isBlock('DIV'), true);391 LegacyUnit.equal(DOM.isBlock('SPAN'), false);392 LegacyUnit.equal(DOM.isBlock('div'), true);393 });394 suite.test('remove', function () {395 DOM.add(document.body, 'div', { id : 'test' });396 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');397 DOM.remove('test2', 1);398 LegacyUnit.equal(DOM.get('test').innerHTML.toLowerCase(), '<span>test</span><span>test2</span>');399 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');400 LegacyUnit.equal(DOM.remove('test2').nodeName, 'SPAN');401 DOM.remove('test');402 });403 suite.test('replace', function () {404 DOM.add(document.body, 'div', { id : 'test' });405 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');406 DOM.replace(DOM.create('div', { id : 'test2' }), 'test2', 1);407 LegacyUnit.equal(DOM.get('test2').innerHTML.toLowerCase(), '<span>test</span><span>test2</span>');408 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');409 DOM.replace(DOM.create('div', { id : 'test2' }), 'test2');410 LegacyUnit.equal(DOM.get('test2').innerHTML, '');411 DOM.remove('test');412 });413 suite.test('toHex', function () {414 LegacyUnit.equal(DOM.toHex('rgb(0, 255, 255)'), '#00ffff');415 LegacyUnit.equal(DOM.toHex('rgb(255, 0, 0)'), '#ff0000');416 LegacyUnit.equal(DOM.toHex('rgb(0, 0, 255)'), '#0000ff');417 LegacyUnit.equal(DOM.toHex('rgb ( 0 , 0 , 255 ) '), '#0000ff');418 LegacyUnit.equal(DOM.toHex(' RGB ( 0 , 0 , 255 ) '), '#0000ff');419 });420 suite.test('getOuterHTML', function () {421 DOM.add(document.body, 'div', { id : 'test' });422 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');423 LegacyUnit.equal(DOM.getOuterHTML('test2').toLowerCase().replace(/\"/g, ''), '<span id=test2><span>test</span><span>test2</span></span>');424 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');425 DOM.setOuterHTML('test2', '<div id="test2">123</div>');426 LegacyUnit.equal(Tools.trim(DOM.getOuterHTML('test2') || '').toLowerCase().replace(/\"/g, ''), '<div id=test2>123</div>');427 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');428 DOM.setOuterHTML('test2', '<div id="test2">123</div><div id="test3">abc</div>');429 LegacyUnit.equal(430 Tools.trim(DOM.get('test').innerHTML).toLowerCase().replace(/>\s+</g, '><').replace(/\"/g, ''),431 '<div id=test2>123</div><div id=test3>abc</div>'432 );433 DOM.setHTML('test', 'test');434 LegacyUnit.equal(Tools.trim(DOM.getOuterHTML(DOM.get('test').firstChild)), 'test');435 DOM.remove('test');436 });437 suite.test('encodeDecode', function () {438 LegacyUnit.equal(DOM.encode('\u00e5\u00e4\u00f6&<>"'), '\u00e5\u00e4\u00f6&amp;&lt;&gt;&quot;');439 LegacyUnit.equal(DOM.decode('&aring;&auml;&ouml;&amp;&lt;&gt;&quot;'), '\u00e5\u00e4\u00f6&<>"');440 });441 suite.test('split', function () {442 var point, parent;443 DOM.add(document.body, 'div', { id : 'test' });444 DOM.setHTML('test', '<p><b>text1<span>inner</span>text2</b></p>');445 parent = DOM.select('p', DOM.get('test'))[0];446 point = DOM.select('span', DOM.get('test'))[0];447 DOM.split(parent, point);448 LegacyUnit.equal(DOM.get('test').innerHTML.toLowerCase().replace(/\s+/g, ''), '<p><b>text1</b></p><span>inner</span><p><b>text2</b></p>');449 DOM.setHTML('test', '<ul><li>first line<br><ul><li><span>second</span> <span>line</span></li><li>third line<br></li></ul></li></ul>');450 parent = DOM.select('li:nth-child(1)', DOM.get('test'))[0];451 point = DOM.select('ul li:nth-child(2)', DOM.get('test'))[0];452 DOM.split(parent, point);453 LegacyUnit.equal(454 HtmlUtils.cleanHtml(DOM.get('test').innerHTML),455 '<ul><li>first line<br><ul><li><span>second</span> <span>line</span></li></ul></li><li>third line<br></li></ul>'456 );457 DOM.remove('test');458 });459 suite.test('nodeIndex', function () {460 DOM.add(document.body, 'div', { id : 'test' }, 'abc<b>abc</b>abc');461 LegacyUnit.equal(DOM.nodeIndex(DOM.get('test').childNodes[0]), 0, 'Index of first child.');462 LegacyUnit.equal(DOM.nodeIndex(DOM.get('test').childNodes[1]), 1, 'Index of second child.');463 LegacyUnit.equal(DOM.nodeIndex(DOM.get('test').childNodes[2]), 2, 'Index of third child.');464 DOM.get('test').insertBefore(DOM.doc.createTextNode('a'), DOM.get('test').firstChild);465 DOM.get('test').insertBefore(DOM.doc.createTextNode('b'), DOM.get('test').firstChild);466 LegacyUnit.equal(DOM.nodeIndex(DOM.get('test').lastChild), 4, 'Index of last child with fragmented DOM.');467 LegacyUnit.equal(DOM.nodeIndex(DOM.get('test').lastChild, true), 2, 'Normalized index of last child with fragmented DOM.');468 DOM.remove('test');469 });470 suite.test('isEmpty without defined schema', function () {471 DOM.add(document.body, 'div', { id : 'test' }, '');472 var domUtils = new DOMUtils(document);473 DOM.setHTML('test', '<hr>');474 LegacyUnit.equal(domUtils.isEmpty(DOM.get('test')), false, 'Should be false since hr is something');475 DOM.setHTML('test', '<p><br></p>');476 LegacyUnit.equal(domUtils.isEmpty(DOM.get('test')), true, 'Should be true since the paragraph is empty');477 DOM.remove('test');478 });479 suite.test('isEmpty', function () {480 DOM.schema = new Schema(); // A schema will be added when used within a editor instance481 DOM.add(document.body, 'div', { id : 'test' }, '');482 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'No children');483 DOM.setHTML('test', '<br />');484 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Br child');485 DOM.setHTML('test', '<br /><br />');486 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Br children');487 DOM.setHTML('test', 'text');488 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Text child');489 DOM.setHTML('test', '<span>text</span>');490 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Text child in span');491 DOM.setHTML('test', '<span></span>');492 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Empty span child');493 DOM.setHTML('test', '<div><span><b></b></span><b></b><em></em></div>');494 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Empty complex HTML');495 DOM.setHTML('test', '<div><span><b></b></span><b></b><em>X</em></div>');496 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Non empty complex HTML');497 DOM.setHTML('test', '<div><span><b></b></span><b></b><em> </em></div>');498 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Non empty complex HTML with space');499 DOM.setHTML('test', '<div><span><b></b></span><b></b><em><a name="x"></a></em></div>');500 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Non empty complex HTML with achor name');501 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif">');502 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Non empty html with img element');503 DOM.setHTML('test', '<span data-mce-bookmark="1"></span>');504 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Span with bookmark attribute.');505 DOM.setHTML('test', '<span data-mce-style="color:Red"></span>');506 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Span with data-mce attribute.');507 DOM.setHTML('test', '<div><!-- comment --></div>');508 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Element with comment.');509 DOM.setHTML('test', '<span data-mce-bogus="1"></span>');510 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Contains just a bogus element.');511 DOM.setHTML('test', '<span data-mce-bogus="1">a</span>');512 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a text node in a bogus element.');513 DOM.setHTML('test', '<span data-mce-bogus="all">a</span>');514 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), true, 'Contains just a bogus all element.');515 DOM.setHTML('test', '<span data-mce-bogus="all">a</span>b');516 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a bogus all element but some text as well.');517 DOM.setHTML('test', '<code> </code>');518 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a code element should be treated as content.');519 DOM.setHTML('test', '<pre> </pre>');520 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a pre element should be treated as content.');521 DOM.setHTML('test', '<code></code>');522 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a code element should be treated as content.');523 DOM.setHTML('test', '<pre></pre>');524 LegacyUnit.equal(DOM.isEmpty(DOM.get('test')), false, 'Contains a pre element should be treated as content.');525 DOM.remove('test');526 });527 suite.test('isEmpty with list of elements considered non-empty', function () {528 var elm = DOM.create('p', null, '<img>');529 LegacyUnit.equal(false, DOM.isEmpty(elm, { img: true }));530 });531 suite.test('isEmpty on pre', function () {532 var elm = DOM.create('pre', null, ' ');533 LegacyUnit.equal(false, DOM.isEmpty(elm));534 });535 suite.test('isEmpty with list of elements considered non-empty without schema', function () {536 var domWithoutSchema = new DOMUtils(document, { keep_values: true });537 var elm = domWithoutSchema.create('p', null, '<img>');538 LegacyUnit.equal(false, domWithoutSchema.isEmpty(elm, { img: true }));539 });540 suite.test('isEmpty on P with BR in EM', function () {541 var elm = DOM.create('p', null, '<em><br></em>');542 LegacyUnit.equal(DOM.isEmpty(elm), true, 'No children');543 });544 suite.test('isEmpty on P with two BR in EM', function () {545 var elm = DOM.create('p', null, '<em><br><br></em>');546 LegacyUnit.equal(false, DOM.isEmpty(elm));547 });548 suite.test('bind/unbind/fire', function () {549 var count = 0;550 DOM.bind(document, 'click', function () {551 count++;552 });553 DOM.fire(document, 'click');554 DOM.unbind(document, 'click');555 LegacyUnit.equal(count, 1);556 count = 0;557 DOM.bind([document, window], 'click', function (e) {558 e.stopPropagation();559 count++;560 });561 DOM.fire(document, 'click');562 DOM.fire(window, 'click');563 DOM.unbind([document, window], 'click');564 LegacyUnit.equal(count, 2);565 count = 0;566 DOM.fire(document, 'click');567 DOM.fire(window, 'click');568 LegacyUnit.equal(count, 0);569 });570 Pipeline.async({}, suite.toSteps({}), function () {571 DOM.remove('test');572 success();573 }, failure);574 }...

Full Screen

Full Screen

DOMUtils.js

Source:DOMUtils.js Github

copy

Full Screen

1(function() {2 module("tinymce.dom.DOMUtils", {3 teardownModule: function() {4 DOM = null;5 }6 });7 var DOM = new tinymce.dom.DOMUtils(document, {keep_values : true, schema : new tinymce.html.Schema()});8 test('parseStyle', 11, function() {9 var dom;10 DOM.add(document.body, 'div', {id : 'test'});11 dom = new tinymce.dom.DOMUtils(document, {hex_colors : true, keep_values : true, url_converter : function(u) {12 return 'X' + u + 'Y';13 }});14 equal(15 dom.serializeStyle(dom.parseStyle('border: 1px solid red; color: green')),16 'border: 1px solid red; color: green;'17 );18 equal(19 dom.serializeStyle(dom.parseStyle('border: 1px solid rgb(0, 255, 255); color: green')),20 'border: 1px solid #00ffff; color: green;'21 );22 equal(23 dom.serializeStyle(dom.parseStyle('border-top: 1px solid red; border-left: 1px solid red; border-bottom: 1px solid red; border-right: 1px solid red;')),24 'border: 1px solid red;'25 );26 equal(27 dom.serializeStyle(dom.parseStyle('border-width: 1pt 1pt 1pt 1pt; border-style: none none none none; border-color: black black black black;')),28 'border: 1pt none black;'29 );30 31 equal(32 dom.serializeStyle(dom.parseStyle('border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;')),33 'border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;'34 );35 equal(36 dom.serializeStyle(dom.parseStyle('background: transparent url(test.gif);')),37 'background: transparent url(\'Xtest.gifY\');'38 );39 equal(40 dom.serializeStyle(dom.parseStyle('background: transparent url(http://www.site.com/test.gif?a=1&b=2);')),41 'background: transparent url(\'Xhttp://www.site.com/test.gif?a=1&b=2Y\');'42 );43 dom.setHTML('test', '<span id="test2" style=" margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px "></span>');44 equal(dom.getAttrib('test2', 'style'), 'margin: 1px;');45 dom.setHTML('test', '<span id="test2" style="background-image: url(test.gif);"></span>');46 equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xtest.gifY\');');47 dom.get('test').innerHTML = '<span id="test2" style="border: 1px solid #00ff00"></span>';48 equal(dom.getAttrib('test2', 'style'), tinymce.isIE && !window.getSelection ? 'border: #00ff00 1px solid;' : 'border: 1px solid #00ff00;'); // IE has a separate output49 dom.get('test').innerHTML = '<span id="test2" style="background-image: url(http://www.site.com/test.gif);"></span>';50 equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xhttp://www.site.com/test.gifY\');');51 DOM.remove('test');52 });53 test('addClass', function() {54 DOM.add(document.body, 'div', {id : 'test'});55 DOM.get('test').className = '';56 DOM.addClass('test', 'abc');57 equal(DOM.get('test').className, 'abc');58 DOM.addClass('test', '123');59 equal(DOM.get('test').className, 'abc 123');60 DOM.get('test').innerHTML = '<span id="test2"></span><span id="test3"></span><span id="test4"></span>';61 DOM.addClass(DOM.select('span', 'test'), 'abc');62 equal(DOM.get('test2').className, 'abc');63 equal(DOM.get('test3').className, 'abc');64 equal(DOM.get('test4').className, 'abc');65 DOM.get('test').innerHTML = '';66 DOM.remove('test');67 });68 test('removeClass', 5, function() {69 DOM.add(document.body, 'div', {id : 'test'});70 DOM.get('test').className = 'abc 123 xyz';71 DOM.removeClass('test', '123');72 equal(DOM.get('test').className, 'abc xyz');73 DOM.get('test').innerHTML = '<span id="test2" class="test1"></span><span id="test3" class="test test1 test"></span><span id="test4" class="test1 test"></span>';74 DOM.removeClass(DOM.select('span', 'test'), 'test1');75 equal(DOM.get('test2').className, '');76 equal(DOM.get('test3').className, 'test test');77 equal(DOM.get('test4').className, 'test');78 DOM.get('test').innerHTML = '<span id="test2" class="test"></span>';79 DOM.removeClass('test2', 'test');80 equal(Utils.normalizeHtml(DOM.get('test').innerHTML), '<span id="test2"></span>');81 DOM.remove('test');82 });83 test('hasClass', 7, function() {84 DOM.add(document.body, 'div', {id : 'test'});85 DOM.get('test').className = 'abc 123 xyz';86 ok(DOM.hasClass('test', 'abc'));87 ok(DOM.hasClass('test', '123'));88 ok(DOM.hasClass('test', 'xyz'));89 ok(!DOM.hasClass('test', 'aaa'));90 DOM.get('test').className = 'abc';91 ok(DOM.hasClass('test', 'abc'));92 DOM.get('test').className = 'aaa abc';93 ok(DOM.hasClass('test', 'abc'));94 DOM.get('test').className = 'abc aaa';95 ok(DOM.hasClass('test', 'abc'));96 DOM.remove('test');97 });98 test('add', 5, function() {99 var e;100 DOM.add(document.body, 'div', {id : 'test'});101 DOM.add('test', 'span', {'class' : 'abc 123'}, 'content <b>abc</b>');102 e = DOM.get('test').getElementsByTagName('span')[0];103 equal(e.className, 'abc 123');104 equal(e.innerHTML.toLowerCase(), 'content <b>abc</b>');105 DOM.remove(e);106 DOM.add('test', 'span', {'class' : 'abc 123'});107 e = DOM.get('test').getElementsByTagName('span')[0];108 equal(e.className, 'abc 123');109 DOM.remove(e);110 DOM.add('test', 'span');111 e = DOM.get('test').getElementsByTagName('span')[0];112 equal(e.nodeName, 'SPAN');113 DOM.remove(e);114 DOM.get('test').innerHTML = '<span id="test2"></span><span id="test3"></span><span id="test4"></span>';115 DOM.add(['test2', 'test3', 'test4'], 'span', {'class' : 'abc 123'});116 equal(DOM.select('span', 'test').length, 6);117 DOM.remove('test');118 });119 test('create', 3, function() {120 var e;121 e = DOM.create('span', {'class' : 'abc 123'}, 'content <b>abc</b>');122 equal(e.nodeName, 'SPAN');123 equal(e.className, 'abc 123');124 equal(e.innerHTML.toLowerCase(), 'content <b>abc</b>');125 });126 test('createHTML', 5, function() {127 equal(DOM.createHTML('span', {'id': 'id1', 'class': 'abc 123'}, 'content <b>abc</b>'), '<span id="id1" class="abc 123">content <b>abc</b></span>');128 equal(DOM.createHTML('span', {'id': 'id1', 'class': 'abc 123'}), '<span id="id1" class="abc 123" />');129 equal(DOM.createHTML('span', {'id': null, 'class': undefined}), '<span />');130 equal(DOM.createHTML('span'), '<span />');131 equal(DOM.createHTML('span', null, 'content <b>abc</b>'), '<span>content <b>abc</b></span>');132 });133 test('uniqueId', 3, function() {134 DOM.counter = 0;135 equal(DOM.uniqueId(), 'mce_0');136 equal(DOM.uniqueId(), 'mce_1');137 equal(DOM.uniqueId(), 'mce_2');138 });139 test('showHide', function() {140 DOM.add(document.body, 'div', {id : 'test'});141 DOM.show('test');142 equal(DOM.get('test').style.display, '');143 ok(!DOM.isHidden('test'));144 DOM.hide('test');145 equal(DOM.get('test').style.display, 'none');146 ok(DOM.isHidden('test'));147 // Cleanup148 DOM.setAttrib('test', 'style', '');149 DOM.remove('test');150 });151 test('select', 4, function() {152 DOM.add(document.body, 'div', {id : 'test'});153 DOM.setHTML('test', '<div>test 1</div><div>test 2 <div>test 3</div></div><div>test 4</div>');154 equal(DOM.select('div', 'test').length, 4);155 ok(DOM.select('div', 'test').reverse);156 DOM.setHTML('test', '<div class="test1 test2 test3">test 1</div><div class="test2">test 2 <div>test 3</div></div><div>test 4</div>');157 equal(DOM.select('div.test2', 'test').length, 2);158 DOM.setHTML('test', '<div class="test1 test2 test3">test 1</div><div class="test2">test 2 <div>test 3</div></div><div>test 4</div>');159 equal(DOM.select('div div', 'test').length, 1, null, tinymce.isWebKit); // Issue: http://bugs.webkit.org/show_bug.cgi?id=17461160 //alert(DOM.select('div div', 'test').length +","+DOM.get('test').querySelectorAll('div div').length);161 DOM.remove('test');162 });163 test('is', 3, function() {164 DOM.add(document.body, 'div', {id : 'test'});165 DOM.setHTML('test', '<div id="textX" class="test">test 1</div>');166 ok(DOM.is(DOM.get('textX'), 'div'));167 ok(DOM.is(DOM.get('textX'), 'div#textX.test'));168 ok(!DOM.is(DOM.get('textX'), 'div#textX2'));169 DOM.remove('test');170 });171 test('encode', 1, function() {172 equal(DOM.encode('abc<>"&\'\u00e5\u00e4\u00f6'), 'abc&lt;&gt;&quot;&amp;&#39;\u00e5\u00e4\u00f6');173 });174 test('setGetAttrib', function() {175 var dom;176 DOM.add(document.body, 'div', {id : 'test'});177 DOM.setAttrib('test', 'class', 'test 123');178 equal(DOM.getAttrib('test', 'class'), 'test 123');179 DOM.setAttrib('test', 'src', 'url');180 equal(DOM.getAttrib('test', 'src'), 'url');181 equal(DOM.getAttrib('test', 'data-mce-src'), 'url');182 equal(DOM.getAttrib('test', 'abc'), '');183 DOM.setAttribs('test', {'class' : '123', title : 'abc'});184 equal(DOM.getAttrib('test', 'class'), '123');185 equal(DOM.getAttrib('test', 'title'), 'abc');186 DOM.setAttribs('test');187 equal(DOM.getAttrib('test', 'class'), '123');188 equal(DOM.getAttrib('test', 'title'), 'abc');189 dom = new tinymce.dom.DOMUtils(document, {keep_values : true, url_converter : function(u, n) {190 return '&<>"' + u + '&<>"' + n;191 }});192 dom.setAttribs('test', {src : '123', href : 'abc'});193 equal(DOM.getAttrib('test', 'src'), '&<>"123&<>"src');194 equal(DOM.getAttrib('test', 'href'), '&<>"abc&<>"href');195 equal(DOM.getAttrib(document, 'test'), false);196 equal(DOM.getAttrib(document, 'test', ''), '');197 equal(DOM.getAttrib(document, 'test', 'x'), 'x');198 DOM.remove('test');199 });200 test('setGetAttrib on null', function() {201 strictEqual(DOM.getAttrib(null, 'test'), '');202 DOM.setAttrib(null, 'test');203 });204 test('getAttribs', 2, function() {205 function check(obj, val) {206 var count = 0;207 val = val.split(',');208 tinymce.each(obj, function(o) {209 if (tinymce.inArray(val, o.nodeName.toLowerCase()) != -1 && o.specified) {210 count++;211 }212 });213 return count == obj.length;214 }215 DOM.add(document.body, 'div', {id : 'test'});216 DOM.get('test').innerHTML = '<span id="test2" class="test"></span>';217 ok(check(DOM.getAttribs('test2'), 'id,class'));218 DOM.get('test').innerHTML = '<input id="test2" type="checkbox" name="test" value="1" disabled readonly checked></span>';219 ok(check(DOM.getAttribs('test2'), 'id,type,name,value,disabled,readonly,checked'), 'Expected attributed: type,name,disabled,readonly,checked');220 DOM.remove('test');221 });222 test('setGetStyles', function() {223 DOM.add(document.body, 'div', {id : 'test'});224 DOM.setStyle('test', 'font-size', '20px');225 equal(DOM.getStyle('test', 'font-size'), '20px');226 DOM.setStyle('test', 'fontSize', '21px');227 equal(DOM.getStyle('test', 'fontSize'), '21px');228 DOM.setStyles('test', {fontSize : '22px', display : 'inline'});229 equal(DOM.getStyle('test', 'fontSize'), '22px');230 equal(DOM.getStyle('test', 'display'), 'inline');231 DOM.setStyle('test', 'fontSize', 23);232 equal(DOM.getStyle('test', 'fontSize'), '23px');233 DOM.setStyle('test', 'fontSize', 23);234 DOM.setStyle('test', 'fontSize', '');235 equal(DOM.getStyle('test', 'fontSize'), '');236 DOM.setStyle('test', 'fontSize', 23);237 DOM.setStyle('test', 'fontSize', null);238 equal(DOM.getStyle('test', 'fontSize'), '');239 DOM.setAttrib('test', 'style', '');240 equal(typeof DOM.getStyle(null, 'fontSize'), 'undefined');241 DOM.remove('test');242 });243 test('getPos', 2, function() {244 DOM.add(document.body, 'div', {id : 'test'});245 DOM.setStyles('test', {position : 'absolute', left : 100, top : 110});246 equal(DOM.getPos('test').x, 100);247 equal(DOM.getPos('test').y, 110);248 DOM.setAttrib('test', 'style', '');249 DOM.remove('test');250 });251 test('getParent', 6, function() {252 DOM.add(document.body, 'div', {id : 'test'});253 DOM.get('test').innerHTML = '<div><span>ab<a id="test2" href="">abc</a>c</span></div>';254 equal(DOM.getParent('test2', function(n) {return n.nodeName == 'SPAN';}).nodeName, 'SPAN');255 equal(DOM.getParent('test2', function(n) {return n.nodeName == 'BODY';}).nodeName, 'BODY');256 equal(DOM.getParent('test2', function(n) {return n.nodeName == 'BODY';}, document.body), null);257 equal(DOM.getParent('test2', function() {return false;}), null);258 equal(DOM.getParent('test2', 'SPAN').nodeName, 'SPAN');259 equal(DOM.getParent('test2', 'body', DOM.get('test')), null);260 DOM.get('test').innerHTML = '';261 DOM.remove('test');262 });263 test('getParents', 4, function() {264 DOM.add(document.body, 'div', {id : 'test'});265 DOM.get('test').innerHTML = '<div><span class="test">ab<span><a id="test2" href="">abc</a>c</span></span></div>';266 equal(DOM.getParents('test2', function(n) {return n.nodeName == 'SPAN';}).length, 2);267 equal(DOM.getParents('test2', 'span').length, 2);268 equal(DOM.getParents('test2', 'span.test').length, 1);269 equal(DOM.getParents('test2', 'body', DOM.get('test')).length, 0);270 DOM.remove('test');271 });272 test('is', 2, function() {273 DOM.add(document.body, 'div', {id : 'test'});274 DOM.get('test').innerHTML = '<div><span class="test">ab<span><a id="test2" href="">abc</a>c</span></span></div>';275 ok(DOM.is(DOM.select('span', 'test'), 'span'));276 ok(DOM.is(DOM.select('#test2', 'test'), '#test2'));277 DOM.remove('test');278 });279 test('getViewPort', 4, function() {280 var wp;281 wp = DOM.getViewPort();282 equal(wp.x, 0);283 equal(wp.y, 0);284 ok(wp.w > 0);285 ok(wp.h > 0);286 });287 test('getRect', 5, function() {288 var r;289 DOM.add(document.body, 'div', {id : 'test'});290 DOM.setStyles('test', {position : 'absolute', left : 100, top : 110, width : 320, height : 240});291 r = DOM.getRect('test');292 equal(r.x, 100);293 equal(r.y, 110);294 equal(r.w, 320);295 equal(r.h, 240);296 DOM.setAttrib('test', 'style', '');297 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:50%;height:240px"></div></div>';298 r = DOM.getRect('test2');299 equal(r.w, 160);300 DOM.remove('test');301 });302 test('getSize', 2, function() {303 var r;304 DOM.add(document.body, 'div', {id : 'test'});305 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:50%;height:240px"></div></div>';306 r = DOM.getSize('test2');307 equal(r.w, 160);308 DOM.get('test').innerHTML = '<div style="width:320px;height:240px"><div id="test2" style="width:100px;height:240px"></div></div>';309 r = DOM.getSize('test2');310 equal(r.w, 100);311 DOM.remove('test');312 });313 test('getNext', 5, function() {314 DOM.add(document.body, 'div', {id : 'test'});315 DOM.get('test').innerHTML = '<strong>A</strong><span>B</span><em>C</em>';316 equal(DOM.getNext(DOM.get('test').firstChild, '*').nodeName, 'SPAN');317 equal(DOM.getNext(DOM.get('test').firstChild, 'em').nodeName, 'EM');318 equal(DOM.getNext(DOM.get('test').firstChild, 'div'), null);319 equal(DOM.getNext(null, 'div'), null);320 equal(DOM.getNext(DOM.get('test').firstChild, function(n) {return n.nodeName == 'EM';}).nodeName, 'EM');321 DOM.remove('test');322 });323 test('getPrev', 5, function() {324 DOM.add(document.body, 'div', {id : 'test'});325 DOM.get('test').innerHTML = '<strong>A</strong><span>B</span><em>C</em>';326 equal(DOM.getPrev(DOM.get('test').lastChild, '*').nodeName, 'SPAN');327 equal(DOM.getPrev(DOM.get('test').lastChild, 'strong').nodeName, 'STRONG');328 equal(DOM.getPrev(DOM.get('test').lastChild, 'div'), null);329 equal(DOM.getPrev(null, 'div'), null);330 equal(DOM.getPrev(DOM.get('test').lastChild, function(n) {return n.nodeName == 'STRONG';}).nodeName, 'STRONG');331 DOM.remove('test');332 });333 test('loadCSS', 1, function() {334 var c = 0;335 DOM.loadCSS('tinymce/dom/test.css?a=1,tinymce/dom/test.css?a=2,tinymce/dom/test.css?a=3');336 tinymce.each(document.getElementsByTagName('link'), function(n) {337 if (n.href.indexOf('test.css?a=') != -1) {338 c++;339 }340 });341 equal(c, 3, null, tinymce.isOpera);342 });343 test('insertAfter', 2, function() {344 DOM.add(document.body, 'div', {id : 'test'});345 DOM.setHTML('test', '<span id="test2"></span>');346 DOM.insertAfter(DOM.create('br'), 'test2');347 equal(DOM.get('test2').nextSibling.nodeName, 'BR');348 DOM.setHTML('test', '<span>test</span><span id="test2"></span><span>test</span>');349 DOM.insertAfter(DOM.create('br'), 'test2');350 equal(DOM.get('test2').nextSibling.nodeName, 'BR');351 DOM.remove('test');352 });353 test('isBlock', 4, function() {354 ok(DOM.isBlock(DOM.create('div')));355 ok(DOM.isBlock('DIV'));356 ok(!DOM.isBlock('SPAN'));357 ok(DOM.isBlock('div'));358 });359 test('remove', 2, function() {360 DOM.add(document.body, 'div', {id : 'test'});361 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');362 DOM.remove('test2', 1);363 equal(DOM.get('test').innerHTML.toLowerCase(), '<span>test</span><span>test2</span>');364 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');365 equal(DOM.remove('test2').nodeName, 'SPAN');366 DOM.remove('test');367 });368 test('replace', 2, function() {369 DOM.add(document.body, 'div', {id : 'test'});370 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');371 DOM.replace(DOM.create('div', {id : 'test2'}), 'test2', 1);372 equal(DOM.get('test2').innerHTML.toLowerCase(), '<span>test</span><span>test2</span>');373 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');374 DOM.replace(DOM.create('div', {id : 'test2'}), 'test2');375 equal(DOM.get('test2').innerHTML, '');376 DOM.remove('test');377 });378 test('toHex', 5, function() {379 equal(DOM.toHex('rgb(0, 255, 255)'), '#00ffff');380 equal(DOM.toHex('rgb(255, 0, 0)'), '#ff0000');381 equal(DOM.toHex('rgb(0, 0, 255)'), '#0000ff');382 equal(DOM.toHex('rgb ( 0 , 0 , 255 ) '), '#0000ff');383 equal(DOM.toHex(' RGB ( 0 , 0 , 255 ) '), '#0000ff');384 });385 test('getOuterHTML', 4, function() {386 DOM.add(document.body, 'div', {id : 'test'});387 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');388 equal(DOM.getOuterHTML('test2').toLowerCase().replace(/\"/g, ''), '<span id=test2><span>test</span><span>test2</span></span>');389 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');390 DOM.setOuterHTML('test2', '<div id="test2">123</div>');391 equal(tinymce.trim(DOM.getOuterHTML('test2') || '').toLowerCase().replace(/\"/g, ''), '<div id=test2>123</div>');392 DOM.setHTML('test', '<span id="test2"><span>test</span><span>test2</span></span>');393 DOM.setOuterHTML('test2', '<div id="test2">123</div><div id="test3">abc</div>');394 equal(tinymce.trim(DOM.get('test').innerHTML).toLowerCase().replace(/>\s+</g, '><').replace(/\"/g, ''), '<div id=test2>123</div><div id=test3>abc</div>');395 DOM.setHTML('test', 'test');396 equal(tinymce.trim(DOM.getOuterHTML(DOM.get('test').firstChild)), 'test');397 DOM.remove('test');398 });399 test('encodeDecode', 2, function() {400 equal(DOM.encode('\u00e5\u00e4\u00f6&<>"'), '\u00e5\u00e4\u00f6&amp;&lt;&gt;&quot;');401 equal(DOM.decode('&aring;&auml;&ouml;&amp;&lt;&gt;&quot;'), '\u00e5\u00e4\u00f6&<>"');402 });403 test('split', 2, function() {404 var point, parent;405 DOM.add(document.body, 'div', {id : 'test'});406 DOM.setHTML('test', '<p><b>text1<span>inner</span>text2</b></p>');407 parent = DOM.select('p', DOM.get('test'))[0];408 point = DOM.select('span', DOM.get('test'))[0];409 DOM.split(parent, point);410 equal(DOM.get('test').innerHTML.toLowerCase().replace(/\s+/g, ''), '<p><b>text1</b></p><span>inner</span><p><b>text2</b></p>');411 DOM.setHTML('test', '<ul><li>first line<br><ul><li><span>second</span> <span>line</span></li><li>third line<br></li></ul></li></ul>');412 parent = DOM.select('li:nth-child(1)', DOM.get('test'))[0];413 point = DOM.select('ul li:nth-child(2)', DOM.get('test'))[0];414 DOM.split(parent, point);415 equal(Utils.cleanHtml(DOM.get('test').innerHTML), '<ul><li>first line<br><ul><li><span>second</span> <span>line</span></li></ul></li><li>third line<br></li></ul>');416 DOM.remove('test');417 });418 test('nodeIndex', 5, function() {419 DOM.add(document.body, 'div', {id : 'test'}, 'abc<b>abc</b>abc');420 equal(DOM.nodeIndex(DOM.get('test').childNodes[0]), 0, 'Index of first child.');421 equal(DOM.nodeIndex(DOM.get('test').childNodes[1]), 1, 'Index of second child.');422 equal(DOM.nodeIndex(DOM.get('test').childNodes[2]), 2, 'Index of third child.');423 DOM.get('test').insertBefore(DOM.doc.createTextNode('a'), DOM.get('test').firstChild);424 DOM.get('test').insertBefore(DOM.doc.createTextNode('b'), DOM.get('test').firstChild);425 equal(DOM.nodeIndex(DOM.get('test').lastChild), 4, 'Index of last child with fragmented DOM.');426 equal(DOM.nodeIndex(DOM.get('test').lastChild, true), 2, 'Normalized index of last child with fragmented DOM.');427 DOM.remove('test');428 });429 test('isEmpty', 14, function() {430 DOM.schema = new tinymce.html.Schema(); // A schema will be added when used within a editor instance431 DOM.add(document.body, 'div', {id : 'test'}, '');432 ok(DOM.isEmpty(DOM.get('test')), 'No children');433 DOM.setHTML('test', '<br />');434 ok(DOM.isEmpty(DOM.get('test')), 'Br child');435 DOM.setHTML('test', '<br /><br />');436 ok(!DOM.isEmpty(DOM.get('test')), 'Br children');437 DOM.setHTML('test', 'text');438 ok(!DOM.isEmpty(DOM.get('test')), 'Text child');439 DOM.setHTML('test', '<span>text</span>');440 ok(!DOM.isEmpty(DOM.get('test')), 'Text child in span');441 DOM.setHTML('test', '<span></span>');442 ok(DOM.isEmpty(DOM.get('test')), 'Empty span child');443 DOM.setHTML('test', '<div><span><b></b></span><b></b><em></em></div>');444 ok(DOM.isEmpty(DOM.get('test')), 'Empty complex HTML');445 DOM.setHTML('test', '<div><span><b></b></span><b></b><em>X</em></div>');446 ok(!DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML');447 DOM.setHTML('test', '<div><span><b></b></span><b></b><em> </em></div>');448 ok(DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML with space');449 DOM.setHTML('test', '<div><span><b></b></span><b></b><em><a name="x"></a></em></div>');450 ok(!DOM.isEmpty(DOM.get('test')), 'Non empty complex HTML with achor name');451 DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif">');452 ok(!DOM.isEmpty(DOM.get('test')), 'Non empty html with img element');453 DOM.setHTML('test', '<span data-mce-bookmark="1"></span>');454 ok(!DOM.isEmpty(DOM.get('test')), 'Span with bookmark attribute.');455 DOM.setHTML('test', '<span data-mce-style="color:Red"></span>');456 ok(DOM.isEmpty(DOM.get('test')), 'Span with data-mce attribute.');457 DOM.setHTML('test', '<div><!-- comment --></div>');458 ok(!DOM.isEmpty(DOM.get('test')), 'Element with comment.');459 DOM.remove('test');460 });461 test('isEmpty with list of elements considered non-empty', function() {462 var elm = DOM.create('p', null, '<img>');463 equal(false, DOM.isEmpty(elm, {img: true}));464 });465 test('isEmpty with list of elements considered non-empty without schema', function() {466 var domWithoutSchema = new tinymce.dom.DOMUtils(document, {keep_values: true});467 var elm = domWithoutSchema.create('p', null, '<img>');468 equal(false, domWithoutSchema.isEmpty(elm, {img: true}));469 });470 test('isEmpty on P with BR in EM', function() {471 var elm = DOM.create('p', null, '<em><br></em>');472 ok(DOM.isEmpty(elm, 'No children'));473 });474 475 test('isEmpty on P with two BR in EM', function() {476 var elm = DOM.create('p', null, '<em><br><br></em>');477 equal(false, DOM.isEmpty(elm));478 });479 test('bind/unbind/fire', function() {480 var count = 0;481 DOM.bind(document, 'click', function() {count++;});482 DOM.fire(document, 'click');483 DOM.unbind(document, 'click');484 equal(count, 1);485 count = 0;486 DOM.bind([document, window], 'click', function(e) {e.stopPropagation(); count++;});487 DOM.fire(document, 'click');488 DOM.fire(window, 'click');489 DOM.unbind([document, window], 'click');490 equal(count, 2);491 count = 0;492 DOM.fire(document, 'click');493 DOM.fire(window, 'click');494 equal(count, 0);495 });496 DOM.remove('test');...

Full Screen

Full Screen

wpt.js

Source:wpt.js Github

copy

Full Screen

1import { app, AppWindow } from '../lib/index.js'2console.log(`3 Note that this example requires some setup first:4 https://web-platform-tests.org/running-tests/from-local-system.html5`)6const runner = new AppWindow('WPT runner')7// TODO: find ../wpt | grep '\.html$' | grep '/dom/'8const BASE = 'http://web-platform.test:8000'9const urls = [10 `${BASE}/dom/attributes-are-nodes.html`,11 `${BASE}/dom/collections/domstringmap-supported-property-names.html`,12 `${BASE}/dom/collections/HTMLCollection-as-prototype.html`,13 `${BASE}/dom/collections/HTMLCollection-delete.html`,14 `${BASE}/dom/collections/HTMLCollection-empty-name.html`,15 `${BASE}/dom/collections/HTMLCollection-iterator.html`,16 `${BASE}/dom/collections/HTMLCollection-own-props.html`,17 `${BASE}/dom/collections/HTMLCollection-supported-property-indices.html`,18 `${BASE}/dom/collections/HTMLCollection-supported-property-names.html`,19 `${BASE}/dom/collections/namednodemap-supported-property-names.html`,20 `${BASE}/dom/events/AddEventListenerOptions-once.html`,21 `${BASE}/dom/events/AddEventListenerOptions-passive.html`,22 `${BASE}/dom/events/CustomEvent.html`,23 // `${BASE}/dom/events/document-level-touchmove-event-listener-passive-by-default.html`,24 // `${BASE}/dom/events/document-level-wheel-event-listener-passive-by-default.html`,25 `${BASE}/dom/events/Event-cancelBubble.html`,26 `${BASE}/dom/events/Event-constants.html`,27 // `${BASE}/dom/events/Event-constructors.html`,28 `${BASE}/dom/events/Event-defaultPrevented-after-dispatch.html`,29 `${BASE}/dom/events/Event-defaultPrevented.html`,30 `${BASE}/dom/events/event-disabled-dynamic.html`,31 // `${BASE}/dom/events/Event-dispatch-bubble-canceled.html`,32 `${BASE}/dom/events/Event-dispatch-bubbles-false.html`,33 `${BASE}/dom/events/Event-dispatch-bubbles-true.html`,34 // `${BASE}/dom/events/Event-dispatch-click.html`,35 // `${BASE}/dom/events/Event-dispatch-click.tentative.html`,36 // `${BASE}/dom/events/Event-dispatch-detached-click.html`,37 `${BASE}/dom/events/Event-dispatch-detached-input-and-change.html`,38 // `${BASE}/dom/events/Event-dispatch-handlers-changed.html`,39 // `${BASE}/dom/events/Event-dispatch-multiple-cancelBubble.html`,40 // `${BASE}/dom/events/Event-dispatch-multiple-stopPropagation.html`,41 `${BASE}/dom/events/Event-dispatch-omitted-capture.html`,42 `${BASE}/dom/events/Event-dispatch-on-disabled-elements.html`,43 `${BASE}/dom/events/Event-dispatch-order-at-target.html`,44 // `${BASE}/dom/events/Event-dispatch-order.html`,45 // `${BASE}/dom/events/Event-dispatch-other-document.html`,46 // `${BASE}/dom/events/Event-dispatch-propagation-stopped.html`,47 // `${BASE}/dom/events/Event-dispatch-redispatch.html`,48 // `${BASE}/dom/events/Event-dispatch-reenter.html`,49 `${BASE}/dom/events/Event-dispatch-target-moved.html`,50 `${BASE}/dom/events/Event-dispatch-target-removed.html`,51 `${BASE}/dom/events/Event-dispatch-throwing.html`,52 `${BASE}/dom/events/event-global.html`,53 `${BASE}/dom/events/Event-init-while-dispatching.html`,54 `${BASE}/dom/events/Event-initEvent.html`,55 `${BASE}/dom/events/Event-propagation.html`,56 `${BASE}/dom/events/Event-returnValue.html`,57 // `${BASE}/dom/events/Event-stopImmediatePropagation.html`,58 // `${BASE}/dom/events/Event-stopPropagation-cancel-bubbling.html`,59 `${BASE}/dom/events/Event-subclasses-constructors.html`,60 `${BASE}/dom/events/Event-timestamp-high-resolution.html`,61 `${BASE}/dom/events/Event-timestamp-safe-resolution.html`,62 `${BASE}/dom/events/Event-type-empty.html`,63 `${BASE}/dom/events/Event-type.html`,64 `${BASE}/dom/events/EventListener-handleEvent.html`,65 // `${BASE}/dom/events/EventListener-incumbent-global-1.sub.html`,66 // `${BASE}/dom/events/EventListener-incumbent-global-2.sub.html`,67 // `${BASE}/dom/events/EventListener-incumbent-global-subframe-1.sub.html`,68 // `${BASE}/dom/events/EventListener-incumbent-global-subframe-2.sub.html`,69 // `${BASE}/dom/events/EventListener-incumbent-global-subsubframe.sub.html`,70 // `${BASE}/dom/events/EventListener-invoke-legacy.html`,71 `${BASE}/dom/events/EventListenerOptions-capture.html`,72 // `${BASE}/dom/events/EventTarget-add-listener-platform-object.html`,73 `${BASE}/dom/events/EventTarget-add-remove-listener.html`,74 `${BASE}/dom/events/EventTarget-addEventListener.html`,75 `${BASE}/dom/events/EventTarget-dispatchEvent-returnvalue.html`,76 // `${BASE}/dom/events/EventTarget-dispatchEvent.html`,77 `${BASE}/dom/events/EventTarget-removeEventListener.html`,78 `${BASE}/dom/events/EventTarget-this-of-listener.html`,79 // `${BASE}/dom/events/replace-event-listener-null-browsing-context-crash.html`,80 // `${BASE}/dom/events/resources/event-global-extra-frame.html`,81 // `${BASE}/dom/events/scrolling/input-text-scroll-event-when-using-arrow-keys.html`,82 // `${BASE}/dom/events/scrolling/overscroll-deltas.html`,83 // `${BASE}/dom/events/scrolling/overscroll-event-fired-to-document.html`,84 // `${BASE}/dom/events/scrolling/overscroll-event-fired-to-element-with-overscroll-behavior.html`,85 // `${BASE}/dom/events/scrolling/overscroll-event-fired-to-scrolled-element.html`,86 // `${BASE}/dom/events/scrolling/overscroll-event-fired-to-window.html`,87 // `${BASE}/dom/events/scrolling/scrollend-event-fired-after-snap.html`,88 // `${BASE}/dom/events/scrolling/scrollend-event-fired-for-programmatic-scroll.html`,89 // `${BASE}/dom/events/scrolling/scrollend-event-fired-for-scrollIntoView.html`,90 // `${BASE}/dom/events/scrolling/scrollend-event-fired-to-document.html`,91 // `${BASE}/dom/events/scrolling/scrollend-event-fired-to-element-with-overscroll-behavior.html`,92 // `${BASE}/dom/events/scrolling/scrollend-event-fired-to-scrolled-element.html`,93 // `${BASE}/dom/events/scrolling/scrollend-event-fired-to-window.html`,94 // `${BASE}/dom/events/scrolling/scrollend-event-for-user-scroll.html`,95 // `${BASE}/dom/events/shadow-relatedTarget.html`,96 // `${BASE}/dom/events/webkit-animation-end-event.html`,97 // `${BASE}/dom/events/webkit-animation-iteration-event.html`,98 // `${BASE}/dom/events/webkit-animation-start-event.html`,99 // `${BASE}/dom/events/webkit-transition-end-event.html`,100 `${BASE}/dom/historical.html`,101 `${BASE}/dom/interface-objects.html`,102 // `${BASE}/dom/lists/DOMTokenList-coverage-for-attributes.html`,103 // `${BASE}/dom/lists/DOMTokenList-Iterable.html`,104 // `${BASE}/dom/lists/DOMTokenList-iteration.html`,105 // `${BASE}/dom/lists/DOMTokenList-stringifier.html`,106 // `${BASE}/dom/lists/DOMTokenList-value.html`,107 // `${BASE}/dom/nodes/append-on-Document.html`,108 // `${BASE}/dom/nodes/aria-attribute-reflection.tentative.html`,109 // `${BASE}/dom/nodes/aria-element-reflection.tentative.html`,110 // `${BASE}/dom/nodes/attributes-namednodemap.html`,111 // `${BASE}/dom/nodes/attributes.html`,112 // `${BASE}/dom/nodes/case.html`,113 // `${BASE}/dom/nodes/CharacterData-appendChild.html`,114 // `${BASE}/dom/nodes/CharacterData-appendData.html`,115 `${BASE}/dom/nodes/CharacterData-data.html`,116 `${BASE}/dom/nodes/CharacterData-deleteData.html`,117 `${BASE}/dom/nodes/CharacterData-insertData.html`,118 // `${BASE}/dom/nodes/CharacterData-remove.html`,119 `${BASE}/dom/nodes/CharacterData-replaceData.html`,120 `${BASE}/dom/nodes/CharacterData-substringData.html`,121 // `${BASE}/dom/nodes/CharacterData-surrogates.html`,122 // `${BASE}/dom/nodes/ChildNode-after.html`,123 // `${BASE}/dom/nodes/ChildNode-before.html`,124 // `${BASE}/dom/nodes/ChildNode-replaceWith.html`,125 // `${BASE}/dom/nodes/Comment-constructor.html`,126 // `${BASE}/dom/nodes/Document-adoptNode.html`,127 // `${BASE}/dom/nodes/Document-characterSet-normalization.html`,128 // `${BASE}/dom/nodes/Document-constructor.html`,129 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_bmp.html`,130 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_css.html`,131 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_datauri_02.html`,132 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_gif.html`,133 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_html.html`,134 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_javascripturi.html`,135 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_jpg.html`,136 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_mimeheader_01.html`,137 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_mimeheader_02.html`,138 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_png.html`,139 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_txt.html`,140 // `${BASE}/dom/nodes/Document-contentType/contentType/contenttype_xml.html`,141 // `${BASE}/dom/nodes/Document-contentType/contentType/createDocument.html`,142 // `${BASE}/dom/nodes/Document-contentType/contentType/createHTMLDocument.html`,143 // `${BASE}/dom/nodes/Document-contentType/contentType/xhr_responseType_document.html`,144 // `${BASE}/dom/nodes/Document-createAttribute.html`,145 // `${BASE}/dom/nodes/Document-createCDATASection.html`,146 // `${BASE}/dom/nodes/Document-createComment.html`,147 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/bare_mathml.html`,148 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/bare_svg.html`,149 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/bare_xhtml.html`,150 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/empty.html`,151 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/mathml.html`,152 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/minimal_html.html`,153 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/svg.html`,154 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/xhtml_ns_changed.html`,155 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/xhtml_ns_removed.html`,156 // `${BASE}/dom/nodes/Document-createElement-namespace-tests/xhtml.html`,157 // `${BASE}/dom/nodes/Document-createElement-namespace.html`,158 // `${BASE}/dom/nodes/Document-createElement.html`,159 // `${BASE}/dom/nodes/Document-createElementNS.html`,160 `${BASE}/dom/nodes/Document-createEvent.https.html`,161 // `${BASE}/dom/nodes/Document-createProcessingInstruction.html`,162 // `${BASE}/dom/nodes/Document-createTextNode.html`,163 // `${BASE}/dom/nodes/Document-createTreeWalker.html`,164 // `${BASE}/dom/nodes/Document-doctype.html`,165 `${BASE}/dom/nodes/Document-getElementById.html`,166 `${BASE}/dom/nodes/Document-getElementsByClassName.html`,167 `${BASE}/dom/nodes/Document-getElementsByTagName.html`,168 `${BASE}/dom/nodes/Document-getElementsByTagNameNS.html`,169 `${BASE}/dom/nodes/Document-implementation.html`,170 // `${BASE}/dom/nodes/Document-importNode.html`,171 // `${BASE}/dom/nodes/Document-URL.html`,172 `${BASE}/dom/nodes/DocumentFragment-constructor.html`,173 // `${BASE}/dom/nodes/DocumentFragment-getElementById.html`,174 // `${BASE}/dom/nodes/DocumentFragment-querySelectorAll-after-modification.html`,175 // `${BASE}/dom/nodes/DocumentType-literal.html`,176 // `${BASE}/dom/nodes/DocumentType-remove.html`,177 // `${BASE}/dom/nodes/DOMImplementation-createDocument-with-null-browsing-context-crash.html`,178 `${BASE}/dom/nodes/DOMImplementation-createDocument.html`,179 // `${BASE}/dom/nodes/DOMImplementation-createDocumentType.html`,180 // `${BASE}/dom/nodes/DOMImplementation-createHTMLDocument-with-null-browsing-context-crash.html`,181 // `${BASE}/dom/nodes/DOMImplementation-createHTMLDocument-with-saved-implementation.html`,182 // `${BASE}/dom/nodes/DOMImplementation-createHTMLDocument.html`,183 // `${BASE}/dom/nodes/DOMImplementation-hasFeature.html`,184 `${BASE}/dom/nodes/Element-childElement-null.html`,185 `${BASE}/dom/nodes/Element-childElementCount-dynamic-add.html`,186 `${BASE}/dom/nodes/Element-childElementCount-dynamic-remove.html`,187 `${BASE}/dom/nodes/Element-childElementCount-nochild.html`,188 `${BASE}/dom/nodes/Element-childElementCount.html`,189 `${BASE}/dom/nodes/Element-children.html`,190 // `${BASE}/dom/nodes/Element-classlist.html`,191 `${BASE}/dom/nodes/Element-closest.html`,192 `${BASE}/dom/nodes/Element-firstElementChild-namespace.html`,193 `${BASE}/dom/nodes/Element-firstElementChild.html`,194 // `${BASE}/dom/nodes/Element-getElementsByClassName.html`,195 // `${BASE}/dom/nodes/Element-getElementsByTagName-change-document-HTMLNess.html`,196 `${BASE}/dom/nodes/Element-getElementsByTagName.html`,197 // `${BASE}/dom/nodes/Element-getElementsByTagNameNS.html`,198 `${BASE}/dom/nodes/Element-hasAttribute.html`,199 `${BASE}/dom/nodes/Element-hasAttributes.html`,200 // `${BASE}/dom/nodes/Element-insertAdjacentElement.html`,201 // `${BASE}/dom/nodes/Element-insertAdjacentText.html`,202 // `${BASE}/dom/nodes/Element-lastElementChild.html`,203 // `${BASE}/dom/nodes/Element-matches-namespaced-elements.html`,204 // `${BASE}/dom/nodes/Element-matches.html`,205 `${BASE}/dom/nodes/Element-nextElementSibling.html`,206 `${BASE}/dom/nodes/Element-previousElementSibling.html`,207 `${BASE}/dom/nodes/Element-remove.html`,208 `${BASE}/dom/nodes/Element-removeAttribute.html`,209 `${BASE}/dom/nodes/Element-removeAttributeNS.html`,210 `${BASE}/dom/nodes/Element-setAttribute-crbug-1138487.html`,211 `${BASE}/dom/nodes/Element-setAttribute.html`,212 `${BASE}/dom/nodes/Element-siblingElement-null.html`,213 `${BASE}/dom/nodes/Element-tagName.html`,214 // `${BASE}/dom/nodes/Element-webkitMatchesSelector.html`,215 // `${BASE}/dom/nodes/getElementsByClassName-32.html`,216 // `${BASE}/dom/nodes/getElementsByClassName-empty-set.html`,217 // `${BASE}/dom/nodes/getElementsByClassName-whitespace-class-names.html`,218 // `${BASE}/dom/nodes/insert-adjacent.html`,219 // `${BASE}/dom/nodes/MutationObserver-attributes.html`,220 // `${BASE}/dom/nodes/MutationObserver-callback-arguments.html`,221 // `${BASE}/dom/nodes/MutationObserver-characterData.html`,222 // `${BASE}/dom/nodes/MutationObserver-childList.html`,223 // `${BASE}/dom/nodes/MutationObserver-disconnect.html`,224 // `${BASE}/dom/nodes/MutationObserver-document.html`,225 // `${BASE}/dom/nodes/MutationObserver-inner-outer.html`,226 // `${BASE}/dom/nodes/MutationObserver-sanity.html`,227 // `${BASE}/dom/nodes/MutationObserver-takeRecords.html`,228 `${BASE}/dom/nodes/Node-appendChild.html`,229 // `${BASE}/dom/nodes/Node-baseURI.html`,230 // `${BASE}/dom/nodes/Node-childNodes.html`,231 // `${BASE}/dom/nodes/Node-cloneNode-document-with-doctype.html`,232 // `${BASE}/dom/nodes/Node-cloneNode-external-stylesheet-no-bc.sub.html`,233 // `${BASE}/dom/nodes/Node-cloneNode-on-inactive-document-crash.html`,234 // `${BASE}/dom/nodes/Node-cloneNode-svg.html`,235 // `${BASE}/dom/nodes/Node-cloneNode-XMLDocument.html`,236 // `${BASE}/dom/nodes/Node-cloneNode.html`,237 // `${BASE}/dom/nodes/Node-compareDocumentPosition.html`,238 `${BASE}/dom/nodes/Node-constants.html`,239 // `${BASE}/dom/nodes/Node-contains.html`,240 // `${BASE}/dom/nodes/Node-insertBefore.html`,241 // `${BASE}/dom/nodes/Node-isConnected-shadow-dom.html`,242 // `${BASE}/dom/nodes/Node-isConnected.html`,243 // `${BASE}/dom/nodes/Node-isEqualNode.html`,244 // `${BASE}/dom/nodes/Node-isSameNode.html`,245 // `${BASE}/dom/nodes/Node-lookupNamespaceURI.html`,246 // `${BASE}/dom/nodes/Node-mutation-adoptNode.html`,247 `${BASE}/dom/nodes/Node-nodeName.html`,248 `${BASE}/dom/nodes/Node-nodeValue.html`,249 // `${BASE}/dom/nodes/Node-normalize.html`,250 `${BASE}/dom/nodes/Node-parentElement.html`,251 // `${BASE}/dom/nodes/Node-parentNode-iframe.html`,252 // `${BASE}/dom/nodes/Node-parentNode.html`,253 // `${BASE}/dom/nodes/Node-properties.html`,254 // `${BASE}/dom/nodes/Node-removeChild.html`,255 // `${BASE}/dom/nodes/Node-replaceChild.html`,256 // `${BASE}/dom/nodes/Node-textContent.html`,257 // `${BASE}/dom/nodes/NodeList-Iterable.html`,258 // `${BASE}/dom/nodes/ParentNode-append.html`,259 // `${BASE}/dom/nodes/ParentNode-children.html`,260 // `${BASE}/dom/nodes/ParentNode-prepend.html`,261 // `${BASE}/dom/nodes/ParentNode-querySelector-All-content.html`,262 // `${BASE}/dom/nodes/ParentNode-querySelector-All.html`,263 // `${BASE}/dom/nodes/ParentNode-querySelector-case-insensitive.html`,264 // `${BASE}/dom/nodes/ParentNode-querySelector-escapes.html`,265 // `${BASE}/dom/nodes/ParentNode-querySelector-scope.html`,266 // `${BASE}/dom/nodes/ParentNode-querySelectorAll-removed-elements.html`,267 // `${BASE}/dom/nodes/ParentNode-querySelectors-exclusive.html`,268 // `${BASE}/dom/nodes/ParentNode-querySelectors-namespaces.html`,269 // `${BASE}/dom/nodes/ParentNode-querySelectors-space-and-dash-attribute-value.html`,270 // `${BASE}/dom/nodes/ParentNode-replaceChildren.html`,271 // `${BASE}/dom/nodes/prepend-on-Document.html`,272 // `${BASE}/dom/nodes/query-target-in-load-event.html`,273 // `${BASE}/dom/nodes/query-target-in-load-event.part.html`,274 // `${BASE}/dom/nodes/remove-and-adopt-thcrash.html`,275 // `${BASE}/dom/nodes/remove-from-shadow-host-and-adopt-into-iframe-ref.html`,276 // `${BASE}/dom/nodes/remove-from-shadow-host-and-adopt-into-iframe.html`,277 // `${BASE}/dom/nodes/remove-unscopable.html`,278 // `${BASE}/dom/nodes/rootNode.html`,279 // `${BASE}/dom/nodes/svg-template-querySelector.html`,280 // `${BASE}/dom/nodes/Text-constructor.html`,281 // `${BASE}/dom/nodes/Text-splitText.html`,282 // `${BASE}/dom/nodes/Text-wholeText.html`,283 // `${BASE}/dom/ranges/Range-adopt-test.html`,284 // `${BASE}/dom/ranges/Range-attributes.html`,285 // `${BASE}/dom/ranges/Range-cloneContents.html`,286 // `${BASE}/dom/ranges/Range-cloneRange.html`,287 // `${BASE}/dom/ranges/Range-collapse.html`,288 // `${BASE}/dom/ranges/Range-commonAncestorContainer-2.html`,289 // `${BASE}/dom/ranges/Range-commonAncestorContainer.html`,290 // `${BASE}/dom/ranges/Range-compareBoundaryPoints.html`,291 // `${BASE}/dom/ranges/Range-comparePoint-2.html`,292 // `${BASE}/dom/ranges/Range-comparePoint.html`,293 // `${BASE}/dom/ranges/Range-constructor.html`,294 // `${BASE}/dom/ranges/Range-deleteContents.html`,295 // `${BASE}/dom/ranges/Range-detach.html`,296 // `${BASE}/dom/ranges/Range-extractContents.html`,297 // `${BASE}/dom/ranges/Range-insertNode.html`,298 // `${BASE}/dom/ranges/Range-intersectsNode-2.html`,299 // `${BASE}/dom/ranges/Range-intersectsNode-binding.html`,300 // `${BASE}/dom/ranges/Range-intersectsNode.html`,301 // `${BASE}/dom/ranges/Range-isPointInRange.html`,302 // `${BASE}/dom/ranges/Range-mutations-appendChild.html`,303 // `${BASE}/dom/ranges/Range-mutations-appendData.html`,304 // `${BASE}/dom/ranges/Range-mutations-dataChange.html`,305 // `${BASE}/dom/ranges/Range-mutations-deleteData.html`,306 // `${BASE}/dom/ranges/Range-mutations-insertBefore.html`,307 // `${BASE}/dom/ranges/Range-mutations-insertData.html`,308 // `${BASE}/dom/ranges/Range-mutations-removeChild.html`,309 // `${BASE}/dom/ranges/Range-mutations-replaceChild.html`,310 // `${BASE}/dom/ranges/Range-mutations-replaceData.html`,311 // `${BASE}/dom/ranges/Range-mutations-splitText.html`,312 // `${BASE}/dom/ranges/Range-selectNode.html`,313 // `${BASE}/dom/ranges/Range-set.html`,314 // `${BASE}/dom/ranges/Range-stringifier.html`,315 // `${BASE}/dom/ranges/Range-surroundContents.html`,316 // `${BASE}/dom/ranges/Range-test-iframe.html`,317 // `${BASE}/dom/ranges/StaticRange-constructor.html`,318 // `${BASE}/dom/slot-recalc-ref.html`,319 // `${BASE}/dom/slot-recalc.html`,320 // `${BASE}/dom/svg-insert-crash.html`,321 // `${BASE}/dom/traversal/NodeFilter-constants.html`,322 // `${BASE}/dom/traversal/NodeIterator-removal.html`,323 // `${BASE}/dom/traversal/NodeIterator.html`,324 // `${BASE}/dom/traversal/TreeWalker-acceptNode-filter.html`,325 // `${BASE}/dom/traversal/TreeWalker-basic.html`,326 // `${BASE}/dom/traversal/TreeWalker-currentNode.html`,327 // `${BASE}/dom/traversal/TreeWalker-previousNodeLastChildReject.html`,328 // `${BASE}/dom/traversal/TreeWalker-previousSiblingLastChildSkip.html`,329 // `${BASE}/dom/traversal/TreeWalker-traversal-reject.html`,330 // `${BASE}/dom/traversal/TreeWalker-traversal-skip-most.html`,331 // `${BASE}/dom/traversal/TreeWalker-traversal-skip.html`,332 // `${BASE}/dom/traversal/TreeWalker-walking-outside-a-tree.html`,333 // `${BASE}/dom/traversal/TreeWalker.html`,334 // `${BASE}/dom/window-extends-event-target.html`,335]336for (const url of urls) {337 console.log('running', url)338 await runner.loadURL(url)339 await new Promise(resolve => setTimeout(resolve, 100))340 const summary = await runner.eval(`document.querySelector("#log > section")?.textContent`)341 if (summary?.match(/Fail/)) {342 console.log(await runner.eval(`document.querySelector("#log")?.textContent`))343 console.log('failed, waiting')344 await new Promise(resolve => setTimeout(resolve, 5000))345 }346 console.log(summary)347 console.log('---')...

Full Screen

Full Screen

pattern_test.js

Source:pattern_test.js Github

copy

Full Screen

1// Copyright 2007 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14goog.provide('goog.dom.patternTest');15goog.setTestOnly('goog.dom.patternTest');16goog.require('goog.dom');17goog.require('goog.dom.NodeType');18goog.require('goog.dom.TagWalkType');19goog.require('goog.dom.pattern.AllChildren');20goog.require('goog.dom.pattern.ChildMatches');21goog.require('goog.dom.pattern.EndTag');22goog.require('goog.dom.pattern.FullTag');23goog.require('goog.dom.pattern.MatchType');24goog.require('goog.dom.pattern.NodeType');25goog.require('goog.dom.pattern.Repeat');26goog.require('goog.dom.pattern.Sequence');27goog.require('goog.dom.pattern.StartTag');28goog.require('goog.dom.pattern.Text');29goog.require('goog.testing.jsunit');30// TODO(robbyw): write a test that checks if backtracking works in Sequence31function testStartTag() {32 var pattern = new goog.dom.pattern.StartTag('DIV');33 assertEquals(34 'StartTag(div) should match div',35 goog.dom.pattern.MatchType.MATCH,36 pattern.matchToken(37 goog.dom.getElement('div1'),38 goog.dom.TagWalkType.START_TAG));39 assertEquals(40 'StartTag(div) should not match span',41 goog.dom.pattern.MatchType.NO_MATCH,42 pattern.matchToken(43 goog.dom.getElement('span1'),44 goog.dom.TagWalkType.START_TAG));45 assertEquals(46 'StartTag(div) should not match /div',47 goog.dom.pattern.MatchType.NO_MATCH,48 pattern.matchToken(49 goog.dom.getElement('div1'),50 goog.dom.TagWalkType.END_TAG));51}52function testStartTagCase() {53 var pattern = new goog.dom.pattern.StartTag('diV');54 assertEquals(55 'StartTag(diV) should match div',56 goog.dom.pattern.MatchType.MATCH,57 pattern.matchToken(58 goog.dom.getElement('div1'),59 goog.dom.TagWalkType.START_TAG));60 assertEquals(61 'StartTag(diV) should not match span',62 goog.dom.pattern.MatchType.NO_MATCH,63 pattern.matchToken(64 goog.dom.getElement('span1'),65 goog.dom.TagWalkType.START_TAG));66}67function testStartTagRegex() {68 var pattern = new goog.dom.pattern.StartTag(/D/);69 assertEquals(70 'StartTag(/D/) should match div',71 goog.dom.pattern.MatchType.MATCH,72 pattern.matchToken(73 goog.dom.getElement('div1'),74 goog.dom.TagWalkType.START_TAG));75 assertEquals(76 'StartTag(/D/) should not match span',77 goog.dom.pattern.MatchType.NO_MATCH,78 pattern.matchToken(79 goog.dom.getElement('span1'),80 goog.dom.TagWalkType.START_TAG));81 assertEquals(82 'StartTag(/D/) should not match /div',83 goog.dom.pattern.MatchType.NO_MATCH,84 pattern.matchToken(85 goog.dom.getElement('div1'),86 goog.dom.TagWalkType.END_TAG));87}88function testStartTagAttributes() {89 var pattern = new goog.dom.pattern.StartTag('DIV', {id: 'div1'});90 assertEquals(91 'StartTag(div,id:div1) should match div1',92 goog.dom.pattern.MatchType.MATCH,93 pattern.matchToken(94 goog.dom.getElement('div1'),95 goog.dom.TagWalkType.START_TAG));96 assertEquals('StartTag(div,id:div2) should not match div1',97 goog.dom.pattern.MatchType.NO_MATCH,98 pattern.matchToken(99 goog.dom.getElement('div2'),100 goog.dom.TagWalkType.START_TAG));101}102function testStartTagStyle() {103 var pattern = new goog.dom.pattern.StartTag('SPAN', null, {color: 'red'});104 assertEquals(105 'StartTag(span,null,color:red) should match span1',106 goog.dom.pattern.MatchType.MATCH,107 pattern.matchToken(108 goog.dom.getElement('span1'),109 goog.dom.TagWalkType.START_TAG));110 assertEquals(111 'StartTag(span,null,color:blue) should not match span1',112 goog.dom.pattern.MatchType.NO_MATCH,113 pattern.matchToken(114 goog.dom.getElement('span2'),115 goog.dom.TagWalkType.START_TAG));116}117function testStartTagAttributeRegex() {118 var pattern = new goog.dom.pattern.StartTag('SPAN', {id: /span\d/});119 assertEquals(120 'StartTag(span,id:/span\\d/) should match span1',121 goog.dom.pattern.MatchType.MATCH,122 pattern.matchToken(123 goog.dom.getElement('span1'),124 goog.dom.TagWalkType.START_TAG));125 assertEquals(126 'StartTag(span,id:/span\\d/) should match span2',127 goog.dom.pattern.MatchType.MATCH,128 pattern.matchToken(129 goog.dom.getElement('span1'),130 goog.dom.TagWalkType.START_TAG));131}132function testEndTag() {133 var pattern = new goog.dom.pattern.EndTag('DIV');134 assertEquals(135 'EndTag should match div',136 goog.dom.pattern.MatchType.MATCH,137 pattern.matchToken(138 goog.dom.getElement('div1'),139 goog.dom.TagWalkType.END_TAG));140}141function testEndTagRegex() {142 var pattern = new goog.dom.pattern.EndTag(/D/);143 assertEquals(144 'EndTag(/D/) should match /div',145 goog.dom.pattern.MatchType.MATCH,146 pattern.matchToken(147 goog.dom.getElement('div1'),148 goog.dom.TagWalkType.END_TAG));149 assertEquals(150 'EndTag(/D/) should not match /span',151 goog.dom.pattern.MatchType.NO_MATCH,152 pattern.matchToken(153 goog.dom.getElement('span1'),154 goog.dom.TagWalkType.END_TAG));155 assertEquals(156 'EndTag(/D/) should not match div',157 goog.dom.pattern.MatchType.NO_MATCH,158 pattern.matchToken(159 goog.dom.getElement('div1'),160 goog.dom.TagWalkType.START_TAG));161}162function testChildMatches() {163 var pattern = new goog.dom.pattern.ChildMatches(164 new goog.dom.pattern.StartTag('DIV'), 2);165 assertEquals(166 'ChildMatches should match div',167 goog.dom.pattern.MatchType.MATCHING,168 pattern.matchToken(169 goog.dom.getElement('div1'),170 goog.dom.TagWalkType.START_TAG));171 assertEquals(172 'ChildMatches should match /div',173 goog.dom.pattern.MatchType.MATCHING,174 pattern.matchToken(175 goog.dom.getElement('div1'),176 goog.dom.TagWalkType.END_TAG));177 assertEquals(178 'ChildMatches should match div',179 goog.dom.pattern.MatchType.MATCHING,180 pattern.matchToken(181 goog.dom.getElement('div2'),182 goog.dom.TagWalkType.START_TAG));183 assertEquals(184 'ChildMatches should match /div',185 goog.dom.pattern.MatchType.MATCHING,186 pattern.matchToken(187 goog.dom.getElement('div2'),188 goog.dom.TagWalkType.END_TAG));189 assertEquals(190 'ChildMatches should finish match at /body',191 goog.dom.pattern.MatchType.BACKTRACK_MATCH,192 pattern.matchToken(193 document.body,194 goog.dom.TagWalkType.END_TAG));195 assertEquals(196 'ChildMatches should match div',197 goog.dom.pattern.MatchType.MATCHING,198 pattern.matchToken(199 goog.dom.getElement('div2'),200 goog.dom.TagWalkType.START_TAG));201 assertEquals(202 'ChildMatches should match /div',203 goog.dom.pattern.MatchType.MATCHING,204 pattern.matchToken(205 goog.dom.getElement('div2'),206 goog.dom.TagWalkType.END_TAG));207 assertEquals(208 'ChildMatches should fail to match at /body: not enough child matches',209 goog.dom.pattern.MatchType.NO_MATCH,210 pattern.matchToken(211 document.body,212 goog.dom.TagWalkType.END_TAG));213}214function testFullTag() {215 var pattern = new goog.dom.pattern.FullTag('DIV');216 assertEquals(217 'FullTag(div) should match div',218 goog.dom.pattern.MatchType.MATCHING,219 pattern.matchToken(220 goog.dom.getElement('div1'),221 goog.dom.TagWalkType.START_TAG));222 assertEquals(223 'FullTag(div) should match /div',224 goog.dom.pattern.MatchType.MATCH,225 pattern.matchToken(226 goog.dom.getElement('div1'),227 goog.dom.TagWalkType.END_TAG));228 assertEquals(229 'FullTag(div) should start match at div',230 goog.dom.pattern.MatchType.MATCHING,231 pattern.matchToken(232 goog.dom.getElement('div1'),233 goog.dom.TagWalkType.START_TAG));234 assertEquals(235 'FullTag(div) should continue to match span',236 goog.dom.pattern.MatchType.MATCHING,237 pattern.matchToken(238 goog.dom.getElement('span1'),239 goog.dom.TagWalkType.START_TAG));240 assertEquals(241 'FullTag(div) should continue to match /span',242 goog.dom.pattern.MatchType.MATCHING,243 pattern.matchToken(244 goog.dom.getElement('span1'),245 goog.dom.TagWalkType.END_TAG));246 assertEquals(247 'FullTag(div) should finish match at /div',248 goog.dom.pattern.MatchType.MATCH,249 pattern.matchToken(250 goog.dom.getElement('div1'),251 goog.dom.TagWalkType.END_TAG));252}253function testAllChildren() {254 var pattern = new goog.dom.pattern.AllChildren();255 assertEquals(256 'AllChildren(div) should match div',257 goog.dom.pattern.MatchType.MATCHING,258 pattern.matchToken(259 goog.dom.getElement('div1'),260 goog.dom.TagWalkType.START_TAG));261 assertEquals(262 'AllChildren(div) should match /div',263 goog.dom.pattern.MatchType.MATCHING,264 pattern.matchToken(265 goog.dom.getElement('div1'),266 goog.dom.TagWalkType.END_TAG));267 assertEquals(268 'AllChildren(div) should match at /body',269 goog.dom.pattern.MatchType.BACKTRACK_MATCH,270 pattern.matchToken(271 document.body,272 goog.dom.TagWalkType.END_TAG));273 assertEquals(274 'AllChildren(div) should start match at div',275 goog.dom.pattern.MatchType.MATCHING,276 pattern.matchToken(277 goog.dom.getElement('div1'),278 goog.dom.TagWalkType.START_TAG));279 assertEquals(280 'AllChildren(div) should continue to match span',281 goog.dom.pattern.MatchType.MATCHING,282 pattern.matchToken(283 goog.dom.getElement('span1'),284 goog.dom.TagWalkType.START_TAG));285 assertEquals(286 'AllChildren(div) should continue to match /span',287 goog.dom.pattern.MatchType.MATCHING,288 pattern.matchToken(289 goog.dom.getElement('span1'),290 goog.dom.TagWalkType.END_TAG));291 assertEquals(292 'AllChildren(div) should continue to match at /div',293 goog.dom.pattern.MatchType.MATCHING,294 pattern.matchToken(295 goog.dom.getElement('div1'),296 goog.dom.TagWalkType.END_TAG));297 assertEquals(298 'AllChildren(div) should finish match at /body',299 goog.dom.pattern.MatchType.BACKTRACK_MATCH,300 pattern.matchToken(301 document.body,302 goog.dom.TagWalkType.END_TAG));303}304function testText() {305 var pattern = new goog.dom.pattern.Text('Text');306 assertEquals(307 'Text should match div3/text()',308 goog.dom.pattern.MatchType.MATCH,309 pattern.matchToken(310 goog.dom.getElement('div3').firstChild,311 goog.dom.TagWalkType.OTHER));312 assertEquals(313 'Text should not match div4/text()',314 goog.dom.pattern.MatchType.NO_MATCH,315 pattern.matchToken(316 goog.dom.getElement('div4').firstChild,317 goog.dom.TagWalkType.OTHER));318 assertEquals(319 'Text should not match div3',320 goog.dom.pattern.MatchType.NO_MATCH,321 pattern.matchToken(322 goog.dom.getElement('div3'),323 goog.dom.TagWalkType.START_TAG));324}325function testTextRegex() {326 var pattern = new goog.dom.pattern.Text(/Text/);327 assertEquals(328 'Text(regex) should match div3/text()',329 goog.dom.pattern.MatchType.MATCH,330 pattern.matchToken(331 goog.dom.getElement('div3').firstChild,332 goog.dom.TagWalkType.OTHER));333 assertEquals(334 'Text(regex) should match div4/text()',335 goog.dom.pattern.MatchType.MATCH,336 pattern.matchToken(337 goog.dom.getElement('div4').firstChild,338 goog.dom.TagWalkType.OTHER));339}340function testNodeType() {341 var pattern = new goog.dom.pattern.NodeType(goog.dom.NodeType.COMMENT);342 assertEquals('Comment matcher should match a comment',343 goog.dom.pattern.MatchType.MATCH,344 pattern.matchToken(345 goog.dom.getElement('nodeTypes').firstChild,346 goog.dom.TagWalkType.OTHER));347 assertEquals('Comment matcher should not match a text node',348 goog.dom.pattern.MatchType.NO_MATCH,349 pattern.matchToken(350 goog.dom.getElement('nodeTypes').lastChild,351 goog.dom.TagWalkType.OTHER));352}353function testSequence() {354 var pattern = new goog.dom.pattern.Sequence([355 new goog.dom.pattern.StartTag('DIV'),356 new goog.dom.pattern.StartTag('SPAN'),357 new goog.dom.pattern.EndTag('SPAN'),358 new goog.dom.pattern.EndTag('DIV')]);359 assertEquals(360 'Sequence[0] should match div1',361 goog.dom.pattern.MatchType.MATCHING,362 pattern.matchToken(363 goog.dom.getElement('div1'),364 goog.dom.TagWalkType.START_TAG));365 assertEquals(366 'Sequence[1] should match span1',367 goog.dom.pattern.MatchType.MATCHING,368 pattern.matchToken(369 goog.dom.getElement('span1'),370 goog.dom.TagWalkType.START_TAG));371 assertEquals(372 'Sequence[2] should match /span1',373 goog.dom.pattern.MatchType.MATCHING,374 pattern.matchToken(375 goog.dom.getElement('span1'),376 goog.dom.TagWalkType.END_TAG));377 assertEquals(378 'Sequence[3] should match /div1',379 goog.dom.pattern.MatchType.MATCH,380 pattern.matchToken(381 goog.dom.getElement('div1'),382 goog.dom.TagWalkType.END_TAG));383 assertEquals(384 'Sequence[0] should match div1 again',385 goog.dom.pattern.MatchType.MATCHING,386 pattern.matchToken(387 goog.dom.getElement('div1'),388 goog.dom.TagWalkType.START_TAG));389 assertEquals(390 'Sequence[1] should match span1 again',391 goog.dom.pattern.MatchType.MATCHING,392 pattern.matchToken(393 goog.dom.getElement('span1'),394 goog.dom.TagWalkType.START_TAG));395 assertEquals(396 'Sequence[2] should match /span1 again',397 goog.dom.pattern.MatchType.MATCHING,398 pattern.matchToken(399 goog.dom.getElement('span1'),400 goog.dom.TagWalkType.END_TAG));401 assertEquals(402 'Sequence[3] should match /div1 again',403 goog.dom.pattern.MatchType.MATCH,404 pattern.matchToken(405 goog.dom.getElement('div1'),406 goog.dom.TagWalkType.END_TAG));407 assertEquals(408 'Sequence[0] should match div1',409 goog.dom.pattern.MatchType.MATCHING,410 pattern.matchToken(411 goog.dom.getElement('div1'),412 goog.dom.TagWalkType.START_TAG));413 assertEquals(414 'Sequence[1] should not match div1',415 goog.dom.pattern.MatchType.NO_MATCH,416 pattern.matchToken(417 goog.dom.getElement('div1'),418 goog.dom.TagWalkType.START_TAG));419 assertEquals(420 'Sequence[0] should match div1 after failure',421 goog.dom.pattern.MatchType.MATCHING,422 pattern.matchToken(423 goog.dom.getElement('div1'),424 goog.dom.TagWalkType.START_TAG));425 assertEquals(426 'Sequence[1] should match span1 after failure',427 goog.dom.pattern.MatchType.MATCHING,428 pattern.matchToken(429 goog.dom.getElement('span1'),430 goog.dom.TagWalkType.START_TAG));431 assertEquals(432 'Sequence[2] should match /span1 after failure',433 goog.dom.pattern.MatchType.MATCHING,434 pattern.matchToken(435 goog.dom.getElement('span1'),436 goog.dom.TagWalkType.END_TAG));437 assertEquals(438 'Sequence[3] should match /div1 after failure',439 goog.dom.pattern.MatchType.MATCH,440 pattern.matchToken(441 goog.dom.getElement('div1'),442 goog.dom.TagWalkType.END_TAG));443}444function testRepeat() {445 var pattern = new goog.dom.pattern.Repeat(446 new goog.dom.pattern.StartTag('B'));447 // Note: this test does not mimic an actual matcher because it is only448 // passing the START_TAG events.449 assertEquals(450 'Repeat[B] should match b1',451 goog.dom.pattern.MatchType.MATCHING,452 pattern.matchToken(453 goog.dom.getElement('b1'),454 goog.dom.TagWalkType.START_TAG));455 assertEquals(456 'Repeat[B] should match b2',457 goog.dom.pattern.MatchType.MATCHING,458 pattern.matchToken(459 goog.dom.getElement('b2'),460 goog.dom.TagWalkType.START_TAG));461 assertEquals(462 'Repeat[B] should backtrack match i1',463 goog.dom.pattern.MatchType.BACKTRACK_MATCH,464 pattern.matchToken(465 goog.dom.getElement('i1'),466 goog.dom.TagWalkType.START_TAG));467 assertEquals(468 'Repeat[B] should have match count of 2',469 2,470 pattern.count);471 assertEquals(472 'Repeat[B] should backtrack match i1 even with no b matches',473 goog.dom.pattern.MatchType.BACKTRACK_MATCH,474 pattern.matchToken(475 goog.dom.getElement('i1'),476 goog.dom.TagWalkType.START_TAG));477 assertEquals(478 'Repeat[B] should have match count of 0',479 0,480 pattern.count);481}482function testRepeatWithMinimum() {483 var pattern = new goog.dom.pattern.Repeat(484 new goog.dom.pattern.StartTag('B'), 1);485 // Note: this test does not mimic an actual matcher because it is only486 // passing the START_TAG events.487 assertEquals(488 'Repeat[B,1] should match b1',489 goog.dom.pattern.MatchType.MATCHING,490 pattern.matchToken(491 goog.dom.getElement('b1'),492 goog.dom.TagWalkType.START_TAG));493 assertEquals(494 'Repeat[B,1] should match b2',495 goog.dom.pattern.MatchType.MATCHING,496 pattern.matchToken(497 goog.dom.getElement('b2'),498 goog.dom.TagWalkType.START_TAG));499 assertEquals(500 'Repeat[B,1] should backtrack match i1',501 goog.dom.pattern.MatchType.BACKTRACK_MATCH,502 pattern.matchToken(503 goog.dom.getElement('i1'),504 goog.dom.TagWalkType.START_TAG));505 assertEquals(506 'Repeat[B,1] should have match count of 2',507 2,508 pattern.count);509 assertEquals(510 'Repeat[B,1] should not match i1',511 goog.dom.pattern.MatchType.NO_MATCH,512 pattern.matchToken(513 goog.dom.getElement('i1'),514 goog.dom.TagWalkType.START_TAG));515}516function testRepeatWithMaximum() {517 var pattern = new goog.dom.pattern.Repeat(518 new goog.dom.pattern.StartTag('B'), 1, 1);519 // Note: this test does not mimic an actual matcher because it is only520 // passing the START_TAG events.521 assertEquals(522 'Repeat[B,1] should match b1',523 goog.dom.pattern.MatchType.MATCH,524 pattern.matchToken(525 goog.dom.getElement('b1'),526 goog.dom.TagWalkType.START_TAG));527}528function testSequenceBacktrack() {529 var pattern = new goog.dom.pattern.Sequence([530 new goog.dom.pattern.Repeat(new goog.dom.pattern.StartTag('SPAN')),531 new goog.dom.pattern.Text('X')]);532 var root = goog.dom.getElement('span3');533 assertEquals(534 'Sequence[Repeat[SPAN],"X"] should match span3',535 goog.dom.pattern.MatchType.MATCHING,536 pattern.matchToken(root, goog.dom.TagWalkType.START_TAG));537 assertEquals(538 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild',539 goog.dom.pattern.MatchType.MATCHING,540 pattern.matchToken(root.firstChild,541 goog.dom.TagWalkType.START_TAG));542 assertEquals(543 'Sequence[Repeat[SPAN],"X"] should match span3.firstChild.firstChild',544 goog.dom.pattern.MatchType.MATCHING,545 pattern.matchToken(root.firstChild.firstChild,546 goog.dom.TagWalkType.START_TAG));547 assertEquals(548 'Sequence[Repeat[SPAN],"X"] should finish match text node',549 goog.dom.pattern.MatchType.MATCH,550 pattern.matchToken(root.firstChild.firstChild.firstChild,551 goog.dom.TagWalkType.OTHER));...

Full Screen

Full Screen

tagname.js

Source:tagname.js Github

copy

Full Screen

1// Copyright 2007 The Closure Library Authors. All Rights Reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS-IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.14/**15 * @fileoverview Defines the goog.dom.TagName class. Its constants enumerate16 * all HTML tag names specified in either the W3C HTML 4.01 index of elements17 * or the HTML5.1 specification.18 *19 * References:20 * https://www.w3.org/TR/html401/index/elements.html21 * https://www.w3.org/TR/html51/dom.html#elements22 */23goog.provide('goog.dom.TagName');24goog.require('goog.dom.HtmlElement');25/**26 * A tag name with the type of the element stored in the generic.27 * @param {string} tagName28 * @constructor29 * @template T30 */31goog.dom.TagName = function(tagName) {32 /** @private {string} */33 this.tagName_ = tagName;34};35/**36 * Returns the tag name.37 * @return {string}38 * @override39 */40goog.dom.TagName.prototype.toString = function() {41 return this.tagName_;42};43// Closure Compiler unconditionally converts the following constants to their44// string value (goog.dom.TagName.A -> 'A'). These are the consequences:45// 1. Don't add any members or static members to goog.dom.TagName as they46// couldn't be accessed after this optimization.47// 2. Keep the constant name and its string value the same:48// goog.dom.TagName.X = new goog.dom.TagName('Y');49// is converted to 'X', not 'Y'.50/** @type {!goog.dom.TagName<!HTMLAnchorElement>} */51goog.dom.TagName.A = new goog.dom.TagName('A');52/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */53goog.dom.TagName.ABBR = new goog.dom.TagName('ABBR');54/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */55goog.dom.TagName.ACRONYM = new goog.dom.TagName('ACRONYM');56/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */57goog.dom.TagName.ADDRESS = new goog.dom.TagName('ADDRESS');58/** @type {!goog.dom.TagName<!HTMLAppletElement>} */59goog.dom.TagName.APPLET = new goog.dom.TagName('APPLET');60/** @type {!goog.dom.TagName<!HTMLAreaElement>} */61goog.dom.TagName.AREA = new goog.dom.TagName('AREA');62/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */63goog.dom.TagName.ARTICLE = new goog.dom.TagName('ARTICLE');64/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */65goog.dom.TagName.ASIDE = new goog.dom.TagName('ASIDE');66/** @type {!goog.dom.TagName<!HTMLAudioElement>} */67goog.dom.TagName.AUDIO = new goog.dom.TagName('AUDIO');68/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */69goog.dom.TagName.B = new goog.dom.TagName('B');70/** @type {!goog.dom.TagName<!HTMLBaseElement>} */71goog.dom.TagName.BASE = new goog.dom.TagName('BASE');72/** @type {!goog.dom.TagName<!HTMLBaseFontElement>} */73goog.dom.TagName.BASEFONT = new goog.dom.TagName('BASEFONT');74/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */75goog.dom.TagName.BDI = new goog.dom.TagName('BDI');76/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */77goog.dom.TagName.BDO = new goog.dom.TagName('BDO');78/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */79goog.dom.TagName.BIG = new goog.dom.TagName('BIG');80/** @type {!goog.dom.TagName<!HTMLQuoteElement>} */81goog.dom.TagName.BLOCKQUOTE = new goog.dom.TagName('BLOCKQUOTE');82/** @type {!goog.dom.TagName<!HTMLBodyElement>} */83goog.dom.TagName.BODY = new goog.dom.TagName('BODY');84/** @type {!goog.dom.TagName<!HTMLBRElement>} */85goog.dom.TagName.BR = new goog.dom.TagName('BR');86/** @type {!goog.dom.TagName<!HTMLButtonElement>} */87goog.dom.TagName.BUTTON = new goog.dom.TagName('BUTTON');88/** @type {!goog.dom.TagName<!HTMLCanvasElement>} */89goog.dom.TagName.CANVAS = new goog.dom.TagName('CANVAS');90/** @type {!goog.dom.TagName<!HTMLTableCaptionElement>} */91goog.dom.TagName.CAPTION = new goog.dom.TagName('CAPTION');92/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */93goog.dom.TagName.CENTER = new goog.dom.TagName('CENTER');94/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */95goog.dom.TagName.CITE = new goog.dom.TagName('CITE');96/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */97goog.dom.TagName.CODE = new goog.dom.TagName('CODE');98/** @type {!goog.dom.TagName<!HTMLTableColElement>} */99goog.dom.TagName.COL = new goog.dom.TagName('COL');100/** @type {!goog.dom.TagName<!HTMLTableColElement>} */101goog.dom.TagName.COLGROUP = new goog.dom.TagName('COLGROUP');102/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */103goog.dom.TagName.COMMAND = new goog.dom.TagName('COMMAND');104/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */105goog.dom.TagName.DATA = new goog.dom.TagName('DATA');106/** @type {!goog.dom.TagName<!HTMLDataListElement>} */107goog.dom.TagName.DATALIST = new goog.dom.TagName('DATALIST');108/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */109goog.dom.TagName.DD = new goog.dom.TagName('DD');110/** @type {!goog.dom.TagName<!HTMLModElement>} */111goog.dom.TagName.DEL = new goog.dom.TagName('DEL');112/** @type {!goog.dom.TagName<!HTMLDetailsElement>} */113goog.dom.TagName.DETAILS = new goog.dom.TagName('DETAILS');114/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */115goog.dom.TagName.DFN = new goog.dom.TagName('DFN');116/** @type {!goog.dom.TagName<!HTMLDialogElement>} */117goog.dom.TagName.DIALOG = new goog.dom.TagName('DIALOG');118/** @type {!goog.dom.TagName<!HTMLDirectoryElement>} */119goog.dom.TagName.DIR = new goog.dom.TagName('DIR');120/** @type {!goog.dom.TagName<!HTMLDivElement>} */121goog.dom.TagName.DIV = new goog.dom.TagName('DIV');122/** @type {!goog.dom.TagName<!HTMLDListElement>} */123goog.dom.TagName.DL = new goog.dom.TagName('DL');124/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */125goog.dom.TagName.DT = new goog.dom.TagName('DT');126/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */127goog.dom.TagName.EM = new goog.dom.TagName('EM');128/** @type {!goog.dom.TagName<!HTMLEmbedElement>} */129goog.dom.TagName.EMBED = new goog.dom.TagName('EMBED');130/** @type {!goog.dom.TagName<!HTMLFieldSetElement>} */131goog.dom.TagName.FIELDSET = new goog.dom.TagName('FIELDSET');132/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */133goog.dom.TagName.FIGCAPTION = new goog.dom.TagName('FIGCAPTION');134/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */135goog.dom.TagName.FIGURE = new goog.dom.TagName('FIGURE');136/** @type {!goog.dom.TagName<!HTMLFontElement>} */137goog.dom.TagName.FONT = new goog.dom.TagName('FONT');138/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */139goog.dom.TagName.FOOTER = new goog.dom.TagName('FOOTER');140/** @type {!goog.dom.TagName<!HTMLFormElement>} */141goog.dom.TagName.FORM = new goog.dom.TagName('FORM');142/** @type {!goog.dom.TagName<!HTMLFrameElement>} */143goog.dom.TagName.FRAME = new goog.dom.TagName('FRAME');144/** @type {!goog.dom.TagName<!HTMLFrameSetElement>} */145goog.dom.TagName.FRAMESET = new goog.dom.TagName('FRAMESET');146/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */147goog.dom.TagName.H1 = new goog.dom.TagName('H1');148/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */149goog.dom.TagName.H2 = new goog.dom.TagName('H2');150/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */151goog.dom.TagName.H3 = new goog.dom.TagName('H3');152/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */153goog.dom.TagName.H4 = new goog.dom.TagName('H4');154/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */155goog.dom.TagName.H5 = new goog.dom.TagName('H5');156/** @type {!goog.dom.TagName<!HTMLHeadingElement>} */157goog.dom.TagName.H6 = new goog.dom.TagName('H6');158/** @type {!goog.dom.TagName<!HTMLHeadElement>} */159goog.dom.TagName.HEAD = new goog.dom.TagName('HEAD');160/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */161goog.dom.TagName.HEADER = new goog.dom.TagName('HEADER');162/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */163goog.dom.TagName.HGROUP = new goog.dom.TagName('HGROUP');164/** @type {!goog.dom.TagName<!HTMLHRElement>} */165goog.dom.TagName.HR = new goog.dom.TagName('HR');166/** @type {!goog.dom.TagName<!HTMLHtmlElement>} */167goog.dom.TagName.HTML = new goog.dom.TagName('HTML');168/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */169goog.dom.TagName.I = new goog.dom.TagName('I');170/** @type {!goog.dom.TagName<!HTMLIFrameElement>} */171goog.dom.TagName.IFRAME = new goog.dom.TagName('IFRAME');172/** @type {!goog.dom.TagName<!HTMLImageElement>} */173goog.dom.TagName.IMG = new goog.dom.TagName('IMG');174/** @type {!goog.dom.TagName<!HTMLInputElement>} */175goog.dom.TagName.INPUT = new goog.dom.TagName('INPUT');176/** @type {!goog.dom.TagName<!HTMLModElement>} */177goog.dom.TagName.INS = new goog.dom.TagName('INS');178/** @type {!goog.dom.TagName<!HTMLIsIndexElement>} */179goog.dom.TagName.ISINDEX = new goog.dom.TagName('ISINDEX');180/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */181goog.dom.TagName.KBD = new goog.dom.TagName('KBD');182// HTMLKeygenElement is deprecated.183/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */184goog.dom.TagName.KEYGEN = new goog.dom.TagName('KEYGEN');185/** @type {!goog.dom.TagName<!HTMLLabelElement>} */186goog.dom.TagName.LABEL = new goog.dom.TagName('LABEL');187/** @type {!goog.dom.TagName<!HTMLLegendElement>} */188goog.dom.TagName.LEGEND = new goog.dom.TagName('LEGEND');189/** @type {!goog.dom.TagName<!HTMLLIElement>} */190goog.dom.TagName.LI = new goog.dom.TagName('LI');191/** @type {!goog.dom.TagName<!HTMLLinkElement>} */192goog.dom.TagName.LINK = new goog.dom.TagName('LINK');193/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */194goog.dom.TagName.MAIN = new goog.dom.TagName('MAIN');195/** @type {!goog.dom.TagName<!HTMLMapElement>} */196goog.dom.TagName.MAP = new goog.dom.TagName('MAP');197/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */198goog.dom.TagName.MARK = new goog.dom.TagName('MARK');199/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */200goog.dom.TagName.MATH = new goog.dom.TagName('MATH');201/** @type {!goog.dom.TagName<!HTMLMenuElement>} */202goog.dom.TagName.MENU = new goog.dom.TagName('MENU');203/** @type {!goog.dom.TagName<!HTMLMenuItemElement>} */204goog.dom.TagName.MENUITEM = new goog.dom.TagName('MENUITEM');205/** @type {!goog.dom.TagName<!HTMLMetaElement>} */206goog.dom.TagName.META = new goog.dom.TagName('META');207/** @type {!goog.dom.TagName<!HTMLMeterElement>} */208goog.dom.TagName.METER = new goog.dom.TagName('METER');209/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */210goog.dom.TagName.NAV = new goog.dom.TagName('NAV');211/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */212goog.dom.TagName.NOFRAMES = new goog.dom.TagName('NOFRAMES');213/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */214goog.dom.TagName.NOSCRIPT = new goog.dom.TagName('NOSCRIPT');215/** @type {!goog.dom.TagName<!HTMLObjectElement>} */216goog.dom.TagName.OBJECT = new goog.dom.TagName('OBJECT');217/** @type {!goog.dom.TagName<!HTMLOListElement>} */218goog.dom.TagName.OL = new goog.dom.TagName('OL');219/** @type {!goog.dom.TagName<!HTMLOptGroupElement>} */220goog.dom.TagName.OPTGROUP = new goog.dom.TagName('OPTGROUP');221/** @type {!goog.dom.TagName<!HTMLOptionElement>} */222goog.dom.TagName.OPTION = new goog.dom.TagName('OPTION');223/** @type {!goog.dom.TagName<!HTMLOutputElement>} */224goog.dom.TagName.OUTPUT = new goog.dom.TagName('OUTPUT');225/** @type {!goog.dom.TagName<!HTMLParagraphElement>} */226goog.dom.TagName.P = new goog.dom.TagName('P');227/** @type {!goog.dom.TagName<!HTMLParamElement>} */228goog.dom.TagName.PARAM = new goog.dom.TagName('PARAM');229/** @type {!goog.dom.TagName<!HTMLPictureElement>} */230goog.dom.TagName.PICTURE = new goog.dom.TagName('PICTURE');231/** @type {!goog.dom.TagName<!HTMLPreElement>} */232goog.dom.TagName.PRE = new goog.dom.TagName('PRE');233/** @type {!goog.dom.TagName<!HTMLProgressElement>} */234goog.dom.TagName.PROGRESS = new goog.dom.TagName('PROGRESS');235/** @type {!goog.dom.TagName<!HTMLQuoteElement>} */236goog.dom.TagName.Q = new goog.dom.TagName('Q');237/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */238goog.dom.TagName.RP = new goog.dom.TagName('RP');239/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */240goog.dom.TagName.RT = new goog.dom.TagName('RT');241/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */242goog.dom.TagName.RTC = new goog.dom.TagName('RTC');243/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */244goog.dom.TagName.RUBY = new goog.dom.TagName('RUBY');245/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */246goog.dom.TagName.S = new goog.dom.TagName('S');247/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */248goog.dom.TagName.SAMP = new goog.dom.TagName('SAMP');249/** @type {!goog.dom.TagName<!HTMLScriptElement>} */250goog.dom.TagName.SCRIPT = new goog.dom.TagName('SCRIPT');251/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */252goog.dom.TagName.SECTION = new goog.dom.TagName('SECTION');253/** @type {!goog.dom.TagName<!HTMLSelectElement>} */254goog.dom.TagName.SELECT = new goog.dom.TagName('SELECT');255/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */256goog.dom.TagName.SMALL = new goog.dom.TagName('SMALL');257/** @type {!goog.dom.TagName<!HTMLSourceElement>} */258goog.dom.TagName.SOURCE = new goog.dom.TagName('SOURCE');259/** @type {!goog.dom.TagName<!HTMLSpanElement>} */260goog.dom.TagName.SPAN = new goog.dom.TagName('SPAN');261/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */262goog.dom.TagName.STRIKE = new goog.dom.TagName('STRIKE');263/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */264goog.dom.TagName.STRONG = new goog.dom.TagName('STRONG');265/** @type {!goog.dom.TagName<!HTMLStyleElement>} */266goog.dom.TagName.STYLE = new goog.dom.TagName('STYLE');267/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */268goog.dom.TagName.SUB = new goog.dom.TagName('SUB');269/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */270goog.dom.TagName.SUMMARY = new goog.dom.TagName('SUMMARY');271/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */272goog.dom.TagName.SUP = new goog.dom.TagName('SUP');273/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */274goog.dom.TagName.SVG = new goog.dom.TagName('SVG');275/** @type {!goog.dom.TagName<!HTMLTableElement>} */276goog.dom.TagName.TABLE = new goog.dom.TagName('TABLE');277/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */278goog.dom.TagName.TBODY = new goog.dom.TagName('TBODY');279/** @type {!goog.dom.TagName<!HTMLTableCellElement>} */280goog.dom.TagName.TD = new goog.dom.TagName('TD');281/** @type {!goog.dom.TagName<!HTMLTemplateElement>} */282goog.dom.TagName.TEMPLATE = new goog.dom.TagName('TEMPLATE');283/** @type {!goog.dom.TagName<!HTMLTextAreaElement>} */284goog.dom.TagName.TEXTAREA = new goog.dom.TagName('TEXTAREA');285/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */286goog.dom.TagName.TFOOT = new goog.dom.TagName('TFOOT');287/** @type {!goog.dom.TagName<!HTMLTableCellElement>} */288goog.dom.TagName.TH = new goog.dom.TagName('TH');289/** @type {!goog.dom.TagName<!HTMLTableSectionElement>} */290goog.dom.TagName.THEAD = new goog.dom.TagName('THEAD');291/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */292goog.dom.TagName.TIME = new goog.dom.TagName('TIME');293/** @type {!goog.dom.TagName<!HTMLTitleElement>} */294goog.dom.TagName.TITLE = new goog.dom.TagName('TITLE');295/** @type {!goog.dom.TagName<!HTMLTableRowElement>} */296goog.dom.TagName.TR = new goog.dom.TagName('TR');297/** @type {!goog.dom.TagName<!HTMLTrackElement>} */298goog.dom.TagName.TRACK = new goog.dom.TagName('TRACK');299/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */300goog.dom.TagName.TT = new goog.dom.TagName('TT');301/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */302goog.dom.TagName.U = new goog.dom.TagName('U');303/** @type {!goog.dom.TagName<!HTMLUListElement>} */304goog.dom.TagName.UL = new goog.dom.TagName('UL');305/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */306goog.dom.TagName.VAR = new goog.dom.TagName('VAR');307/** @type {!goog.dom.TagName<!HTMLVideoElement>} */308goog.dom.TagName.VIDEO = new goog.dom.TagName('VIDEO');309/** @type {!goog.dom.TagName<!goog.dom.HtmlElement>} */...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var assert = require('assert');2var apickli = require('apickli');3var myApickli = new apickli.Apickli('http', 'localhost:8080');4myApickli.addRequestHeader('Content-Type', 'application/json');5myApickli.addRequestHeader('Accept', 'application/json');6myApickli.get('/hello', function (error, response) {7if (error) {8console.log(error);9}10else {11console.log(response);12}13});14var assert = require('assert');15var apickli = require('apickli');16var myApickli = new apickli.Apickli('http', 'localhost:8080');17myApickli.addRequestHeader('Content-Type', 'application/json');18myApickli.addRequestHeader('Accept', 'application/json');19myApickli.get('/hello', function (error, response) {20if (error) {21console.log(error);22}23else {24console.log(response);25}26});

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var dom = require('apickli/apickli-gherkin');3var assert = require('assert');4module.exports = function() {5 this.Given(/^I am on the apickli page$/, function (callback) {6 this.apickli.addRequestHeader('Accept', 'application/json');7 });8 this.Then(/^I should see "([^"]*)" in the page$/, function (text, callback) {9 var dom = this.apickli.getDom();10 assert(dom(window).find('h1').text().indexOf(text) > -1);11 callback();12 });13};14{15 "scripts": {16 },17 "dependencies": {18 }19}

Full Screen

Using AI Code Generation

copy

Full Screen

1var apickli = require('apickli');2var {defineSupportCode} = require('cucumber');3var {setDefaultTimeout} = require('cucumber');4defineSupportCode(function({Given, When, Then}) {5 Given('I set header {string} to {string}', function (header, value, callback) {6 this.apickli.addRequestHeader(header, value);7 callback();8 });9 When('I GET {string}', function (url, callback) {10 this.apickli.get(url, callback);11 });12 Then('I should get HTTP response code {int}', function (code, callback) {13 this.apickli.assertResponseCode(code);14 callback();15 });16 Then('I should get response body containing {string}', function (body, callback) {17 this.apickli.assertResponseBodyContains(body);18 callback();19 });20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Dom = require('xmldom').DOMParser;2var apickli = require('apickli');3var assert = require('assert');4module.exports = function () {5 this.Then(/^I should see the following attributes in the response$/, function (table, callback) {6 var response = this.apickli.getResponseObject();7 var xml = response.body;8 var doc = new Dom().parseFromString(xml);9 var nodes = doc.getElementsByTagName('item');10 var i = 0;11 for (i = 0; i < nodes.length; i++) {12 var node = nodes[i];13 var title = node.getElementsByTagName('title')[0].firstChild.data;14 var link = node.getElementsByTagName('link')[0].firstChild.data;15 var description = node.getElementsByTagName('description')[0].firstChild.data;16 var pubDate = node.getElementsByTagName('pubDate')[0].firstChild.data;17 var guid = node.getElementsByTagName('guid')[0].firstChild.data;18 var category = node.getElementsByTagName('category')[0].firstChild.data;19 var author = node.getElementsByTagName('author')[0].firstChild.data;20 assert.equal(title, table.hashes()[i].title);21 assert.equal(link, table.hashes()[i].link);22 assert.equal(description, table.hashes()[i].description);23 assert.equal(pubDate, table.hashes()[i].pubDate);24 assert.equal(guid, table.hashes()[i].guid);25 assert.equal(category, table.hashes()[i].category);26 assert.equal(author, table.hashes()[i].author);27 }28 callback();29 });30};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run apickli automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful