Skip to content

Commit 0e90a9d

Browse files
authored
Merge branch 'main' into drt-window-hwtl
2 parents 7723292 + aa0e9df commit 0e90a9d

File tree

4 files changed

+194
-0
lines changed

4 files changed

+194
-0
lines changed

Microsoft.DotNet.Wpf.Test.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrtWindow", "src\Test\AppMo
99
EndProject
1010
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrtWindowHeightWidthTopLeft", "src\Test\AppModel\DRT\Window\WindowHeightWidthTopLeft\DrtWindowHeightWidthTopLeft.csproj", "{8A20F8C2-7DB0-4CC2-AD3F-2D63B17E7962}"
1111
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DrtWindowDragMove", "src\Test\AppModel\DRT\Window\WindowDragMove\DrtWindowDragMove.csproj", "{EE7FD4CD-DD8E-4EF1-877B-1C87AD891BB9}"
13+
EndProject
1214
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommonData", "src\Test\BranchCommon\data\CommonData.csproj", "{D5F8FF19-BE50-49D3-9343-EEF2182611B7}"
1315
EndProject
1416
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestServices", "src\Test\Common\DRT\TestServices\TestServices.csproj", "{12B6B1C0-A834-4223-B5F4-5813F2D73FAA}"
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
using System.Diagnostics;
8+
using System.Windows.Threading;
9+
10+
using System.Text;
11+
using System.ComponentModel;
12+
using System.Windows;
13+
using System.Windows.Interop;
14+
using System.Windows.Media;
15+
using System.Windows.Controls;
16+
using System.Windows.Input;
17+
using System.Windows.Markup;
18+
using System.Windows.Automation;
19+
20+
namespace DRT
21+
{
22+
public class Harness
23+
{
24+
[STAThread]
25+
public static int Main()
26+
{
27+
WindowDragMoveApp.DisableProcessWindowsGhosting();
28+
WindowDragMoveApp theApp = new WindowDragMoveApp();
29+
try
30+
{
31+
WindowDragMoveApp.BlockInput(1);
32+
theApp.Run();
33+
}
34+
catch (ApplicationException e)
35+
{
36+
theApp.Logger.Log(e);
37+
return 1;
38+
}
39+
finally
40+
{
41+
WindowDragMoveApp.BlockInput(0);
42+
}
43+
theApp.Logger.Log("Passed");
44+
return 0;
45+
}
46+
}
47+
48+
/// <summary>
49+
// Tests DragMove functionality
50+
/// </summary>
51+
public class WindowDragMoveApp : Application
52+
{
53+
private static Logger _logger;
54+
55+
private Window _win;
56+
57+
private Border _root;
58+
59+
private Point _oldPos;
60+
private Point _newPos;
61+
private Point _expectedPos;
62+
private Point _delta;
63+
private Point _correction;
64+
private static int TestCode = 0;
65+
66+
public WindowDragMoveApp() : base()
67+
{
68+
_logger = new Logger("DrtWindowDragMove", "Microsoft", "Testing Window DragMove behavior");
69+
}
70+
71+
internal Logger Logger
72+
{
73+
get
74+
{
75+
return _logger;
76+
}
77+
}
78+
79+
protected override void OnStartup(StartupEventArgs e)
80+
{
81+
_win = new Window();
82+
_win.WindowStyle = WindowStyle.None;
83+
_win.Width = 500;
84+
_win.Height = 400;
85+
_win.Top = 0;
86+
_win.Left = 0;
87+
88+
_root = new Border ();
89+
_root.Width = _win.Width;
90+
_root.Height = _win.Height;
91+
_root.Background = new SolidColorBrush(Colors.Red);
92+
_win.Content = _root;
93+
_root.AddHandler (Mouse.MouseDownEvent, new MouseButtonEventHandler (OnMouseDown), false);
94+
95+
_win.Title = "Window DragMove test";
96+
_win.Show();
97+
98+
_oldPos = new Point(_win.Left, _win.Top);
99+
_delta = new Point(100, 100);
100+
_correction = new Point(10, 10);
101+
_expectedPos = new Point(_oldPos.X + _delta.X - _correction.X, _oldPos.Y + _delta.Y - _correction.Y);
102+
103+
Dispatcher.CurrentDispatcher.BeginInvoke(
104+
DispatcherPriority.Background,
105+
new DispatcherOperationCallback(DragMoveTest),
106+
this);
107+
108+
base.OnStartup(e);
109+
}
110+
111+
/*
112+
* Test Case: DragMove
113+
*/
114+
private object DragMoveTest(object obj)
115+
{
116+
HwndSource hwndSource = PresentationSource.FromVisual(_root) as HwndSource;
117+
Debug.Assert(hwndSource != null, "PresentaionSource has to be HwndSource here");
118+
119+
Point oldPosDeviceUnits = hwndSource.CompositionTarget.TransformToDevice.Transform(_oldPos);
120+
Point deltaDeviceUnits = hwndSource.CompositionTarget.TransformToDevice.Transform(_delta);
121+
Point correctionDeviceUnits = hwndSource.CompositionTarget.TransformToDevice.Transform(_correction);
122+
123+
Input.MoveTo(new Point(oldPosDeviceUnits.X + correctionDeviceUnits.X, oldPosDeviceUnits.Y + correctionDeviceUnits.Y));
124+
Input.SendMouseInput(oldPosDeviceUnits.X + correctionDeviceUnits.X, oldPosDeviceUnits.Y + correctionDeviceUnits.Y, 0, SystemParameters.SwapButtons ? SendMouseInputFlags.RightDown : SendMouseInputFlags.LeftDown);
125+
Input.MoveTo(new Point(oldPosDeviceUnits.X + deltaDeviceUnits.X, oldPosDeviceUnits.Y + deltaDeviceUnits.Y));
126+
Input.SendMouseInput(oldPosDeviceUnits.X + deltaDeviceUnits.X, oldPosDeviceUnits.Y + deltaDeviceUnits.Y, 0, SystemParameters.SwapButtons ? SendMouseInputFlags.RightUp : SendMouseInputFlags.LeftUp);
127+
128+
Dispatcher.CurrentDispatcher.BeginInvoke(
129+
DispatcherPriority.Background,
130+
new DispatcherOperationCallback(CloseWindow),
131+
this);
132+
return null;
133+
}
134+
135+
private void OnMouseDown(object sender, MouseButtonEventArgs e)
136+
{
137+
_win.DragMove();
138+
e.Handled = true;
139+
}
140+
141+
public static void SetError(string msg)
142+
{
143+
_logger.Log("FAILURE: " + msg);
144+
SetError();
145+
}
146+
147+
public static void SetError()
148+
{
149+
TestCode = 1;
150+
}
151+
152+
public static bool Failed
153+
{
154+
get { return TestCode != 0; }
155+
}
156+
157+
private object CloseWindow(object obj)
158+
{
159+
_newPos = new Point((double)_win.GetValue(Window.LeftProperty), (double)_win.GetValue(Window.TopProperty));
160+
if ((_expectedPos.X != Math.Round(_newPos.X)) || _expectedPos.Y != Math.Round(_newPos.Y))
161+
{
162+
SetError("DragMove failed. The old position is " + _oldPos.ToString() + ". The new position is " + _newPos.ToString() +
163+
". The expected position is " + _expectedPos.ToString());
164+
throw new ApplicationException("DragMove failed");
165+
}
166+
_win.Close();
167+
return null;
168+
}
169+
[DllImport("user32.dll", CharSet = CharSet.Auto)]
170+
public static extern int BlockInput(int fBlockIt);
171+
172+
[DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
173+
internal extern static void DisableProcessWindowsGhosting();
174+
}
175+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<AssemblyName>DrtWindowDragMove</AssemblyName>
4+
<LinkSubsystem>console</LinkSubsystem>
5+
<AssemblyIdentityVersionName>WCP</AssemblyIdentityVersionName>
6+
<OutputType>EXE</OutputType>
7+
<GenerateAssemblyAttribute>false</GenerateAssemblyAttribute>
8+
<TestCode>true</TestCode>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Compile Include="$(DrtCommonRoot)\inc\DrtBase.cs" />
12+
<Compile Include="$(DrtCommonRoot)\inc\DrtBaseInput.cs" />
13+
<Compile Include="DrtWindowDragMove.cs" />
14+
<Compile Include="..\..\Logger\Logger.cs" />
15+
</ItemGroup>
16+
</Project>

src/Test/BranchCommon/data/DrtList.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ Rundrtlist
3939
</SupportFiles>
4040
</Drt>
4141
<Drt Executable="DrtWindowHeightWidthTopLeft.exe" Architecture="all" OS="all" Owner="Microsoft" Team="AppModel" />
42+
<Drt Executable="DrtWindowDragMove.exe" Architecture="all" OS="all" Owner="Microsoft" Team="AppModel" />
4243
</Drts>

0 commit comments

Comments
 (0)