本文整理汇总了TypeScript中@ephox/mcagar.LegacyUnit.createSuite方法的典型用法代码示例。如果您正苦于以下问题:TypeScript LegacyUnit.createSuite方法的具体用法?TypeScript LegacyUnit.createSuite怎么用?TypeScript LegacyUnit.createSuite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/mcagar.LegacyUnit
的用法示例。
在下文中一共展示了LegacyUnit.createSuite方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
UnitTest.asynctest('browser.tinymce.core.dom.TreeWalkerTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
const viewBlock = ViewBlock();
let nodes;
const setup = function () {
const all = function (node) {
let list = [node];
if (node.hasChildNodes()) {
for (let i = 0; i < node.childNodes.length; i++) {
list = list.concat(all(node.childNodes[i]));
}
}
return list;
};
viewBlock.update(
'1' +
'<ul>' +
'<li>' +
'2' +
'<ul>' +
'<li>3</li>' +
'<li>4</li>' +
'</ul>' +
'</li>' +
'<li>' +
'5' +
'<ul>' +
'<li>6</li>' +
'<li>7</li>' +
'</ul>' +
'</li>' +
'</ul>' +
'8'
);
nodes = all(viewBlock.get()).slice(1);
};
const compareNodeLists = function (expectedNodes, actutalNodes) {
if (expectedNodes.length !== actutalNodes.length) {
return false;
}
for (let i = 0; i < expectedNodes.length; i++) {
if (expectedNodes[i] !== actutalNodes[i]) {
return false;
}
}
return true;
};
suite.test('next', function () {
const walker = new TreeWalker(nodes[0], viewBlock.get());
let actualNodes;
actualNodes = [walker.current()];
while ((walker.next())) {
actualNodes.push(walker.current());
}
LegacyUnit.equal(compareNodeLists(nodes, actualNodes), true, 'Should be the same');
});
suite.test('prev2', function () {
const walker = new TreeWalker(nodes[nodes.length - 1], viewBlock.get());
let actualNodes;
actualNodes = [walker.current()];
while ((walker.prev2())) {
actualNodes.push(walker.current());
}
actualNodes = actualNodes.reverse();
LegacyUnit.equal(compareNodeLists(nodes, actualNodes), true, 'Should be the same');
});
suite.test('prev2(shallow:true)', function () {
const walker = new TreeWalker(nodes[nodes.length - 1], viewBlock.get());
let actualNodes;
actualNodes = [walker.current()];
while ((walker.prev2(true))) {
actualNodes.push(walker.current());
}
actualNodes = actualNodes.reverse();
LegacyUnit.equal(compareNodeLists(viewBlock.get().childNodes, actualNodes), true, 'Should be the same');
});
viewBlock.attach();
setup();
Pipeline.async({}, suite.toSteps({}), function () {
//.........这里部分代码省略.........
示例2: function
UnitTest.asynctest('tinymce.lists.browser.BackspaceDeleteTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
Plugin();
Theme();
suite.test('Backspace at beginning of single LI in UL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'<ul>' +
'<li>a</li>' +
'</ul>'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0);
editor.plugins.lists.backspaceDelete();
LegacyUnit.equal(editor.getContent(),
'<p>a</p>'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Backspace at beginning of first LI in UL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'<ul>' +
'<li>a</li>' +
'<li>b</li>' +
'</ul>'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li', 0);
editor.plugins.lists.backspaceDelete();
LegacyUnit.equal(editor.getContent(),
'<p>a</p>' +
'<ul>' +
'<li>b</li>' +
'</ul>'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
});
suite.test('Backspace at beginning of middle LI in UL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'<ul>' +
'<li>a</li>' +
'<li>b</li>' +
'<li>c</li>' +
'</ul>'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li:nth-child(2)', 0);
editor.plugins.lists.backspaceDelete();
LegacyUnit.equal(editor.getContent(),
'<ul>' +
'<li>ab</li>' +
'<li>c</li>' +
'</ul>'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
suite.test('Backspace at beginning of start LI in UL inside UL', function (editor) {
editor.getBody().innerHTML = LegacyUnit.trimBrs(
'<ul>' +
'<li>a' +
'<ul>' +
'<li>b</li>' +
'<li>c</li>' +
'</ul>' +
'</li>' +
'</ul>'
);
editor.focus();
LegacyUnit.setSelection(editor, 'li li', 0);
editor.plugins.lists.backspaceDelete();
LegacyUnit.equal(editor.getContent(),
'<ul>' +
'<li>ab' +
'<ul>' +
'<li>c</li>' +
'</ul>' +
'</li>' +
'</ul>'
);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI');
});
//.........这里部分代码省略.........
示例3: function
UnitTest.asynctest('browser.tinymce.core.CaretWalkerTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
const viewBlock = ViewBlock();
if (!Env.ceFalse) {
return;
}
const getRoot = function () {
return viewBlock.get();
};
const setupHtml = function (html) {
viewBlock.update(html);
};
const findElm = function (selector) {
return DomQuery(selector, getRoot())[0];
};
const findElmPos = function (selector, offset) {
return CaretPosition(DomQuery(selector, getRoot())[0], offset);
};
const findTextPos = function (selector, offset) {
return CaretPosition(DomQuery(selector, getRoot())[0].firstChild, offset);
};
const logicalCaret = CaretWalker(getRoot());
suite.test('inside empty root', function () {
setupHtml('');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null);
});
suite.test('on null', function () {
setupHtml('');
CaretAsserts.assertCaretPosition(logicalCaret.next(null), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(null), null);
});
suite.test('within text node in root', function () {
setupHtml('abc');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 0)), CaretPosition(getRoot().firstChild, 1));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 2));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 3));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot().firstChild, 2));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 1));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 0)), null);
});
suite.test('within text node in element', function () {
setupHtml('<p>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 0)), findTextPos('p', 1));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 1)), findTextPos('p', 2));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 2)), findTextPos('p', 3));
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 3)), null);
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 3)), findTextPos('p', 2));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 2)), findTextPos('p', 1));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 1)), findTextPos('p', 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 0)), null);
});
suite.test('from index text node over comment', function () {
setupHtml('abcd<!-- x -->abcd');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot().firstChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().firstChild, 4));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot().lastChild, 4));
});
suite.test('from text to text across elements', function () {
setupHtml('<p>abc</p><p>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), findTextPos('p:last', 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p:last', 0)), findTextPos('p:first', 3));
});
suite.test('from text to text across elements with siblings', function () {
setupHtml('<p>abc<b><!-- x --></b></p><p><b><!-- x --></b></p><p><b><!-- x --></b>abc</p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), CaretPosition(findElm('p:last').lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last').lastChild, 0)), findTextPos('p:first', 3));
});
suite.test('from input to text', function () {
setupHtml('123<input>456');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().lastChild, 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().firstChild, 3));
});
suite.test('from input to input across elements', function () {
setupHtml('<p><input></p><p><input></p>');
CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(findElm('p:first'), 1)), CaretPosition(findElm('p:last'), 0));
CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last'), 0)), CaretPosition(findElm('p:first'), 1));
});
//.........这里部分代码省略.........
示例4: function
UnitTest.asynctest('browser.tinymce.core.CaretUtilTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
const assertRange = CaretAsserts.assertRange;
const createRange = CaretAsserts.createRange;
const viewBlock = ViewBlock();
if (!Env.ceFalse) {
return;
}
const ZWSP = Zwsp.ZWSP;
const getRoot = function () {
return viewBlock.get();
};
const setupHtml = function (html) {
viewBlock.update(html);
// IE messes zwsp up on innerHTML so we need to first set markers then replace then using dom operations
viewBlock.get().innerHTML = html.replace(new RegExp(ZWSP, 'g'), '__ZWSP__');
replaceWithZwsp(viewBlock.get());
};
const replaceWithZwsp = function (node) {
for (let i = 0; i < node.childNodes.length; i++) {
const childNode = node.childNodes[i];
if (childNode.nodeType === 3) {
childNode.nodeValue = childNode.nodeValue.replace(/__ZWSP__/, ZWSP);
} else {
replaceWithZwsp(childNode);
}
}
};
const findElm = function (selector) {
return $(selector, getRoot())[0];
};
suite.test('isForwards', function () {
LegacyUnit.equal(CaretUtils.isForwards(1), true);
LegacyUnit.equal(CaretUtils.isForwards(10), true);
LegacyUnit.equal(CaretUtils.isForwards(0), false);
LegacyUnit.equal(CaretUtils.isForwards(-1), false);
LegacyUnit.equal(CaretUtils.isForwards(-10), false);
});
suite.test('isBackwards', function () {
LegacyUnit.equal(CaretUtils.isBackwards(1), false);
LegacyUnit.equal(CaretUtils.isBackwards(10), false);
LegacyUnit.equal(CaretUtils.isBackwards(0), false);
LegacyUnit.equal(CaretUtils.isBackwards(-1), true);
LegacyUnit.equal(CaretUtils.isBackwards(-10), true);
});
suite.test('findNode', function () {
setupHtml('<b>abc</b><b><i>123</i></b>def');
const isBold = function (node) {
return node.nodeName === 'B';
};
const isText = function (node) {
return node.nodeType === 3;
};
LegacyUnit.equalDom(CaretUtils.findNode(getRoot(), 1, isBold, getRoot()), getRoot().firstChild);
LegacyUnit.equalDom(CaretUtils.findNode(getRoot(), 1, isText, getRoot()), getRoot().firstChild.firstChild);
LegacyUnit.equal(CaretUtils.findNode(getRoot().childNodes[1], 1, isBold, getRoot().childNodes[1]) === null, true);
LegacyUnit.equal(CaretUtils.findNode(getRoot().childNodes[1], 1, isText, getRoot().childNodes[1]).nodeName, '#text');
LegacyUnit.equalDom(CaretUtils.findNode(getRoot(), -1, isBold, getRoot()), getRoot().childNodes[1]);
LegacyUnit.equalDom(CaretUtils.findNode(getRoot(), -1, isText, getRoot()), getRoot().lastChild);
});
suite.test('getEditingHost', function () {
setupHtml('<span contentEditable="true"><span contentEditable="false"></span></span>');
LegacyUnit.equalDom(CaretUtils.getEditingHost(getRoot(), getRoot()), getRoot());
LegacyUnit.equalDom(CaretUtils.getEditingHost(getRoot().firstChild, getRoot()), getRoot());
LegacyUnit.equalDom(CaretUtils.getEditingHost(getRoot().firstChild.firstChild, getRoot()), getRoot().firstChild);
});
suite.test('getParentBlock', function () {
setupHtml('<p>abc</p><div><p><table><tr><td>X</td></tr></p></div>');
LegacyUnit.equalDom(CaretUtils.getParentBlock(findElm('p:first')), findElm('p:first'));
LegacyUnit.equalDom(CaretUtils.getParentBlock(findElm('td:first').firstChild), findElm('td:first'));
LegacyUnit.equalDom(CaretUtils.getParentBlock(findElm('td:first')), findElm('td:first'));
LegacyUnit.equalDom(CaretUtils.getParentBlock(findElm('table')), findElm('table'));
});
suite.test('isInSameBlock', function () {
setupHtml('<p>abc</p><p>def<b>ghj</b></p>');
LegacyUnit.strictEqual(CaretUtils.isInSameBlock(
CaretPosition(findElm('p:first').firstChild, 0),
CaretPosition(findElm('p:last').firstChild, 0)
//.........这里部分代码省略.........
示例5: function
UnitTest.asynctest('browser.tinymce.core.dom.SerializerTest', function (success, failure) {
const suite = LegacyUnit.createSuite();
const DOM = DOMUtils.DOM;
const viewBlock = ViewBlock();
const teardown = function () {
viewBlock.update('');
};
const addTeardown = function (steps) {
return Arr.bind(steps, function (step) {
return [step, Step.sync(teardown)];
});
};
suite.test('Schema rules', function () {
let ser = Serializer({ fix_list_elements : true });
ser.setRules('@[id|title|class|style],div,img[src|alt|-style|border],span,hr');
DOM.setHTML('test', '<img title="test" src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" alt="test" ' +
'border="0" style="border: 1px solid red" class="test" /><span id="test2">test</span><hr />');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<img title="test" class="test" src="tinymce/ui/img/raster.gif" ' +
'alt="test" border="0" /><span id="test2">test</span><hr />', 'Global rule'
);
ser.setRules('*a[*],em/i[*],strong/b[*i*]');
DOM.setHTML('test', '<a href="test" data-mce-href="test">test</a><strong title="test" class="test">test2</strong><em title="test">test3</em>');
LegacyUnit.equal(ser.serialize(DOM.get('test')), '<a href="test">test</a><strong title="test">test2</strong><em title="test">' +
'test3</em>', 'Wildcard rules');
ser.setRules('br,hr,input[type|name|value],div[id],span[id],strong/b,a,em/i,a[!href|!name],img[src|border=0|title={$uid}]');
DOM.setHTML('test', '<br /><hr /><input type="text" name="test" value="val" class="no" />' +
'<span id="test2" class="no"><b class="no">abc</b><em class="no">123</em></span>123<a href="file.html" ' +
'data-mce-href="file.html">link</a><a name="anchor"></a><a>no</a><img src="tinymce/ui/img/raster.gif" ' +
'data-mce-src="tinymce/ui/img/raster.gif" />');
LegacyUnit.equal(ser.serialize(DOM.get('test')), '<div id="test"><br /><hr /><input type="text" name="test" value="val" />' +
'<span id="test2"><strong>abc</strong><em>123</em></span>123<a href="file.html">link</a>' +
'<a name="anchor"></a>no<img src="tinymce/ui/img/raster.gif" border="0" title="mce_0" /></div>', 'Output name and attribute rules');
ser.setRules('img[src|border=0|alt=]');
DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" border="0" alt="" />');
LegacyUnit.equal(ser.serialize(DOM.get('test')), '<img src="tinymce/ui/img/raster.gif" border="0" alt="" />', 'Default attribute with empty value');
ser.setRules('img[src|border=0|alt=],div[style|id],*[*]');
DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" /><hr />');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<img src="tinymce/ui/img/raster.gif" border="0" alt="" /><hr />'
);
ser = Serializer({
valid_elements : 'img[src|border=0|alt=]',
extended_valid_elements : 'div[id],img[src|alt=]'
});
DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" alt="" />');
LegacyUnit.equal(
ser.serialize(DOM.get('test')),
'<div id="test"><img src="tinymce/ui/img/raster.gif" alt="" /></div>'
);
ser = Serializer({ invalid_elements : 'hr,br' });
DOM.setHTML('test', '<img src="tinymce/ui/img/raster.gif" data-mce-src="tinymce/ui/img/raster.gif" /><hr /><br />');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<img src="tinymce/ui/img/raster.gif" />'
);
});
suite.test('allow_unsafe_link_target (default)', function () {
const ser = Serializer({ });
DOM.setHTML('test', '<a href="a" target="_blank">a</a><a href="b" target="_blank">b</a>');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<a href="a" target="_blank" rel="noopener">a</a><a href="b" target="_blank" rel="noopener">b</a>'
);
DOM.setHTML('test', '<a href="a" rel="lightbox" target="_blank">a</a><a href="b" rel="lightbox" target="_blank">b</a>');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<a href="a" target="_blank" rel="lightbox noopener">a</a><a href="b" target="_blank" rel="lightbox noopener">b</a>'
);
DOM.setHTML('test', '<a href="a" rel="lightbox x" target="_blank">a</a><a href="b" rel="lightbox x" target="_blank">b</a>');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<a href="a" target="_blank" rel="lightbox noopener x">a</a><a href="b" target="_blank" rel="lightbox noopener x">b</a>'
);
DOM.setHTML('test', '<a href="a" rel="noopener a" target="_blank">a</a>');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
'<a href="a" target="_blank" rel="noopener a">a</a>'
);
DOM.setHTML('test', '<a href="a" rel="a noopener b" target="_blank">a</a>');
LegacyUnit.equal(
ser.serialize(DOM.get('test'), { getInner: true }),
//.........这里部分代码省略.........
示例6: Theme
UnitTest.asynctest('browser.tinymce.core.content.InsertContentCommandTest', (success, failure) => {
const suite = LegacyUnit.createSuite();
Theme();
const normalizeRng = function (rng) {
if (rng.startContainer.nodeType === 3) {
if (rng.startOffset === 0) {
rng.setStartBefore(rng.startContainer);
} else if (rng.startOffset >= rng.startContainer.nodeValue.length - 1) {
rng.setStartAfter(rng.startContainer);
}
}
if (rng.endContainer.nodeType === 3) {
if (rng.endOffset === 0) {
rng.setEndBefore(rng.endContainer);
} else if (rng.endOffset >= rng.endContainer.nodeValue.length - 1) {
rng.setEndAfter(rng.endContainer);
}
}
return rng;
};
const ok = function (value, label?) {
return LegacyUnit.equal(value, true, label);
};
const getContent = function (editor) {
return editor.getContent();
};
suite.test('mceInsertContent - p inside text of p', function (editor) {
let rng;
editor.setContent('<p>1234</p>');
editor.focus();
rng = editor.dom.createRng();
rng.setStart(editor.dom.select('p')[0].firstChild, 1);
rng.setEnd(editor.dom.select('p')[0].firstChild, 3);
editor.selection.setRng(rng);
editor.execCommand('mceInsertContent', false, '<p>abc</p>');
LegacyUnit.equal(getContent(editor), '<p>1</p><p>abc</p><p>4</p>');
rng = normalizeRng(editor.selection.getRng(true));
ok(rng.collapsed);
LegacyUnit.equal(rng.startContainer.nodeName, 'P');
LegacyUnit.equal(rng.startOffset, 1);
LegacyUnit.equal(rng.endContainer.nodeName, 'P');
LegacyUnit.equal(rng.endOffset, 1);
LegacyUnit.equal(rng.startContainer.innerHTML, 'abc');
});
suite.test('mceInsertContent before HR', function (editor) {
let rng;
editor.setContent('<hr>');
editor.focus();
rng = editor.dom.createRng();
rng.setStart(editor.getBody(), 0);
rng.setEnd(editor.getBody(), 0);
editor.selection.setRng(rng);
editor.execCommand('mceInsertContent', false, 'x');
LegacyUnit.equal(getContent(editor), '<p>x</p><hr />');
});
suite.test('mceInsertContent HR at end of H1', function (editor) {
editor.setContent('<h1>abc</h1>');
LegacyUnit.setSelection(editor, 'h1', 3);
editor.execCommand('mceInsertContent', false, '<hr>');
LegacyUnit.equalDom(editor.selection.getNode(), editor.getBody().lastChild);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1');
LegacyUnit.equal(getContent(editor), '<h1>abc</h1><hr /><h1>\u00a0</h1>');
});
suite.test('mceInsertContent HR at end of H1 with P sibling', function (editor) {
editor.setContent('<h1>abc</h1><p>def</p>');
LegacyUnit.setSelection(editor, 'h1', 3);
editor.execCommand('mceInsertContent', false, '<hr>');
LegacyUnit.equalDom(editor.selection.getNode(), editor.getBody().lastChild);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
LegacyUnit.equal(getContent(editor), '<h1>abc</h1><hr /><p>def</p>');
});
suite.test('mceInsertContent HR at end of H1 with inline elements with P sibling', function (editor) {
editor.setContent('<h1><strong>abc</strong></h1><p>def</p>');
LegacyUnit.setSelection(editor, 'strong', 3);
editor.execCommand('mceInsertContent', false, '<hr>');
LegacyUnit.equalDom(editor.selection.getNode(), editor.getBody().lastChild);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
LegacyUnit.equal(getContent(editor), '<h1><strong>abc</strong></h1><hr /><p>def</p>');
});
suite.test('mceInsertContent empty block', function (editor) {
editor.setContent('<h1>abc</h1>');
LegacyUnit.setSelection(editor, 'h1', 1);
editor.execCommand('mceInsertContent', false, '<p></p>');
LegacyUnit.equalDom(editor.selection.getNode(), editor.getBody().childNodes[1]);
LegacyUnit.equal(editor.selection.getNode().nodeName, 'P');
LegacyUnit.equal(getContent(editor), '<h1>a</h1><p>\u00a0</p><h1>bc</h1>');
//.........这里部分代码省略.........
示例7: function
UnitTest.asynctest('browser.tinymce.core.util.UriTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
const ok = function (value, label?) {
// console.log(value, label);
return LegacyUnit.equal(value, true, label);
};
/* eslint max-len: 0 */
suite.test('protocol relative url', function () {
const uri = new URI('//www.site.com/dir1/file?query#hash');
LegacyUnit.equal(uri.protocol, '');
LegacyUnit.equal(uri.host, 'www.site.com');
LegacyUnit.equal(uri.path, '/dir1/file');
LegacyUnit.equal(uri.query, 'query');
LegacyUnit.equal(uri.anchor, 'hash');
LegacyUnit.equal(uri.source, '//www.site.com/dir1/file?query#hash');
LegacyUnit.equal(uri.getURI(), '//www.site.com/dir1/file?query#hash');
LegacyUnit.equal(uri.toRelative('//www.site.com/dir1/file2'), 'file2');
LegacyUnit.equal(uri.toRelative('//www.site2.com/dir1/file2'), '//www.site2.com/dir1/file2');
LegacyUnit.equal(uri.toAbsolute('../file2'), '//www.site.com/dir1/file2');
LegacyUnit.equal(uri.toAbsolute('//www.site2.com/dir1/file2'), '//www.site2.com/dir1/file2');
});
suite.test('parseFullURLs', function () {
LegacyUnit.equal(new URI('http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI(), 'http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash');
ok(new URI('http://a2bc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI() !== 'http://abc:123@www.site.com:8080/path/dir/file.ext?key1=val1&key2=val2#hash');
LegacyUnit.equal(new URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890:8080/path/dir/file.ext?key1=val1&key2=val2#hash').getURI(), 'chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890:8080/path/dir/file.ext?key1=val1&key2=val2#hash');
});
suite.test('relativeURLs', function () {
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/file.html').toRelative('http://www.site.com/dir1/dir3/file.html'), '../dir3/file.html');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/file.html').toRelative('http://www.site.com/dir3/dir4/file.html'), '../../dir3/dir4/file.html');
LegacyUnit.equal(new URI('http://www.site.com/dir1/').toRelative('http://www.site.com/dir1/dir3/file.htm'), 'dir3/file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site2.com/dir1/dir3/file.htm'), 'http://www.site2.com/dir1/dir3/file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site.com:8080/dir1/dir3/file.htm'), 'http://www.site.com:8080/dir1/dir3/file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('https://www.site.com/dir1/dir3/file.htm'), 'https://www.site.com/dir1/dir3/file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm'), '../../file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm?id=1#a'), '../../file.htm?id=1#a');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('mailto:test@test.com'), 'mailto:test@test.com');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('news:test'), 'news:test');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('javascript:void(0);'), 'javascript:void(0);');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('about:blank'), 'about:blank');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('#test'), '#test');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('test.htm'), 'test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('http://www.site.com/dir1/dir2/test.htm'), 'test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('dir2/test.htm'), 'dir2/test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('../dir2/test.htm'), 'test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('../dir3/'), '../dir3/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('../../../../../../test.htm'), '../../test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('//www.site.com/test.htm'), '../../test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('@@tinymce'), '@@tinymce'); // Zope 3 URL
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('../@@tinymce'), '../@@tinymce'); // Zope 3 URL
LegacyUnit.equal(new URI('http://www.site.com/').toRelative('dir2/test.htm'), 'dir2/test.htm');
LegacyUnit.equal(new URI('http://www.site.com/').toRelative('./'), './');
LegacyUnit.equal(new URI('http://www.site.com/test/').toRelative('../'), '../');
LegacyUnit.equal(new URI('http://www.site.com/test/test/').toRelative('../'), '../');
LegacyUnit.equal(new URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/').toRelative('/dir1', true), '../');
LegacyUnit.equal(new URI('http://www.site.com/').toRelative('http://www.site.com/'), 'http://www.site.com/');
LegacyUnit.equal(new URI('http://www.site.com/').toRelative('http://www.site.com'), 'http://www.site.com/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm?q=http://site.com/'), '../../file.htm?q=http://site.com/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toRelative('/file.htm#http://site.com/'), '../../file.htm#http://site.com/');
});
suite.test('absoluteURLs', function () {
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute(''), 'http://www.site.com/dir1/dir2/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('../dir3'), 'http://www.site.com/dir1/dir3');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('../dir3', 1), '/dir1/dir3');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('../../../../dir3'), 'http://www.site.com/dir3');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('../abc/def/../../abc/../dir3/file.htm'), 'http://www.site.com/dir1/dir3/file.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('http://www.site.com/dir2/dir3'), 'http://www.site.com/dir2/dir3');
LegacyUnit.equal(new URI('http://www.site2.com/dir1/dir2/').toAbsolute('http://www.site2.com/dir2/dir3'), 'http://www.site2.com/dir2/dir3');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('mailto:test@test.com'), 'mailto:test@test.com');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('news:test'), 'news:test');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('javascript:void(0);'), 'javascript:void(0);');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('about:blank'), 'about:blank');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('#test'), '#test');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('test.htm'), 'http://www.site.com/dir1/dir2/test.htm');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('../@@tinymce'), 'http://www.site.com/dir1/@@tinymce'); // Zope 3 URL
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').getURI(), 'http://www.site.com/dir1/dir2/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('/dir1/dir1/'), 'http://www.site.com/dir1/dir1/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('https://www.site.com/dir1/dir2/', true), 'https://www.site.com/dir1/dir2/');
LegacyUnit.equal(new URI('http://www.site.com/dir1/dir2/').toAbsolute('http://www.site.com/dir1/dir2/', true), '/dir1/dir2/');
LegacyUnit.equal(new URI('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/').toAbsolute('chrome-extension://abcdefghijklmnopqrstuvwzyz1234567890/dir1/dir2/', true), '/dir1/dir2/');
});
suite.test('strangeURLs', function () {
LegacyUnit.equal(new URI('//www.site.com').getURI(), '//www.site.com');
LegacyUnit.equal(new URI('mailto:test@test.com').getURI(), 'mailto:test@test.com');
LegacyUnit.equal(new URI('news:somegroup').getURI(), 'news:somegroup');
LegacyUnit.equal(new URI('skype:somegroup').getURI(), 'skype:somegroup');
LegacyUnit.equal(new URI('tel:somegroup').getURI(), 'tel:somegroup');
LegacyUnit.equal(new URI('//www.site.com/a@b').getURI(), '//www.site.com/a@b');
});
suite.test('isSameOrigin', function () {
//.........这里部分代码省略.........
示例8: function
UnitTest.asynctest('browser.tinymce.ui.ControlTest', function () {
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
const viewBlock = ViewBlock();
Control.translate = function (text) {
return EditorManager.translate(text);
};
// Registers ui widgets to factory
Api.registerToFactory();
suite.test('Initial states', function () {
let ctrl;
ctrl = new Control({});
// Check initial states
LegacyUnit.equal(ctrl.disabled(), false);
LegacyUnit.equal(ctrl.active(), false);
LegacyUnit.equal(ctrl.visible(), true);
LegacyUnit.equal(ctrl.text(), undefined);
LegacyUnit.equal(ctrl.name(), undefined);
LegacyUnit.equal(ctrl.title(), undefined);
LegacyUnit.equal(ctrl.parent(), undefined);
LegacyUnit.equal(ctrl.settings, {});
});
suite.test('Settings', function () {
const ctrl = new Control({
disabled: true,
active: true,
visible: true,
text: 'Text',
title: 'Title',
name: 'Name'
});
// Check settings states
LegacyUnit.equal(ctrl.disabled(), true);
LegacyUnit.equal(ctrl.active(), true);
LegacyUnit.equal(ctrl.visible(), true);
LegacyUnit.equal(ctrl.text(), 'Text');
LegacyUnit.equal(ctrl.name(), 'Name');
LegacyUnit.equal(ctrl.title(), 'Title');
LegacyUnit.equal(ctrl.parent(), undefined);
LegacyUnit.equal(ctrl.settings, {
disabled: true,
active: true,
visible: true,
text: 'Text',
title: 'Title',
name: 'Name'
});
});
suite.test('Properties', function () {
let ctrl, cont;
cont = new Container({});
ctrl = new Control({});
// Set all states
ctrl = ctrl.
disabled(true).
active(true).
visible(true).
text('Text').
title('Title').
name('Name').parent(cont);
// Check states
LegacyUnit.equal(ctrl.disabled(), true);
LegacyUnit.equal(ctrl.active(), true);
LegacyUnit.equal(ctrl.visible(), true);
LegacyUnit.equal(ctrl.text(), 'Text');
LegacyUnit.equal(ctrl.name(), 'Name');
LegacyUnit.equal(ctrl.title(), 'Title');
LegacyUnit.equal(ctrl.parent(), cont);
LegacyUnit.equal(ctrl.settings, {});
});
suite.test('Chained methods', function () {
let ctrl = new Control({});
// Set all states
ctrl = ctrl.
on('click', function () { }).
off().
renderTo(viewBlock.get()).
remove();
// Check so that the chain worked
LegacyUnit.equal(ctrl instanceof Control, true);
});
suite.test('Events', function () {
let ctrl, count;
//.........这里部分代码省略.........
示例9: function
UnitTest.asynctest('browser.tinymce.core.html.DomParserTest', function (success, failure) {
const suite = LegacyUnit.createSuite();
const schema = Schema({ valid_elements: '*[class|title]' });
const serializer = Serializer({}, schema);
let parser, root;
const countNodes = function (node, counter?) {
let sibling;
if (!counter) {
counter = {};
}
if (node.name in counter) {
counter[node.name]++;
} else {
counter[node.name] = 1;
}
for (sibling = node.firstChild; sibling; sibling = sibling.next) {
countNodes(sibling, counter);
}
return counter;
};
schema.addValidChildren('+body[style]');
suite.test('Parse element', function () {
let parser, root;
parser = DomParser({}, schema);
root = parser.parse('<B title="title" class="class">test</B>');
LegacyUnit.equal(serializer.serialize(root), '<b class="class" title="title">test</b>', 'Inline element');
LegacyUnit.equal(root.firstChild.type, 1, 'Element type');
LegacyUnit.equal(root.firstChild.name, 'b', 'Element name');
LegacyUnit.deepEqual(
root.firstChild.attributes, [{ name: 'title', value: 'title' },
{ name: 'class', value: 'class' }],
'Element attributes'
);
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'b': 1, '#text': 1 }, 'Element attributes (count)');
parser = DomParser({}, schema);
root = parser.parse(' \t\r\n <SCRIPT> \t\r\n a < b > \t\r\n </S' + 'CRIPT> \t\r\n ');
LegacyUnit.equal(serializer.serialize(root), '<script> \t\r\n a < b > \t\r\n </s' + 'cript>', 'Retain code inside SCRIPT');
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'script': 1, '#text': 1 }, 'Retain code inside SCRIPT (count)');
});
suite.test('Whitespace', function () {
parser = DomParser({}, schema);
root = parser.parse(' \t\r\n <B> \t\r\n test \t\r\n </B> \t\r\n ');
LegacyUnit.equal(serializer.serialize(root), ' <b> test </b> ', 'Redundant whitespace (inline element)');
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'b': 1, '#text': 3 }, 'Redundant whitespace (inline element) (count)');
parser = DomParser({}, schema);
root = parser.parse(' \t\r\n <P> \t\r\n test \t\r\n </P> \t\r\n ');
LegacyUnit.equal(serializer.serialize(root), '<p>test</p>', 'Redundant whitespace (block element)');
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'p': 1, '#text': 1 }, 'Redundant whitespace (block element) (count)');
parser = DomParser({}, schema);
root = parser.parse(' \t\r\n <SCRIPT> \t\r\n test \t\r\n </S' + 'CRIPT> \t\r\n ');
LegacyUnit.equal(
serializer.serialize(root),
'<script> \t\r\n test \t\r\n </s' + 'cript>',
'Whitespace around and inside SCRIPT'
);
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'script': 1, '#text': 1 }, 'Whitespace around and inside SCRIPT (count)');
parser = DomParser({}, schema);
root = parser.parse(' \t\r\n <STYLE> \t\r\n test \t\r\n </STYLE> \t\r\n ');
LegacyUnit.equal(serializer.serialize(root), '<style> \t\r\n test \t\r\n </style>', 'Whitespace around and inside STYLE');
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'style': 1, '#text': 1 }, 'Whitespace around and inside STYLE (count)');
parser = DomParser({}, schema);
root = parser.parse('<ul>\n<li>Item 1\n<ul>\n<li>\n \t Indented \t \n</li>\n</ul>\n</li>\n</ul>\n');
LegacyUnit.equal(
serializer.serialize(root),
'<ul><li>Item 1<ul><li>Indented</li></ul></li></ul>',
'Whitespace around and inside blocks (ul/li)'
);
LegacyUnit.deepEqual(countNodes(root), { 'body': 1, 'li': 2, 'ul': 2, '#text': 2 }, 'Whitespace around and inside blocks (ul/li) (count)');
parser = DomParser({}, Schema({ invalid_elements: 'hr,br' }));
root = parser.parse(
'\n<hr />\n<br />\n<div>\n<hr />\n<br />\n<img src="file.gif" data-mce-src="file.gif" />\n<hr />\n<br />\n</div>\n<hr />\n<br />\n'
);
LegacyUnit.equal(
serializer.serialize(root),
'<div><img src="file.gif" data-mce-src="file.gif" /></div>',
'Whitespace where SaxParser will produce multiple whitespace nodes'
);
LegacyUnit.deepEqual(
countNodes(root),
{ body: 1, div: 1, img: 1 },
'Whitespace where SaxParser will produce multiple whitespace nodes (count)'
);
});
//.........这里部分代码省略.........
示例10: function
UnitTest.asynctest('browser.tinymce.core.dom.DomUtilsTest', function () {
const DOM = new DOMUtils(document, { keep_values : true, schema : Schema() });
const success = arguments[arguments.length - 2];
const failure = arguments[arguments.length - 1];
const suite = LegacyUnit.createSuite();
suite.test('parseStyle', function () {
let dom;
DOM.add(document.body, 'div', { id : 'test' });
dom = new DOMUtils(document, { hex_colors : true, keep_values : true, url_converter (u) {
return 'X' + u + 'Y';
} });
LegacyUnit.equal(
dom.serializeStyle(dom.parseStyle('border: 1px solid red; color: green')),
'border: 1px solid red; color: green;'
);
LegacyUnit.equal(
dom.serializeStyle(dom.parseStyle('border: 1px solid rgb(0, 255, 255); color: green')),
'border: 1px solid #00ffff; color: green;'
);
LegacyUnit.equal(
dom.serializeStyle(
dom.parseStyle('border-top: 1px solid red; border-left: 1px solid red; border-bottom: 1px solid red; border-right: 1px solid red;')
),
'border: 1px solid red;'
);
LegacyUnit.equal(
dom.serializeStyle(
dom.parseStyle('border-width: 1pt 1pt 1pt 1pt; border-style: none none none none; border-color: black black black black;')
),
'border: 1pt none black;'
);
LegacyUnit.equal(
dom.serializeStyle(
dom.parseStyle('border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;')
),
'border-width: 1pt 4pt 2pt 3pt; border-style: solid dashed dotted none; border-color: black red green blue;'
);
LegacyUnit.equal(
dom.serializeStyle(dom.parseStyle('background: transparent url(test.gif);')),
'background: transparent url(\'Xtest.gifY\');'
);
LegacyUnit.equal(
dom.serializeStyle(dom.parseStyle('background: transparent url(http://www.site.com/test.gif?a=1&b=2);')),
'background: transparent url(\'Xhttp://www.site.com/test.gif?a=1&b=2Y\');'
);
dom.setHTML('test', '<span id="test2" style=" margin-left: 1px; margin-top: 1px; margin-right: 1px; margin-bottom: 1px "></span>');
LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'margin: 1px;');
dom.setHTML('test', '<span id="test2" style="background-image: url(test.gif);"></span>');
LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xtest.gifY\');');
// dom.get('test').innerHTML = '<span id="test2" style="border: 1px solid #00ff00"></span>';
// LegacyUnit.equal(dom.getAttrib('test2', 'style'), Env.ue && !window.getSelection ?
// 'border: #00ff00 1px solid;' : 'border: 1px solid #00ff00;'); // IE has a separate output
dom.get('test').innerHTML = '<span id="test2" style="background-image: url(http://www.site.com/test.gif);"></span>';
LegacyUnit.equal(dom.getAttrib('test2', 'style'), 'background-image: url(\'Xhttp://www.site.com/test.gifY\');');
DOM.remove('test');
});
suite.test('addClass', function () {
DOM.add(document.body, 'div', { id : 'test' });
DOM.get('test').className = '';
DOM.addClass('test', 'abc');
LegacyUnit.equal(DOM.get('test').className, 'abc');
DOM.addClass('test', '123');
LegacyUnit.equal(DOM.get('test').className, 'abc 123');
DOM.get('test').innerHTML = '<span id="test2"></span><span id="test3"></span><span id="test4"></span>';
DOM.addClass(DOM.select('span', 'test'), 'abc');
LegacyUnit.equal(DOM.get('test2').className, 'abc');
LegacyUnit.equal(DOM.get('test3').className, 'abc');
LegacyUnit.equal(DOM.get('test4').className, 'abc');
DOM.get('test').innerHTML = '';
DOM.remove('test');
});
suite.test('removeClass', function () {
DOM.add(document.body, 'div', { id : 'test' });
DOM.get('test').className = 'abc 123 xyz';
DOM.removeClass('test', '123');
LegacyUnit.equal(DOM.get('test').className, 'abc xyz');
DOM.get('test').innerHTML = (
//.........这里部分代码省略.........