Exemple #1
0
        public void Calling_ExecuteLayoutPass_From_ExecuteInitialLayoutPass_Does_Not_Break_Measure()
        {
            // Test for issue #3550.
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };
            var count = 0;

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = false;

            control.DoMeasureOverride = (l, s) =>
            {
                if (count++ == 0)
                {
                    control.InvalidateMeasure();
                    root.LayoutManager.ExecuteLayoutPass();
                    return(new Size(100, 100));
                }
                else
                {
                    return(new Size(200, 200));
                }
            };

            root.InvalidateMeasure();
            control.InvalidateMeasure();
            root.LayoutManager.ExecuteInitialLayoutPass();

            Assert.Equal(new Size(200, 200), control.Bounds.Size);
            Assert.Equal(new Size(200, 200), control.DesiredSize);
        }
Exemple #2
0
        public void Measures_In_Correct_Order()
        {
            LayoutTestControl control1;
            LayoutTestControl control2;
            var root = new LayoutTestRoot
            {
                Child = control1 = new LayoutTestControl
                {
                    Child = control2 = new LayoutTestControl(),
                }
            };

            var order = new List <ILayoutable>();

            Size MeasureOverride(ILayoutable control, Size size)
            {
                order.Add(control);
                return(new Size(10, 10));
            }

            root.DoMeasureOverride     = MeasureOverride;
            control1.DoMeasureOverride = MeasureOverride;
            control2.DoMeasureOverride = MeasureOverride;
            root.LayoutManager.ExecuteInitialLayoutPass();

            control2.InvalidateMeasure();
            control1.InvalidateMeasure();
            root.InvalidateMeasure();

            order.Clear();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.Equal(new ILayoutable[] { root, control1, control2 }, order);
        }
Exemple #3
0
        public void LayoutManager_Should_Recover_From_Infinite_Loop_On_Measure()
        {
            // Test for issue #3041.
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = false;

            control.DoMeasureOverride = (l, s) =>
            {
                control.InvalidateMeasure();
                return(new Size(100, 100));
            };

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            // This is the important part: running a second layout pass in which we exceed the maximum
            // retries causes LayoutQueue<T>.Info.Count to exceed _maxEnqueueCountPerLoop.
            root.LayoutManager.ExecuteLayoutPass();

            control.Measured          = false;
            control.DoMeasureOverride = null;

            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(control.Measured);
            Assert.True(control.IsMeasureValid);
        }
Exemple #4
0
        public void LayoutManager_Should_Prevent_Infinite_Loop_On_Arrange()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Arranged = false;

            int cnt    = 0;
            int maxcnt = 100;

            control.DoArrangeOverride = (l, s) =>
            {
                //emulate a problem in the logic of a control that triggers
                //invalidate measure during arrange
                //it can lead to infinity loop in layoutmanager
                if (++cnt < maxcnt)
                {
                    control.InvalidateArrange();
                }

                return(new Size(100, 100));
            };

            control.InvalidateArrange();

            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(cnt < 100);
        }
Exemple #5
0
        public void Measures_Parent_Of_Newly_Added_Control()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot();

            root.LayoutManager.ExecuteInitialLayoutPass();
            root.Child    = control;
            root.Measured = root.Arranged = false;

            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(root.Measured);
            Assert.True(root.Arranged);
            Assert.True(control.Measured);
            Assert.True(control.Arranged);
        }
Exemple #6
0
        public void Arranges_InvalidateArranged_Control()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = control.Arranged = false;

            control.InvalidateArrange();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(control.Measured);
            Assert.True(control.Arranged);
        }
Exemple #7
0
        public void Doesnt_Measure_And_Arrange_InvalidateMeasured_Control_When_TopLevel_Is_Not_Visible()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control, IsVisible = false
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(control.Measured);
            Assert.False(control.Arranged);
        }
Exemple #8
0
        public void Doesnt_Measure_Removed_Control()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.Child = null;
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(control.Measured);
            Assert.False(control.Arranged);
        }
Exemple #9
0
        public void LayoutManager_Execute_Layout_Pass_Should_Clear_Queued_LayoutPasses()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            int layoutCount = 0;

            root.LayoutUpdated += (_, _) => layoutCount++;

            root.LayoutManager.InvalidateArrange(control);
            root.LayoutManager.ExecuteInitialLayoutPass();

            Dispatcher.UIThread.RunJobs(DispatcherPriority.Layout);

            Assert.Equal(1, layoutCount);
        }