Beispiel #1
0
        public static void DisplayHost(
            Window host,
            string title,
            int width, int height,
            ShowWindowMode mode,
            long startTicks2)
        {
            long startTicks = Log.PRESENTATION("Enter", Common.LOG_CATEGORY);

            host.Title  = title;
            host.Width  = width;
            host.Height = height;

            if (mode == ShowWindowMode.Modal_ShowDialog)
            {
                long endTicks2 = Log.PRESENTATION("Exit", Common.LOG_CATEGORY, startTicks2);

                host.Title = $"{host.GetType()} loadtime: {Log.GetDuration(startTicks2, endTicks2)}";

                host.ShowDialog();
            }
            else
            {
                host.Show();
            }

            long endTicks = Log.PRESENTATION("Exit", Common.LOG_CATEGORY, startTicks2);

            host.Tag = $"{host.GetType()} loadtime: {Log.GetDuration(startTicks2, endTicks)}";

            Log.PRESENTATION("Exit", Common.LOG_CATEGORY, startTicks);
        }
Beispiel #2
0
        private static void ShowEmptyHost(Window host, string title, ShowWindowMode mode)
        {
            long startTicks = Log.EVENT_HANDLER("Enter", Common.PROJECT_NAME);

            if (host is null)
            {
                host        = new DxThemedWindowHost();
                host.Height = Common.DEFAULT_WINDOW_HEIGHT_SMALL;
                host.Width  = Common.DEFAULT_WINDOW_WIDTH_SMALL;
                host.Title  = title;
            }

            if (mode == ShowWindowMode.Modal_ShowDialog)
            {
                long endTicks2 = Log.EVENT_HANDLER("Exit", Common.PROJECT_NAME, startTicks);

                host.Title = $"{host.GetType()} loadtime: {Log.GetDuration(startTicks, endTicks2)}";

                host.ShowDialog();
            }
            else
            {
                host.Show();
            }

            long endTicks = Log.EVENT_HANDLER("Exit", Common.PROJECT_NAME, startTicks);

            host.Title = $"{host.GetType()} loadtime: {Log.GetDuration(startTicks, endTicks)}";
        }
Beispiel #3
0
        public void StartupLocation(Size?size, ShowWindowMode mode, WindowStartupLocation location)
        {
            using var window = OpenWindow(size, mode, location);
            var info = GetWindowInfo();

            if (size.HasValue)
            {
                Assert.Equal(size.Value, info.ClientSize);
            }

            Assert.True(info.FrameSize.Width >= info.ClientSize.Width, "Expected frame width >= client width.");
            Assert.True(info.FrameSize.Height > info.ClientSize.Height, "Expected frame height > client height.");

            var frameRect = new PixelRect(info.Position, PixelSize.FromSize(info.FrameSize, info.Scaling));

            switch (location)
            {
            case WindowStartupLocation.CenterScreen:
            {
                var expected = info.ScreenRect.CenterRect(frameRect);
                AssertCloseEnough(expected.Position, frameRect.Position);
                break;
            }

            case WindowStartupLocation.CenterOwner:
            {
                Assert.NotNull(info.OwnerRect);
                var expected = info.OwnerRect !.Value.CenterRect(frameRect);
                AssertCloseEnough(expected.Position, frameRect.Position);
                break;
            }
            }
        }
Beispiel #4
0
        private IDisposable OpenWindow(Size?size, ShowWindowMode mode, WindowStartupLocation location)
        {
            var sizeTextBox      = _session.FindElementByAccessibilityId("ShowWindowSize");
            var modeComboBox     = _session.FindElementByAccessibilityId("ShowWindowMode");
            var locationComboBox = _session.FindElementByAccessibilityId("ShowWindowLocation");
            var showButton       = _session.FindElementByAccessibilityId("ShowWindow");

            if (size.HasValue)
            {
                sizeTextBox.SendKeys($"{size.Value.Width}, {size.Value.Height}");
            }

            modeComboBox.Click();
            _session.FindElementByName(mode.ToString()).SendClick();

            locationComboBox.Click();
            _session.FindElementByName(location.ToString()).SendClick();

            return(showButton.OpenWindowWithClick());
        }
Beispiel #5
0
        public void WindowState(ShowWindowMode mode)
        {
            using var window = OpenWindow(null, mode, WindowStartupLocation.Manual);
            var windowState = _session.FindElementByAccessibilityId("WindowState");
            var original    = GetWindowInfo();

            Assert.Equal("Normal", windowState.GetComboBoxValue());

            windowState.Click();
            _session.FindElementByName("Maximized").SendClick();
            Assert.Equal("Maximized", windowState.GetComboBoxValue());

            windowState.Click();
            _session.FindElementByName("Normal").SendClick();

            var current = GetWindowInfo();

            Assert.Equal(original.Position, current.Position);
            Assert.Equal(original.FrameSize, current.FrameSize);

            // On macOS, only non-owned windows can go fullscreen.
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || mode == ShowWindowMode.NonOwned)
            {
                windowState.Click();
                _session.FindElementByName("Fullscreen").SendClick();
                Assert.Equal("Fullscreen", windowState.GetComboBoxValue());

                current = GetWindowInfo();
                var clientSize = PixelSize.FromSize(current.ClientSize, current.Scaling);
                Assert.True(clientSize.Width >= current.ScreenRect.Width);
                Assert.True(clientSize.Height >= current.ScreenRect.Height);

                windowState.SendClick();

                _session.FindElementByName("Normal").SendClick();

                current = GetWindowInfo();
                Assert.Equal(original.Position, current.Position);
                Assert.Equal(original.FrameSize, current.FrameSize);
            }
        }
Beispiel #6
0
        public static void DisplayUserControlInHost(
            ref WindowHost host,
            string title,
            int width, int height,
            ShowWindowMode mode,
            string userControlName = null)
        {
            long startTicks = Log.PRESENTATION("Enter", Common.LOG_CATEGORY);

            if (host is null)
            {
                host = new WindowHost();

                if (!(userControlName is null))
                {
                    host.LoadUserControl(userControlName);
                }
            }

            DisplayHost(host, title, width, height, mode, startTicks);
        }
Beispiel #7
0
        public void Minimize_Button_Minimizes_Window(ShowWindowMode mode)
        {
            using (OpenWindow(new PixelSize(200, 100), mode, WindowStartupLocation.Manual))
            {
                var secondaryWindow = FindWindow(_session, "SecondaryWindow");
                var(_, miniaturizeButton, _) = secondaryWindow.GetChromeButtons();

                miniaturizeButton.Click();
                Thread.Sleep(1000);

                var hittable = _session.FindElementsByXPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")
                               .Select(x => x.GetAttribute("hittable")).ToList();
                Assert.Equal(new[] { "true", "false" }, hittable);

                _session.FindElementByAccessibilityId("RestoreAll").Click();
                Thread.Sleep(1000);

                hittable = _session.FindElementsByXPath("/XCUIElementTypeApplication/XCUIElementTypeWindow")
                           .Select(x => x.GetAttribute("hittable")).ToList();
                Assert.Equal(new[] { "true", "true" }, hittable);
            }
        }
Beispiel #8
0
        public static void DisplayUserControlInHost(
            ref DxWindowHost host,
            string title,
            int width, int height,
            ShowWindowMode mode,
            System.Windows.Controls.UserControl userControl)
        {
            long startTicks = Log.PRESENTATION("Enter", Common.LOG_CATEGORY);

            if (host is null)
            {
                host = new DxWindowHost();

                if (!(userControl is null))
                {
                    host.LoadUserControl(userControl);
                }
            }

            DisplayHost(host, title, width, height, mode, startTicks);

            Log.PRESENTATION("Exit", Common.LOG_CATEGORY, startTicks);
        }
Beispiel #9
0
        public static void DisplayUserControlInHost(
            ref DxThemedWindowHost host,
            string title,
            int width, int height,
            ShowWindowMode mode,
            ViewModelBase viewModel)
        {
            long startTicks = Log.PRESENTATION("Enter", Common.LOG_CATEGORY);

            if (host is null)
            {
                host = new DxThemedWindowHost();

                if (!(viewModel.View is null))
                {
                    host.LoadUserControl((UserControl)viewModel.View);
                }
            }

            DisplayHost(host, title, width, height, mode, startTicks);

            Log.PRESENTATION("Exit", Common.LOG_CATEGORY, startTicks);
        }
Beispiel #10
0
 /// <summary>
 /// NOTE: This does not normally not work in Visual Studio with the developer console
 /// </summary>
 /// <param name="showWindowMode"></param>
 public static void ChangeConsoleMode(ShowWindowMode showWindowMode)
 {
     ShowWindow(Process.GetCurrentProcess().MainWindowHandle, (int)showWindowMode);
 }
Beispiel #11
0
 internal static extern bool ShowWindow(IntPtr hWnd, ShowWindowMode flags);
Beispiel #12
0
 public static extern bool ShowWindow(IntPtr hWnd, ShowWindowMode nCmdShow);