public async Task ReactInstanceManager_CreateReactContextAsync_EnsuresOneCall() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var caught = false; await DispatcherHelpers.CallOnDispatcherAsync(async() => { var task = manager.CreateReactContextAsync(CancellationToken.None); try { await manager.CreateReactContextAsync(CancellationToken.None); } catch (InvalidOperationException) { caught = true; } }); Assert.IsTrue(caught); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_Lifecycle_Missing_Background() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile, LifecycleState.Foreground)); var listener = new LifecycleEventsListener(new LifecycleEventsListener.Step[] { LifecycleEventsListener.Step.EnteredBackground, LifecycleEventsListener.Step.Suspend, }); await DispatcherHelpers.CallOnDispatcherAsync(async() => { var context = await manager.CreateReactContextAsync(CancellationToken.None); context.AddBackgroundEventListener(listener); context.AddLifecycleEventListener(listener); manager.OnSuspend(); context.RemoveLifecycleEventListener(listener); context.RemoveBackgroundEventListener(listener); }); listener.Dispose(); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_DisposeAsync_WhileBusy() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var reactContext = await DispatcherHelpers.CallOnDispatcherAsync( () => manager.CreateReactContextAsync(CancellationToken.None)); var e = new AutoResetEvent(false); reactContext.RunOnNativeModulesQueueThread(() => { e.WaitOne(); var x = DispatcherHelpers.CallOnDispatcherAsync(() => { return(42); }).Result; }); var task = DispatcherHelpers.CallOnDispatcherAsync(async() => { e.Set(); await DisposeInstanceManager(manager); ; }); var completedTask = await Task.WhenAny( Task.Delay(5000), task); Assert.IsTrue(task.IsCompleted); }
public async Task ReactRootView_SecondaryWindowStress() { var jsBundleFile = "ms-appx:///Resources/mwtest.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var reactContext = await DispatcherHelpers.CallOnDispatcherAsync( () => manager.CreateReactContextAsync(CancellationToken.None)); int currentDelay = 2000; for (int i = 0; i < 30; i++) { currentDelay /= 2; // Create a window var dispatcher = await CreateView(() => { var rv = new ReactRootView(); rv.StartReactApplication( manager, "alt_window", null); return(rv); }); await Task.Delay(currentDelay); await CloseView(manager, dispatcher); } await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_CreateReactContextAsync() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var reactContext = await DispatcherHelpers.CallOnDispatcherAsync( () => manager.CreateReactContextAsync(CancellationToken.None)); Assert.AreEqual(jsBundleFile, manager.SourceUrl); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_TryGetReactContextAsync_Finished() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var initialContext = await DispatcherHelpers.CallOnDispatcherAsync(async() => await manager.CreateReactContextAsync(CancellationToken.None)); var context = await DispatcherHelpers.CallOnDispatcherAsync(async() => await manager.TryGetReactContextAsync(CancellationToken.None)); Assert.AreSame(initialContext, context); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_CreateReactContextAsync_Canceled() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.Cancel(); await AssertEx.ThrowsAsync <OperationCanceledException>( async() => await DispatcherHelpers.CallOnDispatcherAsync(() => manager.CreateReactContextAsync(cancellationTokenSource.Token)), ex => Assert.AreEqual(cancellationTokenSource.Token, ex.CancellationToken)); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }
public async Task ReactInstanceManager_RecreateReactContextAsync() { var jsBundleFile = "ms-appx:///Resources/test.js"; ReactInstanceManager manager = null; await DispatcherHelpers.CallOnDispatcherAsync(() => manager = CreateReactInstanceManager(jsBundleFile)); var task = default(Task <ReactContext>); var reactContext = await DispatcherHelpers.CallOnDispatcherAsync(async() => { task = manager.CreateReactContextAsync(CancellationToken.None); return(await manager.RecreateReactContextAsync(CancellationToken.None)); }); var initialReactContext = await task; Assert.IsNotNull(reactContext); Assert.AreEqual(jsBundleFile, manager.SourceUrl); Assert.AreNotEqual(initialReactContext, reactContext); await DispatcherHelpers.CallOnDispatcherAsync(async() => await DisposeInstanceManager(manager)); }