diff --git a/src/tests/frontend/helper.js b/src/tests/frontend/helper.js index cf8cdcee6..37d5d548c 100644 --- a/src/tests/frontend/helper.js +++ b/src/tests/frontend/helper.js @@ -15,7 +15,7 @@ const helper = {}; return randomstring; }; - const getFrameJQuery = async ($iframe, includeSendkeys = false) => { + helper.getFrameJQuery = async ($iframe, includeSendkeys = false) => { const win = $iframe[0].contentWindow; const doc = win.document; @@ -123,7 +123,7 @@ const helper = {}; // set new iframe $('#iframe-container').append($iframe); await new Promise((resolve) => $iframe.one('load', resolve)); - helper.padChrome$ = await getFrameJQuery($('#iframe-container iframe'), true); + helper.padChrome$ = await helper.getFrameJQuery($('#iframe-container iframe'), true); helper.padChrome$.padeditor = helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_editor').padeditor; if (opts.clearCookies) { @@ -139,8 +139,10 @@ const helper = {}; if (opts._retry++ >= 4) throw new Error('Pad never loaded'); return await helper.aNewPad(opts); } - helper.padOuter$ = await getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'), false); - helper.padInner$ = await getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'), true); + helper.padOuter$ = + await helper.getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'), false); + helper.padInner$ = + await helper.getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'), true); // disable all animations, this makes tests faster and easier helper.padChrome$.fx.off = true; @@ -183,7 +185,7 @@ const helper = {}; // set new iframe $('#iframe-container').append($iframe); $iframe.one('load', async () => { - helper.admin$ = await getFrameJQuery($('#iframe-container iframe'), false); + helper.admin$ = await helper.getFrameJQuery($('#iframe-container iframe'), false); }); }; diff --git a/src/tests/frontend/helper/multipleUsers.js b/src/tests/frontend/helper/multipleUsers.js index 206913265..b4dfc9188 100644 --- a/src/tests/frontend/helper/multipleUsers.js +++ b/src/tests/frontend/helper/multipleUsers.js @@ -34,11 +34,11 @@ helper.multipleUsers = { }, async _loadJQueryForUser1Frame() { - this._user1.padChrome$ = await getFrameJQuery(this._user1.$frame, true); + this._user1.padChrome$ = await helper.getFrameJQuery(this._user1.$frame, true); this._user1.padOuter$ = - await getFrameJQuery(this._user1.padChrome$('iframe[name="ace_outer"]'), false); + await helper.getFrameJQuery(this._user1.padChrome$('iframe[name="ace_outer"]'), false); this._user1.padInner$ = - await getFrameJQuery(this._user1.padOuter$('iframe[name="ace_inner"]'), true); + await helper.getFrameJQuery(this._user1.padOuter$('iframe[name="ace_inner"]'), true); // update helper vars now that they are available helper.padChrome$ = this._user1.padChrome$; @@ -79,37 +79,6 @@ helper.multipleUsers = { }, }; -// copied from helper.js -const getFrameJQuery = async ($iframe, includeSendkeys = false) => { - const win = $iframe[0].contentWindow; - const doc = win.document; - - const load = async (url) => { - const elem = doc.createElement('script'); - elem.setAttribute('src', url); - const p = new Promise((resolve, reject) => { - const handler = (evt) => { - elem.removeEventListener('load', handler); - elem.removeEventListener('error', handler); - if (evt.type === 'error') return reject(new Error(`failed to load ${url}`)); - resolve(); - }; - elem.addEventListener('load', handler); - elem.addEventListener('error', handler); - }); - doc.head.appendChild(elem); - await p; - }; - - if (!win.$) await load('../../static/js/vendors/jquery.js'); - if (!win.bililiteRange && includeSendkeys) await load('../tests/frontend/lib/sendkeys.js'); - - win.$.window = win; - win.$.document = doc; - - return win.$; -}; - const getCookies = () => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils').Cookies;