emit once for each session and add spec
This commit is contained in:
		
					parent
					
						
							
								cb5e648502
							
						
					
				
			
			
				commit
				
					
						b91217f29e
					
				
			
		
					 2 changed files with 41 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -10,9 +10,7 @@ const fromPartition = function (partition, persist) {
 | 
			
		|||
    throw new Error('session module can only be used when app is ready')
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  let session = bindings.fromPartition(partition, persist)
 | 
			
		||||
  process.emit('session-created', session)
 | 
			
		||||
  return session
 | 
			
		||||
  return bindings.fromPartition(partition, persist)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns the Session from |partition| string.
 | 
			
		||||
| 
						 | 
				
			
			@ -37,6 +35,7 @@ Object.defineProperty(exports, 'defaultSession', {
 | 
			
		|||
const wrapSession = function (session) {
 | 
			
		||||
  // Session is an EventEmitter.
 | 
			
		||||
  Object.setPrototypeOf(session, EventEmitter.prototype)
 | 
			
		||||
  process.emit('session-created', session)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bindings._setWrapSession(wrapSession)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -883,6 +883,45 @@ describe('browser-window module', function () {
 | 
			
		|||
      })
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    it('works when used with partitions', function (done) {
 | 
			
		||||
      this.timeout(10000)
 | 
			
		||||
 | 
			
		||||
      if (w != null) {
 | 
			
		||||
        w.destroy()
 | 
			
		||||
      }
 | 
			
		||||
      w = new BrowserWindow({
 | 
			
		||||
        show: false,
 | 
			
		||||
        webPreferences: {
 | 
			
		||||
          partition: 'temp'
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo')
 | 
			
		||||
      BrowserWindow.removeDevToolsExtension('foo')
 | 
			
		||||
      BrowserWindow.addDevToolsExtension(extensionPath)
 | 
			
		||||
 | 
			
		||||
      w.webContents.on('devtools-opened', function () {
 | 
			
		||||
        var showPanelIntevalId = setInterval(function () {
 | 
			
		||||
          if (w && w.devToolsWebContents) {
 | 
			
		||||
            w.devToolsWebContents.executeJavaScript('(' + (function () {
 | 
			
		||||
              var lastPanelId = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id
 | 
			
		||||
              WebInspector.inspectorView.showPanel(lastPanelId)
 | 
			
		||||
            }).toString() + ')()')
 | 
			
		||||
          } else {
 | 
			
		||||
            clearInterval(showPanelIntevalId)
 | 
			
		||||
          }
 | 
			
		||||
        }, 100)
 | 
			
		||||
      })
 | 
			
		||||
 | 
			
		||||
      w.loadURL('about:blank')
 | 
			
		||||
      w.webContents.openDevTools({mode: 'bottom'})
 | 
			
		||||
 | 
			
		||||
      ipcMain.once('answer', function (event, message) {
 | 
			
		||||
        assert.equal(message.runtimeId, 'foo')
 | 
			
		||||
        done()
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    it('serializes the registered extensions on quit', function () {
 | 
			
		||||
      var extensionName = 'foo'
 | 
			
		||||
      var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', extensionName)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue