diff --git a/CefSharp.Test/Framework/RequestContextExtensionFacts.cs b/CefSharp.Test/Framework/RequestContextExtensionFacts.cs
index a174c114b0..5531f64dd1 100644
--- a/CefSharp.Test/Framework/RequestContextExtensionFacts.cs
+++ b/CefSharp.Test/Framework/RequestContextExtensionFacts.cs
@@ -4,12 +4,15 @@
using System;
using System.Collections.Generic;
+using System.Threading.Tasks;
using Moq;
using Xunit;
using Xunit.Abstractions;
namespace CefSharp.Test.Framework
{
+ //NOTE: All Test classes must be part of this collection as it manages the Cef Initialize/Shutdown lifecycle
+ [Collection(CefSharpFixtureCollection.Key)]
public class RequestContextExtensionFacts
{
private const string ProxyPreferenceKey = "proxy";
@@ -70,5 +73,20 @@ public void SetProxyThrowsExceptionOnInvalidScheme()
mockRequestContext.Object.SetProxy("myscheme", "localhost", 0, out msg);
});
}
+
+ [Fact]
+ public async Task CanGetCookieManagerForRequestContextAsync()
+ {
+ var requestContext = RequestContext
+ .Configure()
+ .Create();
+
+ var cookieManager = await requestContext.GetCookieManagerAsync();
+
+ var cookies = await cookieManager.VisitAllCookiesAsync();
+
+ Assert.NotNull(cookies);
+ output.WriteLine("Cookie Count {0}", cookies.Count);
+ }
}
}
diff --git a/CefSharp/RequestContextExtensions.cs b/CefSharp/RequestContextExtensions.cs
index 78d8e694ef..b3f3cef55a 100644
--- a/CefSharp/RequestContextExtensions.cs
+++ b/CefSharp/RequestContextExtensions.cs
@@ -59,6 +59,29 @@ public static void LoadExtensionsFromDirectory(this IRequestContext requestConte
}
}
+ ///
+ /// Gets the cookie manager associated with the . Once the cookie manager
+ /// storage has been initialized the method will return.
+ ///
+ /// Thrown when an exception error condition occurs.
+ /// The instance this method extends.
+ /// returns if the store was successfully loaded otherwise null.
+ public static async Task GetCookieManagerAsync(this IRequestContext requestContext)
+ {
+ if (requestContext == null)
+ {
+ throw new Exception("RequestContext is null, unable to obtain cookie manager");
+ }
+
+ var callback = new TaskCompletionCallback();
+
+ var cookieManager = requestContext.GetCookieManager(callback);
+
+ var success = await callback.Task;
+
+ return success ? cookieManager : null;
+ }
+
///
/// Set the value associated with preference name. If value is null the
/// preference will be restored to its default value. If setting the preference