Example #1
0
        public void TestViewport_ChangeViewport_VisibleChanged()
        {
            // TODO: probably it's good idea to make this input values random.
            const double offsetX   = 50;
            const double offsetY   = 25;
            const double scaleBias = 1;

            JsVisible offset = new JsVisible(offsetX, offsetY, scaleBias);

            JsVisible visibleBefore = vcPage.GetViewport();
            JsVisible newVisible    = visibleBefore;
            JsVisible visibleAfter;

            newVisible += offset;

            vcPage.SetVisible(newVisible);
            visibleAfter = vcPage.GetViewport();

            Assert.AreEqual(newVisible, visibleAfter);

            newVisible -= offset;

            vcPage.SetVisible(newVisible);
            visibleAfter = vcPage.GetViewport();

            Assert.AreEqual(visibleBefore, visibleAfter);
        }
Example #2
0
        public void TestMouseBehavior_Panning_VisibleChangedCorrectly()
        {
            const int offsetX = 100;
            const int offsetY = 100;

            action = new ActionsExtension(Driver);
            JsVisible visibleBefore = vcPageObj.GetViewport();
            JsVisible visibleAfter;

            action.MoveToElement(vcPageObj.VirtualCanvas, offsetX, offsetY);
            action.ClickAndHold();
            action.MoveByOffset(offsetX, offsetY);
            action.Release();
            action.Perform();

            vcPageObj.WaitAnimation();
            visibleAfter = vcPageObj.GetViewport();

            JsCoordinates offsetScreen;
            JsCoordinates offsetVirtual;

            // Firefox browser had an inaccuracy in 3px.
            offsetScreen  = (Browser == BrowserType.Firefox) ? new JsCoordinates(offsetX - 3, offsetY - 3) : new JsCoordinates(offsetX, offsetY);
            offsetVirtual = vcPageObj.VectorScreenToVirtual(offsetScreen);
            Assert.AreEqual(visibleBefore.CenterX - offsetVirtual.X, visibleAfter.CenterX, 1);
            Assert.AreEqual(visibleBefore.CenterY - offsetVirtual.Y, visibleAfter.CenterY, 1);
        }
Example #3
0
        public void TestUrlNavigation_SetNewVisible_UrlUpdatedCorrectly()
        {
            JsVisible visibleBefore = vcPageObj.GetViewport();
            JsVisible visibleAfter  = new JsVisible(-6000000000, 2000000000, 6000000);
            JsVisible urlVisible    = new JsVisible();

            // Get the query string and extract number values from it.
            // It looks like this: #x=7Ga&y=2500000000&s=7000000.
            string          query = new Uri(Driver.Url).Fragment;
            MatchCollection match = Regex.Matches(query, @"[\d]+");

            // It stores in Ga units here, so multiply by one billion. Also, it's negative value.
            urlVisible.CenterX = Convert.ToDouble(match[0].Value) * (-1000000000);
            urlVisible.CenterY = Convert.ToDouble(match[1].Value);
            urlVisible.Scale   = Convert.ToDouble(match[2].Value);

            Assert.AreEqual(visibleBefore, urlVisible);

            // Change visible and check that url changed also.
            vcPageObj.MoveToVisible(visibleAfter, false);
            vcPageObj.WaitAnimation();

            ExecuteScript("updateLayout();");

            // Get the query string and extract number values from it.
            query = new Uri(Driver.Url).Fragment;
            match = Regex.Matches(query, @"[\d]+");

            // It stores in Ga units here, so multiply by one billion. Also, it's negative value.
            urlVisible.CenterX = Convert.ToDouble(match[0].Value) * (-1000000000);
            urlVisible.CenterY = Convert.ToDouble(match[1].Value);
            urlVisible.Scale   = Convert.ToDouble(match[2].Value);

            Assert.AreEqual(visibleAfter, urlVisible);
        }
        public void TestViewportController_ZoomForcesViewportToExceedMaxPermittedZoomOut_ViewportDoesNotExceedMaxPermittedZoomOut()
        {
            /* Arrange
             * Set up the viewport such that a zoom gesture
             * forces the viewport to exceed maximum zoomout level.
             */
            IWebElement vcElem = Driver.FindElement(By.Id("vc"));

            double maxScale      = ExecuteScriptGetNumber("return window.maxPermitedScale");
            double belowMaxScale = maxScale / 1.1;

            var vc = new VirtualCanvasComponent(Driver);

            vc.SetVisible(new JsVisible(-13.7 * Ga / 2, 0, belowMaxScale));
            vc.UpdateViewport();

            /* Act
             * ZoomOut.
             */
            ExecuteScript(@"setZoomOut()");
            action = new ActionsExtension(Driver);
            action.MoveToElement(vcElem, 1, 1);
            action.DoubleClick();
            action.Perform();
            vc.WaitAnimation();

            /* Assert
             * Verify that the viewport after zooming doesn't
             * exceed the maximum zoomout level.
             */
            var vp = vc.GetViewport();

            Assert.IsTrue(vp.Scale <= maxScale);
        }
Example #5
0
        public void TestViewportController_ZoomForcesViewportToExceedMinPermittedZoomIn_ViewportDoesNotExceedMinPermittedZoomIn()
        {
            GoToUrl();

            double  zoomFactor = ExecuteScriptGetNumber(@"return window.zoomLevelFactor;");
            dynamic timelines  = ExecuteScript("return window.deeperZoomConstraints;");

            for (int i = 0; i < timelines.Count; i++)
            {
                /* Arrange
                 * Set up the viewport such that a zoom gesture
                 * forces the viewport to exceed the minimum zoomin level.
                 */
                Driver.Navigate().Refresh();

                IWebElement vcElem = Driver.FindElement(By.Id("vc"));

                dynamic timeline      = timelines[i];
                double  left          = timeline["left"];
                double  right         = timeline["right"];
                double  minScale      = timeline["scale"];
                double  aboveMinScale = minScale * zoomFactor;

                // for all scale in [minScale, aboveMinScale) => scale / zoomFactor < minScale
                Random rnd   = new Random();
                double scale = minScale + rnd.NextDouble() * (aboveMinScale - minScale);

                var vc = new VirtualCanvasComponent(Driver);
                vc.SetVisible(new JsVisible((left + right) / 2, 0, scale));
                vc.UpdateViewport();

                /* Act
                 * ZoomIn.
                 */
                ActionsExtension act = new ActionsExtension(Driver);
                act.MoveToElement(vcElem, 10, 10);
                act.DoubleClick();
                act.Perform();
                vc.WaitAnimation();

                /* Assert
                 * Verify that the viewport after zooming doesn't
                 * exceed the minimum zoomin level.
                 */
                var vp = vc.GetViewport();
                Assert.IsTrue(vp.Scale >= minScale);
            }
        }
Example #6
0
        public void TestViewportController_PanForcesViewportToExceedLeftBorder_ViewportDoesNotExceedLeftBorder()
        {
            /* Arrange
             * Set up the viewport such that a pan of width
             * forces the viewport to exceed the left border.
             */
            GoToUrl();

            IWebElement vcElem    = Driver.FindElement(By.Id("vc"));
            double      widthInSc = vcElem.Size.Width - 2; // border of 1 px on each side
            double      widthInVc = 1.37 * Ga;
            double      scale     = widthInVc / widthInSc; // 1/10 the age of the universe

            double minLeftCenterX = ExecuteScriptGetNumber(@"return window.maxPermitedTimeRange.left;");

            var vc = new VirtualCanvasComponent(Driver);

            vc.SetVisible(new JsVisible(-13 * Ga, 0, scale));
            vc.UpdateViewport();

            /* Act
             * Pan by width to the right.
             */
            Vector           pan = new Vector(widthInSc, 0);
            ActionsExtension act = new ActionsExtension(Driver);

            act.MoveToElement(vcElem, 0, 0);
            act.ClickAndHold();
            act.MoveByOffset(Convert.ToInt32(pan.X), Convert.ToInt32(pan.Y));
            act.Release();
            act.Perform();
            vc.WaitAnimation();

            /* Without the horizontal contraints the viewport centerX will exceed minLeftCenterX
             * after a pan of width as (-13Ga + -1.37Ga < 13.7Ga).
             * With the contraints in place viewport centerX is limited to minLeftCenterX.
             */

            /* Assert
             * Verify that the viewport centerX after
             * panning doesn't exceed the minLeftCenterX.
             */
            var    vp        = vc.GetViewport();
            double vpCenterX = vp.CenterX;

            Assert.AreEqual(minLeftCenterX, vpCenterX, 5);
        }
Example #7
0
        public void TestViewportController_ZoomForcesViewportToExceedMaxPermittedZoomOut_ViewportDoesNotExceedMaxPermittedZoomOut()
        {
            /* Arrange
             * Set up the viewport such that a zoom gesture
             * forces the viewport to exceed maximum zoomout level.
             */
            GoToUrl();

            IWebElement vcElem = Driver.FindElement(By.Id("vc"));
            double      width  = vcElem.Size.Width - 2; // border of 1 px on each side

            double additionalPermitedPixels = ExecuteScriptGetNumber(@"return window.timelinesAbsenceInterval;");
            double zoomFactor = ExecuteScriptGetNumber(@"return window.zoomLevelFactor;");

            double maxScaleWithoutPadding = 13.7 * Ga / width;
            double maxScale      = (13.7 * Ga + 2 * additionalPermitedPixels * maxScaleWithoutPadding) / width;
            double belowMaxScale = maxScale / zoomFactor;

            // for all scale in (belowMaxScale, maxScale] => scale * zoomFactor > maxScale
            Random rnd   = new Random();
            double scale = belowMaxScale + rnd.NextDouble() * (maxScale - belowMaxScale);

            var vc = new VirtualCanvasComponent(Driver);

            vc.SetVisible(new JsVisible(-13.7 * Ga / 2, 0, scale));
            vc.UpdateViewport();

            /* Act
             * ZoomOut.
             */
            ExecuteScript(@"setZoomOut()");
            ActionsExtension act = new ActionsExtension(Driver);

            act.MoveToElement(vcElem, 10, 10);
            act.DoubleClick();
            act.Perform();
            vc.WaitAnimation();

            /* Assert
             * Verify that the viewport after zooming doesn't
             * exceed the maximum zoomout level.
             */
            var vp = vc.GetViewport();

            Assert.IsTrue(vp.Scale <= maxScale);
        }
        public void TestViewportController_PanForcesViewportToExceedRightBorder_ViewportDoesNotExceedRightBorder()
        {
            /* Arrange
             * Set up the viewport such that a pan of width
             * forces the viewport to exceed the right border.
             */
            IWebElement vcElem          = Driver.FindElement(By.Id("vc"));
            double      widthInSc       = vcElem.Size.Width - 2; // border of 1 px on each side
            double      widthInVc       = 1.37 * Ga;
            double      scale           = widthInVc / widthInSc; // 1/10 the age of the universe
            double      maxRightCenterX = 0;

            var vc = new VirtualCanvasComponent(Driver);

            vc.SetVisible(new JsVisible(-1 * Ga, 0, scale));
            vc.UpdateViewport();

            /* Act
             * Pan by width to the left.
             */
            Vector pan = new Vector(1 - widthInSc, 0);

            action = new ActionsExtension(Driver);
            action.MoveToElement(vcElem, (int)widthInSc, 1);
            action.ClickAndHold();
            action.MoveByOffset(Convert.ToInt32(pan.X), Convert.ToInt32(pan.Y));
            action.Release();
            action.Perform();
            vc.WaitAnimation();

            /* Assert
             * Verify that the viewport centerX after
             * panning doesn't exceed the maxRightCenterX.
             */
            var    vp        = vc.GetViewport();
            double vpCenterX = vp.CenterX;

            Assert.IsTrue(vpCenterX <= maxRightCenterX);
        }
Example #9
0
        public void TestRegimes_ClickHumanityLink_HumanityTimelineIsVisible()
        {
            Point     linkPosition  = vcPageObj.HumanityLink.Location;
            JsVisible visibleBefore = vcPageObj.GetViewport();

            action = new ActionsExtension(Driver);

            // Click on the regime link.
            action.MoveByOffset(linkPosition.X + 5, linkPosition.Y + 2).Click().Perform();

            vcPageObj.WaitAnimation();

            JsVisible     visibleAfter   = vcPageObj.GetViewport();
            JsTimeline    timeline       = GetHumanityTimeline();
            double        width          = timeline.right - timeline.left;
            JsCoordinates timelineCenter = new JsCoordinates(timeline.left + width / 2, timeline.y + timeline.height / 2);

            Assert.IsTrue(IsTimlineInFullSize(visibleAfter, timeline));
            Assert.AreEqual(visibleAfter.CenterX, timelineCenter.X, 1);
            Assert.AreEqual(visibleAfter.CenterY, timelineCenter.Y, 1);
            Assert.AreNotEqual(visibleBefore, visibleAfter);
        }