void VerifyLights()

in dev/Lights/ApiTests/Lights_ApiTests/LightConfigurationTests.cs [130:345]


        void VerifyLights(CoreApplicationView whichView, bool forceLightAttachDuringLayout, bool resetWindowContent)
        {
            if (!PlatformConfiguration.IsOsVersionGreaterThanOrEqual(OSVersion.Redstone2))
            {
                Log.Warning("Lights don't work on RS1 and earlier, nothing to verify.");
                return;
            }

            AutoResetEvent popupOpened = null;
            Popup myPopup = null;
            StackPanel mySPRoot = null;

            RunOnUIThread.Execute(whichView, () =>
            {
                mySPRoot = new StackPanel();

                // Lights will be created when the first RevealBrush enters the tree
                if (!forceLightAttachDuringLayout)
                {
                    Button myButton = new Button();
                    myButton.Width = 75;
                    myButton.Height = 50;
                    myButton.Style = Application.Current.Resources["ButtonRevealStyle"] as Style;
                    mySPRoot.Children.Add(myButton);
                }
                else
                {
                    string popupWithGridview = TestUtilities.ProcessTestXamlForRepo(
                        @"<Popup 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' x:Name='MarkupPopup' IsOpen='False'>
                        <Popup.Resources>
                            <Style TargetType='GridViewItem' x:Key='RevealExampleGridViewItem'>
                                <Setter Property='Background' Value='Transparent' />
                                <Setter Property='HorizontalContentAlignment' Value='Center' />
                                <Setter Property='VerticalContentAlignment' Value='Center' />
                                <Setter Property='Template'>
                                    <Setter.Value>
                                        <ControlTemplate TargetType='GridViewItem'>
                                            <controls:RevealListViewItemPresenter ContentTransitions='{TemplateBinding ContentTransitions}'
                                        SelectionCheckMarkVisualEnabled='{ThemeResource GridViewItemSelectionCheckMarkVisualEnabled}'
                                        CheckBrush='Transparent'
                                        CheckBoxBrush='Transparent'
                                        DragBackground='{ThemeResource GridViewItemDragBackground}'
                                        DragForeground='{ThemeResource GridViewItemDragForeground}'
                                        FocusBorderBrush='{ThemeResource GridViewItemFocusBorderBrush}'
                                        FocusSecondaryBorderBrush='{ThemeResource GridViewItemFocusSecondaryBorderBrush}'
                                        PlaceholderBackground='Transparent'
                                        PointerOverBackground='Transparent'
                                        PointerOverForeground='{ThemeResource GridViewItemForegroundPointerOver}'
                                        SelectedBackground='Transparent'
                                        SelectedForeground='{ThemeResource GridViewItemForegroundSelected}'
                                        SelectedPointerOverBackground='Transparent'
                                        PressedBackground='Transparent'
                                        SelectedPressedBackground='Transparent'
                                        DisabledOpacity='{ThemeResource ListViewItemDisabledThemeOpacity}'
                                        DragOpacity='{ThemeResource ListViewItemDragThemeOpacity}'
                                        ReorderHintOffset='{ThemeResource GridViewItemReorderHintThemeOffset}'
                                        HorizontalContentAlignment='{TemplateBinding HorizontalContentAlignment}'
                                        VerticalContentAlignment='{TemplateBinding VerticalContentAlignment}'
                                        ContentMargin='{TemplateBinding Padding}'
                                        CheckMode='{ThemeResource GridViewItemCheckMode}' />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                            <DataTemplate x:Key='BackgroundBrushDataTemplate'>
                                <Grid Margin='5' Background='{Binding Value}' >
                                    <TextBlock
                                Margin='3'
                                FontSize='12'
                                MinWidth='200'
                                MinHeight='36'
                                MaxWidth='330'
                                TextWrapping='Wrap'
                                Text='{Binding Key}' />
                                </Grid>
                            </DataTemplate>
                            <DataTemplate x:Key='BorderBrushDataTemplate'>
                                <Border Margin='5' BorderBrush='{Binding Value}' BorderThickness='3'>
                                    <TextBlock
                                Margin='3'
                                FontSize='12'
                                MinWidth='200'
                                MinHeight='36'
                                MaxWidth='330'
                                TextWrapping='Wrap'
                                Text='{Binding Key}' />
                                </Border>
                            </DataTemplate>
                        </Popup.Resources>
                        <GridView Name='BackgroundList' ItemsSource='{Binding RevealBackgroundBrushes, Mode=OneWay}' ItemContainerStyle='{StaticResource RevealExampleGridViewItem}' ItemTemplate='{StaticResource BackgroundBrushDataTemplate}' MaxWidth='700' Margin='10' MaxHeight='200'/>
                    </Popup>");

                    myPopup = XamlReader.Load(popupWithGridview) as Popup;
                    myPopup.DataContext = this;
                    mySPRoot.Children.Add(myPopup);
                }

                if (whichView != CoreApplication.MainView)
                {
                    Window.Current.Content = mySPRoot;
                }
                else
                {
                    Content = mySPRoot;
                }
            });
            IdleSynchronizer.Wait();

            if (resetWindowContent)
            {
                RunOnUIThread.Execute(whichView, () =>
                {
                    StackPanel newSPRoot = new StackPanel();
                    Button myButton = new Button();
                    myButton.Width = 75;
                    myButton.Height = 50;
                    myButton.Style = Application.Current.Resources["ButtonRevealStyle"] as Style;
                    newSPRoot.Children.Add(myButton);

                    if (whichView != CoreApplication.MainView)
                    {
                        Window.Current.Content = newSPRoot;
                        
                    }
                    else
                    {
                        Content = newSPRoot;
                    }
                });
                IdleSynchronizer.Wait();
            }

            RunOnUIThread.Execute(whichView, () =>
            {
                if (forceLightAttachDuringLayout)
                {
                    myPopup.IsOpen = true;
                }

            // Find and store public Visual Root
            _visualRoot = GetTopParent(Window.Current.Content);

                popupOpened = new AutoResetEvent(false);
            // Make an unparented popup and open it so we can check that the popup root has lights set on it too.
            Popup popup = new Popup();
                popup.Child = new Grid();
                popup.Opened += (sender, args) =>
                {

                // Find and store Popup Root
                _popupRoot = GetTopParent(popup.Child);
                    Verify.AreNotEqual(_visualRoot, _popupRoot);
                    popup.IsOpen = false;
                    popupOpened.Set();
                };
                popup.IsOpen = true;
            });
            IdleSynchronizer.Wait();

            Verify.IsTrue(popupOpened.WaitOne(TimeSpan.FromMinutes(2)), "Waiting for popup to open ");
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(whichView, () =>
            {
                _mediaFullScreened = new AutoResetEvent(false);

                Log.Comment("Creating MediaPlayerElement and going to full screen.");
                _mpe = new MediaPlayerElement();
                _mpe.AreTransportControlsEnabled = true;
                mySPRoot.Children.Add(_mpe);
                _mpe.IsFullWindow = true;
                XamlControlsResources.EnsureRevealLights(_mpe.TransportControls);
                CompositionTarget.Rendering += CompositionTarget_Rendering;
            });

            Verify.IsTrue(_mediaFullScreened.WaitOne(TimeSpan.FromMinutes(2)), "Waiting for media player to go full screen");
            IdleSynchronizer.Wait();

            // Validate each root has the expected lights
            RunOnUIThread.Execute(whichView, () =>
            {
                _pollRetry = 0;
                _validationCompleted = new AutoResetEvent(false);
                _lightValidationTimer = new DispatcherTimer();
                _lightValidationTimer.Interval = _pollInterval;
                _lightValidationTimer.Tick += PollTimer_Tick;
                _lightValidationTimer.Start();
            });

            Verify.IsTrue(_validationCompleted.WaitOne(TimeSpan.FromMinutes(2)), "Waiting for light validation to complete");
            IdleSynchronizer.Wait();

            RunOnUIThread.Execute(whichView, () =>
            {
                if (whichView == CoreApplication.MainView)
                {
                    Content = null;
                }
                else
                {
                    Window.Current.Content = null;
                }
            });
            IdleSynchronizer.Wait();

            _cleanupVerified = new AutoResetEvent(false);
            RunOnUIThread.Execute(whichView, () =>
            {
            // RevealBrush cleans itself up in a CompositionTarget.Rendering callback. Put the cleanup validation in CT.R
            // as well to let the cleanup code run.
            CompositionTarget.Rendering += CTR_CheckCleanup;
            });

            Verify.IsTrue(_cleanupVerified.WaitOne(TimeSpan.FromMinutes(1)), "Waiting for cleanup validation");
        }