electron/spec/webview-spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

432 lines
14 KiB
JavaScript
Raw Normal View History

const { expect } = require('chai');
2016-03-25 20:03:49 +00:00
const path = require('path');
const http = require('http');
const url = require('url');
const { ipcRenderer } = require('electron');
2018-09-13 16:10:51 +00:00
const { emittedOnce, waitForEvent } = require('./events-helpers');
const { ifdescribe, ifit, delay } = require('./spec-helpers');
2018-06-19 11:25:26 +00:00
const features = process._linkedBinding('electron_common_features');
const nativeModulesEnabled = !process.env.ELECTRON_SKIP_NATIVE_MODULE_TESTS;
2017-11-23 22:22:43 +00:00
/* Most of the APIs here don't use standard callbacks */
/* eslint-disable standard/no-callback-literal */
2017-05-07 05:14:52 +00:00
describe('<webview> tag', function () {
this.timeout(3 * 60 * 1000);
const fixtures = path.join(__dirname, 'fixtures');
let webview = null;
2018-06-19 11:25:26 +00:00
const loadWebView = async (webview, attributes = {}) => {
2018-05-14 22:00:49 +00:00
for (const [name, value] of Object.entries(attributes)) {
webview.setAttribute(name, value);
}
document.body.appendChild(webview);
2018-06-19 11:25:26 +00:00
await waitForEvent(webview, 'did-finish-load');
return webview;
2018-05-14 22:00:49 +00:00
};
2018-06-19 11:25:26 +00:00
const startLoadingWebViewAndWaitForMessage = async (webview, attributes = {}) => {
2018-09-13 16:10:51 +00:00
loadWebView(webview, attributes); // Don't wait for load to be finished.
2018-06-19 11:25:26 +00:00
const event = await waitForEvent(webview, 'console-message');
return event.message;
2018-05-14 22:00:49 +00:00
};
beforeEach(() => {
2016-03-28 20:47:31 +00:00
webview = new WebView();
2016-03-25 20:03:49 +00:00
});
afterEach(() => {
if (!document.body.contains(webview)) {
document.body.appendChild(webview);
2016-01-12 02:40:23 +00:00
}
webview.remove();
});
// FIXME(zcbenz): Disabled because of moving to OOPIF webview.
xdescribe('setDevToolsWebContents() API', () => {
2018-05-14 22:00:49 +00:00
it('sets webContents of webview as devtools', async () => {
2017-11-30 12:04:50 +00:00
const webview2 = new WebView();
2018-05-14 22:00:49 +00:00
loadWebView(webview2);
// Setup an event handler for further usage.
const waitForDomReady = waitForEvent(webview2, 'dom-ready');
2018-09-13 16:10:51 +00:00
loadWebView(webview, { src: 'about:blank' });
2018-05-14 22:00:49 +00:00
await waitForEvent(webview, 'dom-ready');
webview.getWebContents().setDevToolsWebContents(webview2.getWebContents());
webview.getWebContents().openDevTools();
await waitForDomReady;
// Its WebContents should be a DevTools.
const devtools = webview2.getWebContents();
expect(devtools.getURL().startsWith('devtools://devtools')).to.be.true();
2018-05-14 22:00:49 +00:00
const name = await devtools.executeJavaScript('InspectorFrontendHost.constructor.name');
document.body.removeChild(webview2);
expect(name).to.be.equal('InspectorFrontendHostImpl');
2017-11-30 12:04:50 +00:00
});
});
describe('<webview>.reload()', () => {
2018-05-14 22:00:49 +00:00
it('should emit beforeunload handler', async () => {
await loadWebView(webview, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
2018-05-14 22:00:49 +00:00
src: `file://${fixtures}/pages/beforeunload-false.html`
});
// Event handler has to be added before reload.
const waitForOnbeforeunload = waitForEvent(webview, 'ipc-message');
webview.reload();
2018-09-13 16:10:51 +00:00
const { channel } = await waitForOnbeforeunload;
expect(channel).to.equal('onbeforeunload');
2016-03-25 20:03:49 +00:00
});
});
describe('<webview>.goForward()', () => {
it('should work after a replaced history entry', (done) => {
let loadCount = 1;
const listener = (e) => {
if (loadCount === 1) {
expect(e.channel).to.equal('history');
expect(e.args[0]).to.equal(1);
expect(webview.canGoBack()).to.be.false();
expect(webview.canGoForward()).to.be.false();
} else if (loadCount === 2) {
expect(e.channel).to.equal('history');
expect(e.args[0]).to.equal(2);
expect(webview.canGoBack()).to.be.false();
expect(webview.canGoForward()).to.be.true();
webview.removeEventListener('ipc-message', listener);
}
};
2018-05-14 22:00:49 +00:00
const loadListener = () => {
try {
if (loadCount === 1) {
webview.src = `file://${fixtures}/pages/base-page.html`;
} else if (loadCount === 2) {
expect(webview.canGoBack()).to.be.true();
expect(webview.canGoForward()).to.be.false();
webview.goBack();
} else if (loadCount === 3) {
webview.goForward();
} else if (loadCount === 4) {
expect(webview.canGoBack()).to.be.true();
expect(webview.canGoForward()).to.be.false();
webview.removeEventListener('did-finish-load', loadListener);
done();
}
loadCount += 1;
} catch (e) {
done(e);
}
};
webview.addEventListener('ipc-message', listener);
webview.addEventListener('did-finish-load', loadListener);
2018-05-14 22:00:49 +00:00
loadWebView(webview, {
nodeintegration: 'on',
src: `file://${fixtures}/pages/history-replace.html`
});
});
});
// FIXME: https://github.com/electron/electron/issues/19397
xdescribe('<webview>.clearHistory()', () => {
2018-05-14 22:00:49 +00:00
it('should clear the navigation history', async () => {
const message = waitForEvent(webview, 'ipc-message');
await loadWebView(webview, {
2018-05-14 22:00:49 +00:00
nodeintegration: 'on',
src: `file://${fixtures}/pages/history.html`
});
const event = await message;
2018-05-14 22:00:49 +00:00
expect(event.channel).to.equal('history');
expect(event.args[0]).to.equal(2);
expect(webview.canGoBack()).to.be.true();
2018-05-14 22:00:49 +00:00
webview.clearHistory();
expect(webview.canGoBack()).to.be.false();
2016-03-25 20:03:49 +00:00
});
});
describe('basic auth', () => {
const auth = require('basic-auth');
2016-03-25 20:03:49 +00:00
it('should authenticate with correct credentials', (done) => {
const message = 'Authenticated';
const server = http.createServer((req, res) => {
const credentials = auth(req);
2016-01-12 02:40:23 +00:00
if (credentials.name === 'test' && credentials.pass === 'test') {
2016-03-25 20:03:49 +00:00
res.end(message);
2016-01-12 02:40:23 +00:00
} else {
2016-03-25 20:03:49 +00:00
res.end('failed');
2016-01-12 02:40:23 +00:00
}
2016-03-25 20:03:49 +00:00
server.close();
});
server.listen(0, '127.0.0.1', () => {
const port = server.address().port;
webview.addEventListener('ipc-message', (e) => {
try {
expect(e.channel).to.equal(message);
done();
} catch (e) {
done(e);
}
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
loadWebView(webview, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
2018-05-14 22:00:49 +00:00
src: `file://${fixtures}/pages/basic-auth.html?port=${port}`
});
2016-03-25 20:03:49 +00:00
});
});
});
describe('executeJavaScript', () => {
2018-05-14 22:00:49 +00:00
it('can return the result of the executed script', async () => {
await loadWebView(webview, {
src: 'about:blank'
});
const jsScript = "'4'+2";
const expectedResult = '42';
const result = await webview.executeJavaScript(jsScript);
expect(result).to.equal(expectedResult);
});
2016-03-25 20:03:49 +00:00
});
2019-06-17 15:39:36 +00:00
it('supports inserting CSS', async () => {
await loadWebView(webview, { src: `file://${fixtures}/pages/base-page.html` });
await webview.insertCSS('body { background-repeat: round; }');
const result = await webview.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")');
expect(result).to.equal('round');
});
it('supports removing inserted CSS', async () => {
await loadWebView(webview, { src: `file://${fixtures}/pages/base-page.html` });
const key = await webview.insertCSS('body { background-repeat: round; }');
await webview.removeInsertedCSS(key);
const result = await webview.executeJavaScript('window.getComputedStyle(document.body).getPropertyValue("background-repeat")');
expect(result).to.equal('repeat');
});
describe('sendInputEvent', () => {
2018-05-14 22:00:49 +00:00
it('can send keyboard event', async () => {
loadWebView(webview, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
2018-05-14 22:00:49 +00:00
src: `file://${fixtures}/pages/onkeyup.html`
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
await waitForEvent(webview, 'dom-ready');
const waitForIpcMessage = waitForEvent(webview, 'ipc-message');
webview.sendInputEvent({
type: 'keyup',
keyCode: 'c',
modifiers: ['shift']
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
2018-09-13 16:10:51 +00:00
const { channel, args } = await waitForIpcMessage;
expect(channel).to.equal('keyup');
expect(args).to.deep.equal(['C', 'KeyC', 67, true, false]);
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
it('can send mouse event', async () => {
loadWebView(webview, {
nodeintegration: 'on',
webpreferences: 'contextIsolation=no',
2018-05-14 22:00:49 +00:00
src: `file://${fixtures}/pages/onmouseup.html`
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
await waitForEvent(webview, 'dom-ready');
const waitForIpcMessage = waitForEvent(webview, 'ipc-message');
webview.sendInputEvent({
type: 'mouseup',
modifiers: ['ctrl'],
x: 10,
y: 20
2016-03-25 20:03:49 +00:00
});
2018-05-14 22:00:49 +00:00
2018-09-13 16:10:51 +00:00
const { channel, args } = await waitForIpcMessage;
expect(channel).to.equal('mouseup');
expect(args).to.deep.equal([10, 20, false, true]);
2016-03-25 20:03:49 +00:00
});
});
describe('media-started-playing media-paused events', () => {
beforeEach(function () {
if (!document.createElement('audio').canPlayType('audio/wav')) {
this.skip();
}
});
2018-05-14 22:00:49 +00:00
it('emits when audio starts and stops playing', async () => {
await loadWebView(webview, { src: `file://${fixtures}/pages/base-page.html` });
// With the new autoplay policy, audio elements must be unmuted
// see https://goo.gl/xX8pDD.
const source = `
const audio = document.createElement("audio")
audio.src = "../assets/tone.wav"
document.body.appendChild(audio);
audio.play()
`;
webview.executeJavaScript(source, true);
2018-05-14 22:00:49 +00:00
await waitForEvent(webview, 'media-started-playing');
webview.executeJavaScript('document.querySelector("audio").pause()', true);
2018-05-14 22:00:49 +00:00
await waitForEvent(webview, 'media-paused');
2016-03-25 20:03:49 +00:00
});
});
describe('<webview>.getWebContentsId', () => {
it('can return the WebContents ID', async () => {
const src = 'about:blank';
await loadWebView(webview, { src });
expect(webview.getWebContentsId()).to.be.a('number');
});
});
chore: bump chromium to 100.0.4857.0 (main) (#32419) * chore: bump chromium in DEPS to 99.0.4819.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4824.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4827.0 * chore: update patches * 3352511: PiP: Add inkdrop and pointer cursor to PiP window buttons https://chromium-review.googlesource.com/c/chromium/src/+/3352511 * 3309164: webhid: Show FIDO devices in the chooser if allowed https://chromium-review.googlesource.com/c/chromium/src/+/3309164 * 3297868: hid: Add experimental HIDDevice.forget() https://chromium-review.googlesource.com/c/chromium/src/+/3297868 * 3362491: [Extensions] Move i18n API to //extensions https://chromium-review.googlesource.com/c/chromium/src/+/3362491 * MCC Refactor step0: Allow embedders to register associated_interface binders with RenderFrameHostImpl::associated_registry_. https://chromium-review.googlesource.com/c/chromium/src/+/3281481 * 3352616: [Gtk] Remove libgtk from the link-line https://chromium-review.googlesource.com/c/chromium/src/+/3352616 * 3249211: Clear-Site-Data support for partitioned cookies https://chromium-review.googlesource.com/c/chromium/src/+/3249211 * [Extensions][COIL] Use [allow|block]list in //extensions/common https://chromium-review.googlesource.com/c/chromium/src/+/3372668 * Begin ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3376154 * [Code Health] Refactor PrefService GetDict + GetList to use base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3343526 * 3354997: [CodeHealth] Remove deprecated SetDictionary method https://chromium-review.googlesource.com/c/chromium/src/+/3354997 * 3287323: Add LacrosPrefStore for lacros settings https://chromium-review.googlesource.com/c/chromium/src/+/3287323 * 3365916: [PA] Clean up remaining lazy commit code https://chromium-review.googlesource.com/c/chromium/src/+/3365916 * [MPArch] Target the external protocol error at the responsible frame. https://chromium-review.googlesource.com/c/chromium/src/+/3011560 * Pass origin to RegisterNonNetworkSubresourceURLLoaderFactories https://chromium-review.googlesource.com/c/chromium/src/+/3350608 * Linux: Send OSCrypt raw encryption key to the Network Service https://chromium-review.googlesource.com/c/chromium/src/+/3320484 * [PlzServiceWorker] Remove remaining references to PlzServiceWorker. https://chromium-review.googlesource.com/c/chromium/src/+/3359441 * chore: fixup for lint * 3327621: Fix tablet mode detection for Win 11. https://chromium-review.googlesource.com/c/chromium/src/+/3327621 * 3342428: ax_mac: move AXTextMarker conversion utils under ui umbrella https://chromium-review.googlesource.com/c/chromium/src/+/3342428 * 3353974: Mac: Use base::Feature for overlay features https://chromium-review.googlesource.com/c/chromium/src/+/3353974 * chore: bump chromium in DEPS to 99.0.4828.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4837.0 * chore: update patches * chore: update patches * 3379142: Drop FALLTHROUGH macro Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3379142 * 3381749: C++17: Allow use of std::map::try_emplace and std::map::insert_or_assign Ref: https://chromium-review.googlesource.com/c/chromium/src/+/3381749 * chore: bump chromium in DEPS to 99.0.4839.0 * chore: update patches * chore: bump chromium in DEPS to 99.0.4840.0 * chore: bump chromium in DEPS to 99.0.4844.0 * 3395881: [api] Deprecate Local<v8::Context> v8::Object::CreationContext() Ref: https://chromium-review.googlesource.com/c/v8/v8/+/3395881 * chore: update patches * chore: bump chromium in DEPS to 100.0.4845.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4847.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4849.0 * chore: update patches * chore: bump chromium in DEPS to 100.0.4851.0 * chore: bump chromium in DEPS to 100.0.4853.0 * update patches * chore: update patches * update patches * 3383599: Fonts Access: Remove prototype that uses a font picker. https://chromium-review.googlesource.com/c/chromium/src/+/3383599 * 3404768: Remove ALLOW_UNUSED macros https://chromium-review.googlesource.com/c/chromium/src/+/3404768 * 3374762: Remove ignore_result.h https://chromium-review.googlesource.com/c/chromium/src/+/3374762 * 3399305: [unseasoned-pdf] Apply proper frame offsets for touch selections https://chromium-review.googlesource.com/c/chromium/src/+/3399305 * 3402210: [Extensions] Don't trigger unload event for already unloaded extension https://chromium-review.googlesource.com/c/chromium/src/+/3402210 * 3410912: Combine URLLoaderClient OnReceiveResponse and OnStartLoadingResponseBody. https://chromium-review.googlesource.com/c/chromium/src/+/3410912 * 3370428: Make the AuthSchemes policy support dynamic refresh https://chromium-review.googlesource.com/c/chromium/src/+/3370428 * 3407603: Finish ScopedUserPrefUpdate migration to modern base::Value https://chromium-review.googlesource.com/c/chromium/src/+/3407603 * 3378352: ozone/x11: move code from //ui/p/x11 to //ui/ozone/p/x11 https://chromium-review.googlesource.com/c/chromium/src/+/3378352 * 3370810: Delete chrome/service, AKA the Cloud Print service process. https://chromium-review.googlesource.com/c/chromium/src/+/3370810 * chore: bump chromium in DEPS to 100.0.4855.0 * chore: update patches * fixup! 3370810: Delete chrome/service, AKA the Cloud Print service process. * revert 3348007 to fix windows build * 3318572: [Code health] Fix gn check errors in //extensions/browser:* https://chromium-review.googlesource.com/c/chromium/src/+/3318572 * fix printing.patch * fix iwyu issue * 3408515: win: Make ShorcutOperation an enum class and modernize names https://chromium-review.googlesource.com/c/chromium/src/+/3408515 * 3388333: [UIA] Remove dead code accessibility_misc_utils.h/cc https://chromium-review.googlesource.com/c/chromium/src/+/3388333 * fix windows build? i hope * patch gn visibility of //ui/ozone/platform/x11 * missing include base/logging.h * use BUILDFLAG for USE_NSS_CERTS https://chromium-review.googlesource.com/c/chromium/src/+/3379123 * defined(OS_*) ==> BUILDFLAG(IS_*) https://bugs.chromium.org/p/chromium/issues/detail?id=1234043 * fixup! 3404768: Remove ALLOW_UNUSED macros * another attempt to fix windows build * temporarily disable the custom scheme service worker test https://github.com/electron/electron/issues/32664 * fix loading mv3 extensions not sure what cl broke this unfort. * fixup! 3404768: Remove ALLOW_UNUSED macros * patch nan https://chromium-review.googlesource.com/c/v8/v8/+/3395880 * fix node test * fix nullptr in FindPdfFrame * patch perfetto to fix build issue on win-ia32 https://source.chromium.org/chromium/_/android/platform/external/perfetto.git/+/bc44c3c7533c00e56f88c06c592d634aecc884be * fix build for linux-x64-testing-no-run-as-node * fix patch * skip <webview>.capturePage() test https://github.com/electron/electron/issues/32705 * test: fix failing tests of focus/blur events of WebContents (#32711) * inherit stdio from app module test child processes this prevents them from timing out due to full stdout buffers * test to see if we can get better logs on windows ci * try again for appveyor log things * skip contentTracing tests on ia32 * ci: disable gpu compositing * drop applied patch * fix merge fail * Revert "ci: disable gpu compositing" This reverts commit 0344129fcb19ea3e87e06c1110d751f22eba3fec. Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: John Kleinschmidt <jkleinsc@github.com> Co-authored-by: VerteDinde <khammond@slack-corp.com> Co-authored-by: VerteDinde <vertedinde@electronjs.org> Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: Jeremy Rose <nornagon@nornagon.net> Co-authored-by: Cheng Zhao <zcbenz@gmail.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
2022-02-10 02:58:52 +00:00
// TODO(nornagon): this seems to have become much less reliable as of
// https://github.com/electron/electron/pull/32419. Tracked at
// https://github.com/electron/electron/issues/32705.
describe.skip('<webview>.capturePage()', () => {
before(function () {
// TODO(miniak): figure out why this is failing on windows
if (process.platform === 'win32') {
this.skip();
}
});
it('returns a Promise with a NativeImage', async () => {
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebView(webview, { src });
const image = await webview.capturePage();
const imgBuffer = image.toPNG();
// Check the 25th byte in the PNG.
// Values can be 0,2,3,4, or 6. We want 6, which is RGB + Alpha
expect(imgBuffer[25]).to.equal(6);
});
});
ifdescribe(features.isPrintingEnabled())('<webview>.printToPDF()', () => {
it('rejects on incorrectly typed parameters', async () => {
const badTypes = {
landscape: [],
displayHeaderFooter: '123',
printBackground: 2,
scale: 'not-a-number',
pageSize: 'IAmAPageSize',
margins: 'terrible',
pageRanges: { oops: 'im-not-the-right-key' },
headerTemplate: [1, 2, 3],
footerTemplate: [4, 5, 6],
preferCSSPageSize: 'no'
};
// These will hard crash in Chromium unless we type-check
for (const [key, value] of Object.entries(badTypes)) {
const param = { [key]: value };
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebView(webview, { src });
await expect(webview.printToPDF(param)).to.eventually.be.rejected();
}
});
it('can print to PDF', async () => {
const src = 'data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E';
await loadWebView(webview, { src });
const data = await webview.printToPDF({});
refactor: use v8 serialization for ipc (#20214) * refactor: use v8 serialization for ipc * cloning process.env doesn't work * serialize host objects by enumerating key/values * new serialization can handle NaN, Infinity, and undefined correctly * can't allocate v8 objects during GC * backport microtasks fix * fix compile * fix node_stream_loader reentrancy * update subframe spec to expect undefined instead of null * write undefined instead of crashing when serializing host objects * fix webview spec * fix download spec * buffers are transformed into uint8arrays * can't serialize promises * fix chrome.i18n.getMessage * fix devtools tests * fix zoom test * fix debug build * fix lint * update ipcRenderer tests * fix printToPDF test * update patch * remove accidentally re-added remote-side spec * wip * don't attempt to serialize host objects * jump through different hoops to set options.webContents sometimes * whoops * fix lint * clean up error-handling logic * fix memory leak * fix lint * convert host objects using old base::Value serialization * fix lint more * fall back to base::Value-based serialization * remove commented-out code * add docs to breaking-changes.md * Update breaking-changes.md * update ipcRenderer and WebContents docs * lint * use named values for format tag * save a memcpy for ~30% speedup * get rid of calls to ShallowClone * extra debugging for paranoia * d'oh, use the correct named tags * apparently msstl doesn't like this DCHECK * funny story about that DCHECK * disable remote-related functions when enable_remote_module = false * nits * use EnableIf to disable remote methods in mojom * fix include * review comments
2019-10-09 17:59:08 +00:00
expect(data).to.be.an.instanceof(Uint8Array).that.is.not.empty();
});
});
describe('DOM events', () => {
2016-11-03 22:12:54 +00:00
let div;
beforeEach(() => {
2016-11-03 22:12:54 +00:00
div = document.createElement('div');
div.style.width = '100px';
div.style.height = '10px';
div.style.overflow = 'hidden';
webview.style.height = '100%';
webview.style.width = '100%';
});
afterEach(() => {
2016-11-03 22:12:54 +00:00
if (div != null) div.remove();
});
const generateSpecs = (description, sandbox) => {
describe(description, () => {
// TODO(nornagon): disabled during chromium roll 2019-06-11 due to a
// 'ResizeObserver loop limit exceeded' error on Windows
xit('emits resize events', async () => {
const firstResizeSignal = waitForEvent(webview, 'resize');
const domReadySignal = waitForEvent(webview, 'dom-ready');
webview.src = `file://${fixtures}/pages/a.html`;
webview.webpreferences = `sandbox=${sandbox ? 'yes' : 'no'}`;
div.appendChild(webview);
document.body.appendChild(div);
const firstResizeEvent = await firstResizeSignal;
expect(firstResizeEvent.target).to.equal(webview);
expect(firstResizeEvent.newWidth).to.equal(100);
expect(firstResizeEvent.newHeight).to.equal(10);
await domReadySignal;
const secondResizeSignal = waitForEvent(webview, 'resize');
const newWidth = 1234;
const newHeight = 789;
div.style.width = `${newWidth}px`;
div.style.height = `${newHeight}px`;
const secondResizeEvent = await secondResizeSignal;
expect(secondResizeEvent.target).to.equal(webview);
expect(secondResizeEvent.newWidth).to.equal(newWidth);
expect(secondResizeEvent.newHeight).to.equal(newHeight);
});
it('emits focus event', async () => {
const domReadySignal = waitForEvent(webview, 'dom-ready');
webview.src = `file://${fixtures}/pages/a.html`;
webview.webpreferences = `sandbox=${sandbox ? 'yes' : 'no'}`;
document.body.appendChild(webview);
await domReadySignal;
// If this test fails, check if webview.focus() still works.
const focusSignal = waitForEvent(webview, 'focus');
webview.focus();
2020-03-20 20:28:31 +00:00
await focusSignal;
});
});
};
2020-03-20 20:28:31 +00:00
generateSpecs('without sandbox', false);
generateSpecs('with sandbox', true);
2016-11-03 22:12:54 +00:00
});
2016-03-25 20:03:49 +00:00
});