browser: emit did-fail-load for invalid url
This commit is contained in:
parent
027b5345f8
commit
5a8bebc2f8
2 changed files with 21 additions and 4 deletions
|
@ -710,6 +710,14 @@ bool WebContents::Equal(const WebContents* web_contents) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
void WebContents::LoadURL(const GURL& url, const mate::Dictionary& options) {
|
||||||
|
if (!url.is_valid()) {
|
||||||
|
Emit("did-fail-load",
|
||||||
|
static_cast<int>(net::ERR_INVALID_URL),
|
||||||
|
net::ErrorToShortString(net::ERR_INVALID_URL),
|
||||||
|
url.possibly_invalid_spec());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
content::NavigationController::LoadURLParams params(url);
|
content::NavigationController::LoadURLParams params(url);
|
||||||
|
|
||||||
GURL http_referrer;
|
GURL http_referrer;
|
||||||
|
|
|
@ -94,11 +94,20 @@ describe('browser-window module', function() {
|
||||||
});
|
});
|
||||||
return w.loadURL('about:blank');
|
return w.loadURL('about:blank');
|
||||||
});
|
});
|
||||||
return it('should emit did-fail-load event', function(done) {
|
it('should emit did-fail-load event for files that do not exist', function(done) {
|
||||||
w.webContents.on('did-fail-load', function() {
|
w.webContents.on('did-fail-load', function(event, code) {
|
||||||
return done();
|
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() {
|
describe('BrowserWindow.show()', function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue