Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.DotNet.XHarness.CLI.CommandArguments.Wasm
{
internal class BackgroundThrottlingArgument : SwitchArgument
{
public BackgroundThrottlingArgument()
: base("background-throttling", "Hide browser tab and don't prevent timer throttling", false)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS
public NoIncognitoArgument NoIncognito { get; } = new();
public NoHeadlessArgument NoHeadless { get; } = new();
public NoQuitArgument NoQuit { get; } = new();
public BackgroundThrottlingArgument BackgroundThrottling { get; } = new();

public WebServerMiddlewareArgument WebServerMiddlewarePathsAndTypes { get; } = new();
public WebServerHttpEnvironmentVariables WebServerHttpEnvironmentVariables { get; } = new();
Expand All @@ -46,6 +47,7 @@ internal class WasmTestBrowserCommandArguments : XHarnessCommandArguments, IWebS
NoIncognito,
NoHeadless,
NoQuit,
BackgroundThrottling,
WebServerMiddlewarePathsAndTypes,
WebServerHttpEnvironmentVariables,
WebServerHttpsEnvironmentVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public async Task<ExitCode> RunTestsWithWebDriver(DriverService driverService, I
Task.Delay(_arguments.Timeout)
};

if (_arguments.BackgroundThrottling)
{
// throttling only happens when the page is not visible
driver.Manage().Window.Minimize();
}

var task = await Task.WhenAny(tasks).ConfigureAwait(false);
if (task == tasks[^1] || cts.IsCancellationRequested)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)

options.AddArguments(Arguments.BrowserArgs.Value);

if (!Arguments.NoHeadless)
if (!Arguments.NoHeadless && !Arguments.BackgroundThrottling)
options.AddArguments("--headless");

if (Arguments.DebuggerPort.Value != null)
Expand All @@ -171,20 +171,31 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
if (!Arguments.NoIncognito)
options.AddArguments("--incognito");

if (!Arguments.BackgroundThrottling)
{
options.AddArguments(new[]
{
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-renderer-backgrounding",
"--enable-features=NetworkService,NetworkServiceInProcess",
});
}
else
{
options.AddArguments(@"--enable-features=IntensiveWakeUpThrottling:grace_period_seconds/1");
}

options.AddArguments(new[]
{
// added based on https://github.com/puppeteer/puppeteer/blob/main/src/node/Launcher.ts#L159-L181
"--enable-features=NetworkService,NetworkServiceInProcess",
"--allow-insecure-localhost",
"--disable-background-timer-throttling",
"--disable-backgrounding-occluded-windows",
"--disable-breakpad",
"--disable-component-extensions-with-background-pages",
"--disable-dev-shm-usage",
"--disable-extensions",
"--disable-features=TranslateUI",
"--disable-ipc-flooding-protection",
"--disable-renderer-backgrounding",
"--force-color-profile=srgb",
"--metrics-recording-only"
});
Expand Down