Example #1
0
        private void CanUndoAndRedoIn(string textControlName)
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.Redstone5))
            {
                Log.Warning("Test is disabled pre-RS5 because programmatically undoing and redoing in text controls is not supported pre-RS5");
                return;
            }

            using (var setup = new TextCommandBarFlyoutTestSetupHelper())
            {
                UIObject            textControl        = FindElement.ById(textControlName);
                ValueImplementation textControlAsValue = new ValueImplementation(textControl);

                string initialString = textControl.GetText();
                Log.Comment("Initial contents of {0} are '{1}'", textControlName, initialString);

                Log.Comment("Selecting all text in the {0}.", textControlName);
                FindElement.ById <Button>(string.Format("{0}SelectAllButton", textControlName)).InvokeAndWait();

                Log.Comment("Giving the {0} focus.", textControlName);
                FocusHelper.SetFocus(textControl);

                Log.Comment("Typing 'hello' into the {0}.", textControlName);
                TextInput.SendText("hello");
                Wait.ForIdle();

                string finalString = textControl.GetText();
                Log.Comment("Contents of {0} are now '{1}'", textControlName, finalString);

                Log.Comment("Opening TextCommandBarFlyout.");
                OpenFlyoutOn(textControlName, asTransient: false);

                using (ValueChangedEventWaiter waiter = textControlAsValue.IsAvailable ? new ValueChangedEventWaiter(new Edit(textControl), initialString) : null)
                {
                    Log.Comment("Undoing text entry.");
                    FindElement.ByName <Button>("Undo").InvokeAndWait();
                }

                Log.Comment("Contents of {0} are now '{1}'", textControlName, textControl.GetText());
                Verify.AreEqual(initialString, textControl.GetText());

                Log.Comment("Reopening TextCommandBarFlyout.");
                OpenFlyoutOn(textControlName, asTransient: false);

                using (ValueChangedEventWaiter waiter = textControlAsValue.IsAvailable ? new ValueChangedEventWaiter(new Edit(textControl), finalString) : null)
                {
                    Log.Comment("Redoing text entry.");
                    FindElement.ByName <Button>("Redo").InvokeAndWait();
                }

                Log.Comment("Contents of {0} are now '{1}'", textControlName, textControl.GetText());
                Verify.AreEqual(finalString, textControl.GetText());
            }
        }
        public void ValidateSelectionFlyoutDoesNotTakeFocus()
        {
            using (var setup = new TextCommandBarFlyoutTestSetupHelper())
            {
                // RichEditBox only implements the Text pattern, which the "TextBlock" MITA type exposes.
                var richEditBox        = new TextBlock(FindElement.ById("RichEditBox"));
                var fillWithTextButton = new Button(FindElement.ById("RichEditBoxFillWithTextButton"));

                Log.Comment("Give focus to the RichEditBox.");
                FocusHelper.SetFocus(richEditBox);

                Log.Comment("Enter enough text to guarantee that double-tapping the RichEditBox will select text.");
                fillWithTextButton.InvokeAndWait();

                Log.Comment("Double-click to select the text and bring up the selection menu. The CommandBarFlyout should appear, but should not take focus.");
                InputHelper.LeftDoubleClick(richEditBox);
                Wait.ForIdle();

                var boldButton = FindElement.ByName("Bold");
                Verify.IsNotNull(boldButton);
                Verify.IsFalse(boldButton.HasKeyboardFocus);

                Log.Comment("Press backspace to delete the selected text. This should work because the RichEditBox should still have focus.");
                KeyboardHelper.PressKey(Key.Backspace);
                Wait.ForIdle();

                Verify.AreEqual(string.Empty, richEditBox.DocumentText);

                Log.Comment("Enter text again.");
                fillWithTextButton.InvokeAndWait();

                Log.Comment("Double-click to select the text and bring up the selection menu. The CommandBarFlyout should appear, but should not take focus.");
                InputHelper.LeftDoubleClick(richEditBox);
                Wait.ForIdle();

                boldButton = FindElement.ByName("Bold");
                Verify.IsNotNull(boldButton);
                Verify.IsFalse(boldButton.HasKeyboardFocus);

                Log.Comment("Press the A key to overwrite the selected text.");
                richEditBox.SendKeys("a");
                Wait.ForIdle();

                Verify.AreEqual("a", richEditBox.DocumentText);
            }
        }
Example #3
0
        public void ValidateUnhandledKeysOnNonTransientFlyoutDoNotCloseFlyout()
        {
            if (PlatformConfiguration.IsOSVersionLessThan(OSVersion.NineteenH1))
            {
                Log.Warning("Test is disabled pre-19H1 because the bug fix needed to support this were not available pre-19H1.");
                return;
            }

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

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

                Log.Comment("Press the down arrow key. Focus should stay in the flyout.");
                KeyboardHelper.PressKey(Key.Down);
                Wait.ForIdle();

                Log.Comment("Press the up arrow key. Focus should stay in the flyout.");
                KeyboardHelper.PressKey(Key.Up);
                Wait.ForIdle();

                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);
                    waiter.Wait();
                }
            }
        }
Example #4
0
        private void CanSelectAllIn(string textControlName)
        {
            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())
            {
                OpenFlyoutOn(textControlName, asTransient: false);

                Log.Comment("Selecting all text in the {0}.", textControlName);
                FindElement.ByName <Button>("Select All").InvokeAndWait();

                string textControlSelectionContents = FindElement.ById(textControlName).GetTextSelection();

                Log.Comment("{0} selection contents are now {1}", textControlName, textControlSelectionContents);

                string expectedString = "Lorem ipsum ergo sum";

                if (textControlName == "PasswordBox")
                {
                    string obfuscatedString = string.Empty;

                    for (int i = 0; i < expectedString.Length; i++)
                    {
                        obfuscatedString += "\u25CF";
                    }

                    expectedString = obfuscatedString;
                }

                Verify.AreEqual(expectedString, textControlSelectionContents);
            }
        }
Example #5
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();
                }
            }
        }
Example #6
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));
            }
        }