Skip to content

Commit f7193bc

Browse files
authored
Add missing OOPIF test in headful (#1767)
* Add missing OOPIF test in headful * feature complete * Fix accessibility tests * one more fix
1 parent 713b34d commit f7193bc

File tree

12 files changed

+129
-36
lines changed

12 files changed

+129
-36
lines changed

lib/PuppeteerSharp.Tests/AccessibilityTests/AccessibilityTests.cs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ await Page.SetContentAsync(@"
4343

4444
var nodeToCheck = new SerializedAXNode
4545
{
46-
Role = "WebArea",
46+
Role = "RootWebArea",
4747
Name = "Accessibility Test",
4848
Children = new SerializedAXNode[]
4949
{
5050
new SerializedAXNode
5151
{
52-
Role = "text",
52+
Role = "StaticText",
5353
Name = "Hello World"
5454
},
5555
new SerializedAXNode
@@ -143,7 +143,7 @@ public async Task ShouldReportUninterestingNodes()
143143
{
144144
new SerializedAXNode
145145
{
146-
Role = "text",
146+
Role = "StaticText",
147147
Name = "hi"
148148
}
149149
}
@@ -213,7 +213,7 @@ await Page.SetContentAsync(@"
213213
Assert.Equal(
214214
new SerializedAXNode
215215
{
216-
Role = "WebArea",
216+
Role = "RootWebArea",
217217
Name = "",
218218
Children = new SerializedAXNode[]
219219
{
@@ -251,7 +251,7 @@ await Page.SetContentAsync(@"
251251
{
252252
new SerializedAXNode
253253
{
254-
Role = "text",
254+
Role = "StaticText",
255255
Name = "Edit this image:"
256256
},
257257
new SerializedAXNode
@@ -278,11 +278,12 @@ await Page.SetContentAsync(@"
278278
Role = "textbox",
279279
Name = "",
280280
Value = "Edit this image: ",
281+
Multiline = true,
281282
Children = new SerializedAXNode[]
282283
{
283284
new SerializedAXNode
284285
{
285-
Role = "text",
286+
Role = "StaticText",
286287
Name = "Edit this image:"
287288
},
288289
new SerializedAXNode
@@ -305,22 +306,8 @@ public async Task PlainTextFieldWithRoleShouldNotHaveChildren()
305306
{
306307
Role = "textbox",
307308
Name = "",
308-
Value = "Edit this image:"
309-
},
310-
(await Page.Accessibility.SnapshotAsync()).Children[0]);
311-
}
312-
313-
[PuppeteerTest("accessibility.spec.ts", "plaintext contenteditable", "plain text field without role should not have content")]
314-
[SkipBrowserFact(skipFirefox: true)]
315-
public async Task PlainTextFieldWithTabindexAndWithoutRoleShouldNotHaveContent()
316-
{
317-
await Page.SetContentAsync("<div contenteditable='plaintext-only' role='textbox' tabIndex=0>Edit this image:<img src='fakeimage.png' alt='my fake image'></div>");
318-
Assert.Equal(
319-
new SerializedAXNode
320-
{
321-
Role = "textbox",
322-
Name = "",
323-
Value = "Edit this image:"
309+
Value = "Edit this image:",
310+
Multiline = true,
324311
},
325312
(await Page.Accessibility.SnapshotAsync()).Children[0]);
326313
}

lib/PuppeteerSharp.Tests/AccessibilityTests/RootOptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public async Task ShouldSupportTheInterestingOnlyOption()
122122
{
123123
new SerializedAXNode
124124
{
125-
Role = "text",
125+
Role = "StaticText",
126126
Name = "My Button",
127127
}
128128
}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
console.log('hey from the content-script');
22
self.thisIsTheContentScript = true;
3-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// Mock script for background extension
2-
window.MAGIC = 42;
2+
window.MAGIC = 42;

lib/PuppeteerSharp.Tests/HeadfulTests/HeadfulTests.cs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Threading.Tasks;
45
using PuppeteerSharp.Helpers;
6+
using PuppeteerSharp.Messaging;
57
using PuppeteerSharp.Tests.Attributes;
68
using PuppeteerSharp.Xunit;
79
using Xunit;
@@ -12,8 +14,17 @@ namespace PuppeteerSharp.Tests.HeadfulTests
1214
[Collection(TestConstants.TestFixtureCollectionName)]
1315
public class HeadfulTests : PuppeteerBaseTest
1416
{
17+
private readonly LaunchOptions _forcedOopifOptions;
18+
1519
public HeadfulTests(ITestOutputHelper output) : base(output)
1620
{
21+
_forcedOopifOptions = TestConstants.DefaultBrowserOptions();
22+
_forcedOopifOptions.Headless = false;
23+
_forcedOopifOptions.Devtools = true;
24+
_forcedOopifOptions.Args = new[] {
25+
$"--host-rules=\"MAP oopifdomain 127.0.0.1\"",
26+
$"--isolate-origins=\"{TestConstants.ServerUrl.Replace("localhost", "oopifdomain")}\""
27+
};
1728
}
1829

1930
[PuppeteerTest("headful.spec.ts", "HEADFUL", "background_page target type should be available")]
@@ -117,6 +128,69 @@ await page.EvaluateFunctionHandleAsync(@"() => {
117128
}
118129
}
119130

131+
[PuppeteerTest("headful.spec.ts", "HEADFUL", "OOPIF: should expose events within OOPIFs")]
132+
[SkipBrowserFact(skipFirefox: true)]
133+
public async Task OOPIFShouldExposeEventsWithinOOPIFs()
134+
{
135+
await using (var browser = await Puppeteer.LaunchAsync(_forcedOopifOptions))
136+
await using (var page = await browser.NewPageAsync())
137+
{
138+
// Setup our session listeners to observe OOPIF activity.
139+
var session = await page.Target.CreateCDPSessionAsync();
140+
var networkEvents = new List<string>();
141+
var otherSessions = new List<CDPSession>();
142+
143+
await session.SendAsync("Target.setAutoAttach", new TargetSetAutoAttachRequest
144+
{
145+
AutoAttach = true,
146+
Flatten = true,
147+
WaitForDebuggerOnStart = true,
148+
});
149+
150+
session.SessionAttached += async (_, e) =>
151+
{
152+
otherSessions.Add(e.Session);
153+
154+
await e.Session.SendAsync("Network.enable");
155+
await e.Session.SendAsync("Runtime.runIfWaitingForDebugger");
156+
157+
e.Session.MessageReceived += (_, e) =>
158+
{
159+
if (e.MessageID.Equals("Network.requestWillBeSent", StringComparison.CurrentCultureIgnoreCase))
160+
{
161+
networkEvents.Add(e.MessageData.SelectToken("request").SelectToken("url").ToObject<string>());
162+
}
163+
};
164+
};
165+
166+
// Navigate to the empty page and add an OOPIF iframe with at least one request.
167+
await page.GoToAsync(TestConstants.EmptyPage);
168+
await page.EvaluateFunctionAsync(@"(frameUrl) => {
169+
const frame = document.createElement('iframe');
170+
frame.setAttribute('src', frameUrl);
171+
document.body.appendChild(frame);
172+
return new Promise((x, y) => {
173+
frame.onload = x;
174+
frame.onerror = y;
175+
});
176+
}", TestConstants.ServerUrl.Replace("localhost", "oopifdomain") + "/one-style.html");
177+
await page.WaitForSelectorAsync("iframe");
178+
179+
// Ensure we found the iframe session.
180+
Assert.Single(otherSessions);
181+
182+
// Resume the iframe and trigger another request.
183+
var iframeSession = otherSessions[0];
184+
await iframeSession.SendAsync("Runtime.evaluate", new RuntimeEvaluateRequest {
185+
Expression = "fetch('/fetch')",
186+
AwaitPromise = true,
187+
});
188+
await browser.CloseAsync();
189+
190+
Assert.Contains($"http://oopifdomain:{TestConstants.Port}/fetch", networkEvents);
191+
}
192+
}
193+
120194
[PuppeteerTest("headful.spec.ts", "HEADFUL", "should close browser with beforeunload page")]
121195
[SkipBrowserFact(skipFirefox: true)]
122196
public async Task ShouldCloseBrowserWithBeforeunloadPage()
@@ -143,7 +217,7 @@ public async Task ShouldOpenDevtoolsWhenDevtoolsTrueOptionIsGiven()
143217
var context = await browser.CreateIncognitoBrowserContextAsync();
144218
await Task.WhenAll(
145219
context.NewPageAsync(),
146-
context.WaitForTargetAsync(target => target.Url.Contains("devtools://")));
220+
browser.WaitForTargetAsync(target => target.Url.Contains("devtools://")));
147221
}
148222
}
149223
}

lib/PuppeteerSharp.Tests/TestConstants.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
43
using System.IO;
54
using Microsoft.Extensions.Logging;
65
using PuppeteerSharp.Mobile;
7-
using Xunit.Abstractions;
6+
using PuppeteerSharp.Helpers;
7+
using System.Reflection;
88

99
namespace PuppeteerSharp.Tests
1010
{
@@ -22,14 +22,14 @@ public static class TestConstants
2222
public static readonly string CrossProcessHttpPrefix = "http://127.0.0.1:8081";
2323
public static readonly string EmptyPage = $"{ServerUrl}/empty.html";
2424
public static readonly string CrossProcessUrl = ServerIpUrl;
25-
public static readonly string ExtensionPath = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "simple-extension");
25+
public static readonly string ExtensionPath = Path.Combine(AppContext.BaseDirectory, "Assets", "simple-extension");
2626
public static readonly bool IsChrome = Environment.GetEnvironmentVariable("PRODUCT") != "FIREFOX";
2727

2828
public static readonly DeviceDescriptor IPhone = Puppeteer.Devices[DeviceDescriptorName.IPhone6];
2929
public static readonly DeviceDescriptor IPhone6Landscape = Puppeteer.Devices[DeviceDescriptorName.IPhone6Landscape];
3030

3131
public static ILoggerFactory LoggerFactory { get; private set; }
32-
public static string FileToUpload => Path.Combine(Directory.GetCurrentDirectory(), "Assets", "file-to-upload.txt");
32+
public static string FileToUpload => Path.Combine(AppContext.BaseDirectory, "Assets", "file-to-upload.txt");
3333

3434
public static readonly IEnumerable<string> NestedFramesDumpResult = new List<string>()
3535
{
@@ -60,8 +60,8 @@ public static class TestConstants
6060
Headless = false,
6161
Args = new[]
6262
{
63-
$"--disable-extensions-except={ExtensionPath}",
64-
$"--load-extension={ExtensionPath}"
63+
$"--disable-extensions-except={ExtensionPath.Quote()}",
64+
$"--load-extension={ExtensionPath.Quote()}"
6565
}
6666
};
6767
}

lib/PuppeteerSharp/BrowserFetcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class BrowserFetcher
6060
/// <summary>
6161
/// Default Chromium revision.
6262
/// </summary>
63-
public const string DefaultChromiumRevision = "848005";
63+
public const string DefaultChromiumRevision = "884014";
6464

6565
/// <summary>
6666
/// Default Chromium revision.

lib/PuppeteerSharp/CDPSession.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,42 @@ internal CDPSession(Connection connection, TargetType targetType, string session
5656
/// </summary>
5757
/// <value>The target type.</value>
5858
public TargetType TargetType { get; }
59+
5960
/// <summary>
6061
/// Gets the session identifier.
6162
/// </summary>
6263
/// <value>The session identifier.</value>
6364
public string SessionId { get; }
65+
6466
/// <summary>
6567
/// Gets the connection.
6668
/// </summary>
6769
/// <value>The connection.</value>
6870
internal Connection Connection { get; private set; }
71+
6972
/// <summary>
7073
/// Occurs when message received from Chromium.
7174
/// </summary>
7275
public event EventHandler<MessageEventArgs> MessageReceived;
76+
7377
/// <summary>
7478
/// Occurs when the connection is closed.
7579
/// </summary>
7680
public event EventHandler Disconnected;
81+
82+
internal event EventHandler<SessionAttachedEventArgs> SessionAttached;
83+
7784
/// <summary>
7885
/// Gets or sets a value indicating whether this <see cref="CDPSession"/> is closed.
7986
/// </summary>
8087
/// <value><c>true</c> if is closed; otherwise, <c>false</c>.</value>
8188
public bool IsClosed { get; internal set; }
89+
8290
/// <summary>
8391
/// Connection close reason.
8492
/// </summary>
8593
public string CloseReason { get; private set; }
94+
8695
/// <summary>
8796
/// Gets the logger factory.
8897
/// </summary>
@@ -221,6 +230,9 @@ internal void Close(string closeReason)
221230
Connection = null;
222231
}
223232

233+
internal void OnSessionAttached(CDPSession session)
234+
=> SessionAttached?.Invoke(this, new SessionAttachedEventArgs { Session = session });
235+
224236
#endregion
225237
}
226238
}

lib/PuppeteerSharp/Connection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,31 @@ internal Connection(string url, int delay, bool enqueueAsyncMessages, IConnectio
5151
/// </summary>
5252
/// <value>The URL.</value>
5353
public string Url { get; }
54+
5455
/// <summary>
5556
/// Gets the sleep time when a message is received.
5657
/// </summary>
5758
/// <value>The delay.</value>
5859
public int Delay { get; }
60+
5961
/// <summary>
6062
/// Gets the Connection transport.
6163
/// </summary>
6264
/// <value>Connection transport.</value>
6365
public IConnectionTransport Transport { get; }
66+
6467
/// <summary>
6568
/// Occurs when the connection is closed.
6669
/// </summary>
6770
public event EventHandler Disconnected;
71+
6872
/// <summary>
6973
/// Occurs when a message from chromium is received.
7074
/// </summary>
7175
public event EventHandler<MessageEventArgs> MessageReceived;
76+
77+
internal event EventHandler<SessionAttachedEventArgs> SessionAttached;
78+
7279
/// <summary>
7380
/// Gets or sets a value indicating whether this <see cref="Connection"/> is closed.
7481
/// </summary>
@@ -236,6 +243,13 @@ private void ProcessIncomingMessage(ConnectionResponse obj)
236243
var sessionId = param.SessionId;
237244
var session = new CDPSession(this, param.TargetInfo.Type, sessionId);
238245
_asyncSessions.AddItem(sessionId, session);
246+
247+
SessionAttached?.Invoke(this, new SessionAttachedEventArgs { Session = session });
248+
249+
if (obj.SessionId != null && _sessions.TryGetValue(obj.SessionId, out var parentSession))
250+
{
251+
parentSession.OnSessionAttached(session);
252+
}
239253
}
240254
else if (method == "Target.detachedFromTarget")
241255
{

lib/PuppeteerSharp/Page.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ private async Task OnAttachedToTargetAsync(TargetAttachedToTargetResponse e)
22442244
{
22452245
var targetInfo = e.TargetInfo;
22462246
var sessionId = e.SessionId;
2247-
if (targetInfo.Type != TargetType.Worker)
2247+
if (targetInfo.Type != TargetType.Worker && targetInfo.Type != TargetType.iFrame)
22482248
{
22492249
try
22502250
{

0 commit comments

Comments
 (0)