Merge pull request #7146 from electron/resolve-empty-url-values
Tweak how empty URLs are resolved
This commit is contained in:
Коммит
693ba1375b
|
@ -139,7 +139,11 @@ window.open = function (url, frameName, features) {
|
|||
}
|
||||
|
||||
// Resolve relative urls.
|
||||
url = resolveURL(url)
|
||||
if (url == null || url === '') {
|
||||
url = 'about:blank'
|
||||
} else {
|
||||
url = resolveURL(url)
|
||||
}
|
||||
for (j = 0, len1 = ints.length; j < len1; j++) {
|
||||
name = ints[j]
|
||||
if (options[name] != null) {
|
||||
|
|
|
@ -9,6 +9,7 @@ const remote = require('electron').remote
|
|||
var a = document.createElement('a')
|
||||
|
||||
var resolveURL = function (url) {
|
||||
if (url === '') return ''
|
||||
a.href = url
|
||||
return a.href
|
||||
}
|
||||
|
|
|
@ -250,8 +250,7 @@ describe('chromium feature', function () {
|
|||
|
||||
it('defines a window.location setter', function (done) {
|
||||
// Load a page that definitely won't redirect
|
||||
var b
|
||||
b = window.open('about:blank')
|
||||
var b = window.open('about:blank')
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
// When it loads, redirect
|
||||
b.location = 'file://' + fixtures + '/pages/base-page.html'
|
||||
|
@ -262,6 +261,23 @@ describe('chromium feature', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('open a blank page when no URL is specified', function (done) {
|
||||
let b = window.open()
|
||||
webContents.fromId(b.guestId).once('did-finish-load', function () {
|
||||
const {location} = b
|
||||
b.close()
|
||||
assert.equal(location, 'about:blank')
|
||||
|
||||
let c = window.open('')
|
||||
webContents.fromId(c.guestId).once('did-finish-load', function () {
|
||||
const {location} = c
|
||||
c.close()
|
||||
assert.equal(location, 'about:blank')
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('window.opener', function () {
|
||||
|
|
|
@ -75,6 +75,27 @@ describe('<webview> tag', function () {
|
|||
webview.src = 'file://' + fixtures + '/pages/a.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('resolves relative URLs', function (done) {
|
||||
var listener = function (e) {
|
||||
assert.equal(e.message, 'Window script is loaded before preload script')
|
||||
webview.removeEventListener('console-message', listener)
|
||||
done()
|
||||
}
|
||||
webview.addEventListener('console-message', listener)
|
||||
webview.src = '../fixtures/pages/e.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('ignores empty values', function () {
|
||||
assert.equal(webview.src, '')
|
||||
webview.src = ''
|
||||
assert.equal(webview.src, '')
|
||||
webview.src = null
|
||||
assert.equal(webview.src, '')
|
||||
webview.src = undefined
|
||||
assert.equal(webview.src, '')
|
||||
})
|
||||
})
|
||||
|
||||
describe('nodeintegration attribute', function () {
|
||||
|
@ -198,6 +219,28 @@ describe('<webview> tag', function () {
|
|||
webview.src = 'file://' + fixtures + '/pages/base-page.html'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('resolves relative URLs', function (done) {
|
||||
var listener = function (e) {
|
||||
assert.equal(e.message, 'function object object')
|
||||
webview.removeEventListener('console-message', listener)
|
||||
done()
|
||||
}
|
||||
webview.addEventListener('console-message', listener)
|
||||
webview.src = 'file://' + fixtures + '/pages/e.html'
|
||||
webview.preload = '../fixtures/module/preload.js'
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
|
||||
it('ignores empty values', function () {
|
||||
assert.equal(webview.preload, '')
|
||||
webview.preload = ''
|
||||
assert.equal(webview.preload, '')
|
||||
webview.preload = null
|
||||
assert.equal(webview.preload, '')
|
||||
webview.preload = undefined
|
||||
assert.equal(webview.preload, '')
|
||||
})
|
||||
})
|
||||
|
||||
describe('httpreferrer attribute', function () {
|
||||
|
|
Загрузка…
Ссылка в новой задаче