Best JavaScript code snippet using testcafe
SaxParserTest.js
Source:SaxParserTest.js
...76 };77 };78 suite.test('Parse elements', function () {79 var counter, parser;80 counter = createCounter(writer);81 parser = new SaxParser(counter, schema);82 writer.reset();83 parser.parse(84 '<span id=id1 title="title value" class=\'class1 class2\' data-value="value1" ' +85 'MYATTR="val1" myns:myattr="val2" disabled empty=""></span>'86 );87 LegacyUnit.equal(88 writer.getContent(),89 '<span id="id1" title="title value" class="class1 class2" data-value="value1" myattr="val1" ' +90 'myns:myattr="val2" disabled="disabled" empty=""></span>',91 'Parse attribute formats.'92 );93 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Parse attribute formats counts.');94 counter = createCounter(writer);95 parser = new SaxParser(counter, schema);96 writer.reset();97 parser.parse('<b href=\'"&<>\'></b>');98 LegacyUnit.equal(writer.getContent(), '<b href=""&<>"></b>', 'Parse attributes with <> in them.');99 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Parse attributes with <> in them (count).');100 counter = createCounter(writer);101 parser = new SaxParser(counter, schema);102 writer.reset();103 parser.parse('<span title=" "class=" "></span>');104 LegacyUnit.equal(writer.getContent(), '<span title=" " class=" "></span>', 'Parse compressed attributes.');105 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Parse compressed attributes (count).');106 counter = createCounter(writer);107 parser = new SaxParser(counter, schema);108 writer.reset();109 parser.parse('<span title></span>');110 LegacyUnit.equal(writer.getContent(), '<span title=""></span>', 'Single empty attribute.');111 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Single empty attributes (count).');112 counter = createCounter(writer);113 parser = new SaxParser(counter, schema);114 writer.reset();115 parser.parse('<span class="class" title></span>');116 LegacyUnit.equal(writer.getContent(), '<span class="class" title=""></span>', 'Empty attribute at end.');117 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Empty attribute at end (count).');118 counter = createCounter(writer);119 parser = new SaxParser(counter, schema);120 writer.reset();121 parser.parse('<span title class="class"></span>');122 LegacyUnit.equal(writer.getContent(), '<span title="" class="class"></span>', 'Empty attribute at start.');123 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Empty attribute at start (count).');124 counter = createCounter(writer);125 parser = new SaxParser(counter, schema);126 writer.reset();127 parser.parse('<img src="test">');128 LegacyUnit.equal(writer.getContent(), '<img src="test" />', 'Parse empty element.');129 LegacyUnit.deepEqual(counter.counts, { start: 1 }, 'Parse empty element counts.');130 counter = createCounter(writer);131 parser = new SaxParser(counter, schema);132 writer.reset();133 parser.parse('<img\nsrc="test"\ntitle="row1\nrow2">');134 LegacyUnit.equal(writer.getContent(), '<img src="test" title="row1\nrow2" />', 'Parse attributes with linebreak.');135 LegacyUnit.deepEqual(counter.counts, { start: 1 }, 'Parse attributes with linebreak counts.');136 counter = createCounter(writer);137 parser = new SaxParser(counter, schema);138 writer.reset();139 parser.parse('<img \t \t src="test" \t \t title="\t row1\t row2">');140 LegacyUnit.equal(writer.getContent(), '<img src="test" title="\t row1\t row2" />', 'Parse attributes with whitespace.');141 LegacyUnit.deepEqual(counter.counts, { start: 1 }, 'Parse attributes with whitespace counts.');142 counter = createCounter(writer);143 parser = new SaxParser(counter, schema);144 writer.reset();145 parser.parse('<myns:mytag>text</myns:mytag>');146 LegacyUnit.equal(writer.getContent(), '<myns:mytag>text</myns:mytag>', 'Parse element with namespace.');147 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 1, end: 1 }, 'Parse element with namespace counts.');148 counter = createCounter(writer);149 parser = new SaxParser(counter, schema);150 writer.reset();151 parser.parse('<myns-mytag>text</myns-mytag>');152 LegacyUnit.equal(writer.getContent(), '<myns-mytag>text</myns-mytag>', 'Parse element with dash name.');153 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 1, end: 1 }, 'Parse element with dash name counts.');154 counter = createCounter(writer);155 parser = new SaxParser(counter, schema);156 writer.reset();157 parser.parse('<myns_mytag>text</myns_mytag>');158 LegacyUnit.equal(writer.getContent(), '<myns_mytag>text</myns_mytag>', 'Parse element with underscore name.');159 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 1, end: 1 }, 'Parse element with underscore name counts.');160 counter = createCounter(writer);161 parser = new SaxParser(counter, schema);162 writer.reset();163 parser.parse('text1<p>text2<b>text3</p>text4</b>text5');164 LegacyUnit.equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>text4text5', 'Parse tag soup 1.');165 LegacyUnit.deepEqual(counter.counts, { text: 5, start: 2, end: 2 }, 'Parse tag soup 1 counts.');166 counter = createCounter(writer);167 parser = new SaxParser(counter, schema);168 writer.reset();169 parser.parse('text1<P>text2<B>text3</p>text4</b>text5');170 LegacyUnit.equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>text4text5', 'Parse tag soup 2.');171 LegacyUnit.deepEqual(counter.counts, { text: 5, start: 2, end: 2 }, 'Parse tag soup 2 counts.');172 counter = createCounter(writer);173 parser = new SaxParser(counter, schema);174 writer.reset();175 parser.parse('text1<P>text2<B>tex<t3</p>te>xt4</b>text5');176 LegacyUnit.equal(writer.getContent(), 'text1<p>text2<b>tex<t3</b></p>te>xt4text5', 'Parse tag soup 3.');177 LegacyUnit.deepEqual(counter.counts, { text: 5, start: 2, end: 2 }, 'Parse tag soup 3 counts.');178 counter = createCounter(writer);179 parser = new SaxParser(counter, schema);180 writer.reset();181 parser.parse('text1<p>text2<b>text3');182 LegacyUnit.equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>', 'Parse tag soup 4.');183 LegacyUnit.deepEqual(counter.counts, { text: 3, start: 2, end: 2 }, 'Parse tag soup 4 counts.');184 counter = createCounter(writer);185 parser = new SaxParser(counter, schema);186 writer.reset();187 parser.parse('text1<script>text2');188 LegacyUnit.equal(writer.getContent(), 'text1<script>text2</s' + 'cript>', 'Parse tag soup 5.');189 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 1, end: 1 }, 'Parse tag soup 5 counts.');190 counter = createCounter(writer);191 parser = new SaxParser(counter, schema);192 writer.reset();193 parser.parse('text1<style>text2');194 LegacyUnit.equal(writer.getContent(), 'text1<style>text2</st' + 'yle>', 'Parse tag soup 6.');195 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 1, end: 1 }, 'Parse tag soup 6 counts.');196 counter = createCounter(writer);197 parser = new SaxParser(counter, schema);198 writer.reset();199 parser.parse('text1<span title="<test" data-test="test>"></span>');200 LegacyUnit.equal(201 writer.getContent(),202 'text1<span title="<test" data-test="test>"></span>',203 'Parse element with </> in attributes.'204 );205 LegacyUnit.deepEqual(counter.counts, { text: 1, start: 1, end: 1 }, 'Parse element with </> in attributes counts.');206 counter = createCounter(writer);207 parser = new SaxParser(counter, schema);208 writer.reset();209 parser.parse("text\n<SC" + "RIPT type=mce-text/javascript>// <![CDATA[\nalert('HELLO WORLD!');\n// ]]></SC" + "RIPT>");210 LegacyUnit.equal(211 writer.getContent(),212 "text\n<sc" + "ript type=\"mce-text/javascript\">// <![CDATA[\nalert('HELLO WORLD!');\n// ]]></sc" + "ript>",213 'Parse cdata script.'214 );215 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 1, end: 1 }, 'Parse cdata script counts.');216 counter = createCounter(writer);217 parser = new SaxParser(counter, schema);218 writer.reset();219 parser.parse('text1<noscript>te<br>xt2</noscript>text3');220 LegacyUnit.equal(writer.getContent(), 'text1<noscript>te<br>xt2</noscript>text3', 'Parse noscript elements.');221 LegacyUnit.deepEqual(counter.counts, { text: 3, start: 1, end: 1 }, 'Parse noscript elements counts.');222 counter = createCounter(writer);223 parser = new SaxParser(counter, schema);224 writer.reset();225 parser.parse('<p>a</p><p /><p>b</p>');226 LegacyUnit.equal(writer.getContent(), '<p>a</p><p></p><p>b</p>', 'Parse invalid closed element.');227 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 3, end: 3 }, 'Parse invalid closed element counts.');228 counter = createCounter(writer);229 parser = new SaxParser(counter, schema);230 writer.reset();231 parser.parse('<br><br /><br/>');232 LegacyUnit.equal(writer.getContent(), '<br /><br /><br />', 'Parse short ended elements.');233 LegacyUnit.deepEqual(counter.counts, { start: 3 }, 'Parse short ended elements counts.');234 counter = createCounter(writer);235 parser = new SaxParser(counter, schema);236 writer.reset();237 parser.parse('<p ></p>');238 LegacyUnit.equal(writer.getContent(), '<p></p>', 'Parse start elements with whitespace only attribs part.');239 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 }, 'Parse start elements with whitespace only attribs part (counts).');240 });241 suite.test('Parse style elements', function () {242 var counter, parser;243 counter = createCounter(writer);244 parser = new SaxParser(counter, schema);245 writer.reset();246 parser.parse('text1<em><style>// <b>tag</b></st' + 'yle>text2</em>');247 LegacyUnit.equal(writer.getContent(), 'text1<em><style>// <b>tag</b></st' + 'yle>text2</em>', 'Parse style element.');248 LegacyUnit.deepEqual(counter.counts, { start: 2, end: 2, text: 3 }, 'Parse style element counts.');249 counter = createCounter(writer);250 parser = new SaxParser(counter, schema);251 writer.reset();252 parser.parse('text1<em><style id="id">// <b>tag</b></st' + 'yle>text2</em>');253 LegacyUnit.equal(254 writer.getContent(),255 'text1<em><style id="id">// <b>tag</b></st' + 'yle>text2</em>',256 'Parse style element with attributes.'257 );258 LegacyUnit.deepEqual(counter.counts, { text: 3, start: 2, end: 2 }, 'Parse style element with attributes counts.');259 counter = createCounter(writer);260 parser = new SaxParser(counter, schema);261 writer.reset();262 parser.parse('text1<em><style></st' + 'yle>text2</span>');263 LegacyUnit.equal(writer.getContent(), 'text1<em><style></st' + 'yle>text2</em>', 'Parse empty style element.');264 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 2, end: 2 }, 'Parse empty style element counts.');265 counter = createCounter(writer);266 parser = new SaxParser(Tools.extend({ validate: true }, counter), new Schema({ invalid_elements: 'style' }));267 writer.reset();268 parser.parse('text1<em><style>text2</st' + 'yle>text3</em>');269 LegacyUnit.equal(writer.getContent(), 'text1<em>text3</em>', 'Parse invalid style element.');270 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 1, end: 1 }, 'Parse invalid style element (count).');271 });272 suite.test('Parse script elements', function () {273 var counter, parser;274 counter = createCounter(writer);275 parser = new SaxParser(counter, schema);276 writer.reset();277 parser.parse('text1<em><script>// <b>tag</b></s' + 'cript>text2</em>');278 LegacyUnit.equal(writer.getContent(), 'text1<em><script>// <b>tag</b></s' + 'cript>text2</em>', 'Parse script element.');279 LegacyUnit.deepEqual(counter.counts, { start: 2, end: 2, text: 3 }, 'Parse script element counts.');280 counter = createCounter(writer);281 parser = new SaxParser(counter, schema);282 writer.reset();283 parser.parse('text1<em><script id="id">// <b>tag</b></s' + 'cript>text2</em>');284 LegacyUnit.equal(285 writer.getContent(),286 'text1<em><script id="id">// <b>tag</b></s' + 'cript>text2</em>',287 'Parse script element with attributes.'288 );289 LegacyUnit.deepEqual(counter.counts, { start: 2, end: 2, text: 3 }, 'Parse script element with attributes counts.');290 counter = createCounter(writer);291 parser = new SaxParser(counter, schema);292 writer.reset();293 parser.parse('text1<em><script></s' + 'cript>text2</em>');294 LegacyUnit.equal(writer.getContent(), 'text1<em><script></s' + 'cript>text2</em>', 'Parse empty script element.');295 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 2, end: 2 }, 'Parse empty script element counts.');296 counter = createCounter(writer);297 parser = new SaxParser(Tools.extend({ validate: true }, counter), new Schema({ invalid_elements: 'script' }));298 writer.reset();299 parser.parse('text1<em><s' + 'cript>text2</s' + 'cript>text3</em>');300 LegacyUnit.equal(writer.getContent(), 'text1<em>text3</em>', 'Parse invalid script element.');301 LegacyUnit.deepEqual(counter.counts, { text: 2, start: 1, end: 1 }, 'Parse invalid script element (count).');302 });303 suite.test('Parse text', function () {304 var counter, parser;305 counter = createCounter(writer);306 parser = new SaxParser(counter, schema);307 writer.reset();308 parser.parse('');309 LegacyUnit.equal(writer.getContent(), '', 'Parse empty.');310 LegacyUnit.deepEqual(counter.counts, {}, 'Parse empty counts.');311 counter = createCounter(writer);312 parser = new SaxParser(counter, schema);313 writer.reset();314 parser.parse('text');315 LegacyUnit.equal(writer.getContent(), 'text', 'Parse single text node.');316 LegacyUnit.deepEqual(counter.counts, { text: 1 }, 'Parse single text node counts.');317 counter = createCounter(writer);318 parser = new SaxParser(counter, schema);319 writer.reset();320 parser.parse('<b>text</b>');321 LegacyUnit.equal(writer.getContent(), '<b>text</b>', 'Parse wrapped text.');322 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 1, end: 1 }, 'Parse wrapped text counts');323 counter = createCounter(writer);324 parser = new SaxParser(counter, schema);325 writer.reset();326 parser.parse('text1<b>text2</b>');327 LegacyUnit.equal(writer.getContent(), 'text1<b>text2</b>', 'Parse text at start.');328 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 2, end: 1 }, 'Parse text at start counts.');329 counter = createCounter(writer);330 parser = new SaxParser(counter, schema);331 writer.reset();332 parser.parse('<b>text1</b>text2');333 LegacyUnit.equal(writer.getContent(), '<b>text1</b>text2', 'Parse text at end.');334 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1, text: 2 }, 'Parse text at end counts.');335 });336 suite.test('Parsing comments', function () {337 var counter, parser;338 counter = createCounter(writer);339 parser = new SaxParser(counter, schema);340 writer.reset();341 parser.parse('<!-- comment value -->');342 LegacyUnit.equal(writer.getContent(), '<!-- comment value -->', 'Parse comment with value.');343 LegacyUnit.deepEqual(counter.counts, { comment: 1 }, 'Parse comment with value count.');344 counter = createCounter(writer);345 parser = new SaxParser(counter, schema);346 writer.reset();347 parser.parse('<!---->');348 LegacyUnit.equal(writer.getContent(), '', 'Parse comment without value.');349 LegacyUnit.deepEqual(counter.counts, {}, 'Parse comment without value count.');350 counter = createCounter(writer);351 parser = new SaxParser(counter, schema);352 writer.reset();353 parser.parse('<!--<b></b>-->');354 LegacyUnit.equal(writer.getContent(), '<!--<b></b>-->', 'Parse comment with tag inside.');355 LegacyUnit.deepEqual(counter.counts, { comment: 1 }, 'Parse comment with tag inside counts.');356 counter = createCounter(writer);357 parser = new SaxParser(counter, schema);358 writer.reset();359 parser.parse('<b>a<!-- value -->b</b>');360 LegacyUnit.equal(writer.getContent(), '<b>a<!-- value -->b</b>', 'Parse comment with tags around it.');361 LegacyUnit.deepEqual(counter.counts, { comment: 1, text: 2, start: 1, end: 1 }, 'Parse comment with tags around it counts.');362 });363 suite.test('Parsing cdata', function () {364 var counter, parser;365 counter = createCounter(writer);366 parser = new SaxParser(counter, schema);367 writer.reset();368 parser.parse('<![CDATA[test text]]>');369 LegacyUnit.equal(writer.getContent(), '<![CDATA[test text]]>', 'Parse cdata with value.');370 LegacyUnit.deepEqual(counter.counts, { cdata: 1 }, 'Parse cdata with value counts.');371 counter = createCounter(writer);372 parser = new SaxParser(counter, schema);373 writer.reset();374 parser.parse('<![CDATA[]]>');375 LegacyUnit.equal(writer.getContent(), '', 'Parse cdata without value.');376 LegacyUnit.deepEqual(counter.counts, {}, 'Parse cdata without value counts.');377 counter = createCounter(writer);378 parser = new SaxParser(counter, schema);379 writer.reset();380 parser.parse('<![CDATA[<b>a</b>]]>');381 LegacyUnit.equal(writer.getContent(), '<![CDATA[<b>a</b>]]>', 'Parse cdata with tag inside.');382 LegacyUnit.deepEqual(counter.counts, { cdata: 1 }, 'Parse cdata with tag inside counts.');383 counter = createCounter(writer);384 parser = new SaxParser(counter, schema);385 writer.reset();386 parser.parse('<b>a<![CDATA[value]]>b</b>');387 LegacyUnit.equal(writer.getContent(), '<b>a<![CDATA[value]]>b</b>', 'Parse cdata with tags around it.');388 LegacyUnit.deepEqual(counter.counts, { cdata: 1, start: 1, end: 1, text: 2 }, 'Parse cdata with tags around it counts.');389 });390 suite.test('Parse PI', function () {391 var counter, parser;392 counter = createCounter(writer);393 parser = new SaxParser(counter, schema);394 writer.reset();395 parser.parse('<?xml version="1.0" encoding="UTF-8" ?>text1');396 LegacyUnit.equal(writer.getContent(), '<?xml version="1.0" encoding="UTF-8" ?>text1', 'Parse PI with attributes.');397 LegacyUnit.deepEqual(counter.counts, { pi: 1, text: 1 }, 'Parse PI with attributes counts.');398 counter = createCounter(writer);399 parser = new SaxParser(counter, schema);400 writer.reset();401 parser.parse('<?xml?>text1');402 LegacyUnit.equal(writer.getContent(), '<?xml?>text1', 'Parse PI with no data.');403 LegacyUnit.deepEqual(counter.counts, { pi: 1, text: 1 }, 'Parse PI with data counts.');404 counter = createCounter(writer);405 parser = new SaxParser(counter, schema);406 writer.reset();407 parser.parse('<?xml somevalue/>text1');408 LegacyUnit.equal(writer.getContent(), '<?xml somevalue?>text1', 'Parse PI with IE style ending.');409 LegacyUnit.deepEqual(counter.counts, { pi: 1, text: 1 }, 'Parse PI with IE style ending counts.');410 });411 suite.test('Parse doctype', function () {412 var counter, parser;413 counter = createCounter(writer);414 parser = new SaxParser(counter, schema);415 writer.reset();416 parser.parse(417 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">text1'418 );419 LegacyUnit.equal(420 writer.getContent(),421 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">text1',422 'Parse DOCTYPE.'423 );424 LegacyUnit.deepEqual(counter.counts, { doctype: 1, text: 1 }, 'Parse HTML5 DOCTYPE counts.');425 counter = createCounter(writer);426 parser = new SaxParser(counter, schema);427 writer.reset();428 parser.parse('<!DOCTYPE html>text1');429 LegacyUnit.equal(writer.getContent(), '<!DOCTYPE html>text1', 'Parse HTML5 DOCTYPE.');430 LegacyUnit.deepEqual(counter.counts, { doctype: 1, text: 1 }, 'Parse HTML5 DOCTYPE counts.');431 });432 suite.test('Parse (validate)', function () {433 var counter, parser;434 counter = createCounter(writer);435 counter.validate = true;436 parser = new SaxParser(counter, schema);437 writer.reset();438 parser.parse('<invalid1>123<invalid2 />456<span title="title" invalid3="value">789</span>012</invalid1>');439 LegacyUnit.equal(writer.getContent(), '123456<span title="title">789</span>012', 'Parse invalid elements and attributes.');440 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1, text: 4 }, 'Parse invalid elements and attributes counts.');441 });442 suite.test('Self closing', function () {443 var counter, parser;444 counter = createCounter(writer);445 counter.validate = true;446 parser = new SaxParser(counter, schema);447 writer.reset();448 parser.parse('<ul><li>1<li><b>2</b><li><em><b>3</b></em></ul>');449 LegacyUnit.equal(450 writer.getContent(),451 '<ul><li>1</li><li><b>2</b></li><li><em><b>3</b></em></li></ul>',452 'Parse list with self closing items.'453 );454 });455 suite.test('Preserve internal elements', function () {456 var counter, parser, schema;457 schema = new Schema({ valid_elements: 'b' });458 counter = createCounter(writer);459 counter.validate = true;460 parser = new SaxParser(counter, schema);461 writer.reset();462 parser.parse('<span id="id"><b>text</b></span><span id="id" data-mce-type="something"></span>');463 LegacyUnit.equal(464 writer.getContent(),465 '<b>text</b><span id="id" data-mce-type="something"></span>',466 'Preserve internal span element without any span schema rule.'467 );468 schema = new Schema({ valid_elements: 'b,span[class]' });469 counter = createCounter(writer);470 counter.validate = true;471 parser = new SaxParser(counter, schema);472 writer.reset();473 parser.parse('<span id="id" class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>');474 LegacyUnit.equal(475 writer.getContent(),476 '<span class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>',477 'Preserve internal span element with a span schema rule.'478 );479 });480 suite.test('Remove internal elements', function () {481 var counter, parser, schema;482 schema = new Schema({ valid_elements: 'b' });483 counter = createCounter(writer);484 counter.validate = true;485 counter.remove_internals = true;486 parser = new SaxParser(counter, schema);487 writer.reset();488 parser.parse('<span id="id"><b>text</b></span><span id="id" data-mce-type="something"></span>');489 LegacyUnit.equal(writer.getContent(), '<b>text</b>', 'Remove internal span element without any span schema rule.');490 schema = new Schema({ valid_elements: 'b,span[class]' });491 counter = createCounter(writer);492 counter.validate = true;493 counter.remove_internals = true;494 parser = new SaxParser(counter, schema);495 writer.reset();496 parser.parse('<span id="id" class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>');497 LegacyUnit.equal(498 writer.getContent(),499 '<span class="class"><b>text</b></span>',500 'Remove internal span element with a span schema rule.'501 );502 // Reset503 counter.remove_internals = false;504 });505 suite.test('Parse attr with backslash #5436', function () {506 var counter, parser;507 counter = createCounter(writer);508 parser = new SaxParser(counter, schema);509 writer.reset();510 parser.parse('<a title="\\" href="h">x</a>');511 LegacyUnit.equal(writer.getContent(), '<a title="\\" href="h">x</a>');512 });513 suite.test('Parse no attributes span before strong', function () {514 var counter, parser;515 counter = createCounter(writer);516 counter.validate = true;517 parser = new SaxParser(counter, schema);518 writer.reset();519 parser.parse('<p><span>A</span> <strong>B</strong></p>');520 LegacyUnit.equal(writer.getContent(), '<p>A <strong>B</strong></p>');521 });522 suite.test('Conditional comments (allowed)', function () {523 var counter, parser;524 counter = createCounter(writer);525 counter.validate = false;526 counter.allow_conditional_comments = true;527 parser = new SaxParser(counter, schema);528 writer.reset();529 parser.parse('<!--[if gte IE 4]>alert(1)<![endif]-->');530 LegacyUnit.equal(writer.getContent(), '<!--[if gte IE 4]>alert(1)<![endif]-->');531 });532 suite.test('Conditional comments (denied)', function () {533 var counter, parser;534 counter = createCounter(writer);535 counter.validate = false;536 counter.allow_conditional_comments = false;537 parser = new SaxParser(counter, schema);538 writer.reset();539 parser.parse('<!--[if gte IE 4]>alert(1)<![endif]-->');540 LegacyUnit.equal(writer.getContent(), '<!-- [if gte IE 4]>alert(1)<![endif]-->');541 writer.reset();542 parser.parse('<!--[if !IE]>alert(1)<![endif]-->');543 LegacyUnit.equal(writer.getContent(), '<!-- [if !IE]>alert(1)<![endif]-->');544 writer.reset();545 parser.parse('<!--[iF !IE]>alert(1)<![endif]-->');546 LegacyUnit.equal(writer.getContent(), '<!-- [iF !IE]>alert(1)<![endif]-->');547 });548 suite.test('Parse script urls (allowed)', function () {549 var counter, parser;550 counter = createCounter(writer);551 counter.validate = false;552 counter.allow_script_urls = true;553 parser = new SaxParser(counter, schema);554 writer.reset();555 parser.parse(556 '<a href="javascript:alert(1)">1</a>' +557 '<a href=" 2 ">2</a>' +558 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">3</a>'559 );560 LegacyUnit.equal(561 writer.getContent(),562 '<a href="javascript:alert(1)">1</a><a href=" 2 ">2</a>' +563 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">3</a>'564 );565 });566 suite.test('Parse script urls (allowed html data uris)', function () {567 var counter, parser;568 counter = createCounter(writer);569 counter.validate = false;570 counter.allow_html_data_urls = true;571 parser = new SaxParser(counter, schema);572 writer.reset();573 parser.parse(574 '<a href="javascript:alert(1)">1</a>' +575 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">2</a>'576 );577 LegacyUnit.equal(578 writer.getContent(),579 '<a>1</a>' +580 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">2</a>'581 );582 });583 suite.test('Parse script urls (denied)', function () {584 var counter, parser;585 counter = createCounter(writer);586 counter.validate = false;587 parser = new SaxParser(counter, schema);588 writer.reset();589 parser.parse(590 '<a href="jAvaScript:alert(1)">1</a>' +591 '<a href="vbscript:alert(2)">2</a>' +592 '<a href="java\u0000script:alert(3)">3</a>' +593 '<a href="\njavascript:alert(4)">4</a>' +594 '<a href="java\nscript:alert(5)">5</a>' +595 '<a href="java\tscript:alert(6)">6</a>' +596 '<a href="%6aavascript:alert(7)">7</a>' +597 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">8</a>' +598 '<a href=" dAt%61: tExt/html ; bAse64 , PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">9</a>' +599 '<object data="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">10</object>' +600 '<button formaction="javascript:alert(11)">11</button>' +601 '<table background="javascript:alert(12)"><tr><tr>12</tr></tr></table>' +602 '<a href="mhtml:13">13</a>' +603 '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">' +604 '<a href="%E3%82%AA%E3%83%BC%E3%83">Invalid url</a>'605 );606 LegacyUnit.equal(607 writer.getContent(),608 '<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a><a>6</a><a>7</a><a>8</a><a>9</a>' +609 '<object>10</object><button>11</button><table><tr></tr><tr>12</tr></table><a>13</a>' +610 '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />' +611 '<a href="%E3%82%AA%E3%83%BC%E3%83">Invalid url</a>'612 );613 });614 suite.test('Parse away bogus elements', function () {615 var testBogusSaxParse = function (inputHtml, outputHtml, counters) {616 var counter, parser;617 counter = createCounter(writer);618 counter.validate = true;619 parser = new SaxParser(counter, schema);620 writer.reset();621 parser.parse(inputHtml);622 LegacyUnit.equal(writer.getContent(), outputHtml);623 LegacyUnit.deepEqual(counter.counts, counters);624 };625 testBogusSaxParse('a<b data-mce-bogus="1">b</b>c', 'abc', { text: 3 });626 testBogusSaxParse('a<b data-mce-bogus="true">b</b>c', 'abc', { text: 3 });627 testBogusSaxParse('a<b data-mce-bogus="1"></b>c', 'ac', { text: 2 });628 testBogusSaxParse('a<b data-mce-bogus="all">b</b>c', 'ac', { text: 2 });629 testBogusSaxParse('a<b data-mce-bogus="all"><!-- x --><?xml?></b>c', 'ac', { text: 2 });630 testBogusSaxParse('a<b data-mce-bogus="all"><b>b</b></b>c', 'ac', { text: 2 });631 testBogusSaxParse('a<b data-mce-bogus="all"><br>b</b><b>c</b>', 'a<b>c</b>', { start: 1, end: 1, text: 2 });632 testBogusSaxParse('a<b data-mce-bogus="all"><img>b</b><b>c</b>', 'a<b>c</b>', { start: 1, end: 1, text: 2 });633 testBogusSaxParse('a<b data-mce-bogus="all"><b attr="x">b</b></b>c', 'ac', { text: 2 });634 testBogusSaxParse('a<b data-mce-bogus="all"></b>c', 'ac', { text: 2 });635 testBogusSaxParse('a<b data-mce-bogus="all"></b><b>c</b>', 'a<b>c</b>', { start: 1, end: 1, text: 2 });636 });637 suite.test('findEndTag', function () {638 var testFindEndTag = function (html, startIndex, expectedIndex) {639 LegacyUnit.equal(SaxParser.findEndTag(schema, html, startIndex), expectedIndex);640 };641 testFindEndTag('<b>', 3, 3);642 testFindEndTag('<img>', 3, 3);643 testFindEndTag('<b></b>', 3, 7);644 testFindEndTag('<b><img></b>', 3, 12);645 testFindEndTag('<b><!-- </b> --></b>', 3, 20);646 testFindEndTag('<span><b><i>a<img>b</i><b>c</b></b></span>', 9, 35);647 });648 suite.test('parse XSS PI', function () {649 var counter, parser;650 counter = createCounter(writer);651 counter.validate = false;652 parser = new SaxParser(counter, schema);653 writer.reset();654 parser.parse(655 '<?xml><iframe SRC=javascript:alert('XSS')>?>'656 );657 LegacyUnit.equal(658 writer.getContent(),659 '<?xml ><iframe SRC=&#106&#97&#118&#97&#115&#99&#114&#105&#112&' +660 '#116&#58&#97&#108&#101&#114&#116&#40&#39&#88&#83&#83&#39&#41>?>'661 );662 });663 suite.test('aria attributes', function () {664 var counter, parser;665 counter = createCounter(writer);666 parser = new SaxParser(Tools.extend({ validate: true }, counter), schema);667 writer.reset();668 parser.parse('<span aria-label="test" role="myrole" unsupportedattr="2">a</span>');669 LegacyUnit.equal(670 writer.getContent(),671 '<span aria-label="test" role="myrole">a</span>'672 );673 });674 suite.test('Parse elements with numbers', function () {675 var counter, parser;676 counter = createCounter(writer);677 parser = new SaxParser(counter, schema);678 writer.reset();679 parser.parse('<a5>text</a5>');680 LegacyUnit.equal(writer.getContent(), '<a5>text</a5>', 'Parse element with numbers.');681 LegacyUnit.deepEqual(counter.counts, { start: 1, text: 1, end: 1 }, 'Parse element with numbers counts.');682 });683 suite.test('Parse internal elements with disallowed attributes', function () {684 var counter, parser;685 counter = createCounter(writer);686 parser = new SaxParser(counter, schema);687 writer.reset();688 parser.parse('<b data-mce-type="test" id="x" style="color: red" src="1" data="2" onclick="3"></b>');689 LegacyUnit.equal(writer.getContent(), '<b data-mce-type="test" id="x" style="color: red"></b>');690 LegacyUnit.deepEqual(counter.counts, { start: 1, end: 1 });691 });692 suite.test('Parse cdata with comments and trim those comments away', function () {693 var counter, parser;694 counter = createCounter(writer);695 parser = new SaxParser(counter, schema);696 writer.reset();697 parser.parse('<![CDATA[<!--x--><!--y-->--><!--]]>');698 LegacyUnit.equal(writer.getContent(), '<![CDATA[xy]]>');699 LegacyUnit.deepEqual(counter.counts, { cdata: 1 });700 });701 suite.test('Parse special elements', function () {702 var counter, parser;703 var specialHtml = (704 '<b>' +705 '<textarea></b></textarea><title></b></title><script></b></script>' +706 '<noframes></b></noframes><noscript></b></noscript><style></b></style>' +707 '<xmp></b></xmp>' +708 '<noembed></b></noembed>' +709 '</b>'710 );711 counter = createCounter(writer);712 parser = new SaxParser(counter, schema);713 writer.reset();714 parser.parse(specialHtml);715 LegacyUnit.equal(writer.getContent(), specialHtml);716 LegacyUnit.deepEqual(counter.counts, { start: 9, text: 8, end: 9 });717 });718 suite.test('Parse malformed elements that start with numbers', function () {719 var counter, parser;720 counter = createCounter(writer);721 parser = new SaxParser(counter, schema);722 writer.reset();723 parser.parse('a <2 b b b b b b b b b b b b b b b b b b b b b b');724 LegacyUnit.equal(writer.getContent(), 'a <2 b b b b b b b b b b b b b b b b b b b b b b');725 counter = createCounter(writer);726 parser = new SaxParser(counter, schema);727 writer.reset();728 parser.parse('a <2b>a</2b> b');729 LegacyUnit.equal(writer.getContent(), 'a <2b>a</2b> b');730 });731 suite.test('Parse malformed elements without an end', function () {732 var counter, parser;733 counter = createCounter(writer);734 parser = new SaxParser(counter, schema);735 writer.reset();736 parser.parse('<b b b b b b b b b b b b b b b b b b b b b b b');737 LegacyUnit.equal(738 writer.getContent(),739 '<b b b b b b b b b b b b b b b b b b b b b b b'740 );741 counter = createCounter(writer);742 parser = new SaxParser(counter, schema);743 writer.reset();744 parser.parse('a a<b c');745 LegacyUnit.equal(746 writer.getContent(),747 'a a<b c'748 );749 });750 Pipeline.async({}, suite.toSteps({}), function () {751 success();752 }, failure);753 }...
SaxParser.js
Source:SaxParser.js
1(function() {2 module("tinymce.html.SaxParser");3 var writer = new tinymce.html.Writer(), schema = new tinymce.html.Schema();4 function createCounter(writer) {5 var counts = {};6 return {7 counts : counts,8 comment: function(text) {9 if ("comment" in counts) {10 counts.comment++;11 } else {12 counts.comment = 1;13 }14 writer.comment(text);15 },16 cdata: function(text) {17 if ("cdata" in counts) {18 counts.cdata++;19 } else {20 counts.cdata = 1;21 }22 writer.cdata(text);23 },24 text: function(text, raw) {25 if ("text" in counts) {26 counts.text++;27 } else {28 counts.text = 1;29 }30 writer.text(text, raw);31 },32 start: function(name, attrs, empty) {33 if ("start" in counts) {34 counts.start++;35 } else {36 counts.start = 1;37 }38 writer.start(name, attrs, empty);39 },40 end: function(name) {41 if ("end" in counts) {42 counts.end++;43 } else {44 counts.end = 1;45 }46 writer.end(name);47 },48 pi: function(name, text) {49 if ("pi" in counts) {50 counts.pi++;51 } else {52 counts.pi = 1;53 }54 writer.pi(name, text);55 },56 doctype: function(text) {57 if ("doctype:" in counts) {58 counts.doctype++;59 } else {60 counts.doctype = 1;61 }62 writer.doctype(text);63 }64 };65 }66 test('Parse elements', function() {67 var counter, parser;68 expect(48);69 counter = createCounter(writer);70 parser = new tinymce.html.SaxParser(counter, schema);71 writer.reset();72 parser.parse('<span id=id1 title="title value" class=\'class1 class2\' data-value="value1" MYATTR="val1" myns:myattr="val2" disabled empty=""></span>');73 equal(writer.getContent(), '<span id="id1" title="title value" class="class1 class2" data-value="value1" myattr="val1" myns:myattr="val2" disabled="disabled" empty=""></span>', 'Parse attribute formats.');74 deepEqual(counter.counts, {start:1, end:1}, 'Parse attribute formats counts.');75 counter = createCounter(writer);76 parser = new tinymce.html.SaxParser(counter, schema);77 writer.reset();78 parser.parse('<b href=\'"&<>\'></b>');79 equal(writer.getContent(), '<b href=""&<>"></b>', 'Parse attributes with <> in them.');80 deepEqual(counter.counts, {start:1, end:1}, 'Parse attributes with <> in them (count).');81 counter = createCounter(writer);82 parser = new tinymce.html.SaxParser(counter, schema);83 writer.reset();84 parser.parse('<span title=" "class=" "></span>');85 equal(writer.getContent(), '<span title=" " class=" "></span>', 'Parse compressed attributes.');86 deepEqual(counter.counts, {start:1, end:1}, 'Parse compressed attributes (count).');87 counter = createCounter(writer);88 parser = new tinymce.html.SaxParser(counter, schema);89 writer.reset();90 parser.parse('<span title></span>');91 equal(writer.getContent(), '<span title=""></span>', 'Single empty attribute.');92 deepEqual(counter.counts, {start:1, end:1}, 'Single empty attributes (count).');93 counter = createCounter(writer);94 parser = new tinymce.html.SaxParser(counter, schema);95 writer.reset();96 parser.parse('<span class="class" title></span>');97 equal(writer.getContent(), '<span class="class" title=""></span>', 'Empty attribute at end.');98 deepEqual(counter.counts, {start:1, end:1}, 'Empty attribute at end (count).');99 counter = createCounter(writer);100 parser = new tinymce.html.SaxParser(counter, schema);101 writer.reset();102 parser.parse('<span title class="class"></span>');103 equal(writer.getContent(), '<span title="" class="class"></span>', 'Empty attribute at start.');104 deepEqual(counter.counts, {start:1, end:1}, 'Empty attribute at start (count).');105 counter = createCounter(writer);106 parser = new tinymce.html.SaxParser(counter, schema);107 writer.reset();108 parser.parse('<img src="test">');109 equal(writer.getContent(), '<img src="test" />', 'Parse empty element.');110 deepEqual(counter.counts, {start:1}, 'Parse empty element counts.');111 counter = createCounter(writer);112 parser = new tinymce.html.SaxParser(counter, schema);113 writer.reset();114 parser.parse('<img\nsrc="test"\ntitle="row1\nrow2">');115 equal(writer.getContent(), '<img src="test" title="row1\nrow2" />', 'Parse attributes with linebreak.');116 deepEqual(counter.counts, {start: 1}, 'Parse attributes with linebreak counts.');117 counter = createCounter(writer);118 parser = new tinymce.html.SaxParser(counter, schema);119 writer.reset();120 parser.parse('<img \t \t src="test" \t \t title="\t row1\t row2">');121 equal(writer.getContent(), '<img src="test" title="\t row1\t row2" />', 'Parse attributes with whitespace.');122 deepEqual(counter.counts, {start: 1}, 'Parse attributes with whitespace counts.');123 counter = createCounter(writer);124 parser = new tinymce.html.SaxParser(counter, schema);125 writer.reset();126 parser.parse('<myns:mytag>text</myns:mytag>');127 equal(writer.getContent(), '<myns:mytag>text</myns:mytag>', 'Parse element with namespace.');128 deepEqual(counter.counts, {start:1, text:1, end: 1}, 'Parse element with namespace counts.');129 counter = createCounter(writer);130 parser = new tinymce.html.SaxParser(counter, schema);131 writer.reset();132 parser.parse('<myns-mytag>text</myns-mytag>');133 equal(writer.getContent(), '<myns-mytag>text</myns-mytag>', 'Parse element with dash name.');134 deepEqual(counter.counts, {start:1, text:1, end:1}, 'Parse element with dash name counts.');135 counter = createCounter(writer);136 parser = new tinymce.html.SaxParser(counter, schema);137 writer.reset();138 parser.parse('<myns_mytag>text</myns_mytag>');139 equal(writer.getContent(), '<myns_mytag>text</myns_mytag>', 'Parse element with underscore name.');140 deepEqual(counter.counts, {start:1, text:1, end:1}, 'Parse element with underscore name counts.');141 counter = createCounter(writer);142 parser = new tinymce.html.SaxParser(counter, schema);143 writer.reset();144 parser.parse('text1<p>text2<b>text3</p>text4</b>text5');145 equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>text4text5', 'Parse tag soup 1.');146 deepEqual(counter.counts, {text:5, start: 2, end: 2}, 'Parse tag soup 1 counts.');147 counter = createCounter(writer);148 parser = new tinymce.html.SaxParser(counter, schema);149 writer.reset();150 parser.parse('text1<P>text2<B>text3</p>text4</b>text5');151 equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>text4text5', 'Parse tag soup 2.');152 deepEqual(counter.counts, {text: 5, start: 2, end: 2}, 'Parse tag soup 2 counts.');153 counter = createCounter(writer);154 parser = new tinymce.html.SaxParser(counter, schema);155 writer.reset();156 parser.parse('text1<P>text2<B>tex<t3</p>te>xt4</b>text5');157 equal(writer.getContent(), 'text1<p>text2<b>tex<t3</b></p>te>xt4text5', 'Parse tag soup 3.');158 deepEqual(counter.counts, {text: 5, start: 2, end: 2}, 'Parse tag soup 3 counts.');159 counter = createCounter(writer);160 parser = new tinymce.html.SaxParser(counter, schema);161 writer.reset();162 parser.parse('text1<p>text2<b>text3');163 equal(writer.getContent(), 'text1<p>text2<b>text3</b></p>', 'Parse tag soup 4.');164 deepEqual(counter.counts, {text: 3, start: 2, end: 2}, 'Parse tag soup 4 counts.');165 counter = createCounter(writer);166 parser = new tinymce.html.SaxParser(counter, schema);167 writer.reset();168 parser.parse('text1<script>text2');169 equal(writer.getContent(), 'text1<script>text2</s' + 'cript>', 'Parse tag soup 5.');170 deepEqual(counter.counts, {text: 2, start: 1, end: 1}, 'Parse tag soup 5 counts.');171 counter = createCounter(writer);172 parser = new tinymce.html.SaxParser(counter, schema);173 writer.reset();174 parser.parse('text1<style>text2');175 equal(writer.getContent(), 'text1<style>text2</st' + 'yle>', 'Parse tag soup 6.');176 deepEqual(counter.counts, {text: 2, start: 1, end: 1}, 'Parse tag soup 6 counts.');177 counter = createCounter(writer);178 parser = new tinymce.html.SaxParser(counter, schema);179 writer.reset();180 parser.parse('text1<span title="<test" data-test="test>"></span>');181 equal(writer.getContent(), 'text1<span title="<test" data-test="test>"></span>', 'Parse element with </> in attributes.');182 deepEqual(counter.counts, {text: 1, start: 1, end: 1}, 'Parse element with </> in attributes counts.');183 counter = createCounter(writer);184 parser = new tinymce.html.SaxParser(counter, schema);185 writer.reset();186 parser.parse("text\n<SC"+"RIPT type=mce-text/javascript>// <![CDATA[\nalert('HELLO WORLD!');\n// ]]></SC"+"RIPT>");187 equal(writer.getContent(), "text\n<sc"+"ript type=\"mce-text/javascript\">// <![CDATA[\nalert('HELLO WORLD!');\n// ]]></sc"+"ript>", 'Parse cdata script.');188 deepEqual(counter.counts, {text: 2, start: 1, end: 1}, 'Parse cdata script counts.');189 counter = createCounter(writer);190 parser = new tinymce.html.SaxParser(counter, schema);191 writer.reset();192 parser.parse('text1<noscript>te<br>xt2</noscript>text3');193 equal(writer.getContent(), 'text1<noscript>te<br>xt2</noscript>text3', 'Parse noscript elements.');194 deepEqual(counter.counts, {text: 3, start: 1, end: 1}, 'Parse noscript elements counts.');195 counter = createCounter(writer);196 parser = new tinymce.html.SaxParser(counter, schema);197 writer.reset();198 parser.parse('<p>a</p><p /><p>b</p>');199 equal(writer.getContent(), '<p>a</p><p></p><p>b</p>', 'Parse invalid closed element.');200 deepEqual(counter.counts, {text: 2, start: 3, end: 3}, 'Parse invalid closed element counts.');201 counter = createCounter(writer);202 parser = new tinymce.html.SaxParser(counter, schema);203 writer.reset();204 parser.parse('<br><br /><br/>');205 equal(writer.getContent(), '<br /><br /><br />', 'Parse short ended elements.');206 deepEqual(counter.counts, {start: 3}, 'Parse short ended elements counts.');207 counter = createCounter(writer);208 parser = new tinymce.html.SaxParser(counter, schema);209 writer.reset();210 parser.parse('<p ></p>');211 equal(writer.getContent(), '<p></p>', 'Parse start elements with whitespace only attribs part.');212 deepEqual(counter.counts, {start: 1, end: 1}, 'Parse start elements with whitespace only attribs part (counts).');213 });214 test('Parse style elements', function() {215 var counter, parser;216 expect(8);217 counter = createCounter(writer);218 parser = new tinymce.html.SaxParser(counter, schema);219 writer.reset();220 parser.parse('text1<em><style>// <b>tag</b></st' + 'yle>text2</em>');221 equal(writer.getContent(), 'text1<em><style>// <b>tag</b></st' + 'yle>text2</em>', 'Parse style element.');222 deepEqual(counter.counts, {start: 2, end: 2, text: 3}, 'Parse style element counts.');223 counter = createCounter(writer);224 parser = new tinymce.html.SaxParser(counter, schema);225 writer.reset();226 parser.parse('text1<em><style id="id">// <b>tag</b></st' + 'yle>text2</em>');227 equal(writer.getContent(), 'text1<em><style id="id">// <b>tag</b></st' + 'yle>text2</em>', 'Parse style element with attributes.');228 deepEqual(counter.counts, {text:3, start:2, end:2}, 'Parse style element with attributes counts.');229 counter = createCounter(writer);230 parser = new tinymce.html.SaxParser(counter, schema);231 writer.reset();232 parser.parse('text1<em><style></st' + 'yle>text2</span>');233 equal(writer.getContent(), 'text1<em><style></st' + 'yle>text2</em>', 'Parse empty style element.');234 deepEqual(counter.counts, {text:2, start:2, end:2}, 'Parse empty style element counts.');235 counter = createCounter(writer);236 parser = new tinymce.html.SaxParser(tinymce.extend({validate : true}, counter), new tinymce.html.Schema({invalid_elements: 'style'}));237 writer.reset();238 parser.parse('text1<em><style>text2</st' + 'yle>text3</em>');239 equal(writer.getContent(), 'text1<em>text3</em>', 'Parse invalid style element.');240 deepEqual(counter.counts, {text:2, start:1, end:1}, 'Parse invalid style element (count).');241 });242 test('Parse script elements', function() {243 var counter, parser;244 expect(8);245 counter = createCounter(writer);246 parser = new tinymce.html.SaxParser(counter, schema);247 writer.reset();248 parser.parse('text1<em><script>// <b>tag</b></s' + 'cript>text2</em>');249 equal(writer.getContent(), 'text1<em><script>// <b>tag</b></s' + 'cript>text2</em>', 'Parse script element.');250 deepEqual(counter.counts, {start:2, end:2, text:3}, 'Parse script element counts.');251 counter = createCounter(writer);252 parser = new tinymce.html.SaxParser(counter, schema);253 writer.reset();254 parser.parse('text1<em><script id="id">// <b>tag</b></s' + 'cript>text2</em>');255 equal(writer.getContent(), 'text1<em><script id="id">// <b>tag</b></s' + 'cript>text2</em>', 'Parse script element with attributes.');256 deepEqual(counter.counts, {start:2, end:2, text:3}, 'Parse script element with attributes counts.');257 counter = createCounter(writer);258 parser = new tinymce.html.SaxParser(counter, schema);259 writer.reset();260 parser.parse('text1<em><script></s' + 'cript>text2</em>');261 equal(writer.getContent(), 'text1<em><script></s' + 'cript>text2</em>', 'Parse empty script element.');262 deepEqual(counter.counts, {text: 2, start:2, end: 2}, 'Parse empty script element counts.');263 counter = createCounter(writer);264 parser = new tinymce.html.SaxParser(tinymce.extend({validate : true}, counter), new tinymce.html.Schema({invalid_elements: 'script'}));265 writer.reset();266 parser.parse('text1<em><s' + 'cript>text2</s' + 'cript>text3</em>');267 equal(writer.getContent(), 'text1<em>text3</em>', 'Parse invalid script element.');268 deepEqual(counter.counts, {text:2, start:1, end:1}, 'Parse invalid script element (count).');269 });270 test('Parse text', function() {271 var counter, parser;272 expect(10);273 counter = createCounter(writer);274 parser = new tinymce.html.SaxParser(counter, schema);275 writer.reset();276 parser.parse('');277 equal(writer.getContent(), '', 'Parse empty.');278 deepEqual(counter.counts, {}, 'Parse empty counts.');279 counter = createCounter(writer);280 parser = new tinymce.html.SaxParser(counter, schema);281 writer.reset();282 parser.parse('text');283 equal(writer.getContent(), 'text', 'Parse single text node.');284 deepEqual(counter.counts, {text: 1}, 'Parse single text node counts.');285 counter = createCounter(writer);286 parser = new tinymce.html.SaxParser(counter, schema);287 writer.reset();288 parser.parse('<b>text</b>');289 equal(writer.getContent(), '<b>text</b>', 'Parse wrapped text.');290 deepEqual(counter.counts, {start:1, text:1, end:1}, 'Parse wrapped text counts');291 counter = createCounter(writer);292 parser = new tinymce.html.SaxParser(counter, schema);293 writer.reset();294 parser.parse('text1<b>text2</b>');295 equal(writer.getContent(), 'text1<b>text2</b>', 'Parse text at start.');296 deepEqual(counter.counts, {start:1, text:2, end:1}, 'Parse text at start counts.');297 counter = createCounter(writer);298 parser = new tinymce.html.SaxParser(counter, schema);299 writer.reset();300 parser.parse('<b>text1</b>text2');301 equal(writer.getContent(), '<b>text1</b>text2', 'Parse text at end.');302 deepEqual(counter.counts, {start:1, end:1, text:2}, 'Parse text at end counts.');303 });304 test('Parsing comments', function() {305 var counter, parser;306 expect(8);307 counter = createCounter(writer);308 parser = new tinymce.html.SaxParser(counter, schema);309 writer.reset();310 parser.parse('<!-- comment value -->');311 equal(writer.getContent(), '<!-- comment value -->', 'Parse comment with value.');312 deepEqual(counter.counts, {comment:1}, 'Parse comment with value count.');313 counter = createCounter(writer);314 parser = new tinymce.html.SaxParser(counter, schema);315 writer.reset();316 parser.parse('<!---->');317 equal(writer.getContent(), '', 'Parse comment without value.');318 deepEqual(counter.counts, {}, 'Parse comment without value count.');319 counter = createCounter(writer);320 parser = new tinymce.html.SaxParser(counter, schema);321 writer.reset();322 parser.parse('<!--<b></b>-->');323 equal(writer.getContent(), '<!--<b></b>-->', 'Parse comment with tag inside.');324 deepEqual(counter.counts, {comment:1}, 'Parse comment with tag inside counts.');325 counter = createCounter(writer);326 parser = new tinymce.html.SaxParser(counter, schema);327 writer.reset();328 parser.parse('<b>a<!-- value -->b</b>');329 equal(writer.getContent(), '<b>a<!-- value -->b</b>', 'Parse comment with tags around it.');330 deepEqual(counter.counts, {comment:1, text:2, start:1, end:1}, 'Parse comment with tags around it counts.');331 });332 test('Parsing cdata', function() {333 var counter, parser;334 expect(8);335 counter = createCounter(writer);336 parser = new tinymce.html.SaxParser(counter, schema);337 writer.reset();338 parser.parse('<![CDATA[test text]]>');339 equal(writer.getContent(), '<![CDATA[test text]]>', 'Parse cdata with value.');340 deepEqual(counter.counts, {cdata:1}, 'Parse cdata with value counts.');341 counter = createCounter(writer);342 parser = new tinymce.html.SaxParser(counter, schema);343 writer.reset();344 parser.parse('<![CDATA[]]>');345 equal(writer.getContent(), '', 'Parse cdata without value.');346 deepEqual(counter.counts, {}, 'Parse cdata without value counts.');347 counter = createCounter(writer);348 parser = new tinymce.html.SaxParser(counter, schema);349 writer.reset();350 parser.parse('<![CDATA[<b>a</b>]]>');351 equal(writer.getContent(), '<![CDATA[<b>a</b>]]>', 'Parse cdata with tag inside.');352 deepEqual(counter.counts, {cdata:1}, 'Parse cdata with tag inside counts.');353 counter = createCounter(writer);354 parser = new tinymce.html.SaxParser(counter, schema);355 writer.reset();356 parser.parse('<b>a<![CDATA[value]]>b</b>');357 equal(writer.getContent(), '<b>a<![CDATA[value]]>b</b>', 'Parse cdata with tags around it.');358 deepEqual(counter.counts, {cdata:1, start:1, end:1, text:2}, 'Parse cdata with tags around it counts.');359 });360 test('Parse PI', function() {361 var counter, parser;362 expect(6);363 counter = createCounter(writer);364 parser = new tinymce.html.SaxParser(counter, schema);365 writer.reset();366 parser.parse('<?xml version="1.0" encoding="UTF-8" ?>text1');367 equal(writer.getContent(), '<?xml version="1.0" encoding="UTF-8" ?>text1', 'Parse PI with attributes.');368 deepEqual(counter.counts, {pi:1, text:1}, 'Parse PI with attributes counts.');369 counter = createCounter(writer);370 parser = new tinymce.html.SaxParser(counter, schema);371 writer.reset();372 parser.parse('<?xml?>text1');373 equal(writer.getContent(), '<?xml?>text1', 'Parse PI with no data.');374 deepEqual(counter.counts, {pi:1, text:1}, 'Parse PI with data counts.');375 counter = createCounter(writer);376 parser = new tinymce.html.SaxParser(counter, schema);377 writer.reset();378 parser.parse('<?xml somevalue/>text1');379 equal(writer.getContent(), '<?xml somevalue?>text1', 'Parse PI with IE style ending.');380 deepEqual(counter.counts, {pi:1, text:1}, 'Parse PI with IE style ending counts.');381 });382 test('Parse doctype', function() {383 var counter, parser;384 expect(4);385 counter = createCounter(writer);386 parser = new tinymce.html.SaxParser(counter, schema);387 writer.reset();388 parser.parse('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">text1');389 equal(writer.getContent(), '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">text1', 'Parse DOCTYPE.');390 deepEqual(counter.counts, {doctype:1, text:1}, 'Parse HTML5 DOCTYPE counts.');391 counter = createCounter(writer);392 parser = new tinymce.html.SaxParser(counter, schema);393 writer.reset();394 parser.parse('<!DOCTYPE html>text1');395 equal(writer.getContent(), '<!DOCTYPE html>text1', 'Parse HTML5 DOCTYPE.');396 deepEqual(counter.counts, {doctype:1, text:1}, 'Parse HTML5 DOCTYPE counts.');397 });398 test('Parse (validate)', function() {399 var counter, parser;400 expect(2);401 counter = createCounter(writer);402 counter.validate = true;403 parser = new tinymce.html.SaxParser(counter, schema);404 writer.reset();405 parser.parse('<invalid1>123<invalid2 />456<span title="title" invalid3="value">789</span>012</invalid1>');406 equal(writer.getContent(), '123456<span title="title">789</span>012', 'Parse invalid elements and attributes.');407 deepEqual(counter.counts, {start:1, end:1, text:4}, 'Parse invalid elements and attributes counts.');408 });409 test('Self closing', function() {410 var counter, parser;411 expect(1);412 counter = createCounter(writer);413 counter.validate = true;414 parser = new tinymce.html.SaxParser(counter, schema);415 writer.reset();416 parser.parse('<ul><li>1<li><b>2</b><li><em><b>3</b></em></ul>');417 equal(writer.getContent(), '<ul><li>1</li><li><b>2</b></li><li><em><b>3</b></em></li></ul>', 'Parse list with self closing items.');418 });419 test('Preserve internal elements', function() {420 var counter, parser, schema;421 expect(2);422 schema = new tinymce.html.Schema({valid_elements : 'b'});423 counter = createCounter(writer);424 counter.validate = true;425 parser = new tinymce.html.SaxParser(counter, schema);426 writer.reset();427 parser.parse('<span id="id"><b>text</b></span><span id="id" data-mce-type="something"></span>');428 equal(writer.getContent(), '<b>text</b><span id="id" data-mce-type="something"></span>', 'Preserve internal span element without any span schema rule.');429 schema = new tinymce.html.Schema({valid_elements : 'b,span[class]'});430 counter = createCounter(writer);431 counter.validate = true;432 parser = new tinymce.html.SaxParser(counter, schema);433 writer.reset();434 parser.parse('<span id="id" class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>');435 equal(writer.getContent(), '<span class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>', 'Preserve internal span element with a span schema rule.');436 });437 test('Remove internal elements', function() {438 var counter, parser, schema;439 expect(2);440 schema = new tinymce.html.Schema({valid_elements : 'b'});441 counter = createCounter(writer);442 counter.validate = true;443 counter.remove_internals = true;444 parser = new tinymce.html.SaxParser(counter, schema);445 writer.reset();446 parser.parse('<span id="id"><b>text</b></span><span id="id" data-mce-type="something"></span>');447 equal(writer.getContent(), '<b>text</b>', 'Remove internal span element without any span schema rule.');448 schema = new tinymce.html.Schema({valid_elements : 'b,span[class]'});449 counter = createCounter(writer);450 counter.validate = true;451 counter.remove_internals = true;452 parser = new tinymce.html.SaxParser(counter, schema);453 writer.reset();454 parser.parse('<span id="id" class="class"><b>text</b></span><span id="id" data-mce-type="something"></span>');455 equal(writer.getContent(), '<span class="class"><b>text</b></span>', 'Remove internal span element with a span schema rule.');456 // Reset457 counter.remove_internals = false;458 });459 test('Parse attr with backslash #5436', function() {460 var counter, parser;461 counter = createCounter(writer);462 parser = new tinymce.html.SaxParser(counter, schema);463 writer.reset();464 parser.parse('<a title="\\" href="h">x</a>');465 equal(writer.getContent(), '<a title="\\" href="h">x</a>');466 });467 test('Parse no attributes span before strong', function() {468 var counter, parser;469 counter = createCounter(writer);470 counter.validate = true;471 parser = new tinymce.html.SaxParser(counter, schema);472 writer.reset();473 parser.parse('<p><span>A</span> <strong>B</strong></p>');474 equal(writer.getContent(), '<p>A <strong>B</strong></p>');475 });476 test('Conditional comments (allowed)', function() {477 var counter, parser;478 counter = createCounter(writer);479 counter.validate = false;480 counter.allow_conditional_comments = true;481 parser = new tinymce.html.SaxParser(counter, schema);482 writer.reset();483 parser.parse('<!--[if gte IE 4]>alert(1)<![endif]-->');484 equal(writer.getContent(), '<!--[if gte IE 4]>alert(1)<![endif]-->');485 });486 test('Conditional comments (denied)', function() {487 var counter, parser;488 counter = createCounter(writer);489 counter.validate = false;490 counter.allow_conditional_comments = false;491 parser = new tinymce.html.SaxParser(counter, schema);492 writer.reset();493 parser.parse('<!--[if gte IE 4]>alert(1)<![endif]-->');494 equal(writer.getContent(), '<!-- [if gte IE 4]>alert(1)<![endif]-->');495 writer.reset();496 parser.parse('<!--[if !IE]>alert(1)<![endif]-->');497 equal(writer.getContent(), '<!-- [if !IE]>alert(1)<![endif]-->');498 });499 test('Parse script urls (allowed)', function() {500 var counter, parser;501 counter = createCounter(writer);502 counter.validate = false;503 counter.allow_script_urls = true;504 parser = new tinymce.html.SaxParser(counter, schema);505 writer.reset();506 parser.parse(507 '<a href="javascript:alert(1)">1</a>' +508 '<a href=" 2 ">2</a>' +509 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">3</a>'510 );511 equal(512 writer.getContent(),513 '<a href="javascript:alert(1)">1</a><a href=" 2 ">2</a>' +514 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">3</a>'515 );516 });517 test('Parse script urls (allowed html data uris)', function() {518 var counter, parser;519 counter = createCounter(writer);520 counter.validate = false;521 counter.allow_html_data_urls = true;522 parser = new tinymce.html.SaxParser(counter, schema);523 writer.reset();524 parser.parse(525 '<a href="javascript:alert(1)">1</a>' +526 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">2</a>'527 );528 equal(529 writer.getContent(),530 '<a>1</a>' +531 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">2</a>'532 );533 });534 test('Parse script urls (denied)', function() {535 var counter, parser;536 counter = createCounter(writer);537 counter.validate = false;538 parser = new tinymce.html.SaxParser(counter, schema);539 writer.reset();540 parser.parse(541 '<a href="jAvaScript:alert(1)">1</a>' +542 '<a href="vbscript:alert(2)">2</a>' +543 '<a href="java\u0000script:alert(3)">3</a>' +544 '<a href="\njavascript:alert(4)">4</a>' +545 '<a href="java\nscript:alert(5)">5</a>' +546 '<a href="java\tscript:alert(6)">6</a>' +547 '<a href="%6aavascript:alert(7)">7</a>' +548 '<a href="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">8</a>' +549 '<a href=" dAt%61: tExt/html ; bAse64 , PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">9</a>' +550 '<object data="data:text/html;base64,PHN2Zy9vbmxvYWQ9YWxlcnQoMik+">10</object>' +551 '<button formaction="javascript:alert(11)">11</button>' +552 '<table background="javascript:alert(12)"><tr><tr>12</tr></tr></table>' +553 '<a href="mhtml:13">13</a>' +554 '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">' +555 '<a href="%E3%82%AA%E3%83%BC%E3%83">Invalid url</a>'556 );557 equal(558 writer.getContent(),559 '<a>1</a><a>2</a><a>3</a><a>4</a><a>5</a><a>6</a><a>7</a><a>8</a><a>9</a>' +560 '<object>10</object><button>11</button><table><tr></tr><tr>12</tr></table><a>13</a>' +561 '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />' +562 '<a href="%E3%82%AA%E3%83%BC%E3%83">Invalid url</a>'563 );564 });565 test('Parse away bogus elements', function() {566 function testBogusSaxParse(inputHtml, outputHtml, counters) {567 var counter, parser;568 counter = createCounter(writer);569 counter.validate = true;570 parser = new tinymce.html.SaxParser(counter, schema);571 writer.reset();572 parser.parse(inputHtml);573 equal(writer.getContent(), outputHtml);574 deepEqual(counter.counts, counters);575 }576 testBogusSaxParse('a<b data-mce-bogus="1">b</b>c', 'abc', {text: 3});577 testBogusSaxParse('a<b data-mce-bogus="true">b</b>c', 'abc', {text: 3});578 testBogusSaxParse('a<b data-mce-bogus="1"></b>c', 'ac', {text: 2});579 testBogusSaxParse('a<b data-mce-bogus="all">b</b>c', 'ac', {text: 2});580 testBogusSaxParse('a<b data-mce-bogus="all"><!-- x --><?xml?></b>c', 'ac', {text: 2});581 testBogusSaxParse('a<b data-mce-bogus="all"><b>b</b></b>c', 'ac', {text: 2});582 testBogusSaxParse('a<b data-mce-bogus="all"><br>b</b><b>c</b>', 'a<b>c</b>', {start: 1, end: 1, text: 2});583 testBogusSaxParse('a<b data-mce-bogus="all"><img>b</b><b>c</b>', 'a<b>c</b>', {start: 1, end: 1, text: 2});584 testBogusSaxParse('a<b data-mce-bogus="all"><b attr="x">b</b></b>c', 'ac', {text: 2});585 testBogusSaxParse('a<b data-mce-bogus="all"></b>c', 'ac', {text: 2});586 testBogusSaxParse('a<b data-mce-bogus="all"></b><b>c</b>', 'a<b>c</b>', {start: 1, end: 1, text:2});587 });588 test('findEndTag', function() {589 function testFindEndTag(html, startIndex, expectedIndex) {590 equal(tinymce.html.SaxParser.findEndTag(schema, html, startIndex), expectedIndex);591 }592 testFindEndTag('<b>', 3, 3);593 testFindEndTag('<img>', 3, 3);594 testFindEndTag('<b></b>', 3, 7);595 testFindEndTag('<b><img></b>', 3, 12);596 testFindEndTag('<b><!-- </b> --></b>', 3, 20);597 testFindEndTag('<span><b><i>a<img>b</i><b>c</b></b></span>', 9, 35);598 });599 test('parse XSS PI', function() {600 var counter, parser;601 counter = createCounter(writer);602 counter.validate = false;603 parser = new tinymce.html.SaxParser(counter, schema);604 writer.reset();605 parser.parse('<?xml><iframe SRC=javascript:alert('XSS')>?>');606 equal(607 writer.getContent(),608 '<?xml ><iframe SRC=&#106&#97&#118&#97&#115&#99&#114&#105&#112&' +609 '#116&#58&#97&#108&#101&#114&#116&#40&#39&#88&#83&#83&#39&#41>?>'610 );611 });...
buildCounter.js
Source:buildCounter.js
...3import createCounter from './createCounter';4var buildCounter = function(scene) {5 if (state.length>1) {6 if (state.walls == 1) {7 if (state.counter>0) scene.add(createCounter(state.length/2 - state.counterProps.depth/2, -state.width/2 + state.counterProps.width/2,Math.PI/2)); 8 if (state.counter==2) scene.add(createCounter(state.length/2 - state.counterProps.depth/2, state.width/2 - state.counterProps.width/2,Math.PI/2)); 9 } else if (state.walls == 2) {10 if (state.counter==1) {11 scene.add(createCounter(state.length/2 - state.counterProps.width/2,state.width/2 - state.counterProps.width/2,Math.PI/4)); 12 } else if (state.counter==2) {13 if (state.cabin>0) {14 if (state.width > 1 && state.length > 1) {15 var offsetX = 1;16 var offsetZ = 0.65;17 if (state.length == 2 ) scene.add(createCounter(-state.length/2 + state.counterProps.width/2 + state.depthWall+0.01, state.width/2 - state.counterProps.depth/2, 0)); 18 else scene.add(createCounter(state.length/2 - state.counterProps.width/2 - state.depthWall+0.01 - offsetX, state.width/2 - state.counterProps.depth/2, 0)); 19 20 if (state.width == 2 ) scene.add(createCounter(state.length/2 - state.counterProps.depth/2, -state.width/2 + state.counterProps.width/2 + state.depthWall+0.01, Math.PI/2)); 21 else scene.add(createCounter(state.length/2 - state.counterProps.depth/2, state.width/2 - state.counterProps.width/2 - state.depthWall-0.01-offsetZ, Math.PI/2)); 22 }23 } else {24 scene.add(createCounter(state.length/2 - state.counterProps.depth/2, -state.width/2 + state.counterProps.width/2 + state.depthWall+0.01, Math.PI/2)); 25 scene.add(createCounter(-state.length/2 + state.counterProps.width/2 + state.depthWall+0.01, state.width/2 - state.counterProps.depth/2, 0)); 26 }27 }28 } else if (state.walls == 3) {29 if (state.cabin>0) {30 if (state.counter>0) scene.add(createCounter(state.length/2 - state.counterProps.width/2 - state.depthWall-0.01, state.width/2 - state.counterProps.depth/2, 0)); 31 if (state.counter==2) {32 if (state.length==3 && state.width>3) scene.add(createCounter(state.length/2 - state.counterProps.depth/2 - state.depthWall-0.01 - state.counterProps.width, state.width/2 - state.counterProps.width/2 - state.counterProps.depth, Math.PI/2)); 33 else if (state.length>3) scene.add(createCounter(state.length/2 - state.counterProps.width/2 - state.depthWall-0.01 - state.counterProps.width, state.width/2 - state.counterProps.depth/2, 0)); 34 }35 } else {36 if (state.counter>0) scene.add(createCounter(-state.length/2 + state.counterProps.width/2 + state.depthWall+0.01, state.width/2 - state.counterProps.depth/2, 0)); 37 if (state.counter==2) scene.add(createCounter(state.length/2 - state.counterProps.width/2 - state.depthWall-0.01, state.width/2 - state.counterProps.depth/2, 0)); 38 }39 }40 }41}...
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6import { Selector } from 'testcafe';7test('My first test', async t => {8 .typeText('#developer-name', 'John Smith')9 .click('#submit-button');10});11import { Selector } from 'testcafe';12test('My first test', async t => {13 .typeText('#developer-name', 'John Smith')14 .click('#submit-button');15});16import { Selector } from 'testcafe';17test('My first test', async t => {18 .typeText('#developer-name', 'John Smith')19 .click('#submit-button');20});21import { Selector } from 'testcafe';22test('My first test', async t => {23 .typeText('#developer-name', 'John Smith')24 .click('#submit-button');25});26import { Selector } from 'testcafe';27test('My first test', async t => {28 .typeText('#developer-name',
Using AI Code Generation
1import { ClientFunction } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5});6const getNativeDialogHistory = ClientFunction(() => window.dialogHistory);7test('My second test', async t => {8 .click('#populate')9 .click('#submit-button')10 .expect(getNativeDialogHistory()).eql([
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3});4import { Selector } from 'testcafe';5test('My first test', async t => {6});
Using AI Code Generation
1import { Selector } from 'testcafe';2import Testcafe from 'testcafe';3test('My first test', async t => {4 const counter = await Testcafe.createCounter(18);5 .typeText('#developer-name', `Peter${counter}`)6 .click('#windows')7 .click('#tried-test-cafe')8 .click(Selector('#submit-button'));9});10import { Selector } from 'testcafe';11import Testcafe from 'testcafe';12test('My first test', async t => {13 const counter = await Testcafe.createCounter(18);14 .typeText('#developer-name', `Peter${counter}`)15 .click('#windows')16 .click('#tried-test-cafe')17 .click(Selector('#submit-button'));18});19import { Selector } from 'testcafe';20import Testcafe from 'testcafe';21test('My first test', async t => {22 const counter = await Testcafe.createCounter(18);23 .typeText('#developer-name', `Peter${counter}`)24 .click('#windows')25 .click('#tried-test-cafe')26 .click(Selector('#submit-button'));27});28import { Selector } from 'testcafe';29import Testcafe from 'testcafe';30test('My first test', async t => {31 const counter = await Testcafe.createCounter(18);32 .typeText('#developer-name', `Peter${counter}`)33 .click('#windows')34 .click('#tried-test-cafe')35 .click(Selector('#submit-button'));36});37import { Selector } from 'testcafe';38import Testcafe from 'test
Using AI Code Generation
1import { Selector } from 'testcafe';2import { createCounter } from 'testcafe-browser-provider-electron';3const counter = createCounter();4test('My Test', async t => {5 .click('#populate')6 .click('#submit-button');7 await counter.set(8);8 .expect(Selector('#article-header').innerText).eql('Thank you, John Smith!')9 .expect(Selector('#articles').childElementCount).eql(8);10});
Using AI Code Generation
1import { Selector } from 'testcafe';2test('My first test', async t => {3 const createCounter = Selector(".createCounter");4 .click(createCounter);5});6const electron = require('electron');7const path = require('path');8module.exports = {9 async openBrowser (id, pageUrl, browserName) {10 this.electronApp = await electron.app.launch({11 path.join(__dirname, '../../app'),12 });13 return this.electronApp;14 },15 async closeBrowser (/* id, pageInfo */) {16 await this.electronApp.stop();17 }18};19const { app, BrowserWindow } = require('electron');20const path = require('path');21let mainWindow;22function createWindow () {23 mainWindow = new BrowserWindow({24 webPreferences: {25 }26 });27 mainWindow.on('closed', function () {28 mainWindow = null;29 });30}31app.on('ready', createWindow);32app.on('window-all-closed', function () {33 if (process.platform !== 'darwin') {34 app.quit();35 }36});37app.on('activate', function () {38 if (mainWindow === null) {39 createWindow();40 }41});42 const createCounter = document.querySelector(".createCounter");43 createCounter.addEventListener("click", () => {44 const counter = document.querySelector("#counter");
Using AI Code Generation
1import { Selector, t } from 'testcafe';2import { createCounter } from 'testcafe-browser-provider-electron';3test('Test', async t => {4 const counter = createCounter();5 const button = Selector('button').withText('Click me');6 await t.click(button);7 await t.expect(counter()).eql(1);8});9import { Selector, t } from 'testcafe';10import { createCounter } from 'testcafe-browser-provider-electron';11test('Test', async t => {12 const counter = createCounter();13 const button = Selector('button').withText('Click me');14 await t.click(button);15 await t.expect(counter()).eql(1);16});
Using AI Code Generation
1import { Selector } from 'testcafe';2import { createCounter } from 'testcafe-browser-provider-electron';3import { ClientFunction } from 'testcafe';4const electronPath = require('electron');5 .beforeEach(async t => {6 .setNativeDialogHandler(() => true)7 .setTestSpeed(0.1)8 .maximizeWindow()9 });10test('Test', async t => {11 .click(Selector('button').withText('Open Window'))12 .switchToIframe(Selector('iframe'))13 .click(Selector('button').withText('Open Window'))14 .switchToMainWindow()15 .click(Selector('button').withText('Open Window'))16 .switchToIframe(Selector('iframe'))17 .click(Selector('button').withText('Open Window'))18 .switchToMainWindow()19 .click(Selector('button').withText('Open Window'))20 .switchToIframe(Selector('iframe'))21 .click(Selector('button').withText('Open Window'))22 .switchToMainWindow()23 .click(Selector('button').withText('Open Window'))24 .switchToIframe(Selector('iframe'))25 .click(Selector('button').withText('Open Window'))26 .switchToMainWindow()27 .click(Selector('button').withText('Open Window'))28 .switchToIframe(Selector('iframe'))29 .click(Selector('button').withText('Open Window'))30 .switchToMainWindow()31 .click(Selector('button').withText('Open Window'))32 .switchToIframe(Selector('iframe'))33 .click(Selector('button').withText('Open Window'))34 .switchToMainWindow()35 .click(Selector('button').withText('Open Window'))36 .switchToIframe(Selector('iframe'))37 .click(Selector('button').withText('Open Window'))38 .switchToMainWindow()39 .click(Selector('button').withText('Open Window'))40 .switchToIframe(Selector('iframe'))41 .click(Selector('button').withText('Open Window'))42 .switchToMainWindow()43 .click(Selector('button').withText('Open Window'))44 .switchToIframe(Selector('iframe'))
Using AI Code Generation
1var counter = new TestcafeCounter();2var count = counter.createCounter();3console.log(count);4module.exports = TestcafeCounter;5class TestcafeCounter {6 createCounter() {7 var count = 0;8 return count++;9 }10}11import { Selector } from 'testcafe';12test('My first test', async t => {13 .click('#preferred-interface')14 .click(Selector('option').withText('JavaScript API'));15});16import { Selector } from 'testcafe';17test('My first test', async t => {18 .click('#preferred-interface')19 .click(Selector('option').withText('JavaScript API'));20});
Using AI Code Generation
1import { Selector } from 'testcafe';2const createCounter = require('./createCounter');3fixture('Counter Tests')4test('Counter test', async t => {5 const counter = createCounter(Selector('h1'));6 await t.expect(counter.count).eql(1);7 await t.click('#populate');8 await t.expect(counter.count).eql(2);9 await t.click('#populate');10 await t.expect(counter.count).eql(3);11});12const createCounter = selector => {13 let count = 0;14 return {15 get count() {16 return count;17 },18 async click() {19 await selector.click();20 count++;21 }22 };23};24module.exports = createCounter;
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!