示例#1
0
        public void ValidateOneScrollerScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport feature is not available below RS5");
                return;
            }

            var      realizationRects         = new List <Rect>();
            Scroller scroller                 = null;
            var      viewChangeCompletedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 600), realizationRects),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                scroller = new Scroller
                {
                    Content = repeater,
                    Width   = 200,
                    Height  = 300
                };

                Content = scroller;
                Content.UpdateLayout();

                Verify.AreEqual(2, realizationRects.Count);
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 300), realizationRects[1]);
                realizationRects.Clear();

                scroller.ViewChangeCompleted += (Scroller sender, ScrollerViewChangeCompletedEventArgs args) =>
                {
                    viewChangeCompletedEvent.Set();
                };
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                scroller.ChangeOffsets(new ScrollerChangeOffsetsOptions(0.0, 100.0, ScrollerViewKind.Absolute, ScrollerViewChangeKind.DisableAnimation, ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints));
            });
            Verify.IsTrue(viewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 300), realizationRects.Last());
                realizationRects.Clear();

                viewChangeCompletedEvent.Reset();
                scroller.ChangeZoomFactor(new ScrollerChangeZoomFactorOptions(2.0f, ScrollerViewKind.Absolute, Vector2.Zero, ScrollerViewChangeKind.DisableAnimation, ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints));
            });
            Verify.IsTrue(viewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(
                    new Rect(0, 100, 100, 150),
                    realizationRects.Last());
                realizationRects.Clear();
            });
        }
示例#2
0
        public void VerifyPrimaryCommandsCanOverflowToSecondaryItemsControl()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled pre-RS2 because CommandBarFlyout is not supported pre-RS2");
                return;
            }

            CommandBarFlyout flyout       = null;
            Button           flyoutTarget = null;

            RunOnUIThread.Execute(() =>
            {
                flyout = new CommandBarFlyout()
                {
                    Placement = FlyoutPlacementMode.Right
                };

                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 1"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 2"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 3"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 4"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 5"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 6"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 7"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 8"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 9"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 10"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 11"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 12"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 13"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 14"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 15"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 16"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 17"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 18"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 19"
                });
                flyout.PrimaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 20"
                });

                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 21"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 22"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 23"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 24"
                });
                flyout.SecondaryCommands.Add(new AppBarButton()
                {
                    Label = "Item 25"
                });

                flyoutTarget = new Button()
                {
                    Content = "Click for flyout"
                };
                Content = flyoutTarget;
                Content.UpdateLayout();
            });

            OpenFlyout(flyout, flyoutTarget);

            RunOnUIThread.Execute(() =>
            {
                Popup flyoutPopup     = VisualTreeHelper.GetOpenPopups(Window.Current).Last();
                CommandBar commandBar = TestUtilities.FindDescendents <CommandBar>(flyoutPopup).Single();

                IList <ItemsControl> itemsControls = TestUtilities.FindDescendents <ItemsControl>(commandBar);

                Log.Comment("We expect there to be 2 ItemsControls inside the CommandBar; {0} were found.", itemsControls.Count);
                Verify.AreEqual(2, itemsControls.Count);

                ItemsControl primaryItemsControl   = itemsControls[0];
                ItemsControl secondaryItemsControl = itemsControls[1];

                Log.Comment("We expect there to be 9 items located inside the primary ItemsControl; {0} were found.", primaryItemsControl.Items.Count);
                Verify.AreEqual(9, primaryItemsControl.Items.Count);
                Log.Comment("We expect there to be 17 items located inside the secondary ItemsControl (16 + autogenerated separator); {0} were found.", secondaryItemsControl.Items.Count);
                Verify.AreEqual(17, secondaryItemsControl.Items.Count);
            });

            CloseFlyout(flyout);
        }
        public void ChangeOffsetsWithAttachedScrollControllers()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping failing test on RS1.");
                return;
            }

            Scroller  scroller = null;
            Rectangle rectangleScrollerChild = null;
            CompositionScrollController horizontalScrollController = null;
            CompositionScrollController verticalScrollController   = null;
            AutoResetEvent loadedEvent = new AutoResetEvent(false);
            AutoResetEvent viewChangeCompletedEvent = new AutoResetEvent(false);
            int            hOffsetChangeId          = -1;
            int            vOffsetChangeId          = -1;

            RunOnUIThread.Execute(() =>
            {
                rectangleScrollerChild = new Rectangle();
                scroller = new Scroller();
                horizontalScrollController = new CompositionScrollController();
                verticalScrollController   = new CompositionScrollController();

                horizontalScrollController.Orientation = Orientation.Horizontal;

                horizontalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                verticalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                scroller.HorizontalScrollController = horizontalScrollController;
                scroller.VerticalScrollController   = verticalScrollController;

                SetupUIWithScrollControllers(
                    scroller,
                    rectangleScrollerChild,
                    horizontalScrollController,
                    verticalScrollController,
                    loadedEvent);

                horizontalScrollController.OffsetChangeCompleted += (CompositionScrollController sender, CompositionScrollControllerOffsetChangeCompletedEventArgs args) =>
                {
                    Log.Comment("ChangeOffset completed (horizontal). OffsetChangeId=" + args.OffsetChangeId + ", Result=" + args.Result);

                    Log.Comment("Setting completion event");
                    viewChangeCompletedEvent.Set();
                };

                verticalScrollController.OffsetChangeCompleted += (CompositionScrollController sender, CompositionScrollControllerOffsetChangeCompletedEventArgs args) =>
                {
                    Log.Comment("ChangeOffset completed (vertical). OffsetChangeId=" + args.OffsetChangeId + ", Result=" + args.Result);
                };
            });

            WaitForEvent("Waiting for Loaded event", loadedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("HorizontalScrollController size={0}, {1}", horizontalScrollController.ActualWidth, horizontalScrollController.ActualHeight);
                Log.Comment("VerticalScrollController size={0}, {1}", verticalScrollController.ActualWidth, verticalScrollController.ActualHeight);
            });

            Log.Comment("Jump to zoomFactor 0.75");
            ChangeZoomFactor(
                scroller,
                0.75f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Jumping to horizontal offset");
                hOffsetChangeId = horizontalScrollController.ChangeOffset(
                    (c_defaultUIScrollerChildWidth * 0.75 - c_defaultUIScrollerWidth) / 4.0,
                    ScrollerViewKind.Absolute,
                    ScrollerViewChangeKind.DisableAnimation);

                Log.Comment("Jumping to vertical offset");
                vOffsetChangeId = verticalScrollController.ChangeOffset(
                    (c_defaultUIScrollerChildHeight * 0.75 - c_defaultUIScrollerHeight) / 4.0,
                    ScrollerViewKind.Absolute,
                    ScrollerViewChangeKind.DisableAnimation);

                Verify.AreEqual(hOffsetChangeId, vOffsetChangeId);
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(scroller.HorizontalOffset, (c_defaultUIScrollerChildWidth * 0.75 - c_defaultUIScrollerWidth) / 4.0);
                Verify.AreEqual(scroller.VerticalOffset, (c_defaultUIScrollerChildHeight * 0.75 - c_defaultUIScrollerHeight) / 4.0);

                Log.Comment("Animating to horizontal offset");
                hOffsetChangeId = horizontalScrollController.ChangeOffset(
                    (c_defaultUIScrollerChildWidth * 0.75 - c_defaultUIScrollerWidth) / 2.0,
                    ScrollerViewKind.Absolute,
                    ScrollerViewChangeKind.AllowAnimation);

                Log.Comment("Animating to vertical offset");
                vOffsetChangeId = verticalScrollController.ChangeOffset(
                    (c_defaultUIScrollerChildHeight * 0.75 - c_defaultUIScrollerHeight) / 2.0,
                    ScrollerViewKind.Absolute,
                    ScrollerViewChangeKind.AllowAnimation);

                Verify.AreEqual(hOffsetChangeId, vOffsetChangeId);

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(scroller.HorizontalOffset, (c_defaultUIScrollerChildWidth * 0.75 - c_defaultUIScrollerWidth) / 2.0);
                Verify.AreEqual(scroller.VerticalOffset, (c_defaultUIScrollerChildHeight * 0.75 - c_defaultUIScrollerHeight) / 2.0);
            });
        }
示例#4
0
        public void ValidateTwoScrollersScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport feature is not available below RS5");
                return;
            }

            var      realizationRects               = new List <Rect>();
            Scroller horizontalScroller             = null;
            Scroller verticalScroller               = null;
            var      horizontalScrollCompletedEvent = new AutoResetEvent(false);
            var      verticalScrollCompletedEvent   = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 500), realizationRects),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                horizontalScroller = new Scroller
                {
                    Content            = repeater,
                    ContentOrientation = ContentOrientation.Horizontal
                };

                // Placing a Grid in between two Scroller controls to avoid
                // unsupported combined use of facades and ElementCompositionPreview.
                var grid = new Grid();
                grid.Children.Add(horizontalScroller);

                verticalScroller = new Scroller
                {
                    Content            = grid,
                    Width              = 200,
                    Height             = 200,
                    ContentOrientation = ContentOrientation.Vertical
                };

                Content = verticalScroller;
                Content.UpdateLayout();

                Verify.AreEqual(2, realizationRects.Count);
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 200), realizationRects[1]);
                realizationRects.Clear();

                horizontalScroller.ScrollCompleted += (Scroller sender, ScrollCompletedEventArgs args) =>
                {
                    horizontalScrollCompletedEvent.Set();
                };

                verticalScroller.ScrollCompleted += (Scroller sender, ScrollCompletedEventArgs args) =>
                {
                    verticalScrollCompletedEvent.Set();
                };
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                verticalScroller.ScrollTo(0.0, 100.0, new ScrollOptions(AnimationMode.Disabled, SnapPointsMode.Ignore));
            });
            Verify.IsTrue(verticalScrollCompletedEvent.WaitOne(DefaultWaitTimeInMS));
            CompositionPropertySpy.SynchronouslyTickUIThread(1);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 200), realizationRects.Last());
                realizationRects.Clear();

                // Max viewport offset is (300, 300). Horizontal viewport offset
                // is expected to get coerced from 400 to 300.
                horizontalScroller.ScrollTo(400.0, 100.0, new ScrollOptions(AnimationMode.Disabled, SnapPointsMode.Ignore));
            });
            Verify.IsTrue(horizontalScrollCompletedEvent.WaitOne(DefaultWaitTimeInMS));
            CompositionPropertySpy.SynchronouslyTickUIThread(1);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(300, 100, 200, 200), realizationRects.Last());
                realizationRects.Clear();
            });
        }
示例#5
0
        public void CanBringIntoViewElements()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                // Note that UIElement.BringIntoViewRequested was added in RS4, and effective viewport was added in RS5
                Log.Warning("Skipping since version is less than RS5 and effective viewport feature is not available below RS5");
                return;
            }

            Scroller      scroller         = null;
            ItemsRepeater repeater         = null;
            var           rootLoadedEvent  = new AutoResetEvent(initialState: false);
            var           viewChangedEvent = new AutoResetEvent(initialState: false);
            var           waitingForIndex  = -1;
            var           indexRealized    = new AutoResetEvent(initialState: false);

            var viewChangedOffsets = new List <double>();

            RunOnUIThread.Execute(() =>
            {
                var lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam laoreet erat vel massa rutrum, eget mollis massa vulputate. Vivamus semper augue leo, eget faucibus nulla mattis nec. Donec scelerisque lacus at dui ultricies, eget auctor ipsum placerat. Integer aliquet libero sed nisi eleifend, nec rutrum arcu lacinia. Sed a sem et ante gravida congue sit amet ut augue. Donec quis pellentesque urna, non finibus metus. Proin sed ornare tellus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam laoreet erat vel massa rutrum, eget mollis massa vulputate. Vivamus semper augue leo, eget faucibus nulla mattis nec. Donec scelerisque lacus at dui ultricies, eget auctor ipsum placerat. Integer aliquet libero sed nisi eleifend, nec rutrum arcu lacinia. Sed a sem et ante gravida congue sit amet ut augue. Donec quis pellentesque urna, non finibus metus. Proin sed ornare tellus.";
                var root  = (Grid)XamlReader.Load(TestUtilities.ProcessTestXamlForRepo(
                                                      @"<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
                             xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                             xmlns:controls='using:Microsoft.UI.Xaml.Controls' 
                             xmlns:primitives='using:Microsoft.UI.Xaml.Controls.Primitives'> 
                         <Grid.Resources>
                           <controls:StackLayout x:Name='VerticalStackLayout' />
                           <controls:RecyclingElementFactory x:Key='ElementFactory'>
                             <controls:RecyclingElementFactory.RecyclePool>
                               <controls:RecyclePool />
                             </controls:RecyclingElementFactory.RecyclePool>
                             <DataTemplate x:Key='ItemTemplate'>
                               <Border Background='LightGray' Margin ='5'>
                                 <TextBlock Text='{Binding}' TextWrapping='WrapWholeWords' />
                               </Border>
                             </DataTemplate>
                           </controls:RecyclingElementFactory>
                         </Grid.Resources>
                         <primitives:Scroller x:Name='Scroller' Width='400' Height='600' ContentOrientation='Vertical' Background='Gray'>
                           <controls:ItemsRepeater
                             x:Name='ItemsRepeater'
                             ItemTemplate='{StaticResource ElementFactory}'
                             Layout='{StaticResource VerticalStackLayout}'
                             HorizontalCacheLength='0'
                             VerticalCacheLength='0' />
                         </primitives:Scroller>
                       </Grid>"));

                var elementFactory = (RecyclingElementFactory)root.Resources["ElementFactory"];
                scroller           = (Scroller)root.FindName("Scroller");
                repeater           = (ItemsRepeater)root.FindName("ItemsRepeater");

                repeater.ElementPrepared += (sender, args) =>
                {
                    Log.Comment($"Realized index: {args.Index} Wating for index {waitingForIndex}");
                    if (args.Index == waitingForIndex)
                    {
                        indexRealized.Set();
                    }
                };

                var items = Enumerable.Range(0, 400).Select(i => string.Format("{0}: {1}", i, lorem.Substring(0, 250)));

                repeater.ItemsSource = items;

                scroller.ViewChanged += (o, e) =>
                {
                    Log.Comment("Scroller.ViewChanged: VerticalOffset=" + scroller.VerticalOffset);
                    viewChangedOffsets.Add(scroller.VerticalOffset);
                    viewChangedEvent.Set();
                };

                scroller.BringingIntoView += (o, e) =>
                {
                    Log.Comment("Scroller.BringingIntoView:");
                    Log.Comment("TargetVerticalOffset=" + e.TargetVerticalOffset);
                    Log.Comment("RequestEventArgs.AnimationDesired=" + e.RequestEventArgs.AnimationDesired);
                    Log.Comment("RequestEventArgs.Handled=" + e.RequestEventArgs.Handled);
                    Log.Comment("RequestEventArgs.VerticalAlignmentRatio=" + e.RequestEventArgs.VerticalAlignmentRatio);
                    Log.Comment("RequestEventArgs.VerticalOffset=" + e.RequestEventArgs.VerticalOffset);
                    Log.Comment("RequestEventArgs.TargetRect=" + e.RequestEventArgs.TargetRect);
                };

                scroller.EffectiveViewportChanged += (o, args) =>
                {
                    Log.Comment("Scroller.EffectiveViewportChanged: VerticalOffset=" + scroller.VerticalOffset);
                };

                root.Loaded += delegate {
                    rootLoadedEvent.Set();
                };

                Content = root;
            });
            Verify.IsTrue(rootLoadedEvent.WaitOne(DefaultWaitTimeInMS));
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                waitingForIndex = 101;
                indexRealized.Reset();
                repeater.GetOrCreateElement(100).StartBringIntoView(new BringIntoViewOptions {
                    VerticalAlignmentRatio = 0.0
                });
                repeater.UpdateLayout();
            });

            Verify.IsTrue(viewChangedEvent.WaitOne(DefaultWaitTimeInMS));
            IdleSynchronizer.Wait();
            Verify.AreEqual(1, viewChangedOffsets.Count);
            viewChangedOffsets.Clear();
            Verify.IsTrue(indexRealized.WaitOne(DefaultWaitTimeInMS));

            ValidateRealizedRange(repeater, 99, 106);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Scroll into view item 105 (already realized) w/ animation.");
                waitingForIndex = 99;
                repeater.TryGetElement(105).StartBringIntoView(new BringIntoViewOptions
                {
                    VerticalAlignmentRatio = 0.5,
                    AnimationDesired       = true
                });
                repeater.UpdateLayout();
            });

            Verify.IsTrue(viewChangedEvent.WaitOne(DefaultWaitTimeInMS));
            IdleSynchronizer.Wait();
            Verify.IsLessThanOrEqual(1, viewChangedOffsets.Count);
            viewChangedOffsets.Clear();
            ValidateRealizedRange(repeater, 101, 109);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Scroll item 0 to the top w/ animation and 0.5 vertical alignment.");
                waitingForIndex = 1;
                indexRealized.Reset();
                repeater.GetOrCreateElement(0).StartBringIntoView(new BringIntoViewOptions
                {
                    VerticalAlignmentRatio = 0.5,
                    AnimationDesired       = true
                });
            });

            Verify.IsTrue(viewChangedEvent.WaitOne(DefaultWaitTimeInMS));
            IdleSynchronizer.Wait();
            viewChangedOffsets.Clear();
            Verify.IsTrue(indexRealized.WaitOne(DefaultWaitTimeInMS));

            // Test Reliability fix. If offset is not 0 yet, give
            // some more time for the animation to settle down.
            double verticalOffset = 0;

            RunOnUIThread.Execute(() =>
            {
                verticalOffset = scroller.VerticalOffset;
            });

            if (verticalOffset != 0)
            {
                Verify.IsTrue(viewChangedEvent.WaitOne(DefaultWaitTimeInMS));
                IdleSynchronizer.Wait();
                viewChangedOffsets.Clear();
            }

            ValidateRealizedRange(repeater, 0, 6);

            RunOnUIThread.Execute(() =>
            {
                // You can't align the first group in the middle obviously.
                Verify.AreEqual(0, scroller.VerticalOffset);

                Log.Comment("Scroll to item 20.");
                waitingForIndex = 21;
                indexRealized.Reset();
                repeater.GetOrCreateElement(20).StartBringIntoView(new BringIntoViewOptions
                {
                    VerticalAlignmentRatio = 0.0
                });
                repeater.UpdateLayout();
            });

            Verify.IsTrue(viewChangedEvent.WaitOne(DefaultWaitTimeInMS));
            IdleSynchronizer.Wait();
            Verify.IsTrue(indexRealized.WaitOne(DefaultWaitTimeInMS));

            ValidateRealizedRange(repeater, 19, 26);
        }
示例#6
0
        public void ValidatePhaseInvokeAndOrdering()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone2))
            {
                Log.Warning("Skipping: GetAvailableSize API is only available in RS3 and above.");
                return;
            }

            ItemsRepeater    repeater           = null;
            int              numPhases          = 6; // 0 to 5
            ManualResetEvent buildTreeCompleted = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var itemTemplate = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
                            <Button Width='100' Height='100'/>
                        </DataTemplate>");
                repeater = new ItemsRepeater()
                {
                    ItemsSource = Enumerable.Range(0, 10),
#if BUILD_WINDOWS
                    ItemTemplate = (Windows.UI.Xaml.IElementFactory) new CustomElementFactory(numPhases),
#else
                    ItemTemplate = new CustomElementFactory(numPhases),
#endif
                    Layout = new StackLayout(),
                };

                repeater.ElementPrepared += (sender, args) =>
                {
                    if (args.Index == expectedLastRealizedIndex)
                    {
                        Log.Comment("Item 8 Created!");
                        RepeaterTestHooks.BuildTreeCompleted += (sender1, args1) =>
                        {
                            buildTreeCompleted.Set();
                        };
                    }
                };

                Content = new ScrollAnchorProvider()
                {
                    Width   = 400,
                    Height  = 400,
                    Content = new ScrollViewer
                    {
                        Content = repeater
                    }
                };

                // CompositionTarget.Rendering += (sender, args) => { Log.Comment("Rendering"); }; // debugging aid
            });

            if (buildTreeCompleted.WaitOne(TimeSpan.FromMilliseconds(2000)))
            {
                RunOnUIThread.Execute(() =>
                {
                    var calls = ElementPhasingManager.ProcessedCalls;

                    Verify.AreEqual(9, calls.Count);
                    calls[0].RemoveAt(0); // Remove the create we did for first measure.
                    foreach (var index in calls.Keys)
                    {
                        var phases = calls[index];
                        Verify.AreEqual(6, phases.Count);
                        for (int i = 0; i < phases.Count; i++)
                        {
                            Verify.AreEqual(i, phases[i]);
                        }
                    }

                    ElementPhasingManager.ProcessedCalls.Clear();
                });
            }
            else
            {
                Verify.Fail("Failed on waiting on build tree.");
            }
        }
示例#7
0
        private UIObject Launch(string deploymentDir)
        {
            UIObject coreWindow = null;

            // When running from MUXControls repo we want to install the app.
            // When running in TestMD we also want to install the app.
#if USING_TAEF
            TestAppInstallHelper.InstallTestAppIfNeeded(deploymentDir, _packageName, _packageFamilyName);
#else
            BuildAndInstallTestAppIfNeeded();
#endif


            Log.Comment("Launching app {0}", _appName);

            coreWindow = LaunchApp(_packageName);

            Verify.IsNotNull(coreWindow, "coreWindow");

            Log.Comment("Waiting for the close-app invoker to be found to signal that the app has launched successfully...");

            for (int retries = 0; retries < 5; ++retries)
            {
                UIObject obj;
                coreWindow.Descendants.TryFind(UICondition.Create("@AutomationId='__CloseAppInvoker'"), out obj);
                if (obj != null)
                {
                    Log.Comment("Invoker found!");
                    break;
                }

                Log.Comment("Invoker not found. Sleeping for 500 ms before trying again...");
                Thread.Sleep(500);
            }

            var unhandledExceptionReportingTextBox = new Edit(coreWindow.Descendants.Find(UICondition.Create("@AutomationId='__UnhandledExceptionReportingTextBox'")));
            var valueChangedSource = new PropertyChangedEventSource(unhandledExceptionReportingTextBox, Scope.Element, UIProperty.Get("Value.Value"));
            valueChangedSource.Start(new TestAppCrashDetector());

            Log.Comment("15056441 tracing, device family:" + Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily);

            // On phone, we work around different scale factors between devices by configuring the test app to
            // lay out the test pages at the device's resolution, effectively giving us a scale factor of 1.0.
            if (PlatformConfiguration.IsDevice(DeviceType.Phone))
            {
                Log.Comment("Enabling view scaling workaround on phone.");

                try
                {
                    var viewScalingCheckBox = new CheckBox(coreWindow.Descendants.Find(UICondition.Create("@AutomationId='__ViewScalingCheckBox'")));
                    using (var waiter = viewScalingCheckBox.GetToggledWaiter())
                    {
                        viewScalingCheckBox.Check();
                    }
                    Log.Comment("15056441 Tracing: New checkbox state is " + viewScalingCheckBox.ToggleState);
                }
                catch (UIObjectNotFoundException)
                {
                    Log.Error("Could not find the view scaling CheckBox.");
                    LogDumpTree();
                    throw;
                }
            }

            return(coreWindow);
        }
示例#8
0
        public void CanClearEveryValueTest()
        {
            using (var setup = new TestSetupHelper("RatingControl Tests")) // This literally clicks the button corresponding to the test page.
            {
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
                {
                    // For some reason this test sometimes fails on RS1 when the "bounding box" of the
                    // RatingControl has negative values, but it's not worth the investigation to fix:
                    Log.Comment("Test is disabled on RS1 due to reliability issues");
                    return;
                }

                TextBlock tb = new TextBlock(FindElement.ById("FrameDetails"));
                Log.Comment("FrameDetails: " + tb.DocumentText);

                Log.Comment("Retrieve rating control as generic UIElement");
                UIObject ratingUIObject = FindElement.ByName("TestRatingControl");
                Verify.IsNotNull(ratingUIObject, "Verifying that we found a UIElement called TestRatingControl");

                Log.Comment("Retrieve the text block as a TextBlock");
                TextBlock textBlock = new TextBlock(FindElement.ByName("TestTextBlockControl"));

                Wait.ForIdle();

                Log.Comment("Verify a tap on the first star sets Rating to 1");
                InputHelper.Tap(ratingUIObject, (0 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("1", textBlock.DocumentText);

                Log.Comment("Verify a tap on the first star sets Rating to 2.5 (placeholder value)");
                InputHelper.Tap(ratingUIObject, (0 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("!2.5", textBlock.DocumentText);

                Log.Comment("Verify a tap on the second star sets Rating to 2");
                InputHelper.Tap(ratingUIObject, (1 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("2", textBlock.DocumentText);

                Log.Comment("Verify a tap on the second star sets Rating to 2.5 (placeholder value)");
                InputHelper.Tap(ratingUIObject, (1 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("!2.5", textBlock.DocumentText);

                Log.Comment("Verify a tap on the third star sets Rating to 3");
                InputHelper.Tap(ratingUIObject, (2 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("3", textBlock.DocumentText);

                Log.Comment("Verify a tap on the third star sets Rating to 2.5 (placeholder value)");
                InputHelper.Tap(ratingUIObject, (2 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("!2.5", textBlock.DocumentText);

                Log.Comment("Verify a tap on the fourth star sets Rating to 4");
                InputHelper.Tap(ratingUIObject, (3 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("4", textBlock.DocumentText);

                Log.Comment("Verify a tap on the fourth star sets Rating to 2.5 (placeholder value)");
                InputHelper.Tap(ratingUIObject, (3 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("!2.5", textBlock.DocumentText);

                Log.Comment("Verify a tap on the fifth star sets Rating to 5");
                InputHelper.Tap(ratingUIObject, (4 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("5", textBlock.DocumentText);

                Log.Comment("Verify a tap on the second star sets Rating to 2.5 (placeholder value)");
                InputHelper.Tap(ratingUIObject, (4 * RATING_ITEM_WIDTH) + (RATING_ITEM_WIDTH / 2), RATING_ITEM_HEIGHT / 2);
                Verify.AreEqual("!2.5", textBlock.DocumentText);
            }
        }
示例#9
0
        //RatingControlTests.GamepadTest unreliable test #155
        //[TestMethod]
        public void GamepadTest()
        {
            using (var setup = new TestSetupHelper("RatingControl Tests")) // This literally clicks the button corresponding to the test page.
            {
                if (!PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone2))
                {
                    Log.Warning("Test is disabled on RS2 or older because Rating's engagement model relies on OnPreviewKey* virtuals");
                    return;
                }

                UIObject ratingUIObject = FindElement.ByName("TestRatingControl");
                Verify.IsNotNull(ratingUIObject, "Verifying that we found a UIElement called TestRatingControl");
                TextBlock textBlock = new TextBlock(FindElement.ByName("TestTextBlockControl"));

                Log.Comment("Verify gamepad engagement");
                ratingUIObject.SetFocus();
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("1", textBlock.DocumentText);

                Log.Comment("Verify gamepad one change and cancel");
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.B);
                Wait.ForIdle();
                Verify.AreEqual("1", textBlock.DocumentText);

                Log.Comment("Verify gamepad one change and accept");
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("2", textBlock.DocumentText);

                Log.Comment("Verify gamepad multiple changes");
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadLeft);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("3", textBlock.DocumentText);

                Log.Comment("Verify gamepad left stick and dpad work");
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadLeft);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.LeftThumbstickRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.LeftThumbstickRight);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("4", textBlock.DocumentText);

                Log.Comment("Verify gamepad dpad up down do nothing");
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadUp);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("4", textBlock.DocumentText);

                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadDown);
                GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual("4", textBlock.DocumentText);
            }
        }
示例#10
0
        // In non fallback mode, we have crossfading and non crossfading effects.
        // crossfading only last for hundren ms in the transition between fallback mode and acrylic mode.
        //
        void RunVerifyAcrylicBrushEffect()
        {
            bool[] results = { false, false };

            AcrylicBrush acrylicBrush1 = new AcrylicBrush
            {
                BackgroundSource = AcrylicBackgroundSource.Backdrop,
                FallbackColor    = Colors.Blue,
                TintColor        = Colors.Green,
                TintOpacity      = 0.1
            };

            // Add Ellipse with Acrylic Fill and Stroke
            Ellipse1.Visibility = Visibility.Visible;
            Ellipse1.Fill       = acrylicBrush1;

            _acrylicTestApi.AcrylicBrush = acrylicBrush1;

            // Force to create a AcrylicBrush which is used for animation. So it's a CrosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(true /*useCrossFadeEffect*/);

            var fallbackColor = Colors.Black;
            var tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Only CrossFading effect brush provides animation properties for both and TryGetColor success.
            CompositionGetValueStatus fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            CompositionGetValueStatus tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);

            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[0] = tintColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColorValueStatus != CompositionGetValueStatus.NotFound &&
                             fallbackColor == acrylicBrush1.FallbackColor;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel
                results[0]        = fallbackColor == acrylicBrush1.FallbackColor &&
                                    expectIintColor == tintColor;
            }

            // Force to create a non crosssFading effect brush
            _acrylicTestApi.ForceCreateAcrylicBrush(false /*useCrossFadeEffect*/);

            fallbackColor = Colors.Black;
            tintColor     = Colors.Black;

            // Get FallbackColor and TintColor. Non CrossFading effect brush doesn't provide FallbackColor.Color.
            fallbackColorValueStatus = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("FallbackColor.Color", out fallbackColor);
            tintColorValueStatus     = _acrylicTestApi.CompositionBrush.Properties.TryGetColor("TintColor.Color", out tintColor);


            if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
            {
                // On 19H1+, Luminosity impacts the effective tint value, so don't validate it here.
                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound;
            }
            else
            {
                var expectIintColor = acrylicBrush1.TintColor;
                expectIintColor.A = (byte)Math.Ceiling(255 * acrylicBrush1.TintOpacity); // alpha channel

                results[1] = fallbackColorValueStatus == CompositionGetValueStatus.NotFound &&
                             expectIintColor == tintColor;
            }

            bool   result       = results[0] && results[1];
            string resultString = System.String.Format("({0},{1})", results[0], results[1]);

            TestResult.Text = "VerifyAcrylicBrushEffect: " + (result ? "Passed" : ("Failed " + resultString));
        }
示例#11
0
        public void ValidateDataTemplateSelectorAsItemTemplate()
        {
            RunOnUIThread.Execute(() =>
            {
                var dataTemplateOdd = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='30' />
						</DataTemplate>"                        );
                var dataTemplateEven = (DataTemplate)XamlReader.Load(
                    @"<DataTemplate  xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
							<TextBlock Text='{Binding}' Height='40' />
						</DataTemplate>"                        );
                ItemsRepeater repeater = null;
                const int numItems     = 10;
                var selector           = new MySelector()
                {
                    TemplateOdd  = dataTemplateOdd,
                    TemplateEven = dataTemplateEven
                };

                Content = CreateAndInitializeRepeater
                          (
                    itemsSource: Enumerable.Range(0, numItems),
                    elementFactory: selector,
                    layout: new StackLayout(),
                    repeater: ref repeater
                          );

                Content.UpdateLayout();
                Verify.AreEqual(numItems, VisualTreeHelper.GetChildrenCount(repeater));
                for (int i = 0; i < numItems; i++)
                {
                    var element = (TextBlock)repeater.TryGetElement(i);
                    Verify.AreEqual(i.ToString(), element.Text);
                    Verify.AreEqual(i % 2 == 0 ? 40 : 30, element.Height);
                }

                repeater.ItemsSource = null;
                Content.UpdateLayout();

                // In versions below RS5 we faked the recycling behaivor on data template
                // so we can get to the recycle pool that we addded internally in ItemsRepeater.
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
                {
                    // All the created items should be in the recycle pool now.
                    var oddPool     = RecyclePool.GetPoolInstance(dataTemplateOdd);
                    var oddElements = GetAllElementsFromPool(oddPool);
                    Verify.AreEqual(5, oddElements.Count);
                    foreach (var element in oddElements)
                    {
                        Verify.AreEqual(30, ((TextBlock)element).Height);
                    }

                    var evenPool     = RecyclePool.GetPoolInstance(dataTemplateEven);
                    var evenElements = GetAllElementsFromPool(evenPool);
                    Verify.AreEqual(5, evenElements.Count);
                    foreach (var element in evenElements)
                    {
                        Verify.AreEqual(40, ((TextBlock)element).Height);
                    }
                }
            });
        }
        public void ChangeOffsetsWhileScrollControllersAreAttached()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping failing test on RS1.");
                return;
            }

            Scroller  scroller = null;
            Rectangle rectangleScrollerContent = null;
            CompositionScrollController horizontalScrollController = null;
            CompositionScrollController verticalScrollController   = null;
            AutoResetEvent loadedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                rectangleScrollerContent = new Rectangle();
                scroller = new Scroller();
                horizontalScrollController = new CompositionScrollController();
                verticalScrollController   = new CompositionScrollController();

                horizontalScrollController.Orientation = Orientation.Horizontal;

                horizontalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                verticalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                scroller.HorizontalScrollController = horizontalScrollController;
                scroller.VerticalScrollController   = verticalScrollController;

                SetupUIWithScrollControllers(
                    scroller,
                    rectangleScrollerContent,
                    horizontalScrollController,
                    verticalScrollController,
                    loadedEvent);
            });

            WaitForEvent("Waiting for Loaded event", loadedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("HorizontalScrollController size={0}, {1}", horizontalScrollController.ActualWidth, horizontalScrollController.ActualHeight);
                Log.Comment("VerticalScrollController size={0}, {1}", verticalScrollController.ActualWidth, verticalScrollController.ActualHeight);
            });

            IdleSynchronizer.Wait();

            Log.Comment("Jump to offsets");
            ChangeOffsets(
                scroller,
                (c_defaultUIScrollerContentWidth - c_defaultUIScrollerWidth) / 2.0,
                (c_defaultUIScrollerContentHeight - c_defaultUIScrollerHeight) / 2.0,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation,
                ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints,
                true /*hookViewChanged*/,
                (c_defaultUIScrollerContentWidth - c_defaultUIScrollerWidth) / 2.0,
                (c_defaultUIScrollerContentHeight - c_defaultUIScrollerHeight) / 2.0);

            Log.Comment("Animate to offsets");
            ChangeOffsets(
                scroller,
                (c_defaultUIScrollerContentWidth - c_defaultUIScrollerWidth) / 4.0,
                (c_defaultUIScrollerContentHeight - c_defaultUIScrollerHeight) / 4.0,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.AllowAnimation,
                ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints,
                false /*hookViewChanged*/,
                (c_defaultUIScrollerContentWidth - c_defaultUIScrollerWidth) / 4.0,
                (c_defaultUIScrollerContentHeight - c_defaultUIScrollerHeight) / 4.0);

            Log.Comment("Jump to zoomFactor 2.0");
            ChangeZoomFactor(
                scroller,
                2.0f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation,
                false /*hookViewChanged*/);

            Log.Comment("Animate to zoomFactor 1.5");
            ChangeZoomFactor(
                scroller,
                1.5f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.AllowAnimation,
                false /*hookViewChanged*/);
        }
        public void ChangeOffsetsWithAdditionalVelocityAndAttachedBiDirectionalScrollController()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping failing test on RS1.");
                return;
            }

            Scroller  scroller = null;
            Rectangle rectangleScrollerContent = null;
            BiDirectionalScrollController biDirectionalScrollController = null;
            AutoResetEvent loadedEvent = new AutoResetEvent(false);
            AutoResetEvent viewChangeCompletedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                rectangleScrollerContent = new Rectangle();
                scroller = new Scroller();
                biDirectionalScrollController = new BiDirectionalScrollController();

                biDirectionalScrollController.LogMessage += (BiDirectionalScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                scroller.HorizontalScrollController = biDirectionalScrollController.HorizontalScrollController;
                scroller.VerticalScrollController   = biDirectionalScrollController.VerticalScrollController;

                SetupUIWithBiDirectionalScrollController(
                    scroller,
                    rectangleScrollerContent,
                    biDirectionalScrollController,
                    loadedEvent);

                biDirectionalScrollController.ViewChangeCompleted += (BiDirectionalScrollController sender, BiDirectionalScrollControllerViewChangeCompletedEventArgs args) =>
                {
                    Log.Comment("ChangeOffsetsWithAdditionalVelocity completed. ViewChangeId=" + args.ViewChangeId + ", Result=" + args.Result);

                    Log.Comment("Setting completion event");
                    viewChangeCompletedEvent.Set();
                };
            });

            WaitForEvent("Waiting for Loaded event", loadedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("BiDirectionalScrollController size={0}, {1}", biDirectionalScrollController.ActualWidth, biDirectionalScrollController.ActualHeight);
            });

            Log.Comment("Jump to zoomFactor 0.75");
            ChangeZoomFactor(
                scroller,
                0.75f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Adding velocity to offsets, with default inertia decay rates");
                biDirectionalScrollController.ChangeOffsetsWithAdditionalVelocity(
                    new ScrollerChangeOffsetsWithAdditionalVelocityOptions(new Vector2(100.0f) /*additionalVelocity*/, null /*inertiaDecayRate*/));
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.IsTrue(scroller.HorizontalOffset > 20.0);
                Verify.IsTrue(scroller.VerticalOffset > 20.0);

                Log.Comment("Adding negative velocity to offsets, with custom inertia decay rates");
                biDirectionalScrollController.ChangeOffsetsWithAdditionalVelocity(
                    new ScrollerChangeOffsetsWithAdditionalVelocityOptions(new Vector2(-50.0f) /*additionalVelocity*/, new Vector2(0.9f) /*inertiaDecayRate*/));

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.IsTrue(scroller.HorizontalOffset < 20.0);
                Verify.IsTrue(scroller.VerticalOffset < 20.0);

                Log.Comment("Adding velocity to offsets, with no inertia decay rates");
                biDirectionalScrollController.ChangeOffsetsWithAdditionalVelocity(
                    new ScrollerChangeOffsetsWithAdditionalVelocityOptions(new Vector2(200.0f) /*additionalVelocity*/, new Vector2(0.0f) /*inertiaDecayRate*/));

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.AreEqual(scroller.HorizontalOffset, 600.0);
                Verify.AreEqual(scroller.VerticalOffset, 250.0);
            });
        }
        public void ChangeOffsetsWithAttachedBiDirectionalScrollController()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping failing test on RS1.");
                return;
            }

            Scroller  scroller = null;
            Rectangle rectangleScrollerContent = null;
            BiDirectionalScrollController biDirectionalScrollController = null;
            AutoResetEvent loadedEvent = new AutoResetEvent(false);
            AutoResetEvent viewChangeCompletedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                rectangleScrollerContent = new Rectangle();
                scroller = new Scroller();
                biDirectionalScrollController = new BiDirectionalScrollController();

                biDirectionalScrollController.LogMessage += (BiDirectionalScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                scroller.HorizontalScrollController = biDirectionalScrollController.HorizontalScrollController;
                scroller.VerticalScrollController   = biDirectionalScrollController.VerticalScrollController;

                SetupUIWithBiDirectionalScrollController(
                    scroller,
                    rectangleScrollerContent,
                    biDirectionalScrollController,
                    loadedEvent);

                biDirectionalScrollController.ViewChangeCompleted += (BiDirectionalScrollController sender, BiDirectionalScrollControllerViewChangeCompletedEventArgs args) =>
                {
                    Log.Comment("ChangeOffset completed. ViewChangeId=" + args.ViewChangeId + ", Result=" + args.Result);

                    Log.Comment("Setting completion event");
                    viewChangeCompletedEvent.Set();
                };
            });

            WaitForEvent("Waiting for Loaded event", loadedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("BiDirectionalScrollController size={0}, {1}", biDirectionalScrollController.ActualWidth, biDirectionalScrollController.ActualHeight);
            });

            Log.Comment("Jump to zoomFactor 0.75");
            ChangeZoomFactor(
                scroller,
                0.75f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Jumping to offsets");
                biDirectionalScrollController.ChangeOffsets(
                    new ScrollerChangeOffsetsOptions(
                        (c_defaultUIScrollerContentWidth * 0.75 - c_defaultUIScrollerWidth) / 4.0,
                        (c_defaultUIScrollerContentHeight * 0.75 - c_defaultUIScrollerHeight) / 4.0,
                        ScrollerViewKind.Absolute,
                        ScrollerViewChangeKind.DisableAnimation,
                        ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints));
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(scroller.HorizontalOffset, (c_defaultUIScrollerContentWidth * 0.75 - c_defaultUIScrollerWidth) / 4.0);
                Verify.AreEqual(scroller.VerticalOffset, (c_defaultUIScrollerContentHeight * 0.75 - c_defaultUIScrollerHeight) / 4.0);

                Log.Comment("Animating to offsets");
                biDirectionalScrollController.ChangeOffsets(
                    new ScrollerChangeOffsetsOptions(
                        (c_defaultUIScrollerContentWidth * 0.75 - c_defaultUIScrollerWidth) / 2.0,
                        (c_defaultUIScrollerContentHeight * 0.75 - c_defaultUIScrollerHeight) / 2.0,
                        ScrollerViewKind.Absolute,
                        ScrollerViewChangeKind.AllowAnimation,
                        ScrollerViewChangeSnapPointRespect.IgnoreSnapPoints));

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(scroller.HorizontalOffset, (c_defaultUIScrollerContentWidth * 0.75 - c_defaultUIScrollerWidth) / 2.0);
                Verify.AreEqual(scroller.VerticalOffset, (c_defaultUIScrollerContentHeight * 0.75 - c_defaultUIScrollerHeight) / 2.0);
            });
        }
示例#15
0
        private void CanStyleTextInARichEditBox(string styleName, string styleStart, string styleEnd)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone2))
            {
                Log.Warning("Test is disabled pre-RS2 because TextCommandBarFlyout is not supported pre-RS2");
                return;
            }

            using (var setup = new TextCommandBarFlyoutTestSetupHelper())
            {
                Log.Comment("Getting initial RichEditBox RTF content.");
                FindElement.ById <Button>(string.Format("GetRichEditBoxRtfContentButton")).InvokeAndWait();
                string textControlContents = FindElement.ById("StatusReportingTextBox").GetText();
                Log.Comment("Content is '{0}'", textControlContents.Replace(Environment.NewLine, " "));

                Log.Comment("Ensuring RichEditBox initially has no {0} content.", styleName.ToLower());
                Verify.IsFalse(textControlContents.Contains(styleStart));
                Verify.IsFalse(textControlContents.Contains(styleEnd));

                var richedit = FindElement.ById <Edit>("RichEditBox");

                FocusAndSelectText(richedit, "ergo");
                OpenFlyoutOn("RichEditBox", asTransient: true);

                var toggleFormatButton = FindElement.ByName <ToggleButton>(styleName);
                Verify.AreEqual(ToggleState.Off, toggleFormatButton.ToggleState);

                Log.Comment("Making text {0}.", styleName.ToLower());
                toggleFormatButton.ToggleAndWait();
                VerifyRichEditBoxHasContent(string.Format("Lorem ipsum {0}ergo{1} sum", styleStart, styleEnd));

                DismissFlyout();

                Log.Comment("Select mixed format text");
                // Note, in this case the selection starts in unstyled text ("sum") and includes styled text ("ergo"). The next case covers
                // starting in styled text and including unstyled text
                FocusAndSelectText(richedit, "sum ergo");

                Log.Comment("Showing flyout should not change bold status");
                OpenFlyoutOn("RichEditBox", asTransient: true);
                Verify.AreEqual(ToggleState.Off, toggleFormatButton.ToggleState);
                VerifyRichEditBoxHasContent(string.Format("Lorem ipsum {0}ergo{1} sum", styleStart, styleEnd));

                Log.Comment("Apply formatting to new selection");
                toggleFormatButton.ToggleAndWait();
                VerifyRichEditBoxHasContent(string.Format("Lorem ip{0}sum ergo{1} sum", styleStart, styleEnd));

                DismissFlyout();

                Log.Comment("Select mixed format text");
                FocusAndSelectText(richedit, "ergo su");
                OpenFlyoutOn("RichEditBox", asTransient: true);
                Verify.AreEqual(ToggleState.Off, toggleFormatButton.ToggleState);
                VerifyRichEditBoxHasContent(string.Format("Lorem ip{0}sum ergo{1} sum", styleStart, styleEnd));

                toggleFormatButton.ToggleAndWait();
                VerifyRichEditBoxHasContent(string.Format("Lorem ip{0}sum ergo su{1}m", styleStart, styleEnd));

                DismissFlyout();
                FocusAndSelectText(richedit, "ergo");
                OpenFlyoutOn("RichEditBox", asTransient: true);
                Verify.AreEqual(ToggleState.On, toggleFormatButton.ToggleState);
                VerifyRichEditBoxHasContent(string.Format("Lorem ip{0}sum ergo su{1}m", styleStart, styleEnd));

                toggleFormatButton.ToggleAndWait();
                VerifyRichEditBoxHasContent(string.Format("Lorem ip{0}sum {1}ergo{0} su{1}m", styleStart, styleEnd));
            }
        }
示例#16
0
        public void UIAValuePatternTest()
        {
            using (var setup = new TestSetupHelper("RatingControl Tests")) // This literally clicks the button corresponding to the test page.
            {
                Log.Comment("Retrieve rating control as generic UIElement");
                UIObject ratingUIObject = FindElement.ByName("TestRatingControl");

                TextBlock textBlock = new TextBlock(FindElement.ByName("TestTextBlockControl"));
                Verify.IsNotNull(ratingUIObject, "Verifying that we found a UIElement called TestRatingControl");

                Log.Comment("Verify the UIA Value before user clicks the control.");
                ratingUIObject.SetFocus(); // Setting focus just so we can use AE.FE below
                Wait.ForIdle();
                AutomationElement ratingPeer = AutomationElement.FocusedElement;

                VerifyValue_ValueEqualsOnAutomationElement(ratingPeer, "Community Rating, 2.5 of 5");

                if (PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone2)) // engagement doesn't work pre RS3
                {
                    Log.Comment("Verify moving right 2 times with the gamepad sets the control to 3");
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadRight);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                    Wait.ForIdle();
                    Verify.AreEqual("3", textBlock.DocumentText);

                    Log.Comment("Verify rating of 3 sets UIA text to 3");

                    VerifyValue_ValueEqualsOnAutomationElement(ratingPeer, "Rating, 3 of 5");

                    // revert:
                    Log.Comment("Resetting control to community rating");
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadLeft);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadLeft);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.DPadLeft);
                    GamepadHelper.PressButton(ratingUIObject, GamepadButton.A);

                    VerifyValue_ValueEqualsOnAutomationElement(ratingPeer, "Community Rating, 2.5 of 5");
                }

                Log.Comment("Verify more complex navigation");
                KeyboardHelper.PressKey(ratingUIObject, Key.Right);
                KeyboardHelper.PressKey(ratingUIObject, Key.Right);
                KeyboardHelper.PressKey(ratingUIObject, Key.Right);
                KeyboardHelper.PressKey(ratingUIObject, Key.Left);
                VerifyValue_ValueEqualsOnAutomationElement(ratingPeer, "Rating, 2 of 5");

                // Verify read an unset rating
                ratingUIObject = FindElement.ByName("RatingBindingSample");
                Log.Comment("Verify the UIA Value of an unset Rating without a placeholder value");
                ratingUIObject.SetFocus();
                InputHelper.ScrollToElement(ratingUIObject);
                ratingPeer = AutomationElement.FocusedElement;

                VerifyValue_ValueEqualsOnAutomationElement(ratingPeer, "Rating Unset");

                // Verify rounding:
                Log.Comment("Verifying Value_Value rounding");
                UIObject round1 = FindElement.ById("ValuePatternRoundTest1");
                round1.SetFocus();
                AutomationElement roundAE1 = AutomationElement.FocusedElement;
                UIObject          round2   = FindElement.ById("ValuePatternRoundTest2");
                round2.SetFocus();
                AutomationElement roundAE2 = AutomationElement.FocusedElement;
                UIObject          round3   = FindElement.ById("ValuePatternRoundTest3");
                round3.SetFocus();
                AutomationElement roundAE3 = AutomationElement.FocusedElement;

                VerifyValue_ValueEqualsOnAutomationElement(roundAE1, "Rating, 1.5 of 5");
                VerifyValue_ValueEqualsOnAutomationElement(roundAE2, "Rating, 1.55 of 5");
                VerifyValue_ValueEqualsOnAutomationElement(roundAE3, "Rating, 1.5 of 5");
            }
        }
示例#17
0
        public void ValidateKeyboarding()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Warning("Test is disabled pre-RS5 because the keyboarding fixes needed to support this were not available pre-RS5.");
                return;
            }

            using (var setup = new TextCommandBarFlyoutTestSetupHelper())
            {
                Log.Comment("Give focus to the TextBox.");
                var textBox = FindElement.ById("TextBox");
                FocusHelper.SetFocus(textBox);

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Select All")))
                {
                    Log.Comment("Use Shift+F10 to bring up the context menu. The Select All button should get focus.");
                    KeyboardHelper.PressKey(Key.F10, ModifierKey.Shift);
                    waiter.Wait();
                }

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromId("TextBox")))
                {
                    Log.Comment("Use Escape to close the context menu. The TextBox should now have focus.");
                    KeyboardHelper.PressKey(Key.Escape);

                    // On 19H1, there's a bug with the focus restoration code, so we'll manually restore focus to allow the rest of the test to run.
                    if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
                    {
                        textBox.SetFocus();
                    }

                    waiter.Wait();
                }

                Log.Comment("Give focus to the RichEditBox.");
                var richEditBox = FindElement.ById("RichEditBox");
                FocusHelper.SetFocus(richEditBox);

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Bold")))
                {
                    Log.Comment("Use Shift+F10 to bring up the context menu. The Bold button should get focus.");
                    KeyboardHelper.PressKey(Key.F10, ModifierKey.Shift);
                    waiter.Wait();
                }

                Log.Comment("Press the spacebar to invoke the bold button. Focus should stay in the flyout.");
                KeyboardHelper.PressKey(Key.Space);
                Wait.ForIdle();

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("More app bar")))
                {
                    Log.Comment("Press the right arrow key three times.  The '...' button should get focus.");
                    KeyboardHelper.PressKey(Key.Right, ModifierKey.None, numPresses: 3);
                    waiter.Wait();
                }

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromName("Select All")))
                {
                    Log.Comment("Press the down arrow key twice.  The Select All button should get focus.");
                    KeyboardHelper.PressKey(Key.Down, ModifierKey.None, numPresses: 2);
                    waiter.Wait();
                }

                using (var waiter = new FocusAcquiredWaiter(UICondition.CreateFromId("RichEditBox")))
                {
                    Log.Comment("Use Escape to close the context menu. The RichEditBox should now have focus.");
                    KeyboardHelper.PressKey(Key.Escape);

                    // On 19H1, there's a bug with the focus restoration code, so we'll manually restore focus to allow the rest of the test to run.
                    if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.NineteenH1))
                    {
                        richEditBox.SetFocus();
                    }

                    waiter.Wait();
                }
            }
        }
示例#18
0
        // [TestMethod]
        public void VerifyRatingItemFallback()
        {
            // This test is actually performed in the test app itself, so go look at RatingControlPage.xaml.cs for the meat of it.

            using (var setup = new TestSetupHelper("RatingControl Tests")) // This literally clicks the button corresponding to the test page.
            {
                if (!PlatformConfiguration.IsOsVersionGreaterThan(OSVersion.Redstone1))
                {
                    Log.Warning("Test is disabled on RS1 due to scrolling unreliability");
                    return;
                }

                Log.Comment("Retrieve PointerOverPlaceholderFallbackRating rating control as generic UIElement");
                UIObject popRating = FindElement.ById("PointerOverPlaceholderFallbackRating");
                Verify.IsNotNull(popRating, "Verifying that we found a UIElement called PointerOverPlaceholderFallbackRating");

                InputHelper.ScrollToElement(popRating);

                popRating.Tap(); // Since on phone it's touch, I do a tap to trigger that.
                popRating.Click();
                Wait.ForIdle();

                Log.Comment("Retrieve PointerOverFallbackRating rating control as generic UIElement");
                UIObject pointerOver = FindElement.ById("PointerOverFallbackRating");
                Verify.IsNotNull(pointerOver, "Verifying that we found a UIElement called PointerOverFallbackRating");
                InputHelper.ScrollToElement(pointerOver);
                pointerOver.Click();
                pointerOver.Tap();
                Wait.ForIdle();

                TextBlock textBlock = new TextBlock(FindElement.ById("UnsetFallbackTextBlock"));
                Verify.AreEqual("+", textBlock.DocumentText, "Verify Unset glyph falls back onto Glyph");
                TextBlock textBlock2 = new TextBlock(FindElement.ById("PlaceholderFallbackTextBlock"));
                Verify.AreEqual("+", textBlock2.DocumentText, "Verify Placeholder glyph falls back onto Glyph");
                TextBlock textBlock3 = new TextBlock(FindElement.ById("DisabledFallbackTextBlock"));
                Verify.AreEqual("+", textBlock3.DocumentText, "Verify Disabled glyph falls back onto Glyph");

                ElementCache.Clear();

                TextBlock textBlock4 = new TextBlock(FindElement.ById("PointerOverPlaceholderFallbackTextBlock"));
                Verify.AreEqual("+", textBlock4.DocumentText, "Verify PointerOverPlaceholder glyph falls back onto Placeholder");
                TextBlock textBlock5 = new TextBlock(FindElement.ById("PointerOverFallbackTextBlock"));
                Verify.AreEqual("+", textBlock5.DocumentText, "Verify PointerOver glyph falls back onto Glyph");
                TextBlock textBlock6 = new TextBlock(FindElement.ById("NoFallbackTextBlock"));
                Verify.AreEqual("+", textBlock6.DocumentText, "Verify a glyph didn't fall back if it wasn't meant to");

                // Image:
                Log.Comment("Retrieve PointerOverPlaceholderImageFallbackRating rating control as generic UIElement");
                popRating = FindElement.ById("PointerOverPlaceholderImageFallbackRating");
                Verify.IsNotNull(popRating, "Verifying that we found a UIElement called PointerOverPlaceholderImageFallbackRating");

                InputHelper.ScrollToElement(popRating);
                Wait.ForIdle();

                popRating.Tap(); // Since on phone it's touch, I do a tap to trigger that.
                popRating.Click();
                Wait.ForIdle();

                Log.Comment("Retrieve PointerOverImageFallbackRating rating control as generic UIElement");
                pointerOver = FindElement.ById("PointerOverImageFallbackRating");
                Verify.IsNotNull(pointerOver, "Verifying that we found a UIElement called PointerOverImageFallbackRating");
                pointerOver.Tap();
                pointerOver.Click();
                Wait.ForIdle();

                textBlock = new TextBlock(FindElement.ById("UnsetImageFallbackTextBlock"));
                Verify.AreEqual("+", textBlock.DocumentText, "Verify Unset image falls back onto Image");
                textBlock2 = new TextBlock(FindElement.ById("PlaceholderImageFallbackTextBlock"));
                Verify.AreEqual("+", textBlock2.DocumentText, "Verify Placeholder image falls back onto Image");
                textBlock3 = new TextBlock(FindElement.ById("DisabledImageFallbackTextBlock"));
                Verify.AreEqual("+", textBlock3.DocumentText, "Verify Disabled image falls back onto Image");

                ElementCache.Clear();
                textBlock4 = new TextBlock(FindElement.ById("PointerOverPlaceholderImageFallbackTextBlock"));
                Verify.AreEqual("+", textBlock4.DocumentText, "Verify PointerOverPlaceholder image falls back onto PlaceholderImage");
                textBlock5 = new TextBlock(FindElement.ById("PointerOverImageFallbackTextBlock"));
                Verify.AreEqual("+", textBlock5.DocumentText, "Verify PointerOver image falls back onto Image");
            }
        }
示例#19
0
        public void ValidateElementEvents()
        {
            CustomItemsSource dataSource = null;

            RunOnUIThread.Execute(() => dataSource = new CustomItemsSource(Enumerable.Range(0, 10).ToList()));

            var repeater = SetupRepeater(dataSource);

            RunOnUIThread.Execute(() =>
            {
                List <int> preparedIndices = new List <int>();
                List <int> clearedIndices  = new List <int>();
                List <KeyValuePair <int, int> > changedIndices = new List <KeyValuePair <int, int> >();

                repeater.ElementPrepared += (sender, args) =>
                {
                    preparedIndices.Add(args.Index);
                };

                repeater.ElementClearing += (sender, args) =>
                {
                    clearedIndices.Add(sender.GetElementIndex(args.Element));
                };

                repeater.ElementIndexChanged += (sender, args) =>
                {
                    changedIndices.Add(new KeyValuePair <int, int>(args.OldIndex, args.NewIndex));
                };

                Log.Comment("Insert in realized range: Inserting 1 item at index 1");
                dataSource.Insert(index: 1, count: 1, reset: false);
                repeater.UpdateLayout();

                Verify.AreEqual(1, preparedIndices.Count);
                Verify.AreEqual(1, preparedIndices[0]);
                Verify.AreEqual(2, changedIndices.Count);
                Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(1, 2)));
                Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(2, 3)));
                Verify.AreEqual(1, clearedIndices.Count);
                Verify.AreEqual(3, clearedIndices[0]);

                preparedIndices.Clear();
                clearedIndices.Clear();
                changedIndices.Clear();

                Log.Comment("Remove in realized range: Removing 1 item at index 0");
                dataSource.Remove(index: 0, count: 1, reset: false);
                repeater.UpdateLayout();
                Verify.AreEqual(1, clearedIndices.Count);
                Verify.AreEqual(0, clearedIndices[0]);

                if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
                {
                    Verify.AreEqual(0, preparedIndices.Count);
                }
                else
                {
                    Verify.AreEqual(1, preparedIndices.Count);
                    Verify.AreEqual(2, preparedIndices[0]);
                }

                Verify.AreEqual(2, changedIndices.Count);
                Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(1, 0)));
                Verify.IsTrue(changedIndices.Contains(new KeyValuePair <int, int>(2, 1)));
            });
        }
示例#20
0
        private Brush GetBrushFromIndex()
        {
            switch (brushPropertyName.SelectedIndex)
            {
            case 0:     // Background
                return(PageCalendar.Background);

            case 2:     // BlackoutForeground
                return(PageCalendar.BlackoutForeground);

            case 4:     // BorderBrush
                return(PageCalendar.BorderBrush);

            case 5:     // CalendarItemBorderBrush
                return(PageCalendar.CalendarItemBorderBrush);

            case 6:     // CalendarItemBackground
                return(PageCalendar.CalendarItemBackground);

            case 8:     // CalendarItemForeground
                return(PageCalendar.CalendarItemForeground);

            case 12:     // Foreground
                return(PageCalendar.Foreground);

            case 13:     // HoverBorderBrush
                return(PageCalendar.HoverBorderBrush);

            case 14:     // OutOfScopeBackground
                return(PageCalendar.OutOfScopeBackground);

            case 15:     // OutOfScopeForeground
                return(PageCalendar.OutOfScopeForeground);

            case 18:     // PressedBorderBrush
                return(PageCalendar.PressedBorderBrush);

            case 19:     // PressedForeground
                return(PageCalendar.PressedForeground);

            case 20:     // SelectedBorderBrush
                return(PageCalendar.SelectedBorderBrush);

            case 23:     // SelectedForeground
                return(PageCalendar.SelectedForeground);

            case 24:     // SelectedHoverBorderBrush
                return(PageCalendar.SelectedHoverBorderBrush);

            case 26:     // SelectedPressedBorderBrush
                return(PageCalendar.SelectedPressedBorderBrush);

            case 32:     // TodayForeground
                return(PageCalendar.TodayForeground);

            case 36:     // CalendarViewDayItem.Background
                return(null);

            default:
                if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.TwentyOneH1))
                {
                    switch (brushPropertyName.SelectedIndex)
                    {
                    case 1:         // BlackoutBackground
                        return(PageCalendar.BlackoutBackground);

                    case 3:         // BlackoutStrikethroughBrush
                        return(PageCalendar.BlackoutStrikethroughBrush);

                    case 4:         // CalendarItemDisabledBackground
                        return(PageCalendar.CalendarItemDisabledBackground);

                    case 9:         // CalendarItemHoverBackground
                        return(PageCalendar.CalendarItemHoverBackground);

                    case 10:         // CalendarItemPressedBackground
                        return(PageCalendar.CalendarItemPressedBackground);

                    case 11:         // DisabledForeground
                        return(PageCalendar.DisabledForeground);

                    case 16:         // OutOfScopeHoverForeground
                        return(PageCalendar.OutOfScopeHoverForeground);

                    case 17:         // OutOfScopePressedForeground
                        return(PageCalendar.OutOfScopePressedForeground);

                    case 21:         // SelectedDisabledBorderBrush
                        return(PageCalendar.SelectedDisabledBorderBrush);

                    case 22:         // SelectedDisabledForeground
                        return(PageCalendar.SelectedDisabledForeground);

                    case 25:         // SelectedHoverForeground
                        return(PageCalendar.SelectedHoverForeground);

                    case 27:         // SelectedPressedForeground
                        return(PageCalendar.SelectedPressedForeground);

                    case 28:         // TodayBackground
                        return(PageCalendar.TodayBackground);

                    case 29:         // TodayBlackoutBackground
                        return(PageCalendar.TodayBlackoutBackground);

                    case 30:         // TodayBlackoutForeground
                        return(PageCalendar.TodayBlackoutForeground);

                    case 31:         // TodayDisabledBackground
                        return(PageCalendar.TodayDisabledBackground);

                    case 33:         // TodayHoverBackground
                        return(PageCalendar.TodayHoverBackground);

                    case 34:         // TodayPressedBackground
                        return(PageCalendar.TodayPressedBackground);

                    case 35:         // TodaySelectedInnerBorderBrush
                        return(PageCalendar.TodaySelectedInnerBorderBrush);

                    default:
                        return(null);
                    }
                }
                return(null);
            }
        }
示例#21
0
        public void VerifyCurrentAnchor()
        {
            ItemsRepeater           rootRepeater = null;
            ScrollViewer            scrollViewer = null;
            ItemsRepeaterScrollHost scrollhost   = null;
            ManualResetEvent        viewChanged  = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                scrollhost = (ItemsRepeaterScrollHost)XamlReader.Load(
                    @"<controls:ItemsRepeaterScrollHost Width='400' Height='600'
                     xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
                     xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
                     xmlns:controls='using:Microsoft.UI.Xaml.Controls'>
                    <controls:ItemsRepeaterScrollHost.Resources>
                        <DataTemplate x:Key='ItemTemplate' >
                            <TextBlock Text='{Binding}' Height='50'/>
                        </DataTemplate>
                    </controls:ItemsRepeaterScrollHost.Resources>
                    <ScrollViewer x:Name='scrollviewer'>
                        <controls:ItemsRepeater x:Name='rootRepeater' ItemTemplate='{StaticResource ItemTemplate}' VerticalCacheLength='0' />
                    </ScrollViewer>
                </controls:ItemsRepeaterScrollHost>");

                rootRepeater              = (ItemsRepeater)scrollhost.FindName("rootRepeater");
                scrollViewer              = (ScrollViewer)scrollhost.FindName("scrollviewer");
                scrollViewer.ViewChanged += (sender, args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        viewChanged.Set();
                    }
                };

                rootRepeater.ItemsSource = Enumerable.Range(0, 500);
                Content = scrollhost;
            });

            // scroll down several times and validate current anchor
            for (int i = 1; i < 10; i++)
            {
                IdleSynchronizer.Wait();
                RunOnUIThread.Execute(() =>
                {
                    scrollViewer.ChangeView(null, i * 200, null);
                });

                Verify.IsTrue(viewChanged.WaitOne(DefaultWaitTimeInMS));
                viewChanged.Reset();

                RunOnUIThread.Execute(() =>
                {
                    Verify.AreEqual(i * 200, scrollViewer.VerticalOffset);
                    var anchor = PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5) ?
                                 scrollhost.CurrentAnchor :
                                 scrollViewer.CurrentAnchor;
                    var anchorIndex = rootRepeater.GetElementIndex(anchor);
                    Log.Comment("CurrentAnchor: " + anchorIndex);
                    Verify.AreEqual(i * 4, anchorIndex);
                });
            }
        }
示例#22
0
        private void SetBrushColor_Click(object sender, RoutedEventArgs e)
        {
            SolidColorBrush solidColorBrush = GetSolidColorBrush();

            if (solidColorBrush == null && brushPropertyName.SelectedIndex != 36)
            {
                return;
            }

            switch (brushPropertyName.SelectedIndex)
            {
            case 0:     // Background
                PageCalendar.Background = PageCalendar2.Background = solidColorBrush;
                break;

            case 2:     // BlackoutForeground
                PageCalendar.BlackoutForeground = PageCalendar2.BlackoutForeground = solidColorBrush;
                break;

            case 4:     // BorderBrush
                PageCalendar.BorderBrush = PageCalendar2.BorderBrush = solidColorBrush;
                break;

            case 5:     // CalendarItemBorderBrush
                PageCalendar.CalendarItemBorderBrush = PageCalendar2.CalendarItemBorderBrush = solidColorBrush;
                break;

            case 6:     // CalendarItemBackground
                PageCalendar.CalendarItemBackground = PageCalendar2.CalendarItemBackground = solidColorBrush;
                break;

            case 8:     // CalendarItemForeground
                PageCalendar.CalendarItemForeground = PageCalendar2.CalendarItemForeground = solidColorBrush;
                break;

            case 12:     // Foreground
                PageCalendar.Foreground = PageCalendar2.Foreground = solidColorBrush;
                break;

            case 13:     // HoverBorderBrush
                PageCalendar.HoverBorderBrush = PageCalendar2.HoverBorderBrush = solidColorBrush;
                break;

            case 14:     // OutOfScopeBackground
                PageCalendar.OutOfScopeBackground = PageCalendar2.OutOfScopeBackground = solidColorBrush;
                break;

            case 15:     // OutOfScopeForeground
                PageCalendar.OutOfScopeForeground = PageCalendar2.OutOfScopeForeground = solidColorBrush;
                break;

            case 18:     // PressedBorderBrush
                PageCalendar.PressedBorderBrush = PageCalendar2.PressedBorderBrush = solidColorBrush;
                break;

            case 19:     // PressedForeground
                PageCalendar.PressedForeground = PageCalendar2.PressedForeground = solidColorBrush;
                break;

            case 20:     // SelectedBorderBrush
                PageCalendar.SelectedBorderBrush = PageCalendar2.SelectedBorderBrush = solidColorBrush;
                break;

            case 23:     // SelectedForeground
                PageCalendar.SelectedForeground = PageCalendar2.SelectedForeground = solidColorBrush;
                break;

            case 24:     // SelectedHoverBorderBrush
                PageCalendar.SelectedHoverBorderBrush = PageCalendar2.SelectedHoverBorderBrush = solidColorBrush;
                break;

            case 26:     // SelectedPressedBorderBrush
                PageCalendar.SelectedPressedBorderBrush = PageCalendar2.SelectedPressedBorderBrush = solidColorBrush;
                break;

            case 32:     // TodayForeground
                PageCalendar.TodayForeground = PageCalendar2.TodayForeground = solidColorBrush;
                break;

            case 36:     // CalendarViewDayItem.Background
                SetBackgrounds(PageCalendar, solidColorBrush);
                SetBackgrounds(PageCalendar2, solidColorBrush);
                break;

            default:
                if (PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.TwentyOneH1))
                {
                    switch (brushPropertyName.SelectedIndex)
                    {
                    case 1:         // BlackoutBackground
                        PageCalendar.BlackoutBackground = PageCalendar2.BlackoutBackground = solidColorBrush;
                        break;

                    case 3:         // BlackoutStrikethroughBrush
                        PageCalendar.BlackoutStrikethroughBrush = PageCalendar2.BlackoutStrikethroughBrush = solidColorBrush;
                        break;

                    case 7:         // CalendarItemDisabledBackground
                        PageCalendar.CalendarItemDisabledBackground = PageCalendar2.CalendarItemDisabledBackground = solidColorBrush;
                        break;

                    case 9:         // CalendarItemHoverBackground
                        PageCalendar.CalendarItemHoverBackground = PageCalendar2.CalendarItemHoverBackground = solidColorBrush;
                        break;

                    case 10:         // CalendarItemPressedBackground
                        PageCalendar.CalendarItemPressedBackground = PageCalendar2.CalendarItemPressedBackground = solidColorBrush;
                        break;

                    case 11:         // DisabledForeground
                        PageCalendar.DisabledForeground = PageCalendar2.DisabledForeground = solidColorBrush;
                        break;

                    case 16:         // OutOfScopeHoverForeground
                        PageCalendar.OutOfScopeHoverForeground = PageCalendar2.OutOfScopeHoverForeground = solidColorBrush;
                        break;

                    case 17:         // OutOfScopePressedForeground
                        PageCalendar.OutOfScopePressedForeground = PageCalendar2.OutOfScopePressedForeground = solidColorBrush;
                        break;

                    case 21:         // SelectedDisabledBorderBrush
                        PageCalendar.SelectedDisabledBorderBrush = PageCalendar2.SelectedDisabledBorderBrush = solidColorBrush;
                        break;

                    case 22:         // SelectedDisabledForeground
                        PageCalendar.SelectedDisabledForeground = PageCalendar2.SelectedDisabledForeground = solidColorBrush;
                        break;

                    case 25:         // SelectedHoverForeground
                        PageCalendar.SelectedHoverForeground = PageCalendar2.SelectedHoverForeground = solidColorBrush;
                        break;

                    case 27:         // SelectedPressedForeground
                        PageCalendar.SelectedPressedForeground = PageCalendar2.SelectedPressedForeground = solidColorBrush;
                        break;

                    case 28:         // TodayBackground
                        PageCalendar.TodayBackground = PageCalendar2.TodayBackground = solidColorBrush;
                        break;

                    case 29:         // TodayBlackoutBackground
                        PageCalendar.TodayBlackoutBackground = PageCalendar2.TodayBlackoutBackground = solidColorBrush;
                        break;

                    case 30:         // TodayBlackoutForeground
                        PageCalendar.TodayBlackoutForeground = PageCalendar2.TodayBlackoutForeground = solidColorBrush;
                        break;

                    case 31:         // TodayDisabledBackground
                        PageCalendar.TodayDisabledBackground = PageCalendar2.TodayDisabledBackground = solidColorBrush;
                        break;

                    case 33:         // TodayHoverBackground
                        PageCalendar.TodayHoverBackground = PageCalendar2.TodayHoverBackground = solidColorBrush;
                        break;

                    case 34:         // TodayPressedBackground
                        PageCalendar.TodayPressedBackground = PageCalendar2.TodayPressedBackground = solidColorBrush;
                        break;

                    case 35:         // TodaySelectedInnerBorderBrush
                        PageCalendar.TodaySelectedInnerBorderBrush = PageCalendar2.TodaySelectedInnerBorderBrush = solidColorBrush;
                        break;
                    }
                }
                break;
            }
        }
示例#23
0
        public void CanGrowCacheBuffer()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport feature is not available below RS5");
                return;
            }

            Scroller      scroller = null;
            ItemsRepeater repeater = null;
            var           measureRealizationRects = new List <Rect>();
            var           arrangeRealizationRects = new List <Rect>();
            var           fullCacheEvent          = new ManualResetEvent(initialState: false);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Preparing the visual tree...");

                scroller = new Scroller
                {
                    Width  = 400,
                    Height = 400
                };

                var layout = new MockVirtualizingLayout
                {
                    MeasureLayoutFunc = (availableSize, context) =>
                    {
                        var ctx = (VirtualizingLayoutContext)context;
                        measureRealizationRects.Add(ctx.RealizationRect);
                        return(new Size(1000, 2000));
                    },

                    ArrangeLayoutFunc = (finalSize, context) =>
                    {
                        var ctx = (VirtualizingLayoutContext)context;
                        arrangeRealizationRects.Add(ctx.RealizationRect);

                        if (ctx.RealizationRect.Height == scroller.Height * (repeater.VerticalCacheLength + 1))
                        {
                            fullCacheEvent.Set();
                        }

                        return(finalSize);
                    }
                };

                repeater = new ItemsRepeater()
                {
                    Layout = layout
                };

                scroller.Content = repeater;
                Content          = scroller;
            });

            if (!fullCacheEvent.WaitOne(500000))
            {
                Verify.Fail("Cache full size never reached.");
            }
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                var cacheLength = repeater.VerticalCacheLength;
                var expectedRealizationWindow = new Rect(
                    -cacheLength / 2 * scroller.Width,
                    -cacheLength / 2 * scroller.Height,
                    (1 + cacheLength) * scroller.Width,
                    (1 + cacheLength) * scroller.Height);

                Log.Comment("Validate that the realization window reached full size.");
                Verify.AreEqual(expectedRealizationWindow, measureRealizationRects.Last());

                Log.Comment("Validate that the realization window grew by 40 pixels each time during the process.");
                for (int i = 2; i < measureRealizationRects.Count; ++i)
                {
                    Verify.AreEqual(-40, measureRealizationRects[i].X - measureRealizationRects[i - 1].X);
                    Verify.AreEqual(-40, measureRealizationRects[i].Y - measureRealizationRects[i - 1].Y);
                    Verify.AreEqual(80, measureRealizationRects[i].Width - measureRealizationRects[i - 1].Width);
                    Verify.AreEqual(80, measureRealizationRects[i].Height - measureRealizationRects[i - 1].Height);

                    Verify.AreEqual(-40, arrangeRealizationRects[i].X - arrangeRealizationRects[i - 1].X);
                    Verify.AreEqual(-40, arrangeRealizationRects[i].Y - arrangeRealizationRects[i - 1].Y);
                    Verify.AreEqual(80, arrangeRealizationRects[i].Width - arrangeRealizationRects[i - 1].Width);
                    Verify.AreEqual(80, arrangeRealizationRects[i].Height - arrangeRealizationRects[i - 1].Height);
                }
            });
        }
示例#24
0
        public void ValidateOneScrollViewerScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport is not available below RS5");
                return;
            }

            var          realizationRects         = new List <Rect>();
            ScrollViewer scrollViewer             = null;
            var          viewChangeCompletedEvent = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 600), realizationRects),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                scrollViewer = new ScrollViewer
                {
                    Content = repeater,
                    Width   = 200,
                    Height  = 300
                };

                Content = scrollViewer;
                Content.UpdateLayout();

                Verify.AreEqual(2, realizationRects.Count);
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 300), realizationRects[1]);
                realizationRects.Clear();

                scrollViewer.ViewChanged += (Object sender, ScrollViewerViewChangedEventArgs args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        viewChangeCompletedEvent.Set();
                    }
                };
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                scrollViewer.ChangeView(0.0, 100.0, null, true);
            });
            Verify.IsTrue(viewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 300), realizationRects.Last());
                realizationRects.Clear();

                viewChangeCompletedEvent.Reset();
                scrollViewer.ChangeView(null, null, 2.0f, true);
            });
            Verify.IsTrue(viewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(
                    new Rect(0, 50, 100, 150),
                    realizationRects.Last());
                realizationRects.Clear();
            });
        }
示例#25
0
        public void ValidateOneScrollerScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport feature is not available below RS5");
                return;
            }

            var      realizationRects     = new List <Rect>();
            Scroller scroller             = null;
            var      scrollCompletedEvent = new AutoResetEvent(false);
            var      zoomCompletedEvent   = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 600), realizationRects),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                scroller = new Scroller
                {
                    Content = repeater,
                    Width   = 200,
                    Height  = 300
                };

                Content = scroller;
                Content.UpdateLayout();

                Verify.AreEqual(2, realizationRects.Count);
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 300), realizationRects[1]);
                realizationRects.Clear();

                scroller.ScrollCompleted += (Scroller sender, ScrollCompletedEventArgs args) =>
                {
                    scrollCompletedEvent.Set();
                };

                scroller.ZoomCompleted += (Scroller sender, ZoomCompletedEventArgs args) =>
                {
                    zoomCompletedEvent.Set();
                };
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                scroller.ScrollTo(0.0, 100.0, new ScrollOptions(AnimationMode.Disabled, SnapPointsMode.Ignore));
            });
            Verify.IsTrue(scrollCompletedEvent.WaitOne(DefaultWaitTimeInMS));
            CompositionPropertySpy.SynchronouslyTickUIThread(1);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 300), realizationRects.Last());
                realizationRects.Clear();

                scroller.ZoomTo(2.0f, Vector2.Zero, new ZoomOptions(AnimationMode.Disabled, SnapPointsMode.Ignore));
            });
            Verify.IsTrue(zoomCompletedEvent.WaitOne(DefaultWaitTimeInMS));
            CompositionPropertySpy.SynchronouslyTickUIThread(1);

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(
                    new Rect(0, 100, 100, 150),
                    realizationRects.Last());
                realizationRects.Clear();
            });
        }
示例#26
0
        public void ValidateTwoScrollViewerScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport is not available below RS5");
                return;
            }

            var          realizationRects   = new List <Rect>();
            ScrollViewer horizontalScroller = null;
            ScrollViewer verticalScroller   = null;
            var          horizontalViewChangeCompletedEvent = new AutoResetEvent(false);
            var          verticalViewChangeCompletedEvent   = new AutoResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 500), realizationRects),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                horizontalScroller = new ScrollViewer
                {
                    Content = repeater,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Disabled,
                    HorizontalScrollMode          = ScrollMode.Enabled,
                    VerticalScrollMode            = ScrollMode.Disabled
                };

                verticalScroller = new ScrollViewer
                {
                    Content = horizontalScroller,
                    Width   = 200,
                    Height  = 200
                };

                Content = verticalScroller;
                Content.UpdateLayout();

                Verify.AreEqual(2, realizationRects.Count);
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 200), realizationRects[1]);
                realizationRects.Clear();

                horizontalScroller.ViewChanged += (Object sender, ScrollViewerViewChangedEventArgs args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        horizontalViewChangeCompletedEvent.Set();
                    }
                };

                verticalScroller.ViewChanged += (Object sender, ScrollViewerViewChangedEventArgs args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        verticalViewChangeCompletedEvent.Set();
                    }
                };
            });
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(() =>
            {
                verticalScroller.ChangeView(0.0, 100.0, null, true);
            });
            Verify.IsTrue(verticalViewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 200), realizationRects.Last());
                realizationRects.Clear();

                // Max viewport offset is (300, 300). Horizontal viewport offset
                // is expected to get coerced from 400 to 300.
                horizontalScroller.ChangeView(400.0, 100.0, null, true);
            });
            Verify.IsTrue(horizontalViewChangeCompletedEvent.WaitOne(DefaultWaitTimeInMS));

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(300, 100, 200, 200), realizationRects.Last());
                realizationRects.Clear();
            });
        }
 public void SetPlatformConfiguration(PlatformConfiguration platformConfiguration)
 {
     PlatformConfiguration = platformConfiguration;
 }
示例#28
0
        public void ValidateBasicScrollViewerScenario()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone5))
            {
                Log.Warning("Skipping since version is less than RS5 and effective viewport is not available below RS5");
                return;
            }

            var              realizationRects         = new List <Rect>();
            var              viewChangeCompletedEvent = new AutoResetEvent(false);
            ScrollViewer     scrollViewer             = null;
            ManualResetEvent viewChanged    = new ManualResetEvent(false);
            ManualResetEvent layoutMeasured = new ManualResetEvent(false);

            RunOnUIThread.Execute(() =>
            {
                var repeater = new ItemsRepeater()
                {
                    Layout = GetMonitoringLayout(new Size(500, 600), realizationRects, layoutMeasured),
                    HorizontalCacheLength = 0.0,
                    VerticalCacheLength   = 0.0
                };

                scrollViewer = new ScrollViewer {
                    Content = repeater,
                    Width   = 200,
                    Height  = 300,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden,
                };

                scrollViewer.ViewChanged += (sender, args) =>
                {
                    if (!args.IsIntermediate)
                    {
                        Log.Comment("ViewChanged " + scrollViewer.HorizontalOffset + ":" + scrollViewer.VerticalOffset);
                        viewChanged.Set();
                    }
                };

                Content = scrollViewer;
            });

            Verify.IsTrue(layoutMeasured.WaitOne(), "Did not receive measure on layout");

            RunOnUIThread.Execute(() =>
            {
                // First layout pass will invalidate measure during the first arrange
                // so that we can get a viewport during the second measure/arrange pass.
                Verify.AreEqual(new Rect(0, 0, 0, 0), realizationRects[0]);
                Verify.AreEqual(new Rect(0, 0, 200, 300), realizationRects[1]);
                realizationRects.Clear();

                viewChanged.Reset();
                layoutMeasured.Reset();
                scrollViewer.ChangeView(null, 100.0, 1.0f, disableAnimation: true);
            });

            IdleSynchronizer.Wait();
            Verify.IsTrue(viewChanged.WaitOne(), "Did not receive view changed event");
            Verify.IsTrue(layoutMeasured.WaitOne(), "Did not receive measure on layout");
            viewChanged.Reset();
            layoutMeasured.Reset();

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(0, 100, 200, 300), realizationRects.Last());
                realizationRects.Clear();
                viewChangeCompletedEvent.Reset();

                // Max viewport offset is (300, 400). Horizontal viewport offset
                // is expected to get coerced from 400 to 300.
                scrollViewer.ChangeView(400, 100.0, 1.0f, disableAnimation: true);
            });

            IdleSynchronizer.Wait();
            Verify.IsTrue(viewChanged.WaitOne(), "Did not receive view changed event");
            Verify.IsTrue(layoutMeasured.WaitOne(), "Did not receive measure on layout");
            viewChanged.Reset();
            layoutMeasured.Reset();

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(300, 100, 200, 300), realizationRects.Last());
                realizationRects.Clear();
                viewChangeCompletedEvent.Reset();

                scrollViewer.ChangeView(null, null, 2.0f, disableAnimation: true);
            });

            IdleSynchronizer.Wait();
            Verify.IsTrue(viewChanged.WaitOne(), "Did not receive view changed event");
            Verify.IsTrue(layoutMeasured.WaitOne(), "Did not receive measure on layout");
            viewChanged.Reset();
            layoutMeasured.Reset();

            RunOnUIThread.Execute(() =>
            {
                Verify.AreEqual(new Rect(150, 50, 100, 150), realizationRects.Last());
                realizationRects.Clear();
            });
        }
        public void ChangeOffsetsWithAdditionalVelocityAndAttachedScrollControllers()
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping failing test on RS1.");
                return;
            }

            Scroller  scroller = null;
            Rectangle rectangleScrollerChild = null;
            CompositionScrollController horizontalScrollController = null;
            CompositionScrollController verticalScrollController   = null;
            AutoResetEvent loadedEvent = new AutoResetEvent(false);
            AutoResetEvent viewChangeCompletedEvent = new AutoResetEvent(false);
            int            hOffsetChangeId          = -1;
            int            vOffsetChangeId          = -1;

            RunOnUIThread.Execute(() =>
            {
                rectangleScrollerChild = new Rectangle();
                scroller = new Scroller();
                horizontalScrollController = new CompositionScrollController();
                verticalScrollController   = new CompositionScrollController();

                horizontalScrollController.Orientation = Orientation.Horizontal;

                horizontalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                verticalScrollController.LogMessage += (CompositionScrollController sender, string args) =>
                {
                    Log.Comment(args);
                };

                scroller.HorizontalScrollController = horizontalScrollController;
                scroller.VerticalScrollController   = verticalScrollController;

                SetupUIWithScrollControllers(
                    scroller,
                    rectangleScrollerChild,
                    horizontalScrollController,
                    verticalScrollController,
                    loadedEvent);

                horizontalScrollController.OffsetChangeCompleted += (CompositionScrollController sender, CompositionScrollControllerOffsetChangeCompletedEventArgs args) =>
                {
                    Log.Comment("ChangeOffset completed. OffsetChangeId=" + args.OffsetChangeId + ", Result=" + args.Result);

                    Log.Comment("Setting completion event");
                    viewChangeCompletedEvent.Set();
                };
            });

            WaitForEvent("Waiting for Loaded event", loadedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("HorizontalScrollController size={0}, {1}", horizontalScrollController.ActualWidth, horizontalScrollController.ActualHeight);
                Log.Comment("VerticalScrollController size={0}, {1}", verticalScrollController.ActualWidth, verticalScrollController.ActualHeight);
            });

            Log.Comment("Jump to zoomFactor 0.75");
            ChangeZoomFactor(
                scroller,
                0.75f,
                0.0f,
                0.0f,
                ScrollerViewKind.Absolute,
                ScrollerViewChangeKind.DisableAnimation);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("Adding velocity to horizontal offset, with default inertia decay rate");
                hOffsetChangeId = horizontalScrollController.ChangeOffset(
                    100.0f /*additionalVelocity*/, null /*inertiaDecayRate*/);

                Log.Comment("Adding velocity to vertical offset, with default inertia decay rate");
                vOffsetChangeId = verticalScrollController.ChangeOffset(
                    100.0f /*additionalVelocity*/, null /*inertiaDecayRate*/);

                Verify.AreEqual(hOffsetChangeId, vOffsetChangeId);
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.IsTrue(scroller.HorizontalOffset > 20.0);
                Verify.IsTrue(scroller.VerticalOffset > 20.0);

                Log.Comment("Adding negative velocity to horizontal offset, with custom inertia decay rate");
                hOffsetChangeId = horizontalScrollController.ChangeOffset(
                    -50.0f /*additionalVelocity*/, 0.9f /*inertiaDecayRate*/);

                Log.Comment("Adding negative velocity to vertical offset, with custom inertia decay rate");
                vOffsetChangeId = verticalScrollController.ChangeOffset(
                    -50.0f /*additionalVelocity*/, 0.9f /*inertiaDecayRate*/);

                Verify.AreEqual(hOffsetChangeId, vOffsetChangeId);

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.IsTrue(scroller.HorizontalOffset < 20.0);
                Verify.IsTrue(scroller.VerticalOffset < 20.0);

                Log.Comment("Adding velocity to horizontal offset, with no inertia decay rate");
                hOffsetChangeId = horizontalScrollController.ChangeOffset(
                    200.0f /*additionalVelocity*/, 0.0f /*inertiaDecayRate*/);

                Log.Comment("Adding velocity to vertical offset, with no inertia decay rate");
                vOffsetChangeId = verticalScrollController.ChangeOffset(
                    200.0f /*additionalVelocity*/, 0.0f /*inertiaDecayRate*/);

                Verify.AreEqual(hOffsetChangeId, vOffsetChangeId);

                viewChangeCompletedEvent.Reset();
            });

            WaitForEvent("Waiting for operation completion", viewChangeCompletedEvent);

            RunOnUIThread.Execute(() =>
            {
                Log.Comment("scroller.HorizontalOffset={0}", scroller.HorizontalOffset);
                Log.Comment("scroller.VerticalOffset={0}", scroller.VerticalOffset);

                Verify.AreEqual(scroller.HorizontalOffset, 600.0);
                Verify.AreEqual(scroller.VerticalOffset, 250.0);
            });
        }
示例#30
0
        private void AnchoringAtFarEdgeWhileDecreasingViewport(Orientation orientation)
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Comment("Skipping test on RS1 where InteractionTracker's AdjustPositionXIfGreaterThanThreshold/AdjustPositionYIfGreaterThanThreshold are ineffective in this scenario.");
                return;
            }

            using (ScrollerTestHooksHelper scrollerTestHooksHelper = new ScrollerTestHooksHelper())
            {
                Scroller       scroller                 = null;
                AutoResetEvent scrollerLoadedEvent      = new AutoResetEvent(false);
                AutoResetEvent scrollerViewChangedEvent = new AutoResetEvent(false);

                RunOnUIThread.Execute(() =>
                {
                    scroller = new Scroller();

                    SetupDefaultAnchoringUI(orientation, scroller, scrollerLoadedEvent);
                });

                WaitForEvent("Waiting for Loaded event", scrollerLoadedEvent);

                ZoomTo(scroller, 2.0f, 0.0f, 0.0f, AnimationMode.Disabled, SnapPointsMode.Ignore);

                double horizontalOffset = 0.0;
                double verticalOffset   = 0.0;

                RunOnUIThread.Execute(() =>
                {
                    if (orientation == Orientation.Vertical)
                    {
                        verticalOffset = scroller.ExtentHeight * 2.0 - scroller.Height;
                        scroller.VerticalAnchorRatio = 1.0;
                    }
                    else
                    {
                        horizontalOffset = scroller.ExtentWidth * 2.0 - scroller.Width;
                        scroller.HorizontalAnchorRatio = 1.0;
                    }
                });

                ScrollTo(scroller, horizontalOffset, verticalOffset, AnimationMode.Disabled, SnapPointsMode.Ignore, false /*hookViewChanged*/);

                RunOnUIThread.Execute(() =>
                {
                    scroller.ViewChanged += delegate(Scroller sender, object args)
                    {
                        Log.Comment("ViewChanged - HorizontalOffset={0}, VerticalOffset={1}, ZoomFactor={2}",
                                    sender.HorizontalOffset, sender.VerticalOffset, sender.ZoomFactor);
                        scrollerViewChangedEvent.Set();
                    };

                    if (orientation == Orientation.Vertical)
                    {
                        Log.Comment("Decreasing viewport height");
                        scroller.Height -= 100;
                    }
                    else
                    {
                        Log.Comment("Decreasing viewport width");
                        scroller.Width -= 100;
                    }
                });

                WaitForEvent("Waiting for Scroller.ViewChanged event", scrollerViewChangedEvent);
                IdleSynchronizer.Wait();

                RunOnUIThread.Execute(() =>
                {
                    if (orientation == Orientation.Vertical)
                    {
                        verticalOffset = scroller.ExtentHeight * 2.0 - scroller.Height;
                    }
                    else
                    {
                        horizontalOffset = scroller.ExtentWidth * 2.0 - scroller.Width;
                    }

                    Log.Comment("Scroller offset change expected");
                    Verify.AreEqual(scroller.HorizontalOffset, horizontalOffset);
                    Verify.AreEqual(scroller.VerticalOffset, verticalOffset);
                });
            }
        }