Files
cefsharp/CefSharp.Test/Fixture.cs
T
Per Lundberg a3bbd6e1f0 Merge commit '36ed4dbdc0cf0cb0d6b294df9d81a6a4fb7c1646' into JsBinding_WIP. This was taking @JanEggers changes and merging them into my local branch.
Conflicts:
	CefSharp.Core/CefSharp.Core.vcxproj
	CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs
	CefSharp/Internals/IWebBrowserInternal.cs
2014-06-12 02:10:08 +03:00

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);
}
}
}