Navigate() 공개 메소드

Navigate the specified browser to the specified url as soon as it is safe to do so (that is, immediately or when all other navigations we know about that were started sooner have completed). Must be called on UI thread.
public Navigate ( Gecko.GeckoWebBrowser browser, string url ) : void
browser Gecko.GeckoWebBrowser
url string
리턴 void
        public void Isolation_AfterLongDelay_GivesUpAndMovesOn()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));

            var browser2 = new BrowserStub();
            string target2 = "http://some other web address";
            isolator.Navigate(browser2, target2);
            var browser3 = new BrowserStub();
            string target3 = "http://yet another web address";
            isolator.Navigate(browser3, target3);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");
            var start = DateTime.Now;
            while (DateTime.Now - start < new TimeSpan(0, 0, 0, 2, 300))
                Application.DoEvents(); // allow timer to tick.
            Assert.That(() => browser2.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded eventually");

            browser2.NormalTermination(); // the second request.
            Assert.That(() => browser3.NavigateTarget, Is.EqualTo(target3), "Third navigation should have proceeded when second finished");

            browser3.NormalTermination(); // hopefully from the third.
            Assert.That(browser3.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
 public void IdleNavigation_NavigationInProgress_ReturnsFalse_NeverProceeds()
 {
     var browser = new BrowserStub();
     string target = "http://any old web address";
     var isolator = new NavigationIsolator();
     isolator.Navigate(browser, target);
     Assert.That(browser.NavigateTarget, Is.EqualTo(target));
     string target2 = "http://some other web address";
     Assert.That(isolator.NavigateIfIdle(browser, target2), Is.False);
     browser.NormalTermination();
     Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed after navigation completes");
     Assert.That(browser.NavigateTarget, Is.EqualTo(target), "failed idle navigation should not happen");
 }
예제 #3
0
        private bool OpenTempFileInBrowser(GeckoWebBrowser browser, string filePath)
        {
            var  order = (ThumbnailOrder)browser.Tag;
            bool navigationHappened = true;

            if (_syncControl.InvokeRequired)
            {
                using (var waitHandle = new AutoResetEvent(false))
                {
                    order.WaitHandle = waitHandle;
                    _syncControl.BeginInvoke(new Action <string>(path =>
                    {
                        if (!_isolator.NavigateIfIdle(browser, path))
                        {
                            navigationHappened = false;                             // some browser is busy, try again later.
                        }
                    }), filePath);
                    waitHandle.WaitOne(10000);
                }
                if (_disposed || !navigationHappened || order.Canceled)
                {
                    return(false);
                }
                if (!order.Done)
                {
                    Logger.WriteEvent("HtmlThumbNailer ({1}): Timed out on ({0})", order.ThumbNailFilePath,
                                      Thread.CurrentThread.ManagedThreadId);
#if DEBUG
                    if (!_thumbnailTimeoutAlreadyDisplayed)
                    {
                        _thumbnailTimeoutAlreadyDisplayed = true;
                        _syncControl.Invoke((Action)(() => Debug.Fail("(debug only) Make thumbnail timed out (won't show again)")));
                    }
#endif
                    return(false);
                }
            }
            else
            {
                _isolator.Navigate(browser, filePath);                 // main thread, not async, we really need it now.
                while (!order.Done)
                {
                    Application.DoEvents();
                    Application.RaiseIdle(new EventArgs());                             // needed on Linux to avoid deadlock starving browser navigation
                }
            }

            return(true);
        }
        public void NoLongerBusy_EvenWithoutEvent_IsNoticed()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            string target2 = "http://some other web address";
            isolator.Navigate(browser, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");
            browser.IsBusy = false; // finished but did not raise event.
            var start = DateTime.Now;
            while (DateTime.Now - start < new TimeSpan(0, 0,0, 0, 150))
                Application.DoEvents(); // allow timer to tick.
            Assert.That(() => browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded soon after first no longer busy");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void RegularNavigation_DelayedProperlyByIdleNavigation()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            Assert.That(isolator.NavigateIfIdle(browser, target), Is.True);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));

            string target2 = "http://some other web address";
            isolator.Navigate(browser, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");

            browser.NormalTermination();
            Assert.That(browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded when first completed");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void TwoPendingNavigations_WithNavigatedEvents_AreHandledCorrectly()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            var browser2 = new BrowserStub();
            string target2 = "http://some other web address";
            isolator.Navigate(browser2, target2);
            var browser3 = new BrowserStub();
            string target3 = "http://yet another other web address";
            isolator.Navigate(browser3, target3);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second and third navigation should not have proceeded at once");

            browser.NormalTermination();
            Assert.That(browser2.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded when first completed (but third should not)");

            browser2.NormalTermination();
            Assert.That(browser3.NavigateTarget, Is.EqualTo(target3), "Third navigation should have proceeded when second completed");

            browser3.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void SpuriousNavigatedEvents_AreIgnored()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            string target2 = "http://some other web address";
            isolator.Navigate(browser, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");

            browser.RaiseNavigated(this, new EventArgs()); // got the event notification, but still busy.
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded even on Navigated while browser still busy");

            browser.NormalTermination();
            Assert.That(browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded when first completed (and browser no longer busy)");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void SingleTask_AfterLongDelay_AllowsIdleNavigation()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));

            string target2 = "http://some other web address";
            var start = DateTime.Now;
            var success = false;
            while (!success && DateTime.Now - start < new TimeSpan(0, 0, 0, 2, 300))
            {
                success = isolator.NavigateIfIdle(browser, target2);
                Application.DoEvents(); // allow timer to tick.
            }
            Assert.That(() => browser.NavigateTarget, Is.EqualTo(target2), "Idle navigation should have proceeded eventually");
            Assert.That(success, "NavigateIfIdle should eventually succeed");

            browser.NormalTermination(); // possibly the long-delayed notification of the first nav, but more likely the idle navigation.
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
 public void SimpleNavigation_JustHappens()
 {
     var browser = new BrowserStub();
     string target = "http://any old web address";
     var isolator = new NavigationIsolator();
     isolator.Navigate(browser, target);
     Assert.That(browser.NavigateTarget, Is.EqualTo(target));
     browser.NormalTermination();
     Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed after navigation completes");
 }
        public void SecondRequest_WhenFirstNoLongerBusy_ProceedsAtOnce()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            browser.IsBusy = false; // clear state without raising event
            string target2 = "http://some other web address";
            isolator.Navigate(browser, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded since browser is already not busy");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void SecondNavigation_OnSameBrowser_HappensWhenFirstRaisesNavigated()
        {
            var browser = new BrowserStub();
            string target = "http://any old web address";
            var isolator = new NavigationIsolator();
            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            string target2 = "http://some other web address";
            isolator.Navigate(browser, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");

            browser.NormalTermination();
            Assert.That(browser.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded when first completed");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        public void SameBrowser_ReplacesPending()
        {
            var isolator = new NavigationIsolator();
            var browser = new BrowserStub();
            string target = "http://whatever";
            isolator.Navigate(browser, target);

            var browser2 = new BrowserStub();
            string target2A = "http://first";
            isolator.Navigate(browser2, target2A);
            string target2B = "http://second";
            isolator.Navigate(browser2, target2B);
            // Signal the first browser to finish.
            browser.NormalTermination();
            Assert.That(() => browser2.NavigateTarget, Is.EqualTo(target2B), "Second navigation should have proceeded with its second choice");
            // Signal the second browser to finish.
            browser2.NormalTermination();

            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
            Assert.That(browser2.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }