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); } }
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); }
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); }