Beispiel #1
0
        public void VerifyThatProgrammaticallyRemovingEngagementResetsValue()
        {
            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;
                }

                TextBlock magicDisengagerTextBlock = new TextBlock(FindElement.ById("MagicDisengagerTextBlock"));
                magicDisengagerTextBlock.SetFocus();
                InputHelper.ScrollToElement(magicDisengagerTextBlock);

                UIObject magicDisengager = FindElement.ById("MagicDisengager");
                Verify.IsNotNull(magicDisengager, "Verifying that we found a UIElement called MagicDisengager");
                magicDisengager.SetFocus();

                Wait.ForIdle();

                GamepadHelper.PressButton(magicDisengager, GamepadButton.A);
                GamepadHelper.PressButton(magicDisengager, GamepadButton.DPadRight);
                Verify.AreEqual("2", magicDisengagerTextBlock.DocumentText);

                // This control is rigged to programmatically disengage at 3
                GamepadHelper.PressButton(magicDisengager, GamepadButton.DPadRight);
                Verify.AreEqual("null", magicDisengagerTextBlock.DocumentText);
            }
        }
Beispiel #2
0
        public void GamePadTest()
        {
            using (var setup = new TestSetupHelper("TabView Tests"))
            {
                Button  tabContent        = FindElement.ByName <Button>("FirstTabButton");
                Button  toggleThemeButton = FindElement.ById <Button>("__ToggleThemeButton");
                TabItem firstTab          = FindElement.ByName <TabItem>("FirstTab");
                TabItem secondTab         = FindElement.ByName <TabItem>("SecondTab");
                TabItem lastTab           = FindElement.ByName <TabItem>("LastTab");
                Button  addButton         = FindElement.ById <Button>("AddButton");

                firstTab.SetFocus();

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickRight);
                Wait.ForIdle();
                Verify.IsTrue(secondTab.HasKeyboardFocus, "GamePad Right should move focus to second tab");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickLeft);
                Wait.ForIdle();
                Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Left should move focus to first tab");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickDown);
                Wait.ForIdle();
                Verify.IsTrue(tabContent.HasKeyboardFocus, "GamePad Down should move focus to tab content");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
                Wait.ForIdle();
                Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Up should move focus to tabs");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
                Wait.ForIdle();
                Verify.IsTrue(toggleThemeButton.HasKeyboardFocus, "GamePad Up should move to toggle theme button");
            }
        }
        public override float GetFloat(Keybind bind)
        {
            if (!ValidController || !bind.Xbox.Valid)
            {
                return(0);
            }

            return(GamepadHelper.GetGamepadTrigger(_playerIndex, bind.Xbox.XboxTrigger));
        }
        public override bool GetButtonReleased(Keybind bind)
        {
            if (!ValidController || !bind.Xbox.Valid)
            {
                return(false);
            }

            return(GamepadHelper.GetGamepadButtonReleased(_playerIndex, bind.Xbox.XboxButton));
        }
        public override Vector2 GetVector(Keybind bind)
        {
            if (!ValidController || !bind.Xbox.Valid)
            {
                return(Vector2.zero);
            }

            return(GamepadHelper.GetGamepadStick(_playerIndex, bind.Xbox.XboxStick));
        }
        public override void Vibrate(float amount, float left, float right, float duration = 0)
        {
            if (!ValidController)
            {
                return;
            }

            GamepadHelper.SetVibration(_playerIndex, left, right);

            // TODO: Duration
        }
        public void GamepadCanEscapeAndDoesNotSelectWithFocus()
        {
            using (var setup = new TestSetupHelper("RadioButtons Tests"))
            {
                elements = new RadioButtonsTestPageElements();
                foreach (RadioButtonsSourceLocation location in Enum.GetValues(typeof(RadioButtonsSourceLocation)))
                {
                    SetSource(location);
                    foreach (RadioButtonsSourceType type in Enum.GetValues(typeof(RadioButtonsSourceType)))
                    {
                        SetItemType(type);
                        bool useBackup = type == RadioButtonsSourceType.String;
                        SetNumberOfColumns(3);

                        // On RS2 the keyboarding model is different which results in different behavior here.
                        if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone3))
                        {
                            TapOnItem(3, useBackup);
                            VerifySelectedFocusedIndex(3);
                        }
                        else
                        {
                            TapOnItem(9, useBackup);
                            VerifySelectedFocusedIndex(9);
                        }
                        GamepadHelper.PressButton(null, GamepadButton.DPadDown);
                        VerifyRadioButtonsHasFocus(false);

                        TapOnItem(0, useBackup);
                        VerifySelectedFocusedIndex(0);
                        GamepadHelper.PressButton(null, GamepadButton.DPadUp);
                        VerifyRadioButtonsHasFocus(false);

                        TapOnItem(7, useBackup);
                        VerifySelectedFocusedIndex(7);
                        GamepadHelper.PressButton(null, GamepadButton.DPadRight);
                        VerifyRadioButtonsHasFocus(false);

                        TapOnItem(7, useBackup);
                        VerifySelectedFocusedIndex(7);
                        GamepadHelper.PressButton(null, GamepadButton.DPadDown);
                        VerifySelectedIndex(7);
                        VerifyFocusedIndex(8);

                        GamepadHelper.PressButton(null, GamepadButton.DPadLeft);
                        VerifySelectedIndex(7);
                        VerifyFocusedIndex(5);
                    }
                }
            }
        }
Beispiel #8
0
        private void PressGamepadButtonAndVerifyOffsetAndFocus(GamepadButton gamepadButton, string expectedFocusedItemName, double expectedHorizontalOffset, double expectedVerticalOffset)
        {
            var  focusChangedWaiter = new FocusAcquiredWaiter();
            bool waitForFocusChange = UIObject.Focused.Name != expectedFocusedItemName;

            GamepadHelper.PressButton(null, gamepadButton);

            if (waitForFocusChange)
            {
                focusChangedWaiter.Wait(TimeSpan.FromSeconds(2));
            }

            WaitForScrollViewerOffsets(expectedHorizontalOffset, expectedVerticalOffset);
            Verify.AreEqual(expectedFocusedItemName, UIObject.Focused.Name, "Verify focused element");
        }
        public void GamepadTest()
        {
            using (var setup = new TestSetupHelper("NumberBox Tests"))
            {
                RangeValueSpinner numBox = FindElement.ByName <RangeValueSpinner>("TestNumberBox");

                Log.Comment("Verify that pressing A validates textbox contents");
                EnterText(numBox, "8", false);
                GamepadHelper.PressButton(numBox, GamepadButton.A);
                Wait.ForIdle();
                Verify.AreEqual(8, numBox.Value);

                Log.Comment("Verify that pressing B cancels entered text");
                EnterText(numBox, "3", false);
                GamepadHelper.PressButton(numBox, GamepadButton.B);
                Wait.ForIdle();
                Verify.AreEqual(8, numBox.Value);
            }
        }
        static void Main()
        {
            using (new Mutex(true, Assembly.GetExecutingAssembly().FullName, out var createdNew))
            {
                if (!createdNew)
                {
                    MessageBox.Show($@"You can run {AppName} only once at a time!", $@"{AppName} Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                var gamepadHelper = new GamepadHelper();
                var gamePadRemote = new GamepadRemote();
                using (var context = new Context(new GamepadScanner(gamepadHelper, gamePadRemote), gamepadHelper, gamePadRemote, AppName, AppVersion))
                    Application.Run(context);
            }
        }
        [TestProperty("Ignore", "True")] // #3956
        public void GamePadTest()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone3))
            {
                // Disabled on RS2 for reliability issues: https://github.com/microsoft/microsoft-ui-xaml/issues/3093
                Log.Warning("This test is unreliable on RS2 and has been disabled.");
                return;
            }
            using (var setup = new TestSetupHelper("TabView Tests"))
            {
                Button       tabContent = FindElement.ByName <Button>("FirstTabButton");
                ToggleButton toggleInnerFrameDimensions = FindElement.ById <ToggleButton>("__InnerFrameInLabDimensions");
                TabItem      firstTab  = FindElement.ByName <TabItem>("FirstTab");
                TabItem      secondTab = FindElement.ByName <TabItem>("SecondTab");
                TabItem      lastTab   = FindElement.ByName <TabItem>("LastTab");
                Button       addButton = FindElement.ById <Button>("AddButton");

                firstTab.SetFocus();

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickRight);
                Wait.ForIdle();
                Verify.IsTrue(secondTab.HasKeyboardFocus, "GamePad Right should move focus to second tab");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickLeft);
                Wait.ForIdle();
                Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Left should move focus to first tab");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickDown);
                Wait.ForIdle();
                Verify.IsTrue(tabContent.HasKeyboardFocus, "GamePad Down should move focus to tab content");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
                Wait.ForIdle();
                Verify.IsTrue(firstTab.HasKeyboardFocus, "GamePad Up should move focus to tabs");

                GamepadHelper.PressButton(null, GamepadButton.LeftThumbstickUp);
                Wait.ForIdle();
                Verify.IsTrue(toggleInnerFrameDimensions.HasKeyboardFocus, "GamePad Up should move to toggle inner frame dimensions button");
            }
        }
        public void VerifyShoulderNavigationEnabledOnlySelectionFollowsFocusIsCorrect()
        {
            using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "Top NavigationView Test" }))
            {
                var navView = FindElement.ByName("NavView");
                var shoulderNavigationEnabled     = new ComboBox(FindElement.ByName("ShoulderNavigationEnabledSetter"));
                var selectionFollowsFocusComboBox = new ComboBox(FindElement.ByName("SelectionFollowsFocusSetter"));

                Log.Comment("Set ShoulderNavigation to always");
                shoulderNavigationEnabled.SelectItemByName("ShoulderNavigationEnabledWhenSelectionFollowsFocus");

                Log.Comment("Set SelectionFollowsFocus to enabled");
                selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusEnabled");

                Log.Comment("Select first item");
                FindElement.ByName("Home").Click();
                Wait.ForIdle();
                Verify.AreEqual("Home", GetSelectedItem());

                GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);
                Wait.ForIdle();
                Verify.AreEqual("Apps", GetSelectedItem());

                Log.Comment("Set SelectionFollowsFocus to disabled");
                selectionFollowsFocusComboBox.SelectItemByName("SelectionFollowsFocusDisabled");
                Wait.ForIdle();

                GamepadHelper.PressButton(navView, GamepadButton.RightShoulder);

                Wait.ForIdle();
                Verify.AreEqual("Apps", GetSelectedItem());
            }

            string GetSelectedItem()
            {
                return(FindElement.ByName("SelectionChangedResult").GetText());
            }
        }
        private void Update()
        {
            if (AnyController)
            {
                for (int i = 0; i < GamepadHelper.GamepadCount; ++i)
                {
                    if (!GamepadHelper.GamepadConnected(i))
                    {
                        continue;
                    }

                    if (GamepadHelper.AnyInput(i))
                    {
                        PlayerIndex = i;
                        break;
                    }
                }

                if (!GamepadHelper.GamepadConnected(PlayerIndex))
                {
                    PlayerIndex = -1;
                }
            }
        }
        public void PaneNotOpeningTopMode()
        {
            var testScenarios = RegressionTestScenario.BuildLeftNavRegressionTestScenarios();

            foreach (var testScenario in testScenarios)
            {
                if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone4))
                {
                    Log.Warning("Test is disabled on pre-RS4 because NavigationView Gamepad interaction is not supported pre-RS4");
                    return;
                }
                using (var setup = new TestSetupHelper(new[] { "NavigationView Tests", "NavigationView TopNav Test" }))
                {
                    CheckBox isPaneOpenCheckBox = new CheckBox(FindElement.ById("IsPaneOpenCheckBox"));

                    Verify.AreEqual(ToggleState.Off, isPaneOpenCheckBox.ToggleState, "IsPaneOpen expected to be false");

                    GamepadHelper.PressButton(FindElement.ById("NavView"), GamepadButton.View);

                    Wait.ForIdle();
                    Verify.AreEqual(ToggleState.Off, isPaneOpenCheckBox.ToggleState, "IsPaneOpen expected to be True after increasing the width of the control from compact to expanded");
                }
            }
        }
Beispiel #15
0
 private void Update()
 {
     GamepadHelper.Update();
 }
 private void OnDestroy()
 {
     GamepadHelper.SetVibration(PlayerIndex, 0, 0);
 }
Beispiel #17
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");
            }
        }
Beispiel #18
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);
            }
        }