-
-
Notifications
You must be signed in to change notification settings - Fork 443
/
PageEventsPopupTests.cs
118 lines (95 loc) · 5.31 KB
/
PageEventsPopupTests.cs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System.Threading.Tasks;
using PuppeteerSharp.Tests.Attributes;
using PuppeteerSharp.Xunit;
using Xunit;
using Xunit.Abstractions;
namespace PuppeteerSharp.Tests.PageTests
{
[Collection(TestConstants.TestFixtureCollectionName)]
public class PageEventsPopupTests : PuppeteerPageBaseTest
{
public PageEventsPopupTests(ITestOutputHelper output) : base(output)
{
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWork()
{
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.EvaluateExpressionAsync("window.open('about:blank')"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.True(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work with noopener")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWorkWithNoopener()
{
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.EvaluateExpressionAsync("window.open('about:blank', null, 'noopener')"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.False(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work with clicking target=_blank and without rel=opener")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWorkWithClickingTargetBlankWithoutRelOpener()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.SetContentAsync("<a target=_blank href='/one-style.html'>yo</a>");
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.ClickAsync("a"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.False(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work with clicking target=_blank and with rel=opener")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWorkWithFakeClickingTargetBlankAndReNoopener()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.SetContentAsync("<a target=_blank rel=noopener href='/one-style.html'>yo</a>");
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.QuerySelectorAsync("a").EvaluateFunctionAsync("a => a.click()"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.False(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work with fake-clicking target=_blank and rel=noopener")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWorkWithFakeClickingTargetBlankAndRelNoopener()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.SetContentAsync("<a target=_blank rel=noopener href='/one-style.html'>yo</a>");
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.QuerySelectorAsync("a").EvaluateFunctionAsync("a => a.click()"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.False(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
[PuppeteerTest("page.spec.ts", "Page.Events.Popup", "should work with clicking target=_blank and rel=noopener")]
[SkipBrowserFact(skipFirefox: true)]
public async Task ShouldWorkWithClickingTargetBlankAndRelNoopener()
{
await Page.GoToAsync(TestConstants.EmptyPage);
await Page.SetContentAsync("<a target=_blank rel=noopener href='/one-style.html'>yo</a>");
var popupTaskSource = new TaskCompletionSource<IPage>();
Page.Popup += (_, e) => popupTaskSource.TrySetResult(e.PopupPage);
await Task.WhenAll(
popupTaskSource.Task,
Page.ClickAsync("a"));
Assert.False(await Page.EvaluateExpressionAsync<bool>("!!window.opener"));
Assert.False(await popupTaskSource.Task.Result.EvaluateExpressionAsync<bool>("!!window.opener"));
}
}
}