public void Test_WPFBrowserNavigator_Navigation_ToSame()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;
                var a1  = new A1();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });


                WindowTest.RunOnUIThread(
                    () =>
                    wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));


                WindowTest.RunOnUIThread(
                    () =>
                {
                    a1.Change.Execute(null);
                });

                Thread.Sleep(200);

                WindowTest.RunOnUIThread(() =>
                                         wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));
            });
        }
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnBaseType_ShoulFailed()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.Register <A>("javascript\\navigation_1.html");
                wpfbuild.Register <A1>("javascript\\navigation_2.html", "Special");

                wpfnav.UseINavigable = true;
                var a1 = new object();

                WindowTest.RunOnUIThread(
                    () =>
                {
                    Action wf = () => wpfnav.NavigateAsync(a1);
                    wf.ShouldThrow <Exception>();
                });
            });
        }
 public void Test_WPFBrowserNavigator_Navition_Debug_One_NoDebug()
 {
     TestNavigation((wpfbuild, wpfnav, WindowTest)
                    =>
     {
         WindowTest.RunOnUIThread(() =>
         {
             wpfnav.IsDebug.Should().BeFalse();
             DispatcherTimer dt = new DispatcherTimer();
             dt.Interval        = TimeSpan.FromSeconds(10);
             dt.Tick           += (o, e) =>
             {
                 dt.Stop();
                 System.Windows.Application.Current.Shutdown();
             };
             dt.Start();
             wpfnav.OpenDebugBrowser();
         });
     });
 }
        public void Test_HTMLWindow_Event()
        {
            bool            fl   = false;
            EventHandler    ea   = null;
            var             a    = new A1();
            string          pn   = Path.Combine(Path.GetTempPath(), "MVMMAWe");
            bool            fslr = false;
            NavigationEvent nea  = null;

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.OnFirstLoad += (o, e) => { fslr = true; };
                wpfnav.OnNavigate  += (o, e) => { nea = e; };

                ea = (o, e) => { fl = true; wpfnav.OnFirstLoad -= ea; };
                wpfnav.OnFirstLoad += ea;
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;

                var mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(() => wpfnav.IsHTMLLoaded.Should().BeFalse());

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                fl.Should().BeTrue();
            });

            fslr.Should().BeTrue();
            nea.Should().NotBeNull();
            nea.OldViewModel.Should().BeNull();
            nea.NewViewModel.Should().Be(a);
        }
        public void Test_WPFBrowserNavigator_Simple()
        {
            bool         fl = false;
            EventHandler ea = null;

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                ea = (o, e) => { fl = true; wpfnav.OnFirstLoad -= ea; };
                wpfnav.OnFirstLoad += ea;
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;
                var a   = new A1();
                var mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(() => wpfnav.IsHTMLLoaded.Should().BeFalse());

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                fl.Should().BeTrue();

                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.IsHTMLLoaded.Should().BeTrue();
                    //a1.Navigation.Should().Be(wpfnav);
                    a.Navigation.Should().NotBeNull();
                });


                mre.WaitOne();
            });
        }
        private void Test_HTMLWindow_WebCoreShutDown_Base(IWebSessionWatcher iWatcher)
        {
            var a = new A1();

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.WebSessionWatcher.Should().NotBeNull();
                if (iWatcher != null)
                {
                    wpfnav.WebSessionWatcher = iWatcher;
                }
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;

                var mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(() => wpfnav.IsHTMLLoaded.Should().BeFalse());

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.IsHTMLLoaded.Should().BeTrue();
                    a.Navigation.Should().NotBeNull();
                });

                WebCore.Shutdown();

                Thread.Sleep(1500);
            });
        }
        public void Test_WPFBrowserNavigator_Navition_3_screens()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfbuild.Register <A1>("javascript\\navigation_3.html", "NewPath");
                wpfnav.UseINavigable = true;
                var a1  = new A1();
                var a2  = new A2();
                var mre = new ManualResetEvent(false);


                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    //a1.Navigation.Should().Be(wpfnav);
                    a1.Navigation.Should().NotBeNull();
                });

                WindowTest.RunOnUIThread(
                    () =>
                    wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html"));

                mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a2).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    a2.Navigation.Should().NotBeNull();
                    a1.Navigation.Should().BeNull();
                });

                WindowTest.RunOnUIThread(() =>
                                         wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_2.html"));


                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a1, "NewPath").ContinueWith
                    (
                        t =>
                    {
                        //a1.Navigation.Should().Be(wpfnav);
                        a1.Navigation.Should().NotBeNull();
                        a2.Navigation.Should().BeNull();
                        mre.Set();
                    });
                });
                mre.WaitOne();

                Thread.Sleep(2000);


                WindowTest.RunOnUIThread(() =>
                                         wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_3.html"));
            });
        }
        private void Test_HTMLWindowRecovery_Capacity_Base(IWebSessionWatcher iWatcher)
        {
            bool         fl = false;
            EventHandler ea = null;
            var          a  = new A1();

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.WebSessionWatcher.Should().NotBeNull();
                if (iWatcher != null)
                {
                    wpfnav.WebSessionWatcher = iWatcher;
                }
                ea = (o, e) => { fl = true; wpfnav.OnFirstLoad -= ea; };
                wpfnav.OnFirstLoad += ea;
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                wpfnav.UseINavigable = true;

                var mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(() => wpfnav.IsHTMLLoaded.Should().BeFalse());

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                fl.Should().BeTrue();

                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.IsHTMLLoaded.Should().BeTrue();
                    //a1.Navigation.Should().Be(wpfnav);
                    a.Navigation.Should().NotBeNull();
                });


                mre.WaitOne();
                var webv = (a.Navigation as IWebViewProvider).WebView;

                mre       = new ManualResetEvent(false);
                Process p = null;
                WindowTest.RunOnUIThread(() =>
                {
                    p = webv.RenderProcess;
                    p.Kill();
                    mre.Set();
                });

                mre.WaitOne();
                Thread.Sleep(500);
                p.WaitForExit();


                Process np = null;
                mre        = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(() =>
                {
                    np = webv.RenderProcess;
                    mre.Set();
                });
                np.Should().NotBe(p);
            });
        }
        public void Test_WPFBrowserNavigator_Navition_Debug_One()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.IsDebug.Should().BeTrue();
                    Action safe = () =>
                                  wpfnav.ShowDebugWindow();
                    safe.ShouldNotThrow <Exception>();
                });



                wpfnav.Should().NotBeNull();
                wpfbuild.Register <A>("javascript\\navigation_1.html");
                wpfbuild.Register <A1>("javascript\\navigation_2.html", "Special");

                wpfnav.UseINavigable = true;
                wpfnav.UseINavigable.Should().BeTrue();

                wpfnav.EnableBrowserDebug = true;
                wpfnav.EnableBrowserDebug.Should().BeTrue();

                wpfnav.OnNavigate += wpfnav_OnNavigate;
                wpfnav.OnNavigate -= wpfnav_OnNavigate;



                var a1  = new A2();
                var mre = new ManualResetEvent(false);

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a1).ContinueWith(t => mre.Set());
                });

                mre.WaitOne();

                WindowTest.RunOnUIThread(() =>
                {
                    a1.Navigation.Should().NotBeNull();
                    wpfnav.Source.LocalPath.Should().EndWith("javascript\\navigation_1.html");
                    wpfnav.ShowDebugWindow();
                    wpfnav.OpenDebugBrowser();
                });


                WindowTest.RunOnUIThread(() =>
                {
                    wpfnav.Focus();

                    wpfnav.RaiseEvent(
                        new System.Windows.Input.KeyEventArgs(
                            Keyboard.PrimaryDevice,
                            PresentationSource.FromVisual(wpfnav),
                            0,
                            Key.F5)
                    {
                        RoutedEvent = Keyboard.PreviewKeyDownEvent
                    }
                        );
                });
            }, true);
        }