@@ -26,6 +26,35 @@ public MouseTests(ITestOutputHelper output) : base(output)
2626 {
2727 }
2828
29+ [ PuppeteerTest ( "mouse.spec.ts" , "Mouse" , "should click the document" ) ]
30+ [ Fact ( Timeout = TestConstants . DefaultTestTimeout ) ]
31+ public async Task ShouldClickTheDocument ( )
32+ {
33+ await Page . EvaluateFunctionAsync ( @"() => {
34+ globalThis.clickPromise = new Promise((resolve) => {
35+ document.addEventListener('click', (event) => {
36+ resolve({
37+ type: event.type,
38+ detail: event.detail,
39+ clientX: event.clientX,
40+ clientY: event.clientY,
41+ isTrusted: event.isTrusted,
42+ button: event.button,
43+ });
44+ });
45+ });
46+ }" ) ;
47+ await Page . Mouse . ClickAsync ( 50 , 60 ) ;
48+ var e = await Page . EvaluateFunctionAsync < MouseEvent > ( "() => globalThis.clickPromise" ) ;
49+
50+ Assert . Equal ( "click" , e . Type ) ;
51+ Assert . Equal ( 1 , e . Detail ) ;
52+ Assert . Equal ( 50 , e . ClientX ) ;
53+ Assert . Equal ( 60 , e . ClientY ) ;
54+ Assert . True ( e . IsTrusted ) ;
55+ Assert . Equal ( 0 , e . Button ) ;
56+ }
57+
2958 [ PuppeteerTest ( "mouse.spec.ts" , "Mouse" , "should resize the textarea" ) ]
3059 [ SkipBrowserFact ( skipFirefox : true ) ]
3160 public async Task ShouldResizeTheTextarea ( )
@@ -115,16 +144,37 @@ public async Task ShouldSetModifierKeysOnClick()
115144 }
116145 }
117146
147+ [ PuppeteerTest ( "mouse.spec.ts" , "Mouse" , "should send mouse wheel events" ) ]
148+ [ SkipBrowserFact ( skipFirefox : true ) ]
149+ public async Task ShouldSendMouseWheelEvents ( )
150+ {
151+ await Page . GoToAsync ( TestConstants . ServerUrl + "/input/wheel.html" ) ;
152+ var elem = await Page . QuerySelectorAsync ( "div" ) ;
153+ var boundingBoxBefore = await elem . BoundingBoxAsync ( ) ;
154+ Assert . Equal ( 115 , boundingBoxBefore . Width ) ;
155+ Assert . Equal ( 115 , boundingBoxBefore . Height ) ;
156+
157+ await Page . Mouse . MoveAsync (
158+ boundingBoxBefore . X + ( boundingBoxBefore . Width / 2 ) ,
159+ boundingBoxBefore . Y + ( boundingBoxBefore . Height / 2 )
160+ ) ;
161+
162+ await Page . Mouse . WheelAsync ( 0 , - 100 ) ;
163+ var boundingBoxAfter = await elem . BoundingBoxAsync ( ) ;
164+ Assert . Equal ( 230 , boundingBoxAfter . Width ) ;
165+ Assert . Equal ( 230 , boundingBoxAfter . Height ) ;
166+ }
167+
118168 [ PuppeteerTest ( "mouse.spec.ts" , "Mouse" , "should tween mouse movement" ) ]
119169 [ SkipBrowserFact ( skipFirefox : true ) ]
120170 public async Task ShouldTweenMouseMovement ( )
121171 {
122172 await Page . Mouse . MoveAsync ( 100 , 100 ) ;
123173 await Page . EvaluateExpressionAsync ( @"{
124- window.result = [];
125- document.addEventListener('mousemove', event => {
126- window.result.push([event.clientX, event.clientY]);
127- });
174+ window.result = [];
175+ document.addEventListener('mousemove', event => {
176+ window.result.push([event.clientX, event.clientY]);
177+ });
128178 }" ) ;
129179 await Page . Mouse . MoveAsync ( 200 , 300 , new MoveOptions { Steps = 5 } ) ;
130180 Assert . Equal ( new [ ] {
@@ -192,5 +242,20 @@ public void Scroll(decimal deltaX, decimal deltaY)
192242 Y = Math . Max ( 0 , Y + deltaY ) ;
193243 }
194244 }
245+
246+ internal struct MouseEvent
247+ {
248+ public string Type { get ; set ; }
249+
250+ public int Detail { get ; set ; }
251+
252+ public int ClientX { get ; set ; }
253+
254+ public int ClientY { get ; set ; }
255+
256+ public bool IsTrusted { get ; set ; }
257+
258+ public int Button { get ; set ; }
259+ }
195260 }
196261}
0 commit comments