public Task Test_HTMLBinding_Stress_Collection_CreateBinding(JavascriptBindingMode imode, TestPerformanceKind context, TestContext ipath = TestContext.Index)
        {
            int r           = 100;
            var datacontext = new TwoList();

            datacontext.L1.AddRange(Enumerable.Range(0, r).Select(i => new Skill()));

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var test = new TestInContext()
            {
                Path = ipath,
                Bind = (win) => HTML_Binding.Bind(win, datacontext, imode),
                Test = (mb) =>
                {
                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {r} iterations");

                    var js = mb.JSRootObject;

                    var col = GetSafe(() => GetCollectionAttribute(js, "L1"));
                    col.GetArrayLength().Should().Be(r);

                    CheckVsExpectation(ts, context);
                }
            };

            return(RunAsync(test));
        }
        public async Task Stress_Big_Vm(int childrenCount)
        {
            var root = new FakeFatherViewModel();
            var test = new TestInContextAsync()
            {
                Bind = (win) => HTML_Binding.Bind(win, root, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var bigVm = BuildBigVm(childrenCount);
                    var js    = mb.JSRootObject;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    await DoSafeAsyncUI(() => root.Other = bigVm);

                    var other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Other"));

                    other.IsObject.Should().BeTrue();

                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double)(ts)) / 1000} sec");
                }
            };

            await RunAsync(test);
        }
        public async Task Stress_Big_Vm_Commands(int commandsCount)
        {
            var root = new FakeViewModelWithCommands();
            var test = new TestInContextAsync()
            {
                Bind = (win) => HTML_Binding.Bind(win, root, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var js = mb.JSRootObject;

                    var commands = Enumerable.Range(0, commandsCount).Select(_ => NSubstitute.Substitute.For <ICommand>()).ToArray();

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    await DoSafeAsyncUI(() => root.Commands = commands);

                    var other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Commands"));

                    other.IsArray.Should().BeTrue();

                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double)(ts)) / 1000} sec");
                }
            };

            await RunAsync(test);
        }
Example #4
0
        public async Task Update_from_int(int value, IJavascriptObjectBuilderStrategyFactory strategyFactory)
        {
            var root = new FakeIntViewModel();
            var test = new TestInContextAsync()
            {
                Bind = (win) => HTML_Binding.Bind(win, root, JavascriptBindingMode.TwoWay, strategyFactory),
                Test = async(mb) =>
                {
                    var js = mb.JSRootObject;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    await DoSafeAsyncUI(() => root.Value = value);

                    var other = await _WebView.EvaluateAsync(() => GetAttribute(js, "Value"));

                    other.GetIntValue().Should().Be(value);

                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double)(ts)) / 1000} sec");
                }
            };

            await RunAsync(test);
        }
        public async Task Stress_Collection_Update_From_Javascript()
        {
            int r           = 100;
            var datacontext = new TwoList();

            datacontext.L1.AddRange(Enumerable.Range(0, r).Select(i => new Skill()));

            var test = new TestInContextAsync()
            {
                Path = TestContext.Simple,
                Bind = (win) => HTML_Binding.Bind(win, datacontext, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var js = mb.JSRootObject;

                    var col1 = GetCollectionAttribute(js, "L1");
                    col1.GetArrayLength().Should().Be(r);

                    var col2 = GetCollectionAttribute(js, "L2");
                    col2.GetArrayLength().Should().Be(0);

                    var l2c = GetAttribute(js, "L2");
                    l2c.Should().NotBeNull();

                    var javascript        = "window.app = function(value,coll){var args = []; args.push(0); args.push(0); for (var i = 0; i < value.length; i++) { args.push(value[i]);} coll.splice.apply(coll, args);  console.log(value.length); console.log(coll.length);};";
                    IJavascriptObject res = null;
                    bool ok = _WebView.Eval(javascript, out res);
                    ok.Should().BeTrue();

                    bool notok     = true;
                    var  stopWatch = new Stopwatch();
                    stopWatch.Start();

                    DoSafe(() => Call(_WebView.GetGlobal(), "app", col1, l2c));
                    while (notok)
                    {
                        await Task.Delay(100);

                        notok = datacontext.L2.Count != r;
                    }
                    stopWatch.Stop();
                    long ts = stopWatch.ElapsedMilliseconds;

                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {r} iterations");
                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Collection_Update_From_Javascript);
                }
            };

            await RunAsync(test);
        }
        public async Task Bind_ShouldBeRobust()
        {
            var test = new TestInContext()
            {
                Bind = (win) => HTML_Binding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = _ => { }
            };

            for (var i = 0; i < 150; i++)
            {
                _Logger.Info($"Runing interaction {i}");
                await RunAsync(test);
            }
        }
        public async Task Binding_Can_Create_More_Object_Than_Max_Stack()
        {
            var dataContext = new BigCollectionVM <Simple>(_ => new Simple());
            var test        = new TestInContext()
            {
                Bind = (win) => HTML_Binding.Bind(win, dataContext, JavascriptBindingMode.TwoWay),
                Test = (mb) =>
                {
                    var js = mb.JSRootObject;

                    var res = GetCollectionAttribute(js, "Values");
                    res.GetArrayLength().Should().Be(BigCollectionVM <Simple> .Limit);

                    var lastElement = res.GetValue(BigCollectionVM <Simple> .Limit - 1);
                    var id          = GetIntAttribute(lastElement, "Id");
                    id.Should().Be(23);
                }
            };

            await RunAsync(test);
        }
        public async Task Binding_Can_Create_Collection_With_Count_Greater_Than_Max_Stack()
        {
            var value       = 3;
            var dataContext = new BigCollectionVM <int>(value);
            var test        = new TestInContext()
            {
                Bind = (win) => HTML_Binding.Bind(win, dataContext, JavascriptBindingMode.TwoWay),
                Test = (mb) =>
                {
                    var js = mb.JSRootObject;

                    var res = GetCollectionAttribute(js, "Values");
                    res.GetArrayLength().Should().Be(BigCollectionVM <int> .Limit);

                    var lastElement = res.GetValue(BigCollectionVM <int> .Limit - 1);
                    lastElement.GetIntValue().Should().Be(value);
                }
            };

            await RunAsync(test);
        }
        public async Task Stress_TwoWay_Int()
        {
            var test = new TestInContextAsync()
            {
                Path = TestContext.Simple,
                Bind = (win) => HTML_Binding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var js  = mb.JSRootObject;
                    int iis = 500;
                    for (int i = 0; i < iis; i++)
                    {
                        _DataContext.Age += 1;
                    }

                    bool notok = true;
                    var  tg    = _DataContext.Age;
                    await Task.Delay(700);

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    while (notok)
                    {
                        await Task.Delay(100);

                        var doublev = GetIntAttribute(js, "Age");
                        notok = doublev != tg;
                    }
                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {iis} iterations");

                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Int);
                }
            };

            await RunAsync(test);
        }
        private Task <IHTMLBinding> Navigate(Uri uri, object iViewModel, JavascriptBindingMode iMode = JavascriptBindingMode.TwoWay)
        {
            if (uri == null)
            {
                throw ExceptionHelper.GetArgument($"ViewModel not registered: {iViewModel.GetType()}");
            }

            _Navigating = true;

            var oldvm = Binding?.Root as INavigable;

            if (_UseINavigable && (oldvm != null))
            {
                oldvm.Navigation = null;
            }

            var wh = new WindowHelper(new HTMLLogicWindow());

            if (_CurrentWebControl != null)
            {
                _CurrentWebControl.HTMLWindow.Crashed -= Crashed;
            }

            var closetask = (_CurrentWebControl != null) ? _Window.CloseAsync() : TaskHelper.Ended();

            _NextWebControl = _WebViewLifeCycleManager.Create();
            _NextWebControl.HTMLWindow.ConsoleMessage += ConsoleMessage;

            var moderWindow = _NextWebControl.HTMLWindow as IModernWebBrowserWindow;

            if (moderWindow != null)
            {
                var debugContext = _WebViewLifeCycleManager.DebugContext;
                EventHandler <BeforeJavascriptExcecutionArgs> before = null;
                before = (o, e) =>
                {
                    moderWindow.BeforeJavascriptExecuted -= before;
                    e.JavascriptExecutor(_javascriptFrameworkManager.GetMainScript(debugContext));
                };
                moderWindow.BeforeJavascriptExecuted += before;
            }

            var tcs = new TaskCompletionSource <IHTMLBinding>();

            EventHandler <LoadEndEventArgs> sourceupdate = null;

            sourceupdate = (o, e) =>
            {
                var injectorFactory = GetInjectorFactory(uri);
                _NextWebControl.HTMLWindow.LoadEnd -= sourceupdate;
                var engine = new HTMLViewEngine(_NextWebControl, injectorFactory, _webSessionLogger);

                HTML_Binding.Bind(engine, iViewModel, iMode, wh).WaitWith(closetask, t => Switch(t, wh.__window__, tcs));
            };

            Url = uri;
            _NextWebControl.HTMLWindow.LoadEnd += sourceupdate;
            _NextWebControl.HTMLWindow.NavigateTo(uri);

            return(tcs.Task);
        }
        public async Task Stress_TwoWay_Collection()
        {
            var test = new TestInContextAsync()
            {
                Bind = (win) => HTML_Binding.Bind(win, _DataContext, JavascriptBindingMode.TwoWay),
                Test = async(mb) =>
                {
                    var js = mb.JSRootObject;

                    var col = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                    col.GetArrayLength().Should().Be(2);

                    Check(col, _DataContext.Skills);

                    _DataContext.Skills.Add(new Skill()
                    {
                        Name = "C++", Type = "Info"
                    });

                    await Task.Delay(150);

                    col = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                    Check(col, _DataContext.Skills);

                    _DataContext.Skills[0] = new Skill()
                    {
                        Name = "HTML5", Type = "Info"
                    };
                    int iis = 500;
                    for (int i = 0; i < iis; i++)
                    {
                        _DataContext.Skills.Insert(0, new Skill()
                        {
                            Name = "HTML5", Type = "Info"
                        });
                    }

                    bool notok  = true;
                    int  tcount = _DataContext.Skills.Count;

                    var stopWatch = new Stopwatch();
                    stopWatch.Start();

                    while (notok)
                    {
                        await Task.Delay(10);

                        col   = GetSafe(() => GetCollectionAttribute(js, "Skills"));
                        notok = col.GetArrayLength() != tcount;
                    }
                    stopWatch.Stop();
                    var ts = stopWatch.ElapsedMilliseconds;
                    _Logger.Info($"Perf: {((double) (ts)) / 1000} sec for {iis} iterations");
                    Check(col, _DataContext.Skills);

                    CheckVsExpectation(ts, TestPerformanceKind.TwoWay_Collection);
                }
            };

            await RunAsync(test);
        }