- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.6k
 
          [dotnet] [bidi] Align Scipt.LocalValue.Map with spec, enable negative zero
          #15395
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 11 commits
      Commits
    
    
            Show all changes
          
          
            30 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      ae2d622
              
                [dotnet] Align `Scipt.LocalValue.Map` with spec
              
              
                RenderMichael bd5aedc
              
                Add test for Set
              
              
                RenderMichael 50f28b5
              
                Remove obsolete assertion
              
              
                RenderMichael 9db00ab
              
                Update new test name
              
              
                RenderMichael d36e44e
              
                Fix build
              
              
                RenderMichael 7e279bc
              
                Replace TestCaseSource with individual tests
              
              
                RenderMichael a91685b
              
                Allow reading numbers from strings
              
              
                RenderMichael 83587d8
              
                Separate CallFunction argument and return tests
              
              
                RenderMichael 9612f5f
              
                Merge branch 'trunk' into bidi-map
              
              
                RenderMichael e7a751d
              
                Split tests into more classes
              
              
                RenderMichael f51248e
              
                remove unused imports
              
              
                RenderMichael 5c0f772
              
                Properly serialize negative zero
              
              
                RenderMichael d7c58f7
              
                Fix variable name
              
              
                RenderMichael 45ecae9
              
                fix formatting
              
              
                RenderMichael 0d8f906
              
                Apply double converter directly to `RemoteValue.Number`
              
              
                RenderMichael 53310f7
              
                Rename and clean up `DoubleConverter`
              
              
                RenderMichael 98cafd1
              
                Clarify "is negative zero" check
              
              
                RenderMichael 6627a82
              
                Merge branch 'trunk' into bidi-map
              
              
                RenderMichael 6c9c303
              
                fix formatting
              
              
                RenderMichael 50abe67
              
                Remove `BiDiDoubleConverter`
              
              
                RenderMichael 79b9274
              
                Ignore failing tests
              
              
                RenderMichael 0a8d550
              
                fix which tet is disabled
              
              
                RenderMichael f2a615e
              
                PR feedback
              
              
                RenderMichael 8c36bb2
              
                PR feedback
              
              
                RenderMichael 034b533
              
                Merge branch 'trunk' into bidi-map
              
              
                RenderMichael 1a7c7f3
              
                PR test feedback
              
              
                RenderMichael f4d3785
              
                Rename local
              
              
                RenderMichael d46e10f
              
                fix further
              
              
                RenderMichael d5c4954
              
                Avoid magic of records for remote primitives
              
              
                RenderMichael c51dc4c
              
                Merge branch 'trunk' into bidi-map
              
              
                RenderMichael File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            331 changes: 331 additions & 0 deletions
          
          331 
        
  dotnet/test/common/BiDi/Script/CallFunctionLocalValueTest.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,331 @@ | ||
| // <copyright file="CallFunctionLocalValueTest.cs" company="Selenium Committers"> | ||
| // Licensed to the Software Freedom Conservancy (SFC) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The SFC licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
| // </copyright> | ||
| 
     | 
||
| using NUnit.Framework; | ||
| using OpenQA.Selenium.BiDi.Modules.Script; | ||
| 
     | 
||
| namespace OpenQA.Selenium.BiDi.Script; | ||
| 
     | 
||
| class CallFunctionLocalValueTest : BiDiTestFixture | ||
| { | ||
| [Test] | ||
| public void CanCallFunctionWithArgumentUndefined() | ||
| { | ||
| var arg = new LocalValue.Undefined(); | ||
                
      
                  nvborisenko marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (typeof arg !== 'undefined') { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNull() | ||
| { | ||
| var arg = new LocalValue.Null(); | ||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== null) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentEmptyString() | ||
| { | ||
| var arg = new LocalValue.String(string.Empty); | ||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== '') { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNonEmptyString() | ||
| { | ||
| var arg = new LocalValue.String("whoa"); | ||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== 'whoa') { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentRecentDate() | ||
| { | ||
| const string PinnedDateTimeString = "2025-03-09T00:30:33.083Z"; | ||
| 
     | 
||
| var arg = new LocalValue.Date(PinnedDateTimeString); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg.toISOString() !== '{{PinnedDateTimeString}}') { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentEpochDate() | ||
| { | ||
| const string EpochString = "1970-01-01T00:00:00.000Z"; | ||
| 
     | 
||
| var arg = new LocalValue.Date(EpochString); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg.toISOString() !== '{{EpochString}}') { | ||
| throw new Error("Assert failed: " + arg.toISOString()); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumber5() | ||
| { | ||
| var arg = new LocalValue.Number(5); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== 5) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumberNegative5() | ||
| { | ||
| var arg = new LocalValue.Number(-5); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== -5) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumber0() | ||
                
      
                  RenderMichael marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| { | ||
| var arg = new LocalValue.Number(0); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== 0) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumberNegative0() | ||
                
      
                  RenderMichael marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| { | ||
| var arg = new LocalValue.Number(double.NegativeZero); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== -0) { | ||
                
      
                  nvborisenko marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumberPositiveInfinity() | ||
| { | ||
| var arg = new LocalValue.Number(double.PositiveInfinity); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== Number.POSITIVE_INFINITY) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumberNegativeInfinity() | ||
| { | ||
| var arg = new LocalValue.Number(double.NegativeInfinity); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg !== Number.NEGATIVE_INFINITY) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentNumberNaN() | ||
| { | ||
| var arg = new LocalValue.Number(double.NaN); | ||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (!isNaN(arg)) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentRegExp() | ||
| { | ||
| var arg = new LocalValue.RegExp(new LocalValue.RegExp.RegExpValue("foo*") { Flags = "g" }); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (!arg.test('foo') || arg.source !== 'foo*' || !arg.global) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentArray() | ||
| { | ||
| var arg = new LocalValue.Array([new LocalValue.String("hi")]); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg.length !== 1 || arg[0] !== 'hi') { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentObject() | ||
| { | ||
| var arg = new LocalValue.Object([[new LocalValue.String("key"), new LocalValue.String("value")]]); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg.key !== 'value' || Object.keys(arg).length !== 1) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentMap() | ||
| { | ||
| var arg = new LocalValue.Map([[new LocalValue.String("key"), new LocalValue.String("value")]]); | ||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (arg.get('key') !== 'value' || arg.size !== 1) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [arg] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| 
     | 
||
| [Test] | ||
| public void CanCallFunctionWithArgumentSet() | ||
| { | ||
| var argument = new LocalValue.Set([new LocalValue.String("key")]); | ||
                
      
                  RenderMichael marked this conversation as resolved.
               
              
                Outdated
          
            Show resolved
            Hide resolved
         | 
||
| 
     | 
||
| Assert.That(async () => | ||
| { | ||
| await context.Script.CallFunctionAsync($$""" | ||
| (arg) => { | ||
| if (!arg.has('key') || arg.size !== 1) { | ||
| throw new Error("Assert failed: " + arg); | ||
| } | ||
| } | ||
| """, false, new() { Arguments = [argument] }); | ||
| }, Throws.Nothing); | ||
| } | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.