예제 #1
0
        private void DeleteCookies()
        {
            var callback = new TaskDeleteCookiesCallback();

            callback.Task.ContinueWith(task =>
            {
                if (!task.IsCompleted || task.Result == TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted)
                {
                    logger.Warn("Failed to delete cookies!");
                }
                else
                {
                    logger.Debug($"Deleted {task.Result} cookies.");
                }
            });

            if (Cef.GetGlobalCookieManager().DeleteCookies(callback: callback))
            {
                logger.Debug("Successfully initiated cookie deletion.");
            }
            else
            {
                logger.Warn("Failed to initiate cookie deletion!");
            }
        }
예제 #2
0
        public async Task TaskDeleteCookiesCallbackDispose()
        {
            var callback = new TaskDeleteCookiesCallback();

            //Execute Dispose on seperate Thread as in practice will be called on the CEF IO Thread.
            Task.Delay(100).ContinueWith(x =>
            {
                var c = (IDeleteCookiesCallback)callback;

                //Dispose of the callback, no cookies were deleted
                //This is a realworld example of how CEF interacts with the callback
                c.Dispose();
            }, TaskScheduler.Default);

            var result = await callback.Task;

            Assert.Equal(TaskDeleteCookiesCallback.InvalidNoOfCookiesDeleted, result);
        }
예제 #3
0
        public async Task TaskDeleteCookiesCallbackOnComplete()
        {
            const int numberOfCookiesDeleted = 10;

            var callback = new TaskDeleteCookiesCallback();

            //Execute OnComplete on seperate Thread as in practice will be called on the CEF IO Thread.
            Task.Delay(100).ContinueWith(x =>
            {
                var c = (IDeleteCookiesCallback)callback;

                c.OnComplete(numberOfCookiesDeleted);
                c.Dispose();
            }, TaskScheduler.Default);

            var result = await callback.Task;

            Assert.Equal(numberOfCookiesDeleted, result);
        }