| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | const assert = require('assert') | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  | const chai = require('chai') | 
					
						
							|  |  |  | const dirtyChai = require('dirty-chai') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | const path = require('path') | 
					
						
							|  |  |  | const http = require('http') | 
					
						
							|  |  |  | const url = require('url') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { ipcRenderer, remote } = require('electron') | 
					
						
							|  |  |  | const { app, session, ipcMain, BrowserWindow } = remote | 
					
						
							|  |  |  | const { closeWindow } = require('./window-helpers') | 
					
						
							|  |  |  | const { emittedOnce, waitForEvent } = require('./events-helpers') | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { expect } = chai | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  | chai.use(dirtyChai) | 
					
						
							| 
									
										
										
										
											2016-03-30 10:33:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-11 14:12:57 +03:00
										 |  |  | const isCI = remote.getGlobal('isCi') | 
					
						
							| 
									
										
										
										
											2017-05-25 16:40:15 -07:00
										 |  |  | const nativeModulesEnabled = remote.getGlobal('nativeModulesEnabled') | 
					
						
							| 
									
										
										
										
											2017-01-16 12:56:39 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 14:22:43 -08:00
										 |  |  | /* Most of the APIs here don't use standard callbacks */ | 
					
						
							|  |  |  | /* eslint-disable standard/no-callback-literal */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-06 22:14:52 -07:00
										 |  |  | describe('<webview> tag', function () { | 
					
						
							| 
									
										
										
										
											2016-12-22 13:31:30 -08:00
										 |  |  |   this.timeout(3 * 60 * 1000) | 
					
						
							| 
									
										
										
										
											2016-02-05 10:27:05 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   const fixtures = path.join(__dirname, 'fixtures') | 
					
						
							|  |  |  |   let webview = null | 
					
						
							| 
									
										
										
										
											2016-05-17 17:04:13 +09:00
										 |  |  |   let w = null | 
					
						
							| 
									
										
										
										
											2016-02-05 10:27:05 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |   const openTheWindow = async (...args) => { | 
					
						
							|  |  |  |     await closeTheWindow() | 
					
						
							|  |  |  |     w = new BrowserWindow(...args) | 
					
						
							|  |  |  |     return w | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const closeTheWindow = async () => { | 
					
						
							|  |  |  |     await closeWindow(w) | 
					
						
							|  |  |  |     w = null | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |   const loadWebView = async (webview, attributes = {}) => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     for (const [name, value] of Object.entries(attributes)) { | 
					
						
							|  |  |  |       webview.setAttribute(name, value) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     document.body.appendChild(webview) | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |     await waitForEvent(webview, 'did-finish-load') | 
					
						
							|  |  |  |     return webview | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |   const startLoadingWebViewAndWaitForMessage = async (webview, attributes = {}) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |     loadWebView(webview, attributes) // Don't wait for load to be finished.
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |     const event = await waitForEvent(webview, 'console-message') | 
					
						
							|  |  |  |     return event.message | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2016-03-28 13:47:31 -07:00
										 |  |  |     webview = new WebView() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-02-05 10:27:05 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   afterEach(() => { | 
					
						
							| 
									
										
										
										
											2016-09-30 09:55:24 -07:00
										 |  |  |     if (!document.body.contains(webview)) { | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-09-30 09:55:24 -07:00
										 |  |  |     webview.remove() | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return closeTheWindow() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |   it('works without script tag in page', async () => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |     const w = await openTheWindow({ show: false }) | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |     w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html')) | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |     await emittedOnce(ipcMain, 'pong') | 
					
						
							| 
									
										
										
										
											2017-05-06 22:10:42 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |   it('is disabled when nodeIntegration is disabled', async () => { | 
					
						
							|  |  |  |     const w = await openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-05-06 22:10:42 -07:00
										 |  |  |       show: false, | 
					
						
							|  |  |  |       webPreferences: { | 
					
						
							|  |  |  |         nodeIntegration: false, | 
					
						
							|  |  |  |         preload: path.join(fixtures, 'module', 'preload-webview.js') | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |     w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html')) | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |     const [, type] = await emittedOnce(ipcMain, 'webview') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(type).to.equal('undefined', 'WebView still exists') | 
					
						
							| 
									
										
										
										
											2017-05-06 22:10:42 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |   it('is enabled when the webviewTag option is enabled and the nodeIntegration option is disabled', async () => { | 
					
						
							|  |  |  |     const w = await openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-05-06 22:10:42 -07:00
										 |  |  |       show: false, | 
					
						
							|  |  |  |       webPreferences: { | 
					
						
							|  |  |  |         nodeIntegration: false, | 
					
						
							|  |  |  |         preload: path.join(fixtures, 'module', 'preload-webview.js'), | 
					
						
							| 
									
										
										
										
											2017-05-17 13:09:24 -07:00
										 |  |  |         webviewTag: true | 
					
						
							| 
									
										
										
										
											2017-05-06 22:10:42 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |     w.loadFile(path.join(fixtures, 'pages', 'webview-no-script.html')) | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |     const [, type] = await emittedOnce(ipcMain, 'webview') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect(type).to.not.equal('undefined', 'WebView is not created') | 
					
						
							| 
									
										
										
										
											2016-04-12 15:10:26 +09:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('src attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('specifies the page to load', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('a') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('navigates to new page when changed', async () => { | 
					
						
							|  |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.src = `file://${fixtures}/pages/b.html` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { message } = await waitForEvent(webview, 'console-message') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('b') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-09-08 16:40:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('resolves relative URLs', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: '../fixtures/pages/e.html' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(message, 'Window script is loaded before preload script') | 
					
						
							| 
									
										
										
										
											2016-09-08 16:56:29 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('ignores empty values', () => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(webview.src, '') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       for (const emptyValue of ['', null, undefined]) { | 
					
						
							|  |  |  |         webview.src = emptyValue | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |         expect(webview.src).to.equal('') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-09-08 16:40:31 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('nodeintegration attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('inserts no node symbols when not set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/c.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'undefined', | 
					
						
							|  |  |  |         module: 'undefined', | 
					
						
							|  |  |  |         process: 'undefined', | 
					
						
							|  |  |  |         global: 'undefined' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('inserts node symbols when set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/d.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('loads node symbols after POST navigation when set', async function () { | 
					
						
							| 
									
										
										
										
											2017-03-27 09:15:40 -07:00
										 |  |  |       // FIXME Figure out why this is timing out on AppVeyor
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       if (process.env.APPVEYOR === 'True') { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         this.skip() | 
					
						
							|  |  |  |         return | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-03-27 09:15:40 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/post.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-30 10:33:15 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('disables node integration on child windows when it is disabled on the webview', (done) => { | 
					
						
							|  |  |  |       app.once('browser-window-created', (event, window) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(window.webContents.getWebPreferences().nodeIntegration, false) | 
					
						
							| 
									
										
										
										
											2016-03-30 10:33:15 -07:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       const src = url.format({ | 
					
						
							| 
									
										
										
										
											2016-03-30 10:33:15 -07:00
										 |  |  |         pathname: `${fixtures}/pages/webview-opener-no-node-integration.html`, | 
					
						
							|  |  |  |         protocol: 'file', | 
					
						
							|  |  |  |         query: { | 
					
						
							|  |  |  |           p: `${fixtures}/pages/window-opener-node.html` | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         slashes: true | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         allowpopups: 'on', | 
					
						
							|  |  |  |         src | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-08-24 14:24:24 -07:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 14:24:24 -07:00
										 |  |  |     (nativeModulesEnabled ? it : it.skip)('loads native modules when navigation happens', async function () { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/native-module.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.reload() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { message } = await waitForEvent(webview, 'console-message') | 
					
						
							|  |  |  |       assert.strictEqual(message, 'function') | 
					
						
							| 
									
										
										
										
											2017-05-25 16:40:15 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-13 19:50:07 +02:00
										 |  |  |   describe('enableremotemodule attribute', () => { | 
					
						
							|  |  |  |     const generateSpecs = (description, sandbox) => { | 
					
						
							|  |  |  |       describe(description, () => { | 
					
						
							|  |  |  |         const preload = `${fixtures}/module/preload-disable-remote.js` | 
					
						
							|  |  |  |         const src = `file://${fixtures}/api/blank.html` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('enables the remote module by default', async () => { | 
					
						
							|  |  |  |           const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							|  |  |  |             preload, | 
					
						
							|  |  |  |             src, | 
					
						
							|  |  |  |             sandbox | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const typeOfRemote = JSON.parse(message) | 
					
						
							|  |  |  |           expect(typeOfRemote).to.equal('object') | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         it('disables the remote module when false', async () => { | 
					
						
							|  |  |  |           const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							|  |  |  |             preload, | 
					
						
							|  |  |  |             src, | 
					
						
							|  |  |  |             sandbox, | 
					
						
							|  |  |  |             enableremotemodule: false | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           const typeOfRemote = JSON.parse(message) | 
					
						
							|  |  |  |           expect(typeOfRemote).to.equal('undefined') | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     generateSpecs('without sandbox', false) | 
					
						
							|  |  |  |     generateSpecs('with sandbox', true) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('preload attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('loads the script before other scripts in window', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         preload: `${fixtures}/module/preload.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/e.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(message).to.be.a('string') | 
					
						
							|  |  |  |       expect(message).to.be.not.equal('Window script is loaded before preload script') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('preload script can still use "process" and "Buffer" when nodeintegration is off', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         preload: `${fixtures}/module/preload-node-off.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/api/blank.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         process: 'object', | 
					
						
							|  |  |  |         Buffer: 'function' | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 21:17:11 -05:00
										 |  |  |     it('runs in the correct scope when sandboxed', async () => { | 
					
						
							|  |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							|  |  |  |         preload: `${fixtures}/module/preload-context.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/api/blank.html`, | 
					
						
							|  |  |  |         webpreferences: 'sandbox=yes' | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', // arguments passed to it should be availale
 | 
					
						
							|  |  |  |         electron: 'undefined', // objects from the scope it is called from should not be available
 | 
					
						
							|  |  |  |         window: 'object', // the window object should be available
 | 
					
						
							|  |  |  |         localVar: 'undefined' // but local variables should not be exposed to the window
 | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('preload script can require modules that still use "process" and "Buffer" when nodeintegration is off', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         preload: `${fixtures}/module/preload-node-off-wrapper.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/api/blank.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         process: 'object', | 
					
						
							|  |  |  |         Buffer: 'function' | 
					
						
							| 
									
										
										
										
											2017-02-23 11:26:37 -08:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('receives ipc message in preload script', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         preload: `${fixtures}/module/preload-ipc.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/e.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const message = 'boom!' | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       webview.send('ping', message) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { channel, args } = await waitForEvent(webview, 'ipc-message') | 
					
						
							|  |  |  |       assert.strictEqual(channel, 'pong') | 
					
						
							|  |  |  |       assert.deepStrictEqual(args, [message]) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-04-12 14:57:40 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('works without script tag in page', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         preload: `${fixtures}/module/preload.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}pages/base-page.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object', | 
					
						
							|  |  |  |         Buffer: 'function' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-04-12 14:57:40 +09:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-09-08 16:40:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('resolves relative URLs', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         preload: '../fixtures/module/preload.js', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/e.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object', | 
					
						
							|  |  |  |         Buffer: 'function' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-09-08 16:56:29 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('ignores empty values', () => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(webview.preload, '') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       for (const emptyValue of ['', null, undefined]) { | 
					
						
							|  |  |  |         webview.preload = emptyValue | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(webview.preload, '') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-09-08 16:40:31 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('httpreferrer attribute', () => { | 
					
						
							|  |  |  |     it('sets the referrer url', (done) => { | 
					
						
							|  |  |  |       const referrer = 'http://github.com/' | 
					
						
							| 
									
										
										
										
											2018-04-06 12:52:52 +05:30
										 |  |  |       const server = http.createServer((req, res) => { | 
					
						
							|  |  |  |         res.end() | 
					
						
							|  |  |  |         server.close() | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(req.headers.referer, referrer) | 
					
						
							| 
									
										
										
										
											2018-04-06 12:52:52 +05:30
										 |  |  |         done() | 
					
						
							|  |  |  |       }).listen(0, '127.0.0.1', () => { | 
					
						
							|  |  |  |         const port = server.address().port | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         loadWebView(webview, { | 
					
						
							|  |  |  |           httpreferrer: referrer, | 
					
						
							|  |  |  |           src: `http://127.0.0.1:${port}` | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-04-06 12:52:52 +05:30
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('useragent attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('sets the user agent', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const referrer = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko' | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/useragent.html`, | 
					
						
							|  |  |  |         useragent: referrer | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal(referrer) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('disablewebsecurity attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('does not disable web security when not set', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const jqueryPath = path.join(__dirname, '/static/jquery-2.0.3.min.js') | 
					
						
							|  |  |  |       const src = `<script src='file://${jqueryPath}'></script> <script>console.log('ok');</script>` | 
					
						
							|  |  |  |       const encoded = btoa(unescape(encodeURIComponent(src))) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `data:text/html;base64,${encoded}` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       expect(message).to.be.a('string') | 
					
						
							|  |  |  |       expect(message).to.contain('Not allowed to load local resource') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('disables web security when set', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const jqueryPath = path.join(__dirname, '/static/jquery-2.0.3.min.js') | 
					
						
							|  |  |  |       const src = `<script src='file://${jqueryPath}'></script> <script>console.log('ok');</script>` | 
					
						
							|  |  |  |       const encoded = btoa(unescape(encodeURIComponent(src))) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         disablewebsecurity: '', | 
					
						
							|  |  |  |         src: `data:text/html;base64,${encoded}` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('ok') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-05-30 15:20:53 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('does not break node integration', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         disablewebsecurity: '', | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/d.html` | 
					
						
							| 
									
										
										
										
											2016-05-30 15:20:53 +09:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-05-30 15:20:53 +09:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('does not break preload script', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         disablewebsecurity: '', | 
					
						
							|  |  |  |         preload: `${fixtures}/module/preload.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/e.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object', | 
					
						
							|  |  |  |         Buffer: 'function' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-05-30 15:20:53 +09:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('partition attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('inserts no node symbols when not set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         partition: 'test1', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/c.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'undefined', | 
					
						
							|  |  |  |         module: 'undefined', | 
					
						
							|  |  |  |         process: 'undefined', | 
					
						
							|  |  |  |         global: 'undefined' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('inserts node symbols when set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         partition: 'test2', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/d.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('isolates storage for different id', async () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       window.localStorage.setItem('test', 'one') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         partition: 'test3', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/partition/one.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const parsedMessage = JSON.parse(message) | 
					
						
							|  |  |  |       expect(parsedMessage).to.include({ | 
					
						
							|  |  |  |         numberOfEntries: 0, | 
					
						
							|  |  |  |         testValue: null | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('uses current session storage when no id is provided', async () => { | 
					
						
							|  |  |  |       const testValue = 'one' | 
					
						
							|  |  |  |       window.localStorage.setItem('test', testValue) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/partition/one.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const parsedMessage = JSON.parse(message) | 
					
						
							|  |  |  |       expect(parsedMessage).to.include({ | 
					
						
							|  |  |  |         numberOfEntries: 1, | 
					
						
							|  |  |  |         testValue | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('allowpopups attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can not open new window when not set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/window-open-hide.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('null') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can open new window when set', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         allowpopups: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/window-open-hide.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('window') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('webpreferences attribute', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can enable nodeintegration', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `file://${fixtures}/pages/d.html`, | 
					
						
							|  |  |  |         webpreferences: 'nodeIntegration' | 
					
						
							| 
									
										
										
										
											2016-10-14 18:04:33 -05:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'function', | 
					
						
							|  |  |  |         module: 'object', | 
					
						
							|  |  |  |         process: 'object' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-10-14 18:04:33 -05:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-13 19:50:07 +02:00
										 |  |  |     it('can disable the remote module', async () => { | 
					
						
							|  |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							|  |  |  |         preload: `${fixtures}/module/preload-disable-remote.js`, | 
					
						
							|  |  |  |         src: `file://${fixtures}/api/blank.html`, | 
					
						
							|  |  |  |         webpreferences: 'enableRemoteModule=no' | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const typeOfRemote = JSON.parse(message) | 
					
						
							|  |  |  |       expect(typeOfRemote).to.equal('undefined') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can disables web security and enable nodeintegration', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const jqueryPath = path.join(__dirname, '/static/jquery-2.0.3.min.js') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       const src = `<script src='file://${jqueryPath}'></script> <script>console.log(typeof require);</script>` | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const encoded = btoa(unescape(encodeURIComponent(src))) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         src: `data:text/html;base64,${encoded}`, | 
					
						
							|  |  |  |         webpreferences: 'webSecurity=no, nodeIntegration=yes' | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(message).to.equal('function') | 
					
						
							| 
									
										
										
										
											2016-10-14 18:04:33 -05:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-01-05 10:17:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('can enable context isolation', async () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         allowpopups: 'yes', | 
					
						
							|  |  |  |         preload: path.join(fixtures, 'api', 'isolated-preload.js'), | 
					
						
							|  |  |  |         src: `file://${fixtures}/api/isolated.html`, | 
					
						
							|  |  |  |         webpreferences: 'contextIsolation=yes' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, data] = await emittedOnce(ipcMain, 'isolated-world') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.deepStrictEqual(data, { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |         preloadContext: { | 
					
						
							|  |  |  |           preloadProperty: 'number', | 
					
						
							|  |  |  |           pageProperty: 'undefined', | 
					
						
							|  |  |  |           typeofRequire: 'function', | 
					
						
							|  |  |  |           typeofProcess: 'object', | 
					
						
							|  |  |  |           typeofArrayPush: 'function', | 
					
						
							| 
									
										
										
										
											2018-09-01 02:21:29 +05:30
										 |  |  |           typeofFunctionApply: 'function', | 
					
						
							|  |  |  |           typeofPreloadExecuteJavaScriptProperty: 'undefined' | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         pageContext: { | 
					
						
							|  |  |  |           preloadProperty: 'undefined', | 
					
						
							|  |  |  |           pageProperty: 'string', | 
					
						
							|  |  |  |           typeofRequire: 'undefined', | 
					
						
							|  |  |  |           typeofProcess: 'undefined', | 
					
						
							|  |  |  |           typeofArrayPush: 'number', | 
					
						
							|  |  |  |           typeofFunctionApply: 'boolean', | 
					
						
							|  |  |  |           typeofPreloadExecuteJavaScriptProperty: 'number', | 
					
						
							|  |  |  |           typeofOpenedWindow: 'object' | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-01-05 10:17:06 -08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-10-14 18:04:33 -05:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('new-window event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when window.open is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/window-open.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { url, frameName } = await waitForEvent(webview, 'new-window') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(url, 'http://host/') | 
					
						
							|  |  |  |       assert.strictEqual(frameName, 'host') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when link with target is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/target-name.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { url, frameName } = await waitForEvent(webview, 'new-window') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(url, 'http://host/') | 
					
						
							|  |  |  |       assert.strictEqual(frameName, 'target') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('ipc-message event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when guest sends a ipc message to browser', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/ipc-message.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { channel, args } = await waitForEvent(webview, 'ipc-message') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(channel, 'channel') | 
					
						
							|  |  |  |       assert.deepStrictEqual(args, ['arg1', 'arg2']) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('page-title-set event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when title is set', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { title, explicitSet } = await waitForEvent(webview, 'page-title-set') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(title, 'test') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       assert(explicitSet) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('page-favicon-updated event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when favicon urls are received', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { favicons } = await waitForEvent(webview, 'page-favicon-updated') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       assert(favicons) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(favicons.length, 2) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       if (process.platform === 'win32') { | 
					
						
							|  |  |  |         assert(/^file:\/\/\/[A-Z]:\/favicon.png$/i.test(favicons[0])) | 
					
						
							|  |  |  |       } else { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(favicons[0], 'file:///favicon.png') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('will-navigate event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when a url that leads to oustide of the page is clicked', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/webview-will-navigate.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { url } = await waitForEvent(webview, 'will-navigate') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(url, 'http://host/') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('did-navigate event', () => { | 
					
						
							|  |  |  |     let p = path.join(fixtures, 'pages', 'webview-will-navigate.html') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     p = p.replace(/\\/g, '/') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     const pageUrl = url.format({ | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |       protocol: 'file', | 
					
						
							|  |  |  |       slashes: true, | 
					
						
							|  |  |  |       pathname: p | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when a url that leads to outside of the page is clicked', async () => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: pageUrl }) | 
					
						
							|  |  |  |       const { url } = await waitForEvent(webview, 'did-navigate') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(url, pageUrl) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('did-navigate-in-page event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when an anchor link is clicked', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       let p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page.html') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       p = p.replace(/\\/g, '/') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const pageUrl = url.format({ | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         protocol: 'file', | 
					
						
							|  |  |  |         slashes: true, | 
					
						
							|  |  |  |         pathname: p | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: pageUrl }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       const event = await waitForEvent(webview, 'did-navigate-in-page') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(event.url, `${pageUrl}#test_content`) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when window.history.replaceState is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/webview-did-navigate-in-page-with-history.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { url } = await waitForEvent(webview, 'did-navigate-in-page') | 
					
						
							|  |  |  |       assert.strictEqual(url, 'http://host/') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when window.location.hash is changed', async () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       let p = path.join(fixtures, 'pages', 'webview-did-navigate-in-page-with-hash.html') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       p = p.replace(/\\/g, '/') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const pageUrl = url.format({ | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         protocol: 'file', | 
					
						
							|  |  |  |         slashes: true, | 
					
						
							|  |  |  |         pathname: p | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: pageUrl }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       const event = await waitForEvent(webview, 'did-navigate-in-page') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(event.url, `${pageUrl}#test`) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('close event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should fire when interior page calls window.close', async () => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: `file://${fixtures}/pages/close.html` }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'close') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |   // FIXME(zcbenz): Disabled because of moving to OOPIF webview.
 | 
					
						
							|  |  |  |   xdescribe('setDevToolsWebContents() API', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('sets webContents of webview as devtools', async () => { | 
					
						
							| 
									
										
										
										
											2017-11-30 21:04:50 +09:00
										 |  |  |       const webview2 = new WebView() | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Setup an event handler for further usage.
 | 
					
						
							|  |  |  |       const waitForDomReady = waitForEvent(webview2, 'dom-ready') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: 'about:blank' }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03: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() | 
					
						
							|  |  |  |       assert.ok(devtools.getURL().startsWith('chrome-devtools://devtools')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const name = await new Promise((resolve) => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         devtools.executeJavaScript('InspectorFrontendHost.constructor.name', (name) => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |           resolve(name) | 
					
						
							| 
									
										
										
										
											2017-11-30 21:04:50 +09:00
										 |  |  |         }) | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       document.body.removeChild(webview2) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(name).to.be.equal('InspectorFrontendHostImpl') | 
					
						
							| 
									
										
										
										
											2017-11-30 21:04:50 +09:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 18:01:31 +02:00
										 |  |  |   describe('devtools-opened event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should fire when webview.openDevTools() is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/base-page.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.openDevTools() | 
					
						
							|  |  |  |       await waitForEvent(webview, 'devtools-opened') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.closeDevTools() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 18:01:31 +02:00
										 |  |  |   describe('devtools-closed event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should fire when webview.closeDevTools() is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/base-page.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.openDevTools() | 
					
						
							|  |  |  |       await waitForEvent(webview, 'devtools-opened') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.closeDevTools() | 
					
						
							|  |  |  |       await waitForEvent(webview, 'devtools-closed') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 18:01:31 +02:00
										 |  |  |   describe('devtools-focused event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should fire when webview.openDevTools() is called', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/base-page.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const waitForDevToolsFocused = waitForEvent(webview, 'devtools-focused') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  |       webview.openDevTools() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await waitForDevToolsFocused | 
					
						
							|  |  |  |       webview.closeDevTools() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('<webview>.reload()', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should emit beforeunload handler', async () => { | 
					
						
							|  |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         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-14 02:10:51 +10:00
										 |  |  |       const { channel } = await waitForOnbeforeunload | 
					
						
							|  |  |  |       assert.strictEqual(channel, 'onbeforeunload') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('<webview>.goForward()', () => { | 
					
						
							|  |  |  |     it('should work after a replaced history entry', (done) => { | 
					
						
							|  |  |  |       let loadCount = 1 | 
					
						
							|  |  |  |       const listener = (e) => { | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |         if (loadCount === 1) { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.strictEqual(e.channel, 'history') | 
					
						
							|  |  |  |           assert.strictEqual(e.args[0], 1) | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |           assert(!webview.canGoBack()) | 
					
						
							|  |  |  |           assert(!webview.canGoForward()) | 
					
						
							|  |  |  |         } else if (loadCount === 2) { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.strictEqual(e.channel, 'history') | 
					
						
							|  |  |  |           assert.strictEqual(e.args[0], 2) | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |           assert(!webview.canGoBack()) | 
					
						
							|  |  |  |           assert(webview.canGoForward()) | 
					
						
							|  |  |  |           webview.removeEventListener('ipc-message', listener) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       const loadListener = () => { | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |         if (loadCount === 1) { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |           webview.src = `file://${fixtures}/pages/base-page.html` | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |         } else if (loadCount === 2) { | 
					
						
							|  |  |  |           assert(webview.canGoBack()) | 
					
						
							|  |  |  |           assert(!webview.canGoForward()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           webview.goBack() | 
					
						
							|  |  |  |         } else if (loadCount === 3) { | 
					
						
							|  |  |  |           webview.goForward() | 
					
						
							|  |  |  |         } else if (loadCount === 4) { | 
					
						
							|  |  |  |           assert(webview.canGoBack()) | 
					
						
							|  |  |  |           assert(!webview.canGoForward()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           webview.removeEventListener('did-finish-load', loadListener) | 
					
						
							|  |  |  |           done() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |         loadCount += 1 | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.addEventListener('ipc-message', listener) | 
					
						
							|  |  |  |       webview.addEventListener('did-finish-load', loadListener) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/history-replace.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-09-16 17:06:16 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('<webview>.clearHistory()', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should clear the navigation history', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/history.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       const event = await waitForEvent(webview, 'ipc-message') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(event.channel, 'history') | 
					
						
							|  |  |  |       assert.strictEqual(event.args[0], 2) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       assert(webview.canGoBack()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       webview.clearHistory() | 
					
						
							|  |  |  |       assert(!webview.canGoBack()) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('basic auth', () => { | 
					
						
							|  |  |  |     const auth = require('basic-auth') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should authenticate with correct credentials', (done) => { | 
					
						
							|  |  |  |       const message = 'Authenticated' | 
					
						
							|  |  |  |       const server = http.createServer((req, res) => { | 
					
						
							|  |  |  |         const credentials = auth(req) | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         if (credentials.name === 'test' && credentials.pass === 'test') { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |           res.end(message) | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |           res.end('failed') | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         server.close() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       server.listen(0, '127.0.0.1', () => { | 
					
						
							|  |  |  |         const port = server.address().port | 
					
						
							|  |  |  |         webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.strictEqual(e.channel, message) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |           done() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         loadWebView(webview, { | 
					
						
							|  |  |  |           nodeintegration: 'on', | 
					
						
							|  |  |  |           src: `file://${fixtures}/pages/basic-auth.html?port=${port}` | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('dom-ready event', () => { | 
					
						
							|  |  |  |     it('emits when document is loaded', (done) => { | 
					
						
							|  |  |  |       const server = http.createServer(() => {}) | 
					
						
							|  |  |  |       server.listen(0, '127.0.0.1', () => { | 
					
						
							|  |  |  |         const port = server.address().port | 
					
						
							|  |  |  |         webview.addEventListener('dom-ready', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |           done() | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         loadWebView(webview, { | 
					
						
							|  |  |  |           src: `file://${fixtures}/pages/dom-ready.html?port=${port}` | 
					
						
							|  |  |  |         }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('throws a custom error when an API method is called before the event is emitted', () => { | 
					
						
							| 
									
										
										
										
											2018-05-14 21:17:31 +03:00
										 |  |  |       const expectedErrorMessage = | 
					
						
							|  |  |  |           'The WebView must be attached to the DOM ' + | 
					
						
							|  |  |  |           'and the dom-ready event emitted before this method can be called.' | 
					
						
							|  |  |  |       expect(() => { webview.stop() }).to.throw(expectedErrorMessage) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-02-05 10:27:05 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('executeJavaScript', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('should support user gesture', async () => { | 
					
						
							|  |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/fullscreen.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // Event handler has to be added before js execution.
 | 
					
						
							|  |  |  |       const waitForEnterHtmlFullScreen = waitForEvent(webview, 'enter-html-full-screen') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const jsScript = "document.querySelector('video').webkitRequestFullscreen()" | 
					
						
							|  |  |  |       webview.executeJavaScript(jsScript, true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return waitForEnterHtmlFullScreen | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can return the result of the executed script', async () => { | 
					
						
							|  |  |  |       await loadWebView(webview, { | 
					
						
							|  |  |  |         src: 'about:blank' | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const jsScript = "'4'+2" | 
					
						
							|  |  |  |       const expectedResult = '42' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const result = await new Promise((resolve) => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |         webview.executeJavaScript(jsScript, false, (result) => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |           resolve(result) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(result, expectedResult) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('sendInputEvent', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can send keyboard event', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/onkeyup.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const waitForIpcMessage = waitForEvent(webview, 'ipc-message') | 
					
						
							|  |  |  |       webview.sendInputEvent({ | 
					
						
							|  |  |  |         type: 'keyup', | 
					
						
							|  |  |  |         keyCode: 'c', | 
					
						
							|  |  |  |         modifiers: ['shift'] | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { channel, args } = await waitForIpcMessage | 
					
						
							|  |  |  |       assert.strictEqual(channel, 'keyup') | 
					
						
							|  |  |  |       assert.deepStrictEqual(args, ['C', 'KeyC', 67, true, false]) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can send mouse event', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         nodeintegration: 'on', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/onmouseup.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03: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 13:03:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { channel, args } = await waitForIpcMessage | 
					
						
							|  |  |  |       assert.strictEqual(channel, 'mouseup') | 
					
						
							|  |  |  |       assert.deepStrictEqual(args, [10, 20, false, true]) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-30 13:50:08 +02:00
										 |  |  |   describe('media-started-playing media-paused events', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when audio starts and stops playing', async () => { | 
					
						
							| 
									
										
										
										
											2018-10-09 06:29:40 +05:30
										 |  |  |       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-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'media-started-playing') | 
					
						
							| 
									
										
										
										
											2018-05-30 13:50:08 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       webview.executeJavaScript('document.querySelector("audio").pause()', true) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'media-paused') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |   describe('found-in-page event', () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when a request is made', (done) => { | 
					
						
							| 
									
										
										
										
											2016-09-08 14:27:10 +09:00
										 |  |  |       let requestId = null | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |       const activeMatchOrdinal = [] | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const listener = (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.result.requestId, requestId) | 
					
						
							|  |  |  |         assert.strictEqual(e.result.matches, 3) | 
					
						
							| 
									
										
										
										
											2016-09-08 14:27:10 +09:00
										 |  |  |         activeMatchOrdinal.push(e.result.activeMatchOrdinal) | 
					
						
							|  |  |  |         if (e.result.activeMatchOrdinal === e.result.matches) { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.deepStrictEqual(activeMatchOrdinal, [1, 2, 3]) | 
					
						
							| 
									
										
										
										
											2016-09-08 14:27:10 +09:00
										 |  |  |           webview.stopFindInPage('clearSelection') | 
					
						
							|  |  |  |           done() | 
					
						
							| 
									
										
										
										
											2016-03-14 06:49:45 +05:30
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2016-09-08 14:27:10 +09:00
										 |  |  |           listener2() | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const listener2 = () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         requestId = webview.findInPage('virtual') | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       webview.addEventListener('found-in-page', listener) | 
					
						
							|  |  |  |       webview.addEventListener('did-finish-load', listener2) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       loadWebView(webview, { src: `file://${fixtures}/pages/content.html` }) | 
					
						
							| 
									
										
										
										
											2017-11-25 20:18:01 +05:30
										 |  |  |       // TODO(deepak1556): With https://codereview.chromium.org/2836973002
 | 
					
						
							|  |  |  |       // focus of the webContents is required when triggering the api.
 | 
					
						
							|  |  |  |       // Remove this workaround after determining the cause for
 | 
					
						
							|  |  |  |       // incorrect focus.
 | 
					
						
							|  |  |  |       webview.focus() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('did-change-theme-color event', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits when theme color changes', async () => { | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/theme-color.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       await waitForEvent(webview, 'did-change-theme-color') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('permission-request event', () => { | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |     function setUpRequestHandler (webview, requestedPermission, completed) { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       assert.ok(webview.partition) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const listener = function (webContents, permission, callback) { | 
					
						
							| 
									
										
										
										
											2018-07-23 18:08:36 +09:00
										 |  |  |         if (webContents.id === webview.getWebContents().id) { | 
					
						
							| 
									
										
										
										
											2016-12-19 15:11:17 -08:00
										 |  |  |           // requestMIDIAccess with sysex requests both midi and midiSysex so
 | 
					
						
							|  |  |  |           // grant the first midi one and then reject the midiSysex one
 | 
					
						
							| 
									
										
										
										
											2016-12-19 16:27:38 -08:00
										 |  |  |           if (requestedPermission === 'midiSysex' && permission === 'midi') { | 
					
						
							| 
									
										
										
										
											2016-12-19 15:11:17 -08:00
										 |  |  |             return callback(true) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.strictEqual(permission, requestedPermission) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |           callback(false) | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |           if (completed) completed() | 
					
						
							| 
									
										
										
										
											2016-02-01 03:05:34 +05:30
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |       session.fromPartition(webview.partition).setPermissionRequestHandler(listener) | 
					
						
							| 
									
										
										
										
											2016-02-01 03:05:34 +05:30
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when using navigator.getUserMedia api', (done) => { | 
					
						
							|  |  |  |       if (isCI) return done() | 
					
						
							| 
									
										
										
										
											2017-07-11 14:12:57 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.channel, 'message') | 
					
						
							|  |  |  |         assert.deepStrictEqual(e.args, ['PermissionDeniedError']) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.src = `file://${fixtures}/pages/permissions/media.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							|  |  |  |       setUpRequestHandler(webview, 'media') | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when using navigator.geolocation api', (done) => { | 
					
						
							|  |  |  |       webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.channel, 'message') | 
					
						
							|  |  |  |         assert.deepStrictEqual(e.args, ['User denied Geolocation']) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.src = `file://${fixtures}/pages/permissions/geolocation.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							|  |  |  |       setUpRequestHandler(webview, 'geolocation') | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when using navigator.requestMIDIAccess without sysex api', (done) => { | 
					
						
							|  |  |  |       webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.channel, 'message') | 
					
						
							|  |  |  |         assert.deepStrictEqual(e.args, ['SecurityError']) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.src = `file://${fixtures}/pages/permissions/midi.html` | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							| 
									
										
										
										
											2016-12-19 15:11:17 -08:00
										 |  |  |       setUpRequestHandler(webview, 'midi') | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when using navigator.requestMIDIAccess with sysex api', (done) => { | 
					
						
							|  |  |  |       webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.channel, 'message') | 
					
						
							|  |  |  |         assert.deepStrictEqual(e.args, ['SecurityError']) | 
					
						
							| 
									
										
										
										
											2016-12-19 15:11:17 -08:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.src = `file://${fixtures}/pages/permissions/midi-sysex.html` | 
					
						
							| 
									
										
										
										
											2016-12-19 15:11:17 -08:00
										 |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       setUpRequestHandler(webview, 'midiSysex') | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-04-20 22:25:15 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when accessing external protocol', (done) => { | 
					
						
							| 
									
										
										
										
											2016-04-20 22:25:15 +05:30
										 |  |  |       webview.src = 'magnet:test' | 
					
						
							|  |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       setUpRequestHandler(webview, 'openExternal', done) | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-10-28 10:34:11 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits when using Notification.requestPermission', (done) => { | 
					
						
							|  |  |  |       webview.addEventListener('ipc-message', (e) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(e.channel, 'message') | 
					
						
							|  |  |  |         assert.deepStrictEqual(e.args, ['granted']) | 
					
						
							| 
									
										
										
										
											2016-10-28 10:34:11 -07:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       webview.src = `file://${fixtures}/pages/permissions/notification.html` | 
					
						
							| 
									
										
										
										
											2016-10-28 10:34:11 -07:00
										 |  |  |       webview.partition = 'permissionTest' | 
					
						
							|  |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       session.fromPartition(webview.partition).setPermissionRequestHandler((webContents, permission, callback) => { | 
					
						
							| 
									
										
										
										
											2018-07-23 18:08:36 +09:00
										 |  |  |         if (webContents.id === webview.getWebContents().id) { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |           assert.strictEqual(permission, 'notifications') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |           setTimeout(() => { callback(true) }, 10) | 
					
						
							| 
									
										
										
										
											2016-10-28 10:34:11 -07:00
										 |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('<webview>.getWebContents', () => { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('can return the webcontents associated', async () => { | 
					
						
							|  |  |  |       const src = 'about:blank' | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       await loadWebView(webview, { src }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const webviewContents = webview.getWebContents() | 
					
						
							|  |  |  |       assert(webviewContents) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(webviewContents.getURL()).to.equal(src) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-04-08 12:55:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 06:43:20 +05:30
										 |  |  |   // FIXME(deepak1556): Ch69 follow up.
 | 
					
						
							|  |  |  |   xdescribe('document.visibilityState/hidden', () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     afterEach(() => { | 
					
						
							| 
									
										
										
										
											2017-06-12 12:51:27 -07:00
										 |  |  |       ipcMain.removeAllListeners('pong') | 
					
						
							| 
									
										
										
										
											2016-05-24 12:37:26 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('updates when the window is shown after the ready-to-show event', async () => { | 
					
						
							|  |  |  |       const w = await openTheWindow({ show: false }) | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       const readyToShowSignal = emittedOnce(w, 'ready-to-show') | 
					
						
							|  |  |  |       const pongSignal1 = emittedOnce(ipcMain, 'pong') | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |       w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html')) | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       await pongSignal1 | 
					
						
							|  |  |  |       const pongSignal2 = emittedOnce(ipcMain, 'pong') | 
					
						
							|  |  |  |       await readyToShowSignal | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       w.show() | 
					
						
							| 
									
										
										
										
											2017-06-12 12:51:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       const [, visibilityState, hidden] = await pongSignal2 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       assert(!hidden) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(visibilityState, 'visible') | 
					
						
							| 
									
										
										
										
											2016-05-24 12:37:26 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('inherits the parent window visibility state and receives visibilitychange events', async () => { | 
					
						
							|  |  |  |       const w = await openTheWindow({ show: false }) | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |       w.loadFile(path.join(fixtures, 'pages', 'webview-visibilitychange.html')) | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |       const [, visibilityState, hidden] = await emittedOnce(ipcMain, 'pong') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(visibilityState, 'hidden') | 
					
						
							|  |  |  |       assert.strictEqual(hidden, true) | 
					
						
							| 
									
										
										
										
											2017-06-12 12:51:27 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       // We have to start waiting for the event
 | 
					
						
							|  |  |  |       // before we ask the webContents to resize.
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const getResponse = emittedOnce(ipcMain, 'pong') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       w.webContents.emit('-window-visibility-change', 'visible') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       return getResponse.then(([, visibilityState, hidden]) => { | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |         assert.strictEqual(visibilityState, 'visible') | 
					
						
							|  |  |  |         assert.strictEqual(hidden, false) | 
					
						
							| 
									
										
										
										
											2017-06-12 12:51:27 -07:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-05-24 12:37:26 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-06-07 09:50:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-09 11:49:14 -08:00
										 |  |  |   describe('will-attach-webview event', () => { | 
					
						
							| 
									
										
										
										
											2018-07-21 11:11:28 +09:00
										 |  |  |     it('does not emit when src is not changed', (done) => { | 
					
						
							|  |  |  |       loadWebView(webview) | 
					
						
							|  |  |  |       setTimeout(() => { | 
					
						
							|  |  |  |         const expectedErrorMessage = | 
					
						
							|  |  |  |             'The WebView must be attached to the DOM ' + | 
					
						
							|  |  |  |             'and the dom-ready event emitted before this method can be called.' | 
					
						
							|  |  |  |         expect(() => { webview.stop() }).to.throw(expectedErrorMessage) | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('supports changing the web preferences', async () => { | 
					
						
							| 
									
										
										
										
											2017-02-03 12:55:37 -08:00
										 |  |  |       ipcRenderer.send('disable-node-on-next-will-attach-webview') | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         nodeintegration: 'yes', | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2017-02-03 12:21:46 -08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const types = JSON.parse(message) | 
					
						
							|  |  |  |       expect(types).to.include({ | 
					
						
							|  |  |  |         require: 'undefined', | 
					
						
							|  |  |  |         module: 'undefined', | 
					
						
							|  |  |  |         process: 'undefined', | 
					
						
							|  |  |  |         global: 'undefined' | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-02-03 12:21:46 -08:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('supports preventing a webview from being created', async () => { | 
					
						
							| 
									
										
										
										
											2017-02-03 12:55:37 -08:00
										 |  |  |       ipcRenderer.send('prevent-next-will-attach-webview') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/c.html` | 
					
						
							| 
									
										
										
										
											2017-02-03 12:21:46 -08:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       await waitForEvent(webview, 'destroyed') | 
					
						
							| 
									
										
										
										
											2017-02-03 12:21:46 -08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-17 13:47:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('supports removing the preload script', async () => { | 
					
						
							| 
									
										
										
										
											2017-05-17 13:47:00 -07:00
										 |  |  |       ipcRenderer.send('disable-preload-on-next-will-attach-webview') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const message = await startLoadingWebViewAndWaitForMessage(webview, { | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |         nodeintegration: 'yes', | 
					
						
							|  |  |  |         preload: path.join(fixtures, 'module', 'preload-set-global.js'), | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2017-05-17 13:47:00 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       assert.strictEqual(message, 'undefined') | 
					
						
							| 
									
										
										
										
											2017-05-17 13:47:00 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-02-03 12:21:46 -08:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-07 01:31:41 +09:00
										 |  |  |   describe('did-attach-webview event', () => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('is emitted when a webview has been attached', async () => { | 
					
						
							|  |  |  |       const w = await openTheWindow({ show: false }) | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |       w.loadFile(path.join(fixtures, 'pages', 'webview-did-attach-event.html')) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, webContents] = await emittedOnce(w.webContents, 'did-attach-webview') | 
					
						
							|  |  |  |       const [, id] = await emittedOnce(ipcMain, 'webview-dom-ready') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(webContents.id).to.equal(id) | 
					
						
							| 
									
										
										
										
											2017-10-07 01:31:41 +09:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 18:01:31 +02:00
										 |  |  |   it('loads devtools extensions registered on the parent window', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     const w = await openTheWindow({ show: false }) | 
					
						
							| 
									
										
										
										
											2016-06-07 09:50:06 -07:00
										 |  |  |     BrowserWindow.removeDevToolsExtension('foo') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo') | 
					
						
							| 
									
										
										
										
											2016-06-07 09:50:06 -07:00
										 |  |  |     BrowserWindow.addDevToolsExtension(extensionPath) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |     w.loadFile(path.join(fixtures, 'pages', 'webview-devtools.html')) | 
					
						
							| 
									
										
										
										
											2016-06-07 09:50:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |     const [, { runtimeId, tabId }] = await emittedOnce(ipcMain, 'answer') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     expect(runtimeId).to.equal('foo') | 
					
						
							|  |  |  |     expect(tabId).to.be.not.equal(w.webContents.id) | 
					
						
							| 
									
										
										
										
											2016-06-07 09:50:06 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-09-08 10:01:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('DOM events', () => { | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07:00
										 |  |  |     let div | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07: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%' | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     afterEach(() => { | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07:00
										 |  |  |       if (div != null) div.remove() | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 16:47:17 +02:00
										 |  |  |     it('emits resize events', async () => { | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       const firstResizeSignal = waitForEvent(webview, 'resize') | 
					
						
							|  |  |  |       const domReadySignal = waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 08:28:02 -08:00
										 |  |  |       webview.src = `file://${fixtures}/pages/a.html` | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07:00
										 |  |  |       div.appendChild(webview) | 
					
						
							|  |  |  |       document.body.appendChild(div) | 
					
						
							| 
									
										
										
										
											2018-06-18 16:47:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       const firstResizeEvent = await firstResizeSignal | 
					
						
							| 
									
										
										
										
											2018-06-18 16:47:17 +02:00
										 |  |  |       expect(firstResizeEvent.target).to.equal(webview) | 
					
						
							|  |  |  |       expect(firstResizeEvent.newWidth).to.equal(100) | 
					
						
							|  |  |  |       expect(firstResizeEvent.newHeight).to.equal(10) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       await domReadySignal | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const secondResizeSignal = waitForEvent(webview, 'resize') | 
					
						
							| 
									
										
										
										
											2018-06-18 16:47:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       const newWidth = 1234 | 
					
						
							|  |  |  |       const newHeight = 789 | 
					
						
							|  |  |  |       div.style.width = `${newWidth}px` | 
					
						
							|  |  |  |       div.style.height = `${newHeight}px` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-16 15:57:40 -07:00
										 |  |  |       const secondResizeEvent = await secondResizeSignal | 
					
						
							| 
									
										
										
										
											2018-06-18 16:47:17 +02:00
										 |  |  |       expect(secondResizeEvent.target).to.equal(webview) | 
					
						
							|  |  |  |       expect(secondResizeEvent.newWidth).to.equal(newWidth) | 
					
						
							|  |  |  |       expect(secondResizeEvent.newHeight).to.equal(newHeight) | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2018-08-29 03:35:44 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it('emits focus event', async () => { | 
					
						
							|  |  |  |       const domReadySignal = waitForEvent(webview, 'dom-ready') | 
					
						
							|  |  |  |       webview.src = `file://${fixtures}/pages/a.html` | 
					
						
							|  |  |  |       document.body.appendChild(webview) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await domReadySignal | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-03 11:41:54 +09:00
										 |  |  |       // If this test fails, check if webview.focus() still works.
 | 
					
						
							| 
									
										
										
										
											2018-08-29 03:35:44 +09:00
										 |  |  |       const focusSignal = waitForEvent(webview, 'focus') | 
					
						
							| 
									
										
										
										
											2018-09-03 11:41:54 +09:00
										 |  |  |       webview.focus() | 
					
						
							| 
									
										
										
										
											2018-08-29 03:35:44 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |       await focusSignal | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-11-03 15:12:54 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-10-24 22:17:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |   describe('zoom behavior', () => { | 
					
						
							| 
									
										
										
										
											2017-02-17 23:28:29 +05:30
										 |  |  |     const zoomScheme = remote.getGlobal('zoomScheme') | 
					
						
							|  |  |  |     const webviewSession = session.fromPartition('webview-temp') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     before((done) => { | 
					
						
							|  |  |  |       const protocol = webviewSession.protocol | 
					
						
							|  |  |  |       protocol.registerStringProtocol(zoomScheme, (request, callback) => { | 
					
						
							|  |  |  |         callback('hello') | 
					
						
							|  |  |  |       }, (error) => done(error)) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     after((done) => { | 
					
						
							|  |  |  |       const protocol = webviewSession.protocol | 
					
						
							|  |  |  |       protocol.unregisterProtocol(zoomScheme, (error) => done(error)) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('inherits the zoomFactor of the parent window', async () => { | 
					
						
							|  |  |  |       const w = await openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |         show: false, | 
					
						
							|  |  |  |         webPreferences: { | 
					
						
							|  |  |  |           zoomFactor: 1.2 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |       w.loadFile(path.join(fixtures, 'pages', 'webview-zoom-factor.html')) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, zoomFactor, zoomLevel] = await emittedOnce(ipcMain, 'webview-parent-zoom-level') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(zoomFactor).to.equal(1.2) | 
					
						
							|  |  |  |       expect(zoomLevel).to.equal(1) | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('maintains zoom level on navigation', async () => { | 
					
						
							|  |  |  |       return openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |         show: false, | 
					
						
							|  |  |  |         webPreferences: { | 
					
						
							|  |  |  |           zoomFactor: 1.2 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       }).then((w) => { | 
					
						
							|  |  |  |         const promise = new Promise((resolve) => { | 
					
						
							|  |  |  |           ipcMain.on('webview-zoom-level', (event, zoomLevel, zoomFactor, newHost, final) => { | 
					
						
							|  |  |  |             if (!newHost) { | 
					
						
							|  |  |  |               expect(zoomFactor).to.equal(1.44) | 
					
						
							|  |  |  |               expect(zoomLevel).to.equal(2.0) | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |               expect(zoomFactor).to.equal(1.2) | 
					
						
							|  |  |  |               expect(zoomLevel).to.equal(1) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (final) { | 
					
						
							|  |  |  |               resolve() | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |         w.loadFile(path.join(fixtures, 'pages', 'webview-custom-zoom-level.html')) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return promise | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-02-17 23:28:29 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('maintains zoom level when navigating within same page', async () => { | 
					
						
							|  |  |  |       return openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-02-17 23:28:29 +05:30
										 |  |  |         show: false, | 
					
						
							|  |  |  |         webPreferences: { | 
					
						
							|  |  |  |           zoomFactor: 1.2 | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       }).then((w) => { | 
					
						
							|  |  |  |         const promise = new Promise((resolve) => { | 
					
						
							|  |  |  |           ipcMain.on('webview-zoom-in-page', (event, zoomLevel, zoomFactor, final) => { | 
					
						
							|  |  |  |             expect(zoomFactor).to.equal(1.44) | 
					
						
							|  |  |  |             expect(zoomLevel).to.equal(2.0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (final) { | 
					
						
							|  |  |  |               resolve() | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }) | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |         w.loadFile(path.join(fixtures, 'pages', 'webview-in-page-navigate.html')) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return promise | 
					
						
							| 
									
										
										
										
											2017-02-17 23:28:29 +05:30
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-03-08 19:05:24 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('inherits zoom level for the origin when available', async () => { | 
					
						
							|  |  |  |       const w = await openTheWindow({ | 
					
						
							| 
									
										
										
										
											2017-03-08 19:05:24 +05:30
										 |  |  |         show: false, | 
					
						
							|  |  |  |         webPreferences: { | 
					
						
							|  |  |  |           zoomFactor: 1.2 | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-04 16:50:53 +02:00
										 |  |  |       w.loadFile(path.join(fixtures, 'pages', 'webview-origin-zoom-level.html')) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, zoomLevel] = await emittedOnce(ipcMain, 'webview-origin-zoom-level') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(zoomLevel).to.equal(2.0) | 
					
						
							| 
									
										
										
										
											2017-03-08 19:05:24 +05:30
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-02-17 21:18:30 +05:30
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-05-23 13:24:51 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe('nativeWindowOpen option', () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-05-23 14:22:09 -07:00
										 |  |  |       webview.setAttribute('allowpopups', 'on') | 
					
						
							| 
									
										
										
										
											2017-05-23 13:59:13 -07:00
										 |  |  |       webview.setAttribute('nodeintegration', 'on') | 
					
						
							|  |  |  |       webview.setAttribute('webpreferences', 'nativeWindowOpen=1') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('opens window of about:blank with cross-scripting enabled', async () => { | 
					
						
							|  |  |  |       // Don't wait for loading to finish.
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${path.join(fixtures, 'api', 'native-window-open-blank.html')}` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, content] = await emittedOnce(ipcMain, 'answer') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(content).to.equal('Hello') | 
					
						
							| 
									
										
										
										
											2017-05-23 13:24:51 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-23 13:28:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('opens window of same domain with cross-scripting enabled', async () => { | 
					
						
							|  |  |  |       // Don't wait for loading to finish.
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${path.join(fixtures, 'api', 'native-window-open-file.html')}` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, content] = await emittedOnce(ipcMain, 'answer') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(content).to.equal('Hello') | 
					
						
							| 
									
										
										
										
											2017-05-23 15:56:06 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('returns null from window.open when allowpopups is not set', async () => { | 
					
						
							| 
									
										
										
										
											2017-05-23 15:56:06 -07:00
										 |  |  |       webview.removeAttribute('allowpopups') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // Don't wait for loading to finish.
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${path.join(fixtures, 'api', 'native-window-open-no-allowpopups.html')}` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const [, { windowOpenReturnedNull }] = await emittedOnce(ipcMain, 'answer') | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       expect(windowOpenReturnedNull).to.be.true() | 
					
						
							| 
									
										
										
										
											2017-05-25 09:39:40 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('blocks accessing cross-origin frames', async () => { | 
					
						
							|  |  |  |       // Don't wait for loading to finish.
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${path.join(fixtures, 'api', 'native-window-open-cross-origin.html')}` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       const [, content] = await emittedOnce(ipcMain, 'answer') | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       const expectedContent = | 
					
						
							|  |  |  |           'Blocked a frame with origin "file://" from accessing a cross-origin frame.' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(content).to.equal(expectedContent) | 
					
						
							| 
									
										
										
										
											2017-05-23 13:28:24 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-23 13:59:13 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |     it('emits a new-window event', async () => { | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       // Don't wait for loading to finish.
 | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/window-open.html` | 
					
						
							| 
									
										
										
										
											2017-05-23 13:59:13 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |       const { url, frameName } = await waitForEvent(webview, 'new-window') | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |       expect(url).to.equal('http://host/') | 
					
						
							|  |  |  |       expect(frameName).to.equal('host') | 
					
						
							| 
									
										
										
										
											2017-05-23 13:59:13 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-23 14:31:20 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 10:56:48 +02:00
										 |  |  |     it('emits a browser-window-created event', async () => { | 
					
						
							|  |  |  |       // Don't wait for loading to finish.
 | 
					
						
							|  |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/window-open.html` | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 13:25:26 +02:00
										 |  |  |       await emittedOnce(app, 'browser-window-created') | 
					
						
							| 
									
										
										
										
											2017-05-23 14:31:20 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('emits a web-contents-created event', (done) => { | 
					
						
							|  |  |  |       app.on('web-contents-created', function listener (event, contents) { | 
					
						
							|  |  |  |         if (contents.getType() === 'window') { | 
					
						
							|  |  |  |           app.removeListener('web-contents-created', listener) | 
					
						
							|  |  |  |           done() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-05-15 01:00:49 +03:00
										 |  |  |       loadWebView(webview, { | 
					
						
							|  |  |  |         src: `file://${fixtures}/pages/window-open.html` | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-05-23 14:31:20 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-05-23 13:24:51 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | }) |