Skip to content

Commit

Permalink
Make sure headful browser closes with beforeuload page (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok authored Feb 9, 2019
1 parent 74deb46 commit b1b8982
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/PuppeteerSharp.Tests/PuppeteerTests/HeadfulTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using PuppeteerSharp.Helpers;
using Xunit;
Expand Down Expand Up @@ -110,6 +105,20 @@ await page.EvaluateFunctionHandleAsync(@"() => {
}
}

[Fact]
public async Task ShouldCloseBrowserWithBeforeunloadPage()
{
var headfulOptions = TestConstants.DefaultBrowserOptions();
headfulOptions.Headless = false;
using (var browser = await Puppeteer.LaunchAsync(headfulOptions))
using (var page = await browser.NewPageAsync())
{
await page.GoToAsync(TestConstants.ServerUrl + "/beforeunload.html");
// We have to interact with a page so that 'beforeunload' handlers fire.
await page.ClickAsync("body");
}
}

private Task<Target> WaitForBackgroundPageTargetAsync(Browser browser)
{
var target = browser.Targets().FirstOrDefault(t => t.Type == TargetType.BackgroundPage);
Expand Down

0 comments on commit b1b8982

Please sign in to comment.