From 5a8bebc2f8faf6a84073e7dd27fd519a14e5ce67 Mon Sep 17 00:00:00 2001 From: Robo Date: Thu, 11 Feb 2016 08:24:50 +0530 Subject: [PATCH] browser: emit did-fail-load for invalid url --- atom/browser/api/atom_api_web_contents.cc | 8 ++++++++ spec/api-browser-window-spec.js | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 80e5b606ef8d..a7946786c514 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -710,6 +710,14 @@ bool WebContents::Equal(const WebContents* web_contents) const { } void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) { + if (!url.is_valid()) { + Emit("did-fail-load", + static_cast(net::ERR_INVALID_URL), + net::ErrorToShortString(net::ERR_INVALID_URL), + url.possibly_invalid_spec()); + return; + } + content::NavigationController::LoadURLParams params(url); GURL http_referrer; diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index fc8d3523c8fb..72d28bcb6ed0 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -94,11 +94,20 @@ describe('browser-window module', function() { }); return w.loadURL('about:blank'); }); - return it('should emit did-fail-load event', function(done) { - w.webContents.on('did-fail-load', function() { - return done(); + it('should emit did-fail-load event for files that do not exist', function(done) { + w.webContents.on('did-fail-load', function(event, code) { + assert.equal(code, -6); + done(); }); - return w.loadURL('file://a.txt'); + w.loadURL('file://a.txt'); + }); + it('should emit did-fail-load event for invalid URL', function(done) { + w.webContents.on('did-fail-load', function(event, code, desc) { + assert.equal(desc, 'ERR_INVALID_URL'); + assert.equal(code, -300); + done(); + }); + w.loadURL('http://example:port'); }); }); describe('BrowserWindow.show()', function() {