diff --git a/lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateNetworkConditionsTests.cs b/lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateNetworkConditionsTests.cs index 00806e5b3..6cf7bb1ef 100644 --- a/lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateNetworkConditionsTests.cs +++ b/lib/PuppeteerSharp.Tests/EmulationTests/PageEmulateNetworkConditionsTests.cs @@ -13,10 +13,16 @@ public PageEmulateNetworkConditionsTests() : base() [Test, Retry(2), PuppeteerTest("emulation.spec", "Emulation Page.emulateNetworkConditions", "should change navigator.connection.effectiveType")] public async Task ShouldChangeNavigatorConnectionEffectiveType() { - var slow3G = Puppeteer.NetworkConditions[NetworkConditions.Slow3G]; + var fast4G = Puppeteer.NetworkConditions[NetworkConditions.Fast4G]; + var slow4G = Puppeteer.NetworkConditions[NetworkConditions.Slow4G]; var fast3G = Puppeteer.NetworkConditions[NetworkConditions.Fast3G]; + var slow3G = Puppeteer.NetworkConditions[NetworkConditions.Slow3G]; Assert.That(await Page.EvaluateExpressionAsync("window.navigator.connection.effectiveType").ConfigureAwait(false), Is.EqualTo("4g")); + await Page.EmulateNetworkConditionsAsync(fast4G); + Assert.That(await Page.EvaluateExpressionAsync("window.navigator.connection.effectiveType").ConfigureAwait(false), Is.EqualTo("4g")); + await Page.EmulateNetworkConditionsAsync(slow4G); + Assert.That(await Page.EvaluateExpressionAsync("window.navigator.connection.effectiveType").ConfigureAwait(false), Is.EqualTo("3g")); await Page.EmulateNetworkConditionsAsync(fast3G); Assert.That(await Page.EvaluateExpressionAsync("window.navigator.connection.effectiveType").ConfigureAwait(false), Is.EqualTo("3g")); await Page.EmulateNetworkConditionsAsync(slow3G); diff --git a/lib/PuppeteerSharp/NetworkConditions.cs b/lib/PuppeteerSharp/NetworkConditions.cs index db7af87a7..9a6a8e3c4 100644 --- a/lib/PuppeteerSharp/NetworkConditions.cs +++ b/lib/PuppeteerSharp/NetworkConditions.cs @@ -15,6 +15,16 @@ public class NetworkConditions /// public const string Fast3G = "Fast 3G"; + /// + /// Key to be used with . + /// + public const string Slow4G = "Slow 4G"; + + /// + /// Key to be used with . + /// + public const string Fast4G = "Fast 4G"; + /// /// Download speed (bytes/s), `-1` to disable. /// diff --git a/lib/PuppeteerSharp/PredefinedNetworkConditions.cs b/lib/PuppeteerSharp/PredefinedNetworkConditions.cs index 19dbfafd4..77c44edae 100644 --- a/lib/PuppeteerSharp/PredefinedNetworkConditions.cs +++ b/lib/PuppeteerSharp/PredefinedNetworkConditions.cs @@ -13,16 +13,51 @@ public static class PredefinedNetworkConditions { [NetworkConditions.Slow3G] = new NetworkConditions { + // ~500Kbps down Download = ((500 * 1000) / 8) * 0.8, + + // ~500Kbps up Upload = ((500 * 1000) / 8) * 0.8, + + // 400ms RTT Latency = 400 * 5, }, [NetworkConditions.Fast3G] = new NetworkConditions { + // ~1.6 Mbps down + Download = ((1.6 * 1000 * 1000) / 8) * 0.9, + + // ~0.75 Mbps up + Upload = ((750 * 1000) / 8) * 0.9, + + // 150ms RTT + Latency = 150 * 3.75, + }, + + // alias to Fast 3G to align with Lighthouse (crbug.com/342406608) + // and DevTools (crbug.com/342406608), + [NetworkConditions.Slow4G] = new NetworkConditions + { + // ~1.6 Mbps down Download = ((1.6 * 1000 * 1000) / 8) * 0.9, + + // ~0.75 Mbps up Upload = ((750 * 1000) / 8) * 0.9, + + // 150ms RTT Latency = 150 * 3.75, }, + [NetworkConditions.Fast4G] = new NetworkConditions + { + // 9 Mbps down + Download = ((9 * 1000 * 1000) / 8) * 0.9, + + // 1.5 Mbps up + Upload = ((1.5 * 1000 * 1000) / 8) * 0.9, + + // 60ms RTT + Latency = 60 * 2.75, + }, }; private static readonly Lazy> _readOnlyConditions =