示例#1
0
        public async Task ListenersAreCalled()
        {
            await Run(async() => {
                var listener1Counter = 0;
                var listener2Counter = 0;
                var taskCompletionSourceListener1  = new TaskCompletionSource <bool>();
                var taskCompletionSourceListener21 = new TaskCompletionSource <bool>();
                var taskCompletionSourceListener22 = new TaskCompletionSource <bool>();

                var listener1      = TargetView.AttachListener("event1_name");
                listener1.Handler += delegate {
                    listener1Counter++;
                    taskCompletionSourceListener1.SetResult(true);
                };

                var listener2      = TargetView.AttachListener("event2_name");
                listener2.Handler += delegate {
                    listener2Counter++;
                    taskCompletionSourceListener21.SetResult(true);
                };
                listener2.Handler += delegate {
                    listener2Counter++;
                    taskCompletionSourceListener22.SetResult(true);
                };

                await Load($"<html><script>{listener1}{listener2}</script><body></body></html>");
                Task.WaitAll(taskCompletionSourceListener1.Task, taskCompletionSourceListener21.Task, taskCompletionSourceListener22.Task);

                Assert.AreEqual(1, listener1Counter);
                Assert.AreEqual(2, listener2Counter);
            });
        }
示例#2
0
        public void ListenersAreCalled()
        {
            var listenerCalled = false;
            var listener       = TargetView.AttachListener("event_name", () => listenerCalled = true);

            LoadAndWaitReady($"<html><script>{listener}</script><body></body></html>");
            WaitFor(() => listenerCalled);
            Assert.IsTrue(listenerCalled);
        }
示例#3
0
        public void ListenersAreCalledInDispatcherThread()
        {
            bool?canAccessDispatcher = null;
            var  listener            = TargetView.AttachListener("event_name", () => canAccessDispatcher = TargetView.Dispatcher.CheckAccess(), executeInUI: true);

            LoadAndWaitReady($"<html><script>{listener}</script><body></body></html>");
            WaitFor(() => canAccessDispatcher != null);
            Assert.IsTrue(canAccessDispatcher);
        }
示例#4
0
        public async Task ListenersAreCalledInDispatcherThread()
        {
            await Run(async() => {
                var taskCompletionSource = new TaskCompletionSource <bool>();

                var listener        = TargetView.AttachListener("event_name");
                listener.UIHandler += delegate {
                    taskCompletionSource.SetResult(Dispatcher.UIThread.CheckAccess());
                };

                await Load($"<html><script>{listener}</script><body></body></html>");
                var canAccessDispatcher = await taskCompletionSource.Task;

                Assert.IsTrue(canAccessDispatcher, "Listeners are not being called in dispatcher thread!");
            });
        }
示例#5
0
        public void UnhandledExceptionEventIsCalledOnListenerError()
        {
            const string ExceptionMessage = "hey";

            Exception exception = null;

            WithUnhandledExceptionHandling(() => {
                var listener = TargetView.AttachListener("event_name", () => throw new Exception(ExceptionMessage), executeInUI: false);

                LoadAndWaitReady($"<html><script>{listener}</script><body></body></html>");

                WaitFor(() => exception != null);
                Assert.IsTrue(exception.Message.Contains(ExceptionMessage));
            },
                                           e => {
                exception = e;
                return(true);
            });
        }
示例#6
0
        public void ListenersAreCalled()
        {
            var listener1Counter = 0;
            var listener2Counter = 0;

            var listener1 = TargetView.AttachListener("event1_name");

            listener1.Handler += delegate { listener1Counter++; };

            var listener2 = TargetView.AttachListener("event2_name");

            listener2.Handler += delegate { listener2Counter++; };
            listener2.Handler += delegate { listener2Counter++; };

            LoadAndWaitReady($"<html><script>{listener1}{listener2}</script><body></body></html>");
            WaitFor(() => listener1Counter > 0 && listener2Counter > 0);
            Assert.AreEqual(1, listener1Counter);
            Assert.AreEqual(2, listener2Counter);
        }
示例#7
0
        public async Task UnhandledExceptionEventIsCalledOnListenerError()
        {
            await Run(() => {
                var taskCompletionSource      = new TaskCompletionSource <Exception>();
                const string ExceptionMessage = "hey";

                WithUnhandledExceptionHandling(async() => {
                    var listener      = TargetView.AttachListener("event_name");
                    listener.Handler += delegate {
                        throw new Exception(ExceptionMessage);
                    };

                    await Load($"<html><script>{listener}</script><body></body></html>");
                    var exception = await taskCompletionSource.Task;
                    StringAssert.Contains(ExceptionMessage, exception.Message);
                },
                                               e => {
                    taskCompletionSource.SetResult(e);
                    return(true);
                });
            });
        }