Example #1
0
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnName()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.Register <A2>("javascript\\navigation_1.html", "Special1");
                wpfbuild.Register <A2>("javascript\\navigation_2.html", "Special2");

                wpfnav.UseINavigable = true;
                wpfnav.UseINavigable = true;
                var a1  = new A2();
                var mre = new ManualResetEvent(false);

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

                mre.WaitOne();

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



                Thread.Sleep(1000);

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


                mre = new ManualResetEvent(false);

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

                mre.WaitOne();

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

                Thread.Sleep(1000);

                WindowTest.RunOnUIThread(
                    () =>
                    wpfnav.Source.Should().EndWith(@"javascript\navigation_2.html"));
            });
        }
        public void Test_WPFBrowserNavigator_Simple()
        {
            var vm = new VM();

            TestNavigation((wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                _INavigationBuilder.Register <VM>("Navigation data\\index.html");
                wpfnav.UseINavigable = true;

                var mre         = new ManualResetEvent(false);
                DateTime?nav    = null;
                DateTime?Opened = null;
                DisplayEvent de = null;

                wpfnav.OnDisplay += (o, e) => { Opened = DateTime.Now; de = e; };

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(vm).ContinueWith
                    (
                        t =>
                    {
                        nav = DateTime.Now;
                        mre.Set();
                    });
                });

                mre.WaitOne();
                mre = new ManualResetEvent(false);
                Thread.Sleep(3000);

                de.Should().NotBeNull();
                de.DisplayedViewModel.Should().Be(vm);
                Opened.HasValue.Should().BeTrue();
                Opened.Value.Subtract(nav.Value).Should().BeGreaterThan(TimeSpan.FromSeconds(1.9)).
                And.BeLessOrEqualTo(TimeSpan.FromSeconds(2.2));

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

                mre.WaitOne();
                Thread.Sleep(500);
            });
        }
Example #3
0
        public void Test_WPFBrowserNavigator_Navition_Resolve_OnName_alernativesignature()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                wpfbuild.RegisterAbsolute <A2>(string.Format("{0}\\{1}", Assembly.GetExecutingAssembly().GetPath(), "javascript\\navigation_1.html"), "Special1");
                wpfbuild.Register <A2>(new Uri(string.Format("{0}\\{1}", Assembly.GetExecutingAssembly().GetPath(), "javascript\\navigation_2.html")), "Special2");

                wpfnav.UseINavigable = true;
                var a1  = new A2();
                var mre = new ManualResetEvent(false);

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

                mre.WaitOne();

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

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

                mre = new ManualResetEvent(false);
                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a1, "Special2").ContinueWith(t => mre.Set());
                });

                mre.WaitOne();


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

                Thread.Sleep(1000);

                WindowTest.RunOnUIThread(
                    () =>
                    wpfnav.Source.Should().EndWith(@"javascript\navigation_2.html"));
            });
        }
Example #4
0
        public void Test_WPFBrowserNavigator_Navition_Simple()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();
                SetUpRoute(wpfbuild);
                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.Should().EndWith(@"javascript\navigation_1.html"));

                mre = new ManualResetEvent(false);

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

                mre.WaitOne();

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

                WindowTest.RunOnUIThread(() =>
                                         wpfnav.Source.Should().EndWith(@"javascript\navigation_2.html"));
            });
        }
Example #5
0
        private Exception Test_HTMLWindow_WebCoreShutDown_Base_Exception(IWebSessionWatcher iWatcher)
        {
            var       a   = new AA1();
            Exception res = null;

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

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

                WindowTest.RunOnUIThread(
                    () =>
                {
                    wpfnav.NavigateAsync(a).ContinueWith(t => { var tt = t as Task <IHTMLBinding>; bind = tt.Result; mre.Set(); });
                });

                mre.WaitOne();

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

                    var js = bind.JSRootObject;

                    var command = js.Invoke("Change", bind.Context);
                    command.Invoke("Execute", bind.Context);

                    //JSObject mycommand = (JSObject)js.Invoke("Change");
                    //mycommand.Invoke("Execute");
                });

                Thread.Sleep(1500);

                res = a.Exception;
            });

            return(res);
        }
Example #6
0
        public void Test_HTMLWindowRecovery_UnderClosure_Capacity_Base()
        {
            //bool fl = false;
            //EventHandler ea = null;
            var a = new A1();
            IWebSessionWatcher watch = Substitute.For <IWebSessionWatcher>();

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.WebSessionWatcher.Should().NotBeNull();
                wpfnav.WebSessionWatcher = watch;
                //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();

                //WindowTest.RunOnUIThread(() =>
                //{
                //    wpfnav.IsHTMLLoaded.Should().BeTrue();
                //    //a1.Navigation.Should().Be(wpfnav);
                //    a.Navigation.Should().NotBeNull();
                //    System.Windows.Application.Current.Shutdown();
                //    var p = (a.Navigation as IWebViewProvider).WebView.RenderProcess;
                //    WebCore.Shutdown();
                //    //p.Kill();
                //    mre.Set();
                //});


                //mre.WaitOne();

                //Thread.Sleep(1000);

                //watch.DidNotReceive().LogCritical("WebView crashed trying recover");
            }, false, false);
        }
Example #7
0
        public void Test_WPFBrowserNavigator_Navition_Resolve_NotFound()
        {
            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.Should().NotBeNull();

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

                WindowTest.RunOnUIThread(
                    () =>
                {
                    Action wf = () => wpfnav.NavigateAsync(a1);
                    wf.ShouldThrow <Exception>();
                });
            });
        }
Example #8
0
        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>();
                });
            });
        }
Example #9
0
 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();
         });
     });
 }
Example #10
0
        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);
        }
Example #11
0
        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);
            });
        }
Example #12
0
        public void Test_HTMLWindow_Path()
        {
            bool         fl = false;
            EventHandler ea = null;
            var          a  = new A1();
            string       pn = Path.Combine(Path.GetTempPath(), "MVMMAWe");

            Directory.Delete(pn);

            TestNavigation((wpfbuild, wpfnav, WindowTest)
                           =>
            {
                wpfnav.SessionPath.Should().BeNull();
                wpfnav.SessionPath = pn;

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

            Directory.Exists(pn).Should().BeTrue();
        }
Example #13
0
        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();
                    a.Navigation.Should().NotBeNull();
                });


                mre.WaitOne();
            });
        }
Example #14
0
        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);
            });
        }
Example #15
0
        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.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);
        }