| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | 'use strict' | 
					
						
							| 
									
										
										
										
											2016-02-22 12:13:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | const assert = require('assert') | 
					
						
							|  |  |  | const path = require('path') | 
					
						
							| 
									
										
										
										
											2016-08-03 12:47:53 -07:00
										 |  |  | const {closeWindow} = require('./window-helpers') | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 15:57:41 -05:00
										 |  |  | const {remote} = require('electron') | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  | const comparePaths = (path1, path2) => { | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |   if (process.platform === 'win32') { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     path1 = path1.toLowerCase() | 
					
						
							|  |  |  |     path2 = path2.toLowerCase() | 
					
						
							| 
									
										
										
										
											2016-01-11 18:40:23 -08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   assert.equal(path1, path2) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 16:01:03 -05:00
										 |  |  | describe('remote module', () => { | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   const fixtures = path.join(__dirname, 'fixtures') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   let w = null | 
					
						
							| 
									
										
										
										
											2016-08-03 12:47:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   afterEach(() => closeWindow(w).then(() => { w = null })) | 
					
						
							| 
									
										
										
										
											2016-08-03 12:47:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote.require', () => { | 
					
						
							|  |  |  |     it('should returns same object for the same module', () => { | 
					
						
							|  |  |  |       const dialog1 = remote.require('electron') | 
					
						
							|  |  |  |       const dialog2 = remote.require('electron') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(dialog1, dialog2) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should work when object contains id property', () => { | 
					
						
							|  |  |  |       const a = remote.require(path.join(fixtures, 'module', 'id.js')) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(a.id, 1127) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should work when object has no prototype', () => { | 
					
						
							|  |  |  |       const a = remote.require(path.join(fixtures, 'module', 'no-prototype.js')) | 
					
						
							| 
									
										
										
										
											2016-07-06 13:06:48 -07:00
										 |  |  |       assert.equal(a.foo.constructor.name, '') | 
					
						
							| 
									
										
										
										
											2016-05-27 10:52:56 -07:00
										 |  |  |       assert.equal(a.foo.bar, 'baz') | 
					
						
							|  |  |  |       assert.equal(a.foo.baz, false) | 
					
						
							| 
									
										
										
										
											2016-05-27 10:41:10 -07:00
										 |  |  |       assert.equal(a.bar, 1234) | 
					
						
							| 
									
										
										
										
											2016-07-06 13:11:25 -07:00
										 |  |  |       assert.equal(a.anonymous.constructor.name, '') | 
					
						
							| 
									
										
										
										
											2016-07-06 13:06:48 -07:00
										 |  |  |       assert.equal(a.getConstructorName(Object.create(null)), '') | 
					
						
							| 
									
										
										
										
											2016-10-13 12:47:43 +11:00
										 |  |  |       assert.equal(a.getConstructorName(new (class {})()), '') | 
					
						
							| 
									
										
										
										
											2016-05-27 10:41:10 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should search module from the user app', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       comparePaths(path.normalize(remote.process.mainModule.filename), path.resolve(__dirname, 'static', 'main.js')) | 
					
						
							|  |  |  |       comparePaths(path.normalize(remote.process.mainModule.paths[0]), path.resolve(__dirname, 'static', 'node_modules')) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-07-11 09:52:34 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should work with function properties', () => { | 
					
						
							|  |  |  |       let a = remote.require(path.join(fixtures, 'module', 'export-function-with-properties.js')) | 
					
						
							| 
									
										
										
										
											2016-08-16 09:24:38 -07:00
										 |  |  |       assert.equal(typeof a, 'function') | 
					
						
							|  |  |  |       assert.equal(a.bar, 'baz') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       a = remote.require(path.join(fixtures, 'module', 'function-with-properties.js')) | 
					
						
							|  |  |  |       assert.equal(typeof a, 'object') | 
					
						
							| 
									
										
										
										
											2016-08-16 13:54:21 -07:00
										 |  |  |       assert.equal(a.foo(), 'hello') | 
					
						
							| 
									
										
										
										
											2016-08-16 09:24:38 -07:00
										 |  |  |       assert.equal(a.foo.bar, 'baz') | 
					
						
							| 
									
										
										
										
											2016-08-16 10:37:51 -07:00
										 |  |  |       assert.equal(a.foo.nested.prop, 'yes') | 
					
						
							| 
									
										
										
										
											2016-08-16 13:54:21 -07:00
										 |  |  |       assert.equal(a.foo.method1(), 'world') | 
					
						
							|  |  |  |       assert.equal(a.foo.method1.prop1(), 123) | 
					
						
							| 
									
										
										
										
											2016-08-17 13:58:48 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       assert.ok(Object.keys(a.foo).includes('bar')) | 
					
						
							|  |  |  |       assert.ok(Object.keys(a.foo).includes('nested')) | 
					
						
							|  |  |  |       assert.ok(Object.keys(a.foo).includes('method1')) | 
					
						
							| 
									
										
										
										
											2016-09-14 10:43:55 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 11:16:44 -07:00
										 |  |  |       a = remote.require(path.join(fixtures, 'module', 'function-with-missing-properties.js')).setup() | 
					
						
							| 
									
										
										
										
											2016-09-14 10:43:55 -07:00
										 |  |  |       assert.equal(a.bar(), true) | 
					
						
							| 
									
										
										
										
											2016-09-14 13:21:44 -07:00
										 |  |  |       assert.equal(a.bar.baz, undefined) | 
					
						
							| 
									
										
										
										
											2016-08-16 09:24:38 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('should work with static class members', () => { | 
					
						
							|  |  |  |       const a = remote.require(path.join(fixtures, 'module', 'remote-static.js')) | 
					
						
							| 
									
										
										
										
											2016-08-16 10:32:32 -07:00
										 |  |  |       assert.equal(typeof a.Foo, 'function') | 
					
						
							|  |  |  |       assert.equal(a.Foo.foo(), 3) | 
					
						
							|  |  |  |       assert.equal(a.Foo.bar, 'baz') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const foo = new a.Foo() | 
					
						
							| 
									
										
										
										
											2016-08-16 10:32:32 -07:00
										 |  |  |       assert.equal(foo.baz(), 123) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('includes the length of functions specified as arguments', () => { | 
					
						
							|  |  |  |       const a = remote.require(path.join(fixtures, 'module', 'function-with-args.js')) | 
					
						
							|  |  |  |       assert.equal(a((a, b, c, d, f) => {}), 5) | 
					
						
							| 
									
										
										
										
											2017-02-07 15:24:49 -08:00
										 |  |  |       assert.equal(a((a) => {}), 1) | 
					
						
							|  |  |  |       assert.equal(a((...args) => {}), 0) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('handles circular references in arrays and objects', () => { | 
					
						
							|  |  |  |       const a = remote.require(path.join(fixtures, 'module', 'circular.js')) | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       let arrayA = ['foo'] | 
					
						
							|  |  |  |       const arrayB = [arrayA, 'bar'] | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       arrayA.push(arrayB) | 
					
						
							|  |  |  |       assert.deepEqual(a.returnArgs(arrayA, arrayB), [ | 
					
						
							|  |  |  |         ['foo', [null, 'bar']], | 
					
						
							|  |  |  |         [['foo', null], 'bar'] | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       let objectA = {foo: 'bar'} | 
					
						
							|  |  |  |       const objectB = {baz: objectA} | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       objectA.objectB = objectB | 
					
						
							|  |  |  |       assert.deepEqual(a.returnArgs(objectA, objectB), [ | 
					
						
							|  |  |  |         {foo: 'bar', objectB: {baz: null}}, | 
					
						
							|  |  |  |         {baz: {foo: 'bar', objectB: null}} | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       arrayA = [1, 2, 3] | 
					
						
							|  |  |  |       assert.deepEqual(a.returnArgs({foo: arrayA}, {bar: arrayA}), [ | 
					
						
							|  |  |  |         {foo: [1, 2, 3]}, | 
					
						
							|  |  |  |         {bar: [1, 2, 3]} | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 10:49:23 -07:00
										 |  |  |       objectA = {foo: 'bar'} | 
					
						
							|  |  |  |       assert.deepEqual(a.returnArgs({foo: objectA}, {bar: objectA}), [ | 
					
						
							|  |  |  |         {foo: {foo: 'bar'}}, | 
					
						
							|  |  |  |         {bar: {foo: 'bar'}} | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       arrayA = [] | 
					
						
							|  |  |  |       arrayA.push(arrayA) | 
					
						
							|  |  |  |       assert.deepEqual(a.returnArgs(arrayA), [ | 
					
						
							|  |  |  |         [null] | 
					
						
							|  |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 10:30:18 -07:00
										 |  |  |       objectA = {} | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       objectA.foo = objectA | 
					
						
							| 
									
										
										
										
											2016-07-11 10:49:23 -07:00
										 |  |  |       objectA.bar = 'baz' | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       assert.deepEqual(a.returnArgs(objectA), [ | 
					
						
							| 
									
										
										
										
											2016-07-11 10:49:23 -07:00
										 |  |  |         {foo: null, bar: 'baz'} | 
					
						
							| 
									
										
										
										
											2016-07-11 09:52:34 -07:00
										 |  |  |       ]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       objectA = {} | 
					
						
							|  |  |  |       objectA.foo = {bar: objectA} | 
					
						
							| 
									
										
										
										
											2016-07-11 10:49:23 -07:00
										 |  |  |       objectA.bar = 'baz' | 
					
						
							| 
									
										
										
										
											2016-07-11 10:27:43 -07:00
										 |  |  |       assert.deepEqual(a.returnArgs(objectA), [ | 
					
						
							| 
									
										
										
										
											2016-07-11 10:49:23 -07:00
										 |  |  |         {foo: {bar: null}, bar: 'baz'} | 
					
						
							| 
									
										
										
										
											2016-07-11 09:52:34 -07:00
										 |  |  |       ]) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote.createFunctionWithReturnValue', () => { | 
					
						
							|  |  |  |     it('should be called in browser synchronously', () => { | 
					
						
							| 
									
										
										
										
											2017-11-23 14:22:31 -08:00
										 |  |  |       const buf = Buffer.from('test') | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const call = remote.require(path.join(fixtures, 'module', 'call.js')) | 
					
						
							|  |  |  |       const result = call.call(remote.createFunctionWithReturnValue(buf)) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(result.constructor.name, 'Buffer') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote modules', () => { | 
					
						
							|  |  |  |     it('includes browser process modules as properties', () => { | 
					
						
							| 
									
										
										
										
											2017-02-24 10:43:39 -08:00
										 |  |  |       assert.equal(typeof remote.app.getPath, 'function') | 
					
						
							|  |  |  |       assert.equal(typeof remote.webContents.getFocusedWebContents, 'function') | 
					
						
							|  |  |  |       assert.equal(typeof remote.clipboard.readText, 'function') | 
					
						
							|  |  |  |       assert.equal(typeof remote.shell.openExternal, 'function') | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-03-17 08:21:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('returns toString() of original function via toString()', () => { | 
					
						
							| 
									
										
										
										
											2017-03-17 10:28:23 -07:00
										 |  |  |       const {readText} = remote.clipboard | 
					
						
							| 
									
										
										
										
											2017-03-17 08:21:37 -07:00
										 |  |  |       assert(readText.toString().startsWith('function')) | 
					
						
							| 
									
										
										
										
											2017-03-17 10:28:23 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const {functionWithToStringProperty} = remote.require(path.join(fixtures, 'module', 'to-string-non-function.js')) | 
					
						
							| 
									
										
										
										
											2017-03-17 10:28:23 -07:00
										 |  |  |       assert.equal(functionWithToStringProperty.toString, 'hello') | 
					
						
							| 
									
										
										
										
											2017-03-17 08:21:37 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-02-24 10:43:39 -08:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote object in renderer', () => { | 
					
						
							|  |  |  |     it('can change its properties', () => { | 
					
						
							|  |  |  |       const property = remote.require(path.join(fixtures, 'module', 'property.js')) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(property.property, 1127) | 
					
						
							| 
									
										
										
										
											2017-04-03 14:26:39 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       property.property = null | 
					
						
							|  |  |  |       assert.equal(property.property, null) | 
					
						
							|  |  |  |       property.property = undefined | 
					
						
							|  |  |  |       assert.equal(property.property, undefined) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       property.property = 1007 | 
					
						
							|  |  |  |       assert.equal(property.property, 1007) | 
					
						
							| 
									
										
										
										
											2017-04-03 14:26:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-17 14:21:50 -07:00
										 |  |  |       assert.equal(property.getFunctionProperty(), 'foo-browser') | 
					
						
							|  |  |  |       property.func.property = 'bar' | 
					
						
							|  |  |  |       assert.equal(property.getFunctionProperty(), 'bar-browser') | 
					
						
							| 
									
										
										
										
											2016-09-08 14:42:59 +09:00
										 |  |  |       property.func.property = 'foo'  // revert back
 | 
					
						
							| 
									
										
										
										
											2016-08-17 14:21:50 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const property2 = remote.require(path.join(fixtures, 'module', 'property.js')) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(property2.property, 1007) | 
					
						
							|  |  |  |       property.property = 1127 | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('rethrows errors getting/setting properties', () => { | 
					
						
							| 
									
										
										
										
											2017-04-03 09:09:37 -07:00
										 |  |  |       const foo = remote.require(path.join(fixtures, 'module', 'error-properties.js')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       assert.throws(() => { | 
					
						
							| 
									
										
										
										
											2017-11-23 14:22:43 -08:00
										 |  |  |         // eslint-disable-next-line
 | 
					
						
							| 
									
										
										
										
											2017-04-03 09:09:37 -07:00
										 |  |  |         foo.bar | 
					
						
							|  |  |  |       }, /getting error/) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       assert.throws(() => { | 
					
						
							| 
									
										
										
										
											2017-04-03 09:09:37 -07:00
										 |  |  |         foo.bar = 'test' | 
					
						
							|  |  |  |       }, /setting error/) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can set a remote property with a remote object', () => { | 
					
						
							| 
									
										
										
										
											2017-04-03 14:17:16 -07:00
										 |  |  |       const foo = remote.require(path.join(fixtures, 'module', 'remote-object-set.js')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       assert.doesNotThrow(() => { | 
					
						
							| 
									
										
										
										
											2017-04-03 14:17:16 -07:00
										 |  |  |         foo.bar = remote.getCurrentWindow() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can construct an object from its member', () => { | 
					
						
							|  |  |  |       const call = remote.require(path.join(fixtures, 'module', 'call.js')) | 
					
						
							|  |  |  |       const obj = new call.constructor() | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(obj.test, 'test') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can reassign and delete its member functions', () => { | 
					
						
							|  |  |  |       const remoteFunctions = remote.require(path.join(fixtures, 'module', 'function.js')) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(remoteFunctions.aFunction(), 1127) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       remoteFunctions.aFunction = () => { return 1234 } | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(remoteFunctions.aFunction(), 1234) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       assert.equal(delete remoteFunctions.aFunction, true) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-04-01 14:50:33 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('is referenced by its members', () => { | 
					
						
							| 
									
										
										
										
											2016-04-01 14:50:33 +09:00
										 |  |  |       let stringify = remote.getGlobal('JSON').stringify | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |       global.gc() | 
					
						
							| 
									
										
										
										
											2016-04-01 14:50:33 +09:00
										 |  |  |       stringify({}) | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote value in browser', () => { | 
					
						
							| 
									
										
										
										
											2016-07-25 16:30:40 +09:00
										 |  |  |     const print = path.join(fixtures, 'module', 'print_name.js') | 
					
						
							|  |  |  |     const printName = remote.require(print) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('keeps its constructor name for objects', () => { | 
					
						
							| 
									
										
										
										
											2017-11-23 14:22:31 -08:00
										 |  |  |       const buf = Buffer.from('test') | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |       assert.equal(printName.print(buf), 'Buffer') | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('supports instanceof Date', () => { | 
					
						
							| 
									
										
										
										
											2016-07-25 16:30:40 +09:00
										 |  |  |       const now = new Date() | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |       assert.equal(printName.print(now), 'Date') | 
					
						
							|  |  |  |       assert.deepEqual(printName.echo(now), now) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-07-25 16:30:40 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('supports instanceof Buffer', () => { | 
					
						
							| 
									
										
										
										
											2016-08-24 15:01:52 -07:00
										 |  |  |       const buffer = Buffer.from('test') | 
					
						
							|  |  |  |       assert.ok(buffer.equals(printName.echo(buffer))) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const objectWithBuffer = {a: 'foo', b: Buffer.from('bar')} | 
					
						
							|  |  |  |       assert.ok(objectWithBuffer.b.equals(printName.echo(objectWithBuffer).b)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-24 16:41:59 -07:00
										 |  |  |       const arrayWithBuffer = [1, 2, Buffer.from('baz')] | 
					
						
							| 
									
										
										
										
											2016-08-24 15:01:52 -07:00
										 |  |  |       assert.ok(arrayWithBuffer[2].equals(printName.echo(arrayWithBuffer)[2])) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('supports TypedArray', () => { | 
					
						
							| 
									
										
										
										
											2016-08-24 16:59:54 -07:00
										 |  |  |       const values = [1, 2, 3, 4] | 
					
						
							| 
									
										
										
										
											2016-08-24 16:46:56 -07:00
										 |  |  |       assert.deepEqual(printName.typedArray(values), values) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-24 16:59:54 -07:00
										 |  |  |       const int16values = new Int16Array([1, 2, 3, 4]) | 
					
						
							|  |  |  |       assert.deepEqual(printName.typedArray(int16values), int16values) | 
					
						
							| 
									
										
										
										
											2016-07-25 16:30:40 +09:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote promise', () => { | 
					
						
							|  |  |  |     it('can be used as promise in each side', (done) => { | 
					
						
							|  |  |  |       const promise = remote.require(path.join(fixtures, 'module', 'promise.js')) | 
					
						
							|  |  |  |       promise.twicePromise(Promise.resolve(1234)).then((value) => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |         assert.equal(value, 2468) | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-05-23 15:06:46 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('handles rejections via catch(onRejected)', (done) => { | 
					
						
							|  |  |  |       const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js')) | 
					
						
							|  |  |  |       promise.reject(Promise.resolve(1234)).catch((error) => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:06:46 -07:00
										 |  |  |         assert.equal(error.message, 'rejected') | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('handles rejections via then(onFulfilled, onRejected)', (done) => { | 
					
						
							|  |  |  |       const promise = remote.require(path.join(fixtures, 'module', 'rejected-promise.js')) | 
					
						
							|  |  |  |       promise.reject(Promise.resolve(1234)).then(() => {}, (error) => { | 
					
						
							| 
									
										
										
										
											2016-05-23 15:06:46 -07:00
										 |  |  |         assert.equal(error.message, 'rejected') | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('does not emit unhandled rejection events in the main process', (done) => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  |       remote.process.once('unhandledRejection', function (reason) { | 
					
						
							|  |  |  |         done(reason) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js')) | 
					
						
							|  |  |  |       promise.reject().then(() => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  |         done(new Error('Promise was not rejected')) | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       }).catch((error) => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  |         assert.equal(error.message, 'rejected') | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('emits unhandled rejection events in the renderer process', (done) => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  |       window.addEventListener('unhandledrejection', function (event) { | 
					
						
							|  |  |  |         event.preventDefault() | 
					
						
							|  |  |  |         assert.equal(event.reason.message, 'rejected') | 
					
						
							|  |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |       const promise = remote.require(path.join(fixtures, 'module', 'unhandled-rejection.js')) | 
					
						
							|  |  |  |       promise.reject().then(() => { | 
					
						
							| 
									
										
										
										
											2016-06-20 17:54:15 -07:00
										 |  |  |         done(new Error('Promise was not rejected')) | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote webContents', () => { | 
					
						
							|  |  |  |     it('can return same object with different getters', () => { | 
					
						
							|  |  |  |       const contents1 = remote.getCurrentWindow().webContents | 
					
						
							|  |  |  |       const contents2 = remote.getCurrentWebContents() | 
					
						
							| 
									
										
										
										
											2016-03-28 16:31:06 -07:00
										 |  |  |       assert(contents1 === contents2) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |   describe('remote class', () => { | 
					
						
							|  |  |  |     const cl = remote.require(path.join(fixtures, 'module', 'class.js')) | 
					
						
							|  |  |  |     const base = cl.base | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     let derived = cl.derived | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can get methods', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(base.method(), 'method') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can get properties', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(base.readonly, 'readonly') | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('can change properties', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(base.value, 'old') | 
					
						
							|  |  |  |       base.value = 'new' | 
					
						
							|  |  |  |       assert.equal(base.value, 'new') | 
					
						
							|  |  |  |       base.value = 'old' | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('has unenumerable methods', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert(!base.hasOwnProperty('method')) | 
					
						
							|  |  |  |       assert(Object.getPrototypeOf(base).hasOwnProperty('method')) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('keeps prototype chain in derived class', () => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |       assert.equal(derived.method(), 'method') | 
					
						
							|  |  |  |       assert.equal(derived.readonly, 'readonly') | 
					
						
							|  |  |  |       assert(!derived.hasOwnProperty('method')) | 
					
						
							|  |  |  |       let proto = Object.getPrototypeOf(derived) | 
					
						
							|  |  |  |       assert(!proto.hasOwnProperty('method')) | 
					
						
							|  |  |  |       assert(Object.getPrototypeOf(proto).hasOwnProperty('method')) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-04-01 15:35:34 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-27 16:45:58 -04:00
										 |  |  |     it('is referenced by methods in prototype chain', () => { | 
					
						
							| 
									
										
										
										
											2016-04-01 15:35:34 +09:00
										 |  |  |       let method = derived.method | 
					
						
							|  |  |  |       derived = null | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |       global.gc() | 
					
						
							| 
									
										
										
										
											2016-04-01 15:35:34 +09:00
										 |  |  |       assert.equal(method(), 'method') | 
					
						
							| 
									
										
										
										
											2016-06-29 09:37:10 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | }) |