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));
            var    browser2 = new BrowserStub();
            string target2  = "http://some other web address";

            isolator.Navigate(browser2, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");
            Assert.That(browser2.NavigateTarget, Is.EqualTo(null), "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(() => browser2.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded soon after first no longer busy");

            browser.NormalTermination();
            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");
        }
        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 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 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));

            var    browser2 = new BrowserStub();
            string target2  = "http://some other web address";

            isolator.Navigate(browser2, target2);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second navigation should not have proceeded at once");
            Assert.That(browser2.NavigateTarget, Is.EqualTo(null), "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");
            Assert.That(browser2.NavigateTarget, Is.EqualTo(null), "Second navigation should not have proceeded even on Navigated while browser still busy");

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

            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");
        }
        public void SecondNavigation_OnSameBrowser_HappensAtOnce()
        {
            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(target2), "Second navigation should have proceeded at once");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
        }
        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 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 TwoPendingNavigationsOnDifferentBrowsers_WithNavigatedEvents_AreHandledCorrectly()
        {
            var    browser  = new BrowserStub();
            string target   = "any old web address";
            var    isolator = new NavigationIsolator();

            isolator.Navigate(browser, target);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target));
            string target2  = "some other web address";
            var    browser2 = new BrowserStub();

            isolator.Navigate(browser2, target2);
            string target3  = "yet another other web address";
            var    browser3 = new BrowserStub();

            isolator.Navigate(browser3, target3);
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "Second and third navigation should not have proceeded at once");
            Assert.That(browser2.NavigateTarget, Is.Null, "browser 2 should not have navigated anywhere yet");
            Assert.That(browser3.NavigateTarget, Is.Null, "browser 3 should not have navigated anywhere yet");

            browser.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
            Assert.That(browser2.NavigateTarget, Is.EqualTo(target2), "Second navigation should have proceeded (on second browser) first completed");
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "First browser should not have navigated again");
            Assert.That(browser3.NavigateTarget, Is.Null, "browser 3 should not have navigated anywhere when first completed");

            browser2.NormalTermination();
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "nothing new should have happened to browser 1");
            Assert.That(browser2.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
            Assert.That(browser3.NavigateTarget, Is.EqualTo(target3), "Third navigation should have proceeded when second completed");
            Assert.That(browser2.NavigateTarget, Is.EqualTo(target2), "Second browser should not have navigated again");
            Assert.That(browser.NavigateTarget, Is.EqualTo(target), "First browser should not have navigated again");

            browser3.NormalTermination();
            Assert.That(browser3.EventHandlerCount, Is.EqualTo(0), "event handlers should be removed once last navigation completed");
            Assert.That(browser.EventHandlerCount, Is.EqualTo(0), "nothing new should have happened to browser 1");
            Assert.That(browser2.EventHandlerCount, Is.EqualTo(0), "nothing new should have happened to browser 2");
        }
        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");
        }
        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");
        }
        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");
        }
Example #12
0
        private void NavigateAndWait(GeckoWebBrowser browser, string url)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                //browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();

                /* in geckofx14, this never fires (perhaps it does for docs, but not javascript?):
                 * browser.DocumentCompleted -= browser_DocumentNavigated;
                 * browser.DocumentCompleted += browser_DocumentNavigated;
                 */

                browser.Navigated -= browser_DocumentNavigated;
                browser.Navigated += browser_DocumentNavigated;

                _isolator.Navigate(browser, url);

                //in geckofx 14, there wasn't a reliable event for knowing when navigating was done
                //this could be simplified when we upgrade
                DateTime giveUpTime = DateTime.Now.AddSeconds(2);
                while (DateTime.Now < giveUpTime && browser.Tag == null)
                {
                    Application.DoEvents();
                }
                if (browser.Tag == null)
                {
                    throw new ApplicationException("Timed out waiting for browser to configure book");
                }

                //the above doesn't really ensure that the javascript is done. Wait another few seconds.
                DateTime minimumTimeToWait = DateTime.Now.AddSeconds(4);
                while (DateTime.Now < minimumTimeToWait)
                {
                    Application.DoEvents();
                }
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
Example #13
0
        private void NavigateAndWait(GeckoWebBrowser browser, string url)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                browser.DocumentCompleted += browser_DocumentCompleted;

                _isolator.Navigate(browser, url);

                //in geckofx 14, there wasn't a reliable event for knowing when navigating was done
                //this could be simplified when we upgrade
                DateTime giveUpTime = DateTime.Now.AddSeconds(2);
                while (DateTime.Now < giveUpTime && browser.Tag == null)
                {
                    Application.DoEvents();
                    Application.RaiseIdle(new EventArgs());                     //required for Mono
                }
                if (browser.Tag == null)
                {
                    throw new ApplicationException("Timed out waiting for browser to configure book");
                }

                //the above doesn't really ensure that the javascript is done. Wait another few seconds.
                DateTime minimumTimeToWait = DateTime.Now.AddSeconds(4);
                while (DateTime.Now < minimumTimeToWait)
                {
                    Application.DoEvents();
                    Application.RaiseIdle(new EventArgs());                     //required for Mono
                }
            }
            finally
            {
                // Ensure this doesn't get added multiple times, or fire on a disposed browser.
                browser.DocumentCompleted -= browser_DocumentCompleted;
                Cursor.Current             = Cursors.Default;
            }
        }
        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");
        }