mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 19:54:53 +00:00
a3bbd6e1f0
Conflicts: CefSharp.Core/CefSharp.Core.vcxproj CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs CefSharp/Internals/IWebBrowserInternal.cs
88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
//using NUnit.Framework;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using CefSharp.Wpf;
|
|
|
|
namespace CefSharp.Test
|
|
{
|
|
public class Fixture : DisposableResource
|
|
{
|
|
public ChromiumWebBrowser Browser { get; set; }
|
|
public Window Window { get; set; }
|
|
public DispatcherThread DispatcherThread { get; set; }
|
|
|
|
|
|
public Fixture()
|
|
{
|
|
DispatcherThread = new DispatcherThread();
|
|
}
|
|
|
|
public Task Initialize()
|
|
{
|
|
return DoInUi(() =>
|
|
{
|
|
Window = new Window();
|
|
|
|
var cefsettings = new CefSettings();
|
|
cefsettings.BrowserSubprocessPath = Path.Combine( Environment.CurrentDirectory, "CefSharp.BrowserSubprocess.exe" );
|
|
cefsettings.LogSeverity = LogSeverity.Verbose;
|
|
cefsettings.LocalesDirPath = Path.Combine(Environment.CurrentDirectory, "locales");
|
|
cefsettings.PackLoadingDisabled = true;
|
|
|
|
if (!Cef.Initialize(cefsettings))
|
|
{
|
|
|
|
}
|
|
|
|
Window.Content = Browser = new ChromiumWebBrowser();
|
|
|
|
Window.Show();
|
|
}).ContinueWith((t) =>
|
|
{
|
|
if (t.IsFaulted)
|
|
{
|
|
throw t.Exception;
|
|
}
|
|
using (var evt = new ManualResetEvent(false))
|
|
{
|
|
Browser.IsBrowserInitializedChanged += (o, e) => evt.Set();
|
|
|
|
DoInUi(() =>
|
|
{
|
|
if (Browser.IsBrowserInitialized)
|
|
{
|
|
evt.Set();
|
|
}
|
|
});
|
|
|
|
evt.WaitOne();
|
|
}
|
|
}, DispatcherThread.TaskFactory.Scheduler);
|
|
}
|
|
|
|
public Task DoInUi(Action action)
|
|
{
|
|
return DispatcherThread.TaskFactory.StartNew(action);
|
|
}
|
|
|
|
public Task<T> DoInUi<T>(Func<T> action)
|
|
{
|
|
return DispatcherThread.TaskFactory.StartNew(action);
|
|
}
|
|
|
|
protected override void DoDispose(bool isDisposing)
|
|
{
|
|
if (DispatcherThread != null)
|
|
{
|
|
DispatcherThread.Dispose();
|
|
DispatcherThread = null;
|
|
}
|
|
Browser = null;
|
|
base.DoDispose(isDisposing);
|
|
}
|
|
}
|
|
}
|