Пример #1
0
        private void evaluateJavascriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LogWriteLine("Request evaluation for [document.body.scrollWidth, document.body.scrollHeight]");
            var retval = WebBrowser.EvaluateJavascript("[document.body.scrollWidth,document.body.scrollHeight]", (value, exception) => {
                if (value != null)
                {
                    var v0 = value.GetValue(0);
                    if (v0 == null)
                    {
                        // seems to be fixed in  3.2987.3
                        MessageBox.Show("This test is broken, please refer to issue #65 in the project repo.");
                    }
                    else
                    {
                        LogWriteLine("Evaluation callback with value: scrollWidth={0}, scrollHeight={1}.",
                                     value.GetValue(0).IntValue, value.GetValue(1).IntValue);
                    }
                }
                else if (exception != null)
                {
                    LogWriteLine("Evaluation callback with exception: {0}.", exception.Message);
                }
                else
                {
                    LogWriteLine("Evaluation callback with value == null && exception == null.");
                }
            });

            if (!retval)
            {
                LogWriteLine("WebBrowser.EvaluateJavascript returned false, evaluation will not succeed.");
            }
        }
Пример #2
0
        private void RemoteLayerStressTest()
        {
            int domCount  = 0;
            int evalCount = 0;

            for (int i = 0; i < 100; ++i)
            {
                WebBrowser.ExecuteJavascript("document.getElementById('testbutton1').click()");

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton2').click()");

                WebBrowser.EvaluateJavascript("document.getElementById('testbutton3').click()", (value, exception) => {
                    LogWriteLine("EVAL {0}: document.getElementById('testbutton3').click() = {1}", ++evalCount, value.StringValue);
                });

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton4').click()");

                WebBrowser.EvaluateJavascript("document.getElementById('testbutton5').click()", (value, exception) => {
                    LogWriteLine("EVAL {0}: document.getElementById('testbutton5').click() = {1}", ++evalCount, value.StringValue);
                });

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton6').click()");

                WebBrowser.EvaluateJavascript("doubleCallback('foo', 123)", (value, exception) => {
                    LogWriteLine("EVAL {0}: doubleCallback('foo', 123) = {1}", ++evalCount, value.StringValue);
                });

                WebBrowser.VisitDom((doc, b) => {
                    //LogWriteLine("VisitDom {0} {1}", doc.ToString(), b.ToString());
                    var n      = doc.GetElementById("testbutton6");
                    var bounds = n.ElementBounds;
                    LogWriteLine("DOM {0} - testbutton6 = {1} ({2}, {3})", ++domCount, n.AsMarkup, bounds.Width, bounds.Height);
                    // must dispose node, otherwise finalizer crash in the render process.
                    n.Dispose();
                });

                //WebBrowser.VisitDom(VisitDOMCallback);
                //for(int ii = 0; ii < 100; ++ii)
                //    VisitDomButton_Click(null, null);

                //MessageBox.Show("GC.WaitForPendingFinalizers();");
                //GC.Collect();
                //GC.WaitForPendingFinalizers();

                // give the browser some time to render and do message loop work
                //Thread.Sleep(20);
            }
        }
Пример #3
0
        private void evaluateJavascriptSynchronouslyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CfxRemoteCallContext.IsInContext && CfrRuntime.CurrentlyOn(CfxThreadId.Renderer))
            {
                throw new Exception("Doing this on the render thread would deadlock.");
            }

            var waitLock = new object();

            lock (waitLock) {
                string documentAllLength = null;

                var evaluationStarted = WebBrowser.EvaluateJavascript("'document.all.length = ' + document.all.length",
                                                                      // Don't invoke, otherwise the ui thread will deadlock!
                                                                      JSInvokeMode.DontInvoke,
                                                                      (v, ex) => {
                    Monitor.Enter(waitLock);
                    try {
                        documentAllLength = v.StringValue;
                    } finally {
                        Monitor.PulseAll(waitLock);
                        Monitor.Exit(waitLock);
                    }
                }
                                                                      );

                if (evaluationStarted)
                {
                    var success = Monitor.Wait(waitLock, 5000);
                    if (success)
                    {
                        LogWriteLine("Synchronous evaluation succeeded: {0}", documentAllLength);
                    }
                    else
                    {
                        LogWriteLine("Evaluation not finished after 5 seconds, giving up.");
                    }
                }
                else
                {
                    LogWriteLine("Failed to start evaluation.");
                }
            }
        }
Пример #4
0
        private void RemoteLayerStressTest()
        {
            for (int i = 0; i < 100; ++i)
            {
                WebBrowser.ExecuteJavascript("document.getElementById('testbutton1').click()");

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton2').click()");

                WebBrowser.EvaluateJavascript("document.getElementById('testbutton3').click()", (value, exception) => {
                    LogWriteLine("document.getElementById('testbutton3').click()");
                    LogWriteLine(value.StringValue);
                });

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton4').click()");

                WebBrowser.EvaluateJavascript("document.getElementById('testbutton5').click()", (value, exception) => {
                    LogWriteLine("document.getElementById('testbutton5').click()");
                    LogWriteLine(value.StringValue);
                });

                WebBrowser.ExecuteJavascript("document.getElementById('testbutton6').click()");

                WebBrowser.EvaluateJavascript("doubleCallback('foo', 123)", (value, exception) => {
                    LogWriteLine("doubleCallback('foo', 123)");
                    LogWriteLine(value.StringValue);
                });

                WebBrowser.VisitDom((doc, b) => {
                    LogWriteLine("VisitDom {0} {1}", doc.ToString(), b.ToString());
                    LogWriteLine("testbutton6", doc.GetElementById("testbutton6").AsMarkup);
                });

                // give the browser some time to render and do message loop work
                //Thread.Sleep(20);
            }
        }
Пример #5
0
 void JSHelloWorldButton_Click(object sender, EventArgs e)
 {
     WebBrowser.EvaluateJavascript("var test = 10; var result = CfxHelloWorld(test, 'foo'); document.body.innerHTML = result;", HelloWorldResult);
 }