"Fossies" - the Fresh Open Source Software Archive

Member "selenium-selenium-4.8.1/dotnet/test/common/CookieTest.cs" (17 Feb 2023, 3381 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 using System;
    2 using NUnit.Framework;
    3 using OpenQA.Selenium.Internal;
    4 
    5 namespace OpenQA.Selenium
    6 {
    7     [TestFixture]
    8     public class CookieTest
    9     {
   10         [Test]
   11         public void CanCreateAWellFormedCookie()
   12         {
   13             new ReturnedCookie("Fish", "cod", "", "", DateTime.Now, false, false);
   14         }
   15 
   16         [Test]
   17         public void ShouldThrowAnExceptionWhenSemiColonExistsInTheCookieAttribute()
   18         {
   19             Assert.That(() => new ReturnedCookie("hi;hi", "value", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
   20         }
   21 
   22         [Test]
   23         public void ShouldThrowAnExceptionWhenNameAndValueAreEmpty()
   24         {
   25             Assert.That(() => new ReturnedCookie("", "", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
   26         }
   27 
   28         [Test]
   29         public void ShouldThrowAnExceptionWhenTheNameIsNull()
   30         {
   31             Assert.That(() => new ReturnedCookie(null, "value", null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentException>());
   32         }
   33 
   34         [Test]
   35         public void ShouldThrowAnExceptionWhenSameSiteIsWrong()
   36         {
   37             Assert.That(() => new ReturnedCookie("name", "value", "" , "/", DateTime.Now, true, true, "Wrong"), Throws.InstanceOf<ArgumentException>());
   38         }
   39 
   40         [Test]
   41         public void CookiesShouldAllowOptionalParametersToBeSet()
   42         {
   43             DateTime expiry = DateTime.Now;
   44             Cookie cookie = new Cookie ("name", "value", "test.com", "/", expiry, true, true, "None");
   45             Assert.That(cookie.Domain, Is.EqualTo("test.com"));
   46             Assert.That(cookie.Path, Is.EqualTo("/"));
   47             Assert.That(cookie.IsHttpOnly, Is.True);
   48             Assert.That(cookie.Secure, Is.True);
   49             Assert.That(cookie.SameSite, Is.EqualTo("None"));
   50         }
   51 
   52         [Test]
   53         public void CookiesShouldAllowSecureToBeSet()
   54         {
   55             Cookie cookie = new ReturnedCookie("name", "value", "", "/", DateTime.Now, true, false);
   56             Assert.That(cookie.Secure, Is.True);
   57         }
   58 
   59         [Test]
   60         public void SecureDefaultsToFalse()
   61         {
   62             Cookie cookie = new Cookie("name", "value");
   63             Assert.That(cookie.Secure, Is.False);
   64         }
   65 
   66         [Test]
   67         public void CookiesShouldAllowHttpOnlyToBeSet()
   68         {
   69             Cookie cookie = new ReturnedCookie("name", "value", "", "/", DateTime.Now, false, true);
   70             Assert.That(cookie.IsHttpOnly, Is.True);
   71         }
   72 
   73         [Test]
   74         public void HttpOnlyDefaultsToFalse()
   75         {
   76             Cookie cookie = new Cookie("name", "value");
   77             Assert.That(cookie.IsHttpOnly, Is.False);
   78         }
   79 
   80         //------------------------------------------------------------------
   81         // Tests below here are not included in the Java test suite
   82         //------------------------------------------------------------------
   83         [Test]
   84         public void ShouldThrowAnExceptionWhenTheValueIsNull()
   85         {
   86             Assert.That(() => new ReturnedCookie("name", null, null, null, DateTime.Now, false, false), Throws.InstanceOf<ArgumentNullException>());
   87         }
   88 
   89         [Test]
   90         public void ShouldAllowExpiryToBeNull()
   91         {
   92             Cookie cookie = new ReturnedCookie("name", "value", "", "/", null, false, false);
   93         }
   94     }
   95 }