OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
core
/
test
/
ts
/
browser
/
dom
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 06:14:55 AM
rwxr-xr-x
📄
ContentCssCorsTest.ts
1.26 KB
02/20/2020 06:13:25 AM
rw-r--r--
📄
ControlSelectionTest.ts
1.8 KB
02/20/2020 06:13:25 AM
rw-r--r--
📄
DimensionsTest.ts
1.59 KB
02/20/2020 06:13:26 AM
rw-r--r--
📄
DomUtilsTest.ts
28.64 KB
02/20/2020 06:13:26 AM
rw-r--r--
📄
ElementTypeTest.ts
4.84 KB
02/20/2020 06:13:27 AM
rw-r--r--
📄
EmptyTest.ts
2 KB
02/20/2020 06:13:27 AM
rw-r--r--
📄
EventUtilsTest.ts
13.79 KB
02/20/2020 06:13:28 AM
rw-r--r--
📄
NodePathTest.ts
1.65 KB
02/20/2020 06:13:28 AM
rw-r--r--
📄
NodeTypeTest.ts
6.15 KB
02/20/2020 06:13:29 AM
rw-r--r--
📄
PaddingBrTest.ts
3.99 KB
02/20/2020 06:13:29 AM
rw-r--r--
📄
ParentsTest.ts
4.24 KB
02/20/2020 06:13:30 AM
rw-r--r--
📄
ScrollIntoViewTest.ts
8.76 KB
02/20/2020 06:13:30 AM
rw-r--r--
📄
SelectionEventsTest.ts
4.32 KB
02/20/2020 06:13:31 AM
rw-r--r--
📄
SelectionQuirksTest.ts
3.6 KB
02/20/2020 06:13:31 AM
rw-r--r--
📄
SelectionTest.ts
52.46 KB
02/20/2020 06:13:33 AM
rw-r--r--
📄
SerializerEventsTest.ts
2.24 KB
02/20/2020 06:13:33 AM
rw-r--r--
📄
SerializerTest.ts
36.74 KB
02/20/2020 06:13:34 AM
rw-r--r--
📄
TreeWalkerTest.ts
2.76 KB
02/20/2020 06:13:34 AM
rw-r--r--
📄
TrimHtmlTest.ts
1.32 KB
02/20/2020 06:13:35 AM
rw-r--r--
📄
TrimNodeTest.ts
1.68 KB
02/20/2020 06:13:35 AM
rw-r--r--
Editing: ScrollIntoViewTest.ts
Close
import { Assertions, GeneralSteps, Logger, Pipeline, Step, Waiter, Cursors } from '@ephox/agar'; import { Cell } from '@ephox/katamari'; import { TinyApis, TinyLoader } from '@ephox/mcagar'; import { Element } from '@ephox/sugar'; import ScrollIntoView from 'tinymce/core/dom/ScrollIntoView'; import Theme from 'tinymce/themes/silver/Theme'; import { UnitTest } from '@ephox/bedrock'; import Editor from 'tinymce/core/api/Editor'; import { window } from '@ephox/dom-globals'; UnitTest.asynctest('browser.tinymce.core.dom.ScrollIntoViewTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; Theme(); const sScrollReset = function (editor) { return Step.sync(function () { editor.getWin().scrollTo(0, 0); }); }; const sSetContent = function (editor, tinyApis, html) { return GeneralSteps.sequence([ tinyApis.sSetContent(html), Waiter.sTryUntil('Wait for scrollHeight to be updated', Step.sync(function () { Assertions.assertEq('Scroll body should be more than 100', true, editor.getBody().scrollHeight > 100); }), 100, 1000) ]); }; const sScrollIntoView = function (editor, selector, alignToTop) { return Step.sync(function () { editor.selection.scrollIntoView(editor.dom.select(selector)[0], alignToTop); }); }; const sScrollElementIntoView = function (editor, selector, alignToTop) { return Step.sync(function () { ScrollIntoView.scrollElementIntoView(editor, editor.dom.select(selector)[0], alignToTop); }); }; const sScrollRangeIntoView = (editor: Editor, path: number[], offset: number) => { return Step.sync(function () { const x = Cursors.calculateOne(Element.fromDom(editor.getBody()), path); const rng = editor.dom.createRng(); rng.setStart(x.dom(), offset); rng.setEnd(x.dom(), offset); ScrollIntoView.scrollRangeIntoView(editor, rng); }); }; const sAssertScrollPosition = function (editor, x, y) { return Step.sync(function () { Assertions.assertEq('Scroll position X should be expected value', x, Math.round(editor.dom.getViewPort(editor.getWin()).x)); Assertions.assertEq('Scroll position Y should be expected value', y, Math.round(editor.dom.getViewPort(editor.getWin()).y)); }); }; const sAssertApproxScrollPosition = function (editor, x, y) { return Step.sync(function () { const actualX = editor.dom.getViewPort(editor.getWin()).x; const actualY = editor.dom.getViewPort(editor.getWin()).y; Assertions.assertEq(`Scroll position X should be expected value: ${x} got ${actualX}`, true, Math.abs(x - actualX) < 5); Assertions.assertEq(`Scroll position Y should be expected value: ${y} got ${actualY}`, true, Math.abs(y - actualY) < 5); }); }; const mBindScrollIntoViewEvent = function (editor) { return Step.stateful(function (value, next, die) { const state = Cell({}); const handler = function (e) { e.preventDefault(); state.set({ elm: e.elm, alignToTop: e.alignToTop }); }; editor.on('ScrollIntoView', handler); next({ handler, state }); }); }; const mAssertScrollIntoViewEventInfo = function (editor, expectedElementSelector, expectedAlignToTop) { return Step.stateful(function (value: any, next, die) { const expectedTarget = Element.fromDom(editor.dom.select(expectedElementSelector)[0]); const actualTarget = Element.fromDom(value.state.get().elm); Assertions.assertDomEq('Target should be expected element', expectedTarget, actualTarget); Assertions.assertEq('Align to top should be expected value', expectedAlignToTop, value.state.get().alignToTop); editor.off('ScrollIntoView', value.handler); next({}); }); }; const steps = function (editor, tinyApis) { return [ tinyApis.sFocus, Logger.t('Public Selection API', GeneralSteps.sequence([ Logger.t('Scroll to element align to bottom', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), sScrollIntoView(editor, 'div:nth-child(2)', false), sAssertScrollPosition(editor, 0, 974) ])), Logger.t('Scroll to element align to top', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), sScrollIntoView(editor, 'div:nth-child(2)', true), sAssertScrollPosition(editor, 0, 924) ])) ])), Logger.t('Private ScrollElementIntoView', GeneralSteps.sequence([ Logger.t('Scroll to element align to bottom', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), sScrollElementIntoView(editor, 'div:nth-child(2)', false), sAssertScrollPosition(editor, 0, 974) ])), Logger.t('Scroll to element align to top', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), sScrollElementIntoView(editor, 'div:nth-child(2)', true), sAssertScrollPosition(editor, 0, 924) ])) ])), Logger.t('Private ScrollRangeIntoView', GeneralSteps.sequence([ Logger.t('Scroll up/down', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), sScrollRangeIntoView(editor, [1, 0], 0), sAssertApproxScrollPosition(editor, 0, 921), sScrollRangeIntoView(editor, [0, 0], 0), sAssertApproxScrollPosition(editor, 0, 0), sScrollRangeIntoView(editor, [2, 0], 0), sAssertApproxScrollPosition(editor, 0, 971) ])) ])), Logger.t('Override scrollIntoView event', GeneralSteps.sequence([ Logger.t('Scroll to element align to bottom', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), mBindScrollIntoViewEvent(editor), sScrollIntoView(editor, 'div:nth-child(2)', false), mAssertScrollIntoViewEventInfo(editor, 'div:nth-child(2)', false), sAssertScrollPosition(editor, 0, 0) ])), Logger.t('Scroll to element align to top', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), mBindScrollIntoViewEvent(editor), sScrollIntoView(editor, 'div:nth-child(2)', true), mAssertScrollIntoViewEventInfo(editor, 'div:nth-child(2)', true), sAssertScrollPosition(editor, 0, 0) ])), Logger.t('Scroll to element align to bottom (private api)', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), mBindScrollIntoViewEvent(editor), sScrollElementIntoView(editor, 'div:nth-child(2)', false), mAssertScrollIntoViewEventInfo(editor, 'div:nth-child(2)', false), sAssertScrollPosition(editor, 0, 0) ])), Logger.t('Scroll to element align to top (private api)', GeneralSteps.sequence([ sScrollReset(editor), sSetContent(editor, tinyApis, '<div style="height: 1000px">a</div><div style="height: 50px">b</div><div style="height: 1000px">a</div>'), mBindScrollIntoViewEvent(editor), sScrollElementIntoView(editor, 'div:nth-child(2)', true), mAssertScrollIntoViewEventInfo(editor, 'div:nth-child(2)', true), sAssertScrollPosition(editor, 0, 0) ])) ])) ]; }; const isPhantomJs = function () { return /PhantomJS/.test(window.navigator.userAgent); }; TinyLoader.setup(function (editor, onSuccess, onFailure) { const tinyApis = TinyApis(editor); // Only run scrolling tests on real browsers doesn't seem to work on phantomjs for some reason Pipeline.async({}, isPhantomJs() ? [ ] : steps(editor, tinyApis), onSuccess, onFailure); }, { add_unload_trigger: false, base_url: '/project/tinymce/js/tinymce', content_style: 'body.mce-content-body { margin: 0 }' }, success, failure); });