protocol: respect requests from partition
This commit is contained in:
		
					parent
					
						
							
								54a7eefa28
							
						
					
				
			
			
				commit
				
					
						85800256de
					
				
			
		
					 7 changed files with 105 additions and 49 deletions
				
			
		| 
						 | 
				
			
			@ -3,6 +3,7 @@ const http = require('http');
 | 
			
		|||
const path = require('path');
 | 
			
		||||
const qs = require('querystring');
 | 
			
		||||
const remote = require('electron').remote;
 | 
			
		||||
const BrowserWindow = remote.require('electron').BrowserWindow;
 | 
			
		||||
const protocol = remote.require('electron').protocol;
 | 
			
		||||
 | 
			
		||||
describe('protocol module', function() {
 | 
			
		||||
| 
						 | 
				
			
			@ -814,4 +815,54 @@ describe('protocol module', function() {
 | 
			
		|||
      });
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('protocol.fromPartition', function() {
 | 
			
		||||
    var partitionName = 'temp';
 | 
			
		||||
    var tempProtocol = protocol.fromPartition(partitionName);
 | 
			
		||||
    var w = null;
 | 
			
		||||
 | 
			
		||||
    beforeEach(function() {
 | 
			
		||||
      if (w != null) {
 | 
			
		||||
        w.destroy();
 | 
			
		||||
      }
 | 
			
		||||
      w = new BrowserWindow({
 | 
			
		||||
        show: false,
 | 
			
		||||
        width: 400,
 | 
			
		||||
        height: 400,
 | 
			
		||||
        webPreferences: {
 | 
			
		||||
          partition: partitionName
 | 
			
		||||
        }
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    afterEach(function() {
 | 
			
		||||
      if (w != null) {
 | 
			
		||||
        w.destroy();
 | 
			
		||||
      }
 | 
			
		||||
      w = null;
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('handles requests from a partition', function(done) {
 | 
			
		||||
      var handler = function(error, callback) {
 | 
			
		||||
        callback({
 | 
			
		||||
          data: text
 | 
			
		||||
        });
 | 
			
		||||
      };
 | 
			
		||||
      tempProtocol.registerStringProtocol(protocolName, handler, function(error) {
 | 
			
		||||
        if (error) {
 | 
			
		||||
          return done(error);
 | 
			
		||||
        }
 | 
			
		||||
        protocol.isProtocolHandled(protocolName, function(result) {
 | 
			
		||||
          assert.equal(result, false);
 | 
			
		||||
        });
 | 
			
		||||
        tempProtocol.isProtocolHandled(protocolName, function(result) {
 | 
			
		||||
          assert.equal(result, true);
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
      w.webContents.on('did-finish-load', function() {
 | 
			
		||||
        done();
 | 
			
		||||
      });
 | 
			
		||||
      w.loadURL(protocolName + "://fake-host");
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue