コード例 #1
0
        public async Task PreloadUsesWebViewFromCache()
        {
            var webviewInstantiatedTaskCompletionSource = new TaskCompletionSource <bool>();

            void OnWebViewInitialized(WebView webview)
            {
                webviewInstantiatedTaskCompletionSource.TrySetResult(true);
            }

            try {
                WebView.GlobalWebViewInitialized += OnWebViewInitialized;
                await Run(async() => {
                    using var newView = new TestReactViewWithPreload();
                    newView.Load();
                    var currentTime = await TargetView.EvaluateMethod <double>("getCurrentTime");

                    // wait for the cached webview to be instantiated
                    await webviewInstantiatedTaskCompletionSource.Task;

                    using var newView2 = new TestReactViewWithPreload();
                    newView2.Load();

                    var startTime = await newView2.EvaluateMethod <double>("getStartTime");
                    Assert.LessOrEqual(startTime, currentTime, "The second webview should have been loaded before!");
                });
            } finally {
                WebView.GlobalWebViewInitialized -= OnWebViewInitialized;
            }
        }
コード例 #2
0
        public async Task PluginModuleReceivesExpectedArguments()
        {
            await Run(async() => {
                var result = await TargetView.EvaluateMethod <bool[]>("checkPluginInContext");

                CollectionAssert.AreEquivalent(new[] { true, true, true }, result);
            });
        }
コード例 #3
0
        public void PreloadUsesWebViewFromCache()
        {
            var start = DateTime.Now;

            while ((DateTime.Now - start).TotalSeconds < 1)
            {
                DoEvents(); // let the cached webview have time to be created
            }

            var currentTime = TargetView.EvaluateMethod <double>("getCurrentTime");

            using (var newView = new TestReactViewWithPreload()) {
                Window.Content = newView;
                WaitFor(() => newView.IsReady, "second view load");
                var startTime = newView.EvaluateMethod <double>("getStartTime");
                Assert.LessOrEqual(startTime, currentTime, "The second webview should have been loaded before");
            }
        }