Add test for opeing HTML file
This commit is contained in:
parent
3eab5df4a4
commit
051e133ce3
3 changed files with 36 additions and 11 deletions
|
@ -1071,19 +1071,28 @@ describe('BrowserWindow module', function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('nativeWindowOpen option', () => {
|
describe('nativeWindowOpen option', () => {
|
||||||
it('allows synchronous access to window opened by window.open()', (done) => {
|
beforeEach(() => {
|
||||||
ipcMain.once('answer', function (event, content) {
|
|
||||||
assert.equal(content, 'Hello')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
w.destroy()
|
w.destroy()
|
||||||
w = new BrowserWindow({
|
w = new BrowserWindow({
|
||||||
show: false,
|
show: true,
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
nativeWindowOpen: true
|
nativeWindowOpen: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html'))
|
})
|
||||||
|
it('opens window of about:blank with cross-scripting enabled', (done) => {
|
||||||
|
ipcMain.once('answer', function (event, content) {
|
||||||
|
assert.equal(content, 'Hello')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#blank'))
|
||||||
|
})
|
||||||
|
it('opens window of same domain with cross-scripting enabled', (done) => {
|
||||||
|
ipcMain.once('answer', function (event, content) {
|
||||||
|
assert.equal(content, 'Hello')
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#file'))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
1
spec/fixtures/api/native-window-open-child.html
vendored
Normal file
1
spec/fixtures/api/native-window-open-child.html
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<h1>Hello</h1>
|
23
spec/fixtures/api/native-window-open.html
vendored
23
spec/fixtures/api/native-window-open.html
vendored
|
@ -2,10 +2,25 @@
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" charset="utf-8">
|
<script type="text/javascript" charset="utf-8">
|
||||||
const {ipcRenderer} = require("electron");
|
const {ipcRenderer} = require("electron");
|
||||||
const otherWin = window.open();
|
const tests = {
|
||||||
otherWin.document.write("<h1>Hello</h1>");
|
'blank': () => {
|
||||||
const content = otherWin.document.querySelector("h1").innerText;
|
const popup = window.open();
|
||||||
ipcRenderer.send('answer', content);
|
popup.document.write('<h1>Hello</h1>');
|
||||||
|
const content = popup.document.querySelector('h1').innerText;
|
||||||
|
ipcRenderer.send('answer', content);
|
||||||
|
},
|
||||||
|
'file': () => {
|
||||||
|
const popup = window.open('native-window-open-child.html');
|
||||||
|
popup.onload = () => {
|
||||||
|
const content = popup.document.querySelector('h1').innerText;
|
||||||
|
ipcRenderer.send('answer', content);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const test = location.hash.slice(1);
|
||||||
|
if (tests.hasOwnProperty(test)) {
|
||||||
|
tests[test]();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue