-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
62 lines (56 loc) · 1.77 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const {expect} = require('chai');
const getWindowCount = async () => (await browser.getWindowHandles()).length
function test({title, linkId, expectToHaveOpener}) {
it(title, async () => {
await browser.url('');
if (linkId != null) {
const link = await $(`#${linkId}`);
const windowCount = await getWindowCount();
await link.click();
// Handle iOS confirmation popup
try {
const contexts = await browser.getContexts();
if (contexts.includes('NATIVE_APP')) {
const prevContext = await browser.getContext();
await browser.switchContext('NATIVE_APP');
const allow = await $('~Allow');
if (allow != null) {
await allow.click();
}
await browser.switchContext(prevContext)
}
// await browser.acceptAlert()
} catch (e) {}
await browser.waitUntil(async () => {
const newWindowCount = await getWindowCount();
return newWindowCount > windowCount;
});
await browser.switchWindow(`#${linkId}`);
}
const hasOpener = await browser.execute(function() {
return window.opener != null;
});
expect(hasOpener).to.equal(expectToHaveOpener);
});
}
describe('window.opener', () => {
test({
title: 'should be null on a fresh page',
expectToHaveOpener: false,
});
test({
title: 'should be present after clicking a link with rel="opener"',
linkId: 'opener',
expectToHaveOpener: true
});
test({
title: 'should be null after clicking a link with rel="noreferrer noopener"',
linkId: 'noreferrer-noopener',
expectToHaveOpener: false
});
test({
title: 'should be null after clicking a link with rel="noreferrer"',
linkId: 'noreferrer',
expectToHaveOpener: false
});
});