diff --git a/browser/api/atom_api_protocol.cc b/browser/api/atom_api_protocol.cc index abeac812b5..70611ea32b 100644 --- a/browser/api/atom_api_protocol.cc +++ b/browser/api/atom_api_protocol.cc @@ -291,7 +291,8 @@ class AdapterProtocolHandler // static v8::Handle Protocol::RegisterProtocol(const v8::Arguments& args) { std::string scheme(*v8::String::Utf8Value(args[0])); - if (net::URLRequest::IsHandledProtocol(scheme)) + if (g_handlers.find(scheme) != g_handlers.end() || + net::URLRequest::IsHandledProtocol(scheme)) return node::ThrowError("The scheme is already registered"); // Store the handler in a map. diff --git a/spec/api/protocol.coffee b/spec/api/protocol.coffee index ab90cb9018..027e622c36 100644 --- a/spec/api/protocol.coffee +++ b/spec/api/protocol.coffee @@ -5,11 +5,14 @@ protocol = remote.require 'protocol' describe 'protocol API', -> describe 'protocol.registerProtocol', -> - it 'throws error when scheme is already registered', -> + it 'throws error when scheme is already registered', (done) -> register = -> protocol.registerProtocol('test1', ->) + protocol.once 'registered', (scheme) -> + assert.equal scheme, 'test1' + assert.throws register, /The scheme is already registered/ + protocol.unregisterProtocol 'test1' + done() register() - assert.throws register, /The scheme is already registered/ - protocol.unregisterProtocol 'test1' it 'calls the callback when scheme is visited', (done) -> protocol.registerProtocol 'test2', (request) ->