Change WebContents::IsLoadingMainFrame
to compare SiteInstances
(per @deepak1556's recommendation) Also updates tests to cover the situation where navigating between pages from the same potential "site" and adds generalized tests for `isLoadingMainFrame()`.
This commit is contained in:
parent
942971b01a
commit
d3e879cd7f
3 changed files with 69 additions and 64 deletions
|
@ -19,6 +19,23 @@ const isCI = remote.getGlobal('isCi')
|
|||
describe('browser-window module', function () {
|
||||
var fixtures = path.resolve(__dirname, 'fixtures')
|
||||
var w = null
|
||||
var server
|
||||
|
||||
before(function (done) {
|
||||
server = http.createServer(function (req, res) {
|
||||
function respond() { res.end(''); }
|
||||
setTimeout(respond, req.url.includes('slow') ? 200 : 0)
|
||||
});
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
server.url = 'http://127.0.0.1:' + server.address().port
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
after(function () {
|
||||
server.close()
|
||||
server = null
|
||||
})
|
||||
|
||||
beforeEach(function () {
|
||||
if (w != null) {
|
||||
|
@ -635,6 +652,44 @@ describe('browser-window module', function () {
|
|||
assert.equal(w.isResizable(), true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('loading main frame state', function () {
|
||||
it('is true when the main frame is loading', function (done) {
|
||||
w.webContents.on('did-start-loading', function() {
|
||||
assert.equal(w.webContents.isLoadingMainFrame(), true)
|
||||
done()
|
||||
})
|
||||
w.webContents.loadURL(server.url)
|
||||
})
|
||||
|
||||
it('is false when only a subframe is loading', function (done) {
|
||||
w.webContents.once('did-finish-load', function() {
|
||||
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
||||
w.webContents.on('did-start-loading', function() {
|
||||
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
||||
done()
|
||||
})
|
||||
w.webContents.executeJavaScript(`
|
||||
var iframe = document.createElement('iframe')
|
||||
iframe.src = '${server.url}/page2'
|
||||
document.body.appendChild(iframe)
|
||||
`)
|
||||
})
|
||||
w.webContents.loadURL(server.url)
|
||||
})
|
||||
|
||||
it('is true when navigating to pages from the same origin', function (done) {
|
||||
w.webContents.once('did-finish-load', function() {
|
||||
assert.equal(w.webContents.isLoadingMainFrame(), false)
|
||||
w.webContents.on('did-start-loading', function() {
|
||||
assert.equal(w.webContents.isLoadingMainFrame(), true)
|
||||
done()
|
||||
})
|
||||
w.webContents.loadURL(`${server.url}/page2`)
|
||||
})
|
||||
w.webContents.loadURL(server.url)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('window states (excluding Linux)', function () {
|
||||
|
@ -786,14 +841,6 @@ describe('browser-window module', function () {
|
|||
describe('window.webContents.executeJavaScript', function () {
|
||||
var expected = 'hello, world!'
|
||||
var code = '(() => "' + expected + '")()'
|
||||
var server
|
||||
|
||||
afterEach(function () {
|
||||
if (server) {
|
||||
server.close()
|
||||
server = null
|
||||
}
|
||||
})
|
||||
|
||||
it('doesnt throw when no calback is provided', function () {
|
||||
const result = ipcRenderer.sendSync('executeJavaScript', code, false)
|
||||
|
@ -809,21 +856,11 @@ describe('browser-window module', function () {
|
|||
})
|
||||
|
||||
it('works after page load and during subframe load', function (done) {
|
||||
var url
|
||||
// a slow server, guaranteeing time to execute code during loading
|
||||
server = http.createServer(function (req, res) {
|
||||
setTimeout(function() { res.end('') }, 200)
|
||||
});
|
||||
server.listen(0, '127.0.0.1', function () {
|
||||
url = 'http://127.0.0.1:' + server.address().port
|
||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'base-page.html'))
|
||||
})
|
||||
|
||||
w.webContents.once('did-finish-load', function() {
|
||||
// initiate a sub-frame load, then try and execute script during it
|
||||
w.webContents.executeJavaScript(`
|
||||
var iframe = document.createElement('iframe')
|
||||
iframe.src = '${url}'
|
||||
iframe.src = '${server.url}/slow'
|
||||
document.body.appendChild(iframe)
|
||||
`, function() {
|
||||
w.webContents.executeJavaScript(`console.log('hello')`, function() {
|
||||
|
@ -831,6 +868,7 @@ describe('browser-window module', function () {
|
|||
})
|
||||
})
|
||||
})
|
||||
w.loadURL(server.url)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue