Skip to content

Commit bab0eb0

Browse files
kblokclaude
andauthored
chore: clean up TestExpectations.upstream.json (#3391)
* chore: bump Chrome to 146.0.7680.76 and package version to 24.39.1 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * test: mark console group test as expected fail for Firefox BiDi Syncs with upstream CanaryTestExpectations.json for known WebDriver BiDi bug: w3c/webdriver-bidi#1097 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: clean up TestExpectations.upstream.json by removing 14 non-upstream entries Move 14 entries from upstream.json to local.json that don't exist in the actual upstream Puppeteer test/TestExpectations.json. The upstream file should only mirror upstream expectations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: remove local.json additions, only clean upstream.json Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: remove unwanted files and reset local.json/CdpPage.cs to master Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align PageReloadTests attribute with upstream page.spec naming Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add missing upstream Response entries and skip Firefox hang Add 2 entries missing from upstream.json: - Response.buffer should throw if response has no body (firefox) - Response.text should throw for redirected response (firefox/bidi) Add local skip for ShouldWaitUntilResponseCompletes on Firefox (hangs). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add local expectations for tests not covered by upstream These entries were removed from upstream.json (correctly, as they don't exist upstream) but still need coverage in local.json since the tests genuinely fail/hang on Firefox BiDi and WebDriver BiDi. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * revert: reset local.json to master Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align ShouldWaitUntilResponseCompletes with upstream to fix Firefox BiDi The test was hanging on Firefox BiDi because the server route handler returned immediately after writing initial data, causing ASP.NET Core to complete the response before the test could write additional chunks. Key fixes: - Keep route handler alive via TaskCompletionSource (matching upstream pattern) - Set Content-Type header before writing (required by Firefox) - Flush writes explicitly so data reaches the browser - Use Page.WaitForResponseAsync instead of manual event wiring Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: align PageEventsConsoleTests spec attributes with upstream console.spec PageEventsConsoleTests used "page.spec" as the spec file, but upstream Puppeteer has all these tests in console.spec. This mismatch caused the upstream SKIP/FAIL expectations to not apply, resulting in tests hanging on Firefox BiDi (console events don't fire for network errors). Changes: - Change spec from "page.spec" to "console.spec" for all tests - Add CancelAfter(30s) to ShouldHaveLocationWhenFetchFails as safety net - Remove ERR_NAME filter in TCS to match upstream pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use Firefox-compatible extension in webExtension test Firefox doesn't support background.service_worker in extensions — it requires background.scripts. Added the upstream Firefox extension asset and updated the test to use the correct extension per browser, matching upstream Puppeteer behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9f758e8 commit bab0eb0

File tree

9 files changed

+3484
-1033
lines changed

9 files changed

+3484
-1033
lines changed

lib/PuppeteerSharp.Nunit/TestExpectations/TestExpectations.upstream.json

Lines changed: 3409 additions & 972 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log('hey from the content-script');
2+
self.thisIsTheContentScript = true;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Mock script for background extension
2+
globalThis.MAGIC = 42;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "Simple extension",
3+
"version": "0.1",
4+
"background": {
5+
"scripts": ["index.js"]
6+
},
7+
"content_scripts": [{
8+
"matches": ["<all_urls>"],
9+
"css": [],
10+
"js": ["content-script.js"]
11+
}],
12+
"permissions": ["background", "activeTab"],
13+
"manifest_version": 3
14+
}

lib/PuppeteerSharp.Tests/ConsoleTests/ConsoleTests.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,7 @@ public async Task ShouldHaveLocationWhenFetchFails()
257257
// Log domain: https://vanilla.aslushnikov.com/?Log.entryAdded
258258
await Page.GoToAsync(TestConstants.EmptyPage);
259259
var consoleTask = new TaskCompletionSource<ConsoleMessage>();
260-
Page.Console += (_, e) =>
261-
{
262-
// Wait for the specific network error message
263-
if (e.Message.Text.Contains("ERR_NAME"))
264-
{
265-
consoleTask.TrySetResult(e.Message);
266-
}
267-
};
260+
Page.Console += (_, e) => consoleTask.TrySetResult(e.Message);
268261

269262
await Task.WhenAll(
270263
consoleTask.Task,

lib/PuppeteerSharp.Tests/NavigationTests/PageReloadTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public async Task ShouldWork()
1515
Assert.That(await Page.EvaluateFunctionAsync<int?>("() => globalThis._foo"), Is.Null);
1616
}
1717

18-
[Test, PuppeteerTest("navigation.spec", "navigation Page.reload", "should enable or disable the cache based on reload params")]
18+
[Test, PuppeteerTest("page.spec", "Page Page.reload", "should enable or disable the cache based on reload params")]
1919
public async Task ShouldEnableOrDisableTheCacheBasedOnReloadParams()
2020
{
2121
await Page.GoToAsync(TestConstants.ServerUrl + "/cached/one-style.html");

lib/PuppeteerSharp.Tests/NetworkTests/ResponseTextTests.cs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,30 @@ public async Task ShouldWaitUntilResponseCompletes()
4747
{
4848
await Page.GoToAsync(TestConstants.EmptyPage);
4949
// Setup server to trap request.
50-
var serverResponseCompletion = new TaskCompletionSource<bool>();
51-
HttpResponse serverResponse = null;
52-
Server.SetRoute("/get", context =>
50+
var serverResponseTcs = new TaskCompletionSource<HttpResponse>();
51+
var serverResponseEnd = new TaskCompletionSource<bool>();
52+
Server.SetRoute("/get", async context =>
5353
{
54-
serverResponse = context.Response;
55-
context.Response.WriteAsync("hello ");
56-
return serverResponseCompletion.Task;
54+
// In Firefox, |fetch| will be hanging until it receives |Content-Type| header
55+
// from server.
56+
context.Response.ContentType = "text/plain; charset=utf-8";
57+
await context.Response.WriteAsync("hello ");
58+
await context.Response.Body.FlushAsync();
59+
serverResponseTcs.TrySetResult(context.Response);
60+
await serverResponseEnd.Task;
5761
});
5862
// Setup page to trap response.
59-
IResponse pageResponse = null;
6063
var requestFinished = false;
61-
Page.Response += (_, e) => pageResponse = e.Response;
62-
Page.RequestFinished += (_, _) => requestFinished = requestFinished || pageResponse.Url.Contains("/get");
64+
Page.RequestFinished += (_, e) => requestFinished = requestFinished || e.Request.Url.Contains("/get");
6365
// send request and wait for server response
64-
Task WaitForPageResponseEvent()
65-
{
66-
var completion = new TaskCompletionSource<bool>();
67-
Page.Response += (_, e) =>
68-
{
69-
if (!TestUtils.IsFavicon(e.Response.Request))
70-
{
71-
completion.SetResult(true);
72-
}
73-
};
74-
return completion.Task;
75-
}
76-
66+
var waitForResponseTask = Page.WaitForResponseAsync(r => !TestUtils.IsFavicon(r.Request));
7767
await Task.WhenAll(
78-
Server.WaitForRequest("/get"),
68+
waitForResponseTask,
7969
Page.EvaluateExpressionAsync("fetch('/get', { method: 'GET'})"),
80-
WaitForPageResponseEvent()
81-
);
70+
Server.WaitForRequest("/get"));
71+
var pageResponse = await waitForResponseTask;
8272

73+
var serverResponse = await serverResponseTcs.Task;
8374
Assert.That(serverResponse, Is.Not.Null);
8475
Assert.That(pageResponse, Is.Not.Null);
8576
Assert.That(pageResponse.Status, Is.EqualTo(HttpStatusCode.OK));
@@ -88,9 +79,10 @@ await Task.WhenAll(
8879
var responseText = pageResponse.TextAsync();
8980
// Write part of the response and wait for it to be flushed.
9081
await serverResponse.WriteAsync("wor");
82+
await serverResponse.Body.FlushAsync();
9183
// Finish response.
9284
await serverResponse.WriteAsync("ld!");
93-
serverResponseCompletion.SetResult(true);
85+
serverResponseEnd.TrySetResult(true);
9486
Assert.That(await responseText, Is.EqualTo("hello world!"));
9587
}
9688
}

lib/PuppeteerSharp.Tests/PageTests/PageEventsConsoleTests.cs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace PuppeteerSharp.Tests.PageTests
88
{
99
public class PageEventsConsoleTests : PuppeteerPageBaseTest
1010
{
11-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should work")]
11+
[Test, PuppeteerTest("console.spec", "console", "should work")]
1212
public async Task ShouldWork()
1313
{
1414
var messageTask = new TaskCompletionSource<ConsoleMessage>();
@@ -37,7 +37,7 @@ await Task.WhenAll(
3737
Assert.That(await fooProperty.JsonValueAsync<string>(), Is.EqualTo("bar"));
3838
}
3939

40-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should work on script call right after navigation")]
40+
[Test, PuppeteerTest("console.spec", "console", "should work on script call right after navigation")]
4141
public async Task ShouldWorkOnScriptCallRightAfterNavigation()
4242
{
4343
var messageTask = new TaskCompletionSource<ConsoleMessage>();
@@ -53,7 +53,7 @@ await Task.WhenAll(
5353
Assert.That(message.Text, Is.EqualTo("SOME_LOG_MESSAGE"));
5454
}
5555

56-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should work for different console API calls with logging functions")]
56+
[Test, PuppeteerTest("console.spec", "console", "should work for different console API calls with logging functions")]
5757
public async Task ShouldWorkForDifferentConsoleApiCallsWithLoggingFunctions()
5858
{
5959
var messages = new List<ConsoleMessage>();
@@ -92,7 +92,7 @@ await Page.EvaluateFunctionAsync(@"() => {
9292
}));
9393
}
9494

95-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should work for different console API calls with timing functions")]
95+
[Test, PuppeteerTest("console.spec", "console", "should work for different console API calls with timing functions")]
9696
public async Task ShouldWorkForDifferentConsoleApiCallsWithTimingFunctions()
9797
{
9898
var messages = new List<ConsoleMessage>();
@@ -116,7 +116,7 @@ await Page.EvaluateFunctionAsync(@"() => {
116116
Assert.That(messages[0].Text, Does.Contain("calling console.time"));
117117
}
118118

119-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should work for different console API calls with group functions")]
119+
[Test, PuppeteerTest("console.spec", "console", "should work for different console API calls with group functions")]
120120
public async Task ShouldWorkForDifferentConsoleApiCallsWithGroupFunctions()
121121
{
122122
var messages = new List<ConsoleMessage>();
@@ -141,7 +141,7 @@ await Page.EvaluateFunctionAsync(@"() => {
141141
Assert.That(messages[0].Text, Does.Contain("calling console.group"));
142142
}
143143

144-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should not fail for window object")]
144+
[Test, PuppeteerTest("console.spec", "console", "should not fail for window object")]
145145
public async Task ShouldNotFailForWindowObject()
146146
{
147147
var messageTask = new TaskCompletionSource<ConsoleMessage>();
@@ -160,7 +160,7 @@ await Task.WhenAll(
160160
Does.Contain(message.Text));
161161
}
162162

163-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should return remote objects")]
163+
[Test, PuppeteerTest("console.spec", "console", "should return remote objects")]
164164
public async Task ShouldReturnRemoteObjects()
165165
{
166166
var logTask = new TaskCompletionSource<ConsoleMessage>();
@@ -183,7 +183,7 @@ await Page.EvaluateFunctionAsync(@"() => {
183183
Assert.That(await property.JsonValueAsync<int>(), Is.EqualTo(1));
184184
}
185185

186-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should trigger correct Log")]
186+
[Test, PuppeteerTest("console.spec", "console", "should trigger correct Log")]
187187
public async Task ShouldTriggerCorrectLog()
188188
{
189189
// Navigate to localhost (one origin)
@@ -212,25 +212,23 @@ await Task.WhenAll(
212212
}
213213
}
214214

215-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should have location when fetch fails")]
215+
[Test, PuppeteerTest("console.spec", "console", "should have location when fetch fails")]
216+
[CancelAfter(30_000)]
216217
public async Task ShouldHaveLocationWhenFetchFails()
217218
{
218219
// The point of this test is to make sure that we report console messages from
219220
// Log domain: https://vanilla.aslushnikov.com/?Log.entryAdded
220221
await Page.GoToAsync(TestConstants.EmptyPage);
221222
var consoleTask = new TaskCompletionSource<ConsoleMessage>();
222-
Page.Console += (_, e) =>
223-
{
224-
// Wait for the specific network error message
225-
if (e.Message.Text.Contains("ERR_NAME"))
226-
{
227-
consoleTask.TrySetResult(e.Message);
228-
}
229-
};
223+
Page.Console += (_, e) => consoleTask.TrySetResult(e.Message);
230224

231-
await Task.WhenAll(
232-
consoleTask.Task,
233-
Page.SetContentAsync("<script>fetch('http://wat');</script>"));
225+
var ct = TestContext.CurrentContext.CancellationToken;
226+
await using (ct.Register(() => consoleTask.TrySetCanceled(ct)))
227+
{
228+
await Task.WhenAll(
229+
consoleTask.Task,
230+
Page.SetContentAsync("<script>fetch('http://wat');</script>"));
231+
}
234232

235233
var message = await consoleTask.Task;
236234
Assert.That(message.Text, Does.Contain("ERR_NAME"));
@@ -242,7 +240,7 @@ await Task.WhenAll(
242240
}));
243241
}
244242

245-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "should have location and stack trace for console API calls")]
243+
[Test, PuppeteerTest("console.spec", "console", "should have location and stack trace for console API calls")]
246244
public async Task ShouldHaveLocationForConsoleAPICalls()
247245
{
248246
await Page.GoToAsync(TestConstants.EmptyPage);
@@ -297,7 +295,7 @@ await Task.WhenAll(
297295
}
298296

299297
// @see https://github.com/puppeteer/puppeteer/issues/3865
300-
[Test, PuppeteerTest("page.spec", "Page Page.Events.Console", "ex")]
298+
[Test, PuppeteerTest("console.spec", "console", "ex")]
301299
public async Task ShouldNotThrowWhenThereAreConsoleMessagesInDetachedIframes()
302300
{
303301
await Page.GoToAsync(TestConstants.EmptyPage);

lib/PuppeteerSharp.Tests/WebExtensionTests/WebExtensionTests.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ namespace PuppeteerSharp.Tests.WebExtensionTests
1111
public class WebExtensionTests : PuppeteerBaseTest
1212
{
1313
private static readonly string _extensionPath = Path.Combine(AppContext.BaseDirectory, "Assets", "simple-extension");
14+
private static readonly string _extensionFirefoxPath = Path.Combine(AppContext.BaseDirectory, "Assets", "simple-extension-firefox");
1415
private const string ExpectedId = "mbljndkcfjhaffohbnmoedabegpolpmd";
1516

1617
[Test, PuppeteerTest("webExtension.spec", "webExtension", "can install and uninstall an extension")]
1718
public async Task CanInstallAndUninstallAnExtension()
1819
{
1920
var options = TestConstants.DefaultBrowserOptions();
21+
var extensionPath = TestConstants.IsChrome ? _extensionPath : _extensionFirefoxPath;
22+
var expectedId = TestConstants.IsChrome ? ExpectedId : null;
2023

2124
if (TestConstants.IsChrome)
2225
{
@@ -28,12 +31,22 @@ public async Task CanInstallAndUninstallAnExtension()
2831
options,
2932
TestConstants.LoggerFactory);
3033

31-
// Install an extension. Since the `key` field is present in the
32-
// manifest, this should always have the same ID.
33-
Assert.That(await browser.InstallExtensionAsync(_extensionPath), Is.EqualTo(ExpectedId));
34+
var id = await browser.InstallExtensionAsync(extensionPath);
35+
36+
if (expectedId != null)
37+
{
38+
// For Chrome, since the `key` field is present in the
39+
// manifest, this should always have the same ID.
40+
Assert.That(id, Is.EqualTo(expectedId));
41+
}
42+
else
43+
{
44+
// Firefox uses temporary addon IDs
45+
Assert.That(id, Does.Contain("temporary-addon"));
46+
}
3447

3548
// Check we can uninstall the extension.
36-
await browser.UninstallExtensionAsync(ExpectedId);
49+
await browser.UninstallExtensionAsync(id);
3750
}
3851
}
3952
}

0 commit comments

Comments
 (0)