public async Task CustomRequestsAreHandledByAnotherThread() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <int>(); var mainThread = Thread.CurrentThread.ManagedThreadId; TargetView.CustomResourceRequested += delegate { taskCompletionSource.SetResult(Thread.CurrentThread.ManagedThreadId); return(null); }; TargetView.ExecuteMethod("loadCustomResource", "custom://resource//test.png"); var customResourceRequestThread = await taskCompletionSource.Task; Assert.AreNotEqual(mainThread, customResourceRequestThread, "Custom resource request thread should be different from main thread"); }); }
public async Task DisposeDoesNotHang() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.Event += delegate { Dispatcher.UIThread.InvokeAsync(() => { TargetView.Dispose(); taskCompletionSource.SetResult(true); }).Wait(); }; TargetView.ExecuteMethod("callEvent"); var eventCalled = await taskCompletionSource.Task; Assert.IsTrue(eventCalled, "View was not disposed!"); }); }
public async Task ExecuteBeforeReady() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.Event += delegate { taskCompletionSource.SetResult(true); }; TargetView.ExecuteMethod("callEvent"); Assert.IsFalse(TargetView.IsReady); Assert.IsFalse(taskCompletionSource.Task.IsCompleted); Window.Show(); var isReady = await taskCompletionSource.Task; Assert.IsTrue(isReady); }); }
public void CustomRequestsAreHandledByAnotherThread() { var requestHandlerCalled = false; var mainThread = Thread.CurrentThread.ManagedThreadId; var customResourceRequestThread = -1; TargetView.CustomResourceRequested += (_, __) => { customResourceRequestThread = Thread.CurrentThread.ManagedThreadId; requestHandlerCalled = true; return(null); }; TargetView.ExecuteMethod("loadCustomResource", "custom://webview/test.png"); WaitFor(() => requestHandlerCalled, "custom request handler called"); Assert.IsTrue(requestHandlerCalled, "Request handler was called"); Assert.AreNotEqual(mainThread, customResourceRequestThread, "custom resource request thread should be different from main thread"); }
public async Task InnerViewIsLoadedWhenWebviewIsReloaded() { await Run(async() => { // Load view for the first time var taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.InnerView.Loaded += () => { taskCompletionSource.TrySetResult(true); }; TargetView.InnerView.Load(); await taskCompletionSource.Task; // Reload view taskCompletionSource = new TaskCompletionSource <bool>(); TargetView.ExecuteMethod("reload"); var isReloaded = await taskCompletionSource.Task; Assert.IsTrue(isReloaded, "Inner view module was not reloaded!"); }); }
public async Task InnerViewIsViewFrameLoadedEventCalled() { await Run(async() => { var taskCompletionSource = new TaskCompletionSource <bool>(); #if DEBUG TargetView.Ready += () => TargetView.InnerView.Load(); #endif TargetView.InnerView.Load(); TargetView.Event += (name) => { if (name == "InnerViewLoaded") { taskCompletionSource.TrySetResult(true); } }; TargetView.ExecuteMethod("checkInnerViewLoaded"); var hasLoaded = await taskCompletionSource.Task; Assert.IsTrue(hasLoaded, "Inner view javascript event was not called!"); }); }
public async Task SecondaryStylesheetIsLoadedWhenDefaultStyleSheetIsRefreshed() { // Arrange var view = TargetView as ReactViewWithStyleSheet; view.LoadPrimaryStyleSheet = false; // Act view.RefreshStyleSheetTests(); // Asssert await Run(async() => { var taskCompletionSource = new TaskCompletionSource <string>(); TargetView.Event += (args) => { taskCompletionSource.SetResult(args); }; TargetView.ExecuteMethod("checkStyleSheetLoaded", "2"); var stylesheet = await taskCompletionSource.Task; StringAssert.Contains(".bazz-version-2", stylesheet); }); }