Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/tests/ce/ve.ce.Surface.test.js

raw symbols SCIP
1 /*!
2 * VisualEditor MediaWiki-specific ContentEditable Surface tests.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 QUnit.module( 've.ce.Surface (MW)', ve.test.utils.newMwEnvironment() );
9
10 /* Tests */
11
12 QUnit.test( 'beforePaste/afterPaste', ( assert ) => {
13 const cases = [
14 {
15 documentHtml: '<p></p>',
16 rangeOrSelection: new ve.Range( 1 ),
17 pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
18 fromVe: true,
19 expectedRangeOrSelection: new ve.Range( 5 ),
20 expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
21 msg: 'RESTBase IDs stripped'
22 },
23 {
24 documentHtml: '<p></p>',
25 rangeOrSelection: new ve.Range( 1 ),
26 pasteHtml: '<span typeof="mw:Entity" id="mwAB">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span>',
27 pasteTargetHtml: '<span>-</span><span>-</span>',
28 fromVe: true,
29 expectedRangeOrSelection: new ve.Range( 5 ),
30 expectedHtml: '<p><span typeof="mw:Entity">-</span><span typeof="mw:Entity" id="mw-reference-cite">-</span></p>',
31 msg: 'RESTBase IDs still stripped if used when important attributes dropped'
32 },
33 {
34 documentHtml: '<p></p>',
35 rangeOrSelection: new ve.Range( 1 ),
36 pasteHtml: '<a href="https://example.net/">Lorem</a> <a href="not-a-protocol:Some%20text">ipsum</a> <a href="mailto:[email protected]">dolor</a> <a href="javascript:alert()">sit amet</a>',
37 expectedRangeOrSelection: new ve.Range( 27 ),
38 // hrefs with invalid protocols get removed by DOMPurify, and these links become spans in
39 // ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later)
40 expectedHtml: '<p>Lorem <span>ipsum</span> dolor <span>sit amet</span></p>',
41 config: {
42 importRules: {
43 external: {
44 blacklist: {
45 'link/mwExternal': true
46 }
47 }
48 }
49 },
50 msg: 'External links stripped'
51 },
52 {
53 documentHtml: '<p></p>',
54 rangeOrSelection: new ve.Range( 1 ),
55 pasteHtml: '<a href="https://example.net/">Lorem</a> <a href="not-a-protocol:Some%20text">ipsum</a> <a href="mailto:[email protected]">dolor</a> <a href="javascript:alert()">sit amet</a>',
56 expectedRangeOrSelection: new ve.Range( 27 ),
57 // hrefs with invalid protocols get removed by DOMPurify, and these links become spans in
58 // ve.dm.LinkAnnotation.static.toDataElement (usually the span is stripped later)
59 expectedHtml: '<p><a href="https://example.net/" rel="mw:ExtLink">Lorem</a> <span>ipsum</span> <a href="mailto:[email protected]" rel="mw:ExtLink">dolor</a> <span>sit amet</span></p>',
60 config: {
61 importRules: {
62 external: {
63 blacklist: {
64 'link/mwExternal': false
65 }
66 }
67 }
68 },
69 msg: 'External links not stripped, but only some protocols allowed'
70 }
71 ];
72
73 cases.forEach( ve.test.utils.runSurfacePasteTest.bind( this, assert ) );
74 } );