Files
cefsharp/CefSharp.Test/Javascript/EvaluateScriptAsyncFacts.cs
T
Alex Maitland 8797880612 Core - V8Serialization incorrectly returns negative numbers
- CEF doesn't differentiate between UINT and INT
  so we have to do some additional bounds checking
  To make sure the correct value is returned
- Add xUnit tests

Issue #3858
2021-10-27 09:58:55 +10:00

103 lines
3.7 KiB
C#

// Copyright © 2021 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
namespace CefSharp.Test.Javascript
{
[Collection(CefSharpFixtureCollection.Key)]
public class EvaluateScriptAsyncFacts : IClassFixture<ChromiumWebBrowserOffScreenFixture>
{
private readonly ITestOutputHelper output;
private readonly CefSharpFixture collectionFixture;
private readonly ChromiumWebBrowserOffScreenFixture classFixture;
public EvaluateScriptAsyncFacts(ITestOutputHelper output, CefSharpFixture collectionFixture, ChromiumWebBrowserOffScreenFixture classFixture)
{
this.output = output;
this.collectionFixture = collectionFixture;
this.classFixture = classFixture;
}
[Theory]
[InlineData(double.MaxValue, "Number.MAX_VALUE")]
[InlineData(double.MaxValue / 2, "Number.MAX_VALUE / 2")]
//https://github.com/cefsharp/CefSharp/issues/3858
public async Task CanEvaluateDoubleComputation(double expectedValue, string script)
{
var browser = classFixture.Browser;
Assert.False(browser.IsLoading);
var javascriptResponse = await browser.EvaluateScriptAsync(script);
Assert.True(javascriptResponse.Success);
var actualType = javascriptResponse.Result.GetType();
Assert.Equal(typeof(double), actualType);
Assert.Equal(expectedValue, (double)javascriptResponse.Result, 5);
output.WriteLine("Script {0} : Result {1}", script, javascriptResponse.Result);
}
[Theory]
[InlineData(0.5d)]
[InlineData(1.5d)]
[InlineData(-0.5d)]
[InlineData(-1.5d)]
[InlineData(100000.24500d)]
[InlineData(-100000.24500d)]
[InlineData((double)uint.MaxValue)]
[InlineData((double)int.MaxValue + 1)]
[InlineData((double)int.MaxValue + 10)]
[InlineData((double)int.MinValue - 1)]
[InlineData((double)int.MinValue - 10)]
[InlineData(((double)uint.MaxValue * 2))]
[InlineData(((double)uint.MaxValue * 2) + 0.1)]
//https://github.com/cefsharp/CefSharp/issues/3858
public async Task CanEvaluateDoubleValues(double num)
{
var browser = classFixture.Browser;
Assert.False(browser.IsLoading);
var javascriptResponse = await browser.EvaluateScriptAsync(num.ToString());
Assert.True(javascriptResponse.Success);
var actualType = javascriptResponse.Result.GetType();
Assert.Equal(typeof(double), actualType);
Assert.Equal(num, (double)javascriptResponse.Result, 5);
output.WriteLine("Expected {0} : Actual {1}", num, javascriptResponse.Result);
}
[Theory]
[InlineData(0)]
[InlineData(-1)]
[InlineData(100)]
[InlineData(int.MaxValue)]
[InlineData(int.MinValue)]
//https://github.com/cefsharp/CefSharp/issues/3858
public async Task CanEvaluateIntValues(object num)
{
var browser = classFixture.Browser;
Assert.False(browser.IsLoading);
var javascriptResponse = await browser.EvaluateScriptAsync(num.ToString());
Assert.True(javascriptResponse.Success);
var actualType = javascriptResponse.Result.GetType();
Assert.Equal(typeof(int), actualType);
Assert.Equal(num, javascriptResponse.Result);
output.WriteLine("Expected {0} : Actual {1}", num, javascriptResponse.Result);
}
}
}