@@ -6,10 +6,6 @@ namespace PuppeteerSharp.Tests.EmulationTests
66{
77 public class PageViewPortTests : PuppeteerPageBaseTest
88 {
9- public PageViewPortTests ( ) : base ( )
10- {
11- }
12-
139 [ Test , Retry ( 2 ) , PuppeteerTest ( "emulation.spec" , "Emulation Page.viewport" , "should get the proper viewport size" ) ]
1410 public async Task ShouldGetTheProperViewPortSize ( )
1511 {
@@ -99,5 +95,42 @@ public async Task ShouldSupportLandscapeEmulation()
9995 await Page . SetViewportAsync ( new ViewPortOptions { Width = 100 , Height = 100 } ) ;
10096 Assert . AreEqual ( "portrait-primary" , await Page . EvaluateExpressionAsync < string > ( "screen.orientation.type" ) ) ;
10197 }
98+
99+ [ Test , Retry ( 2 ) , PuppeteerTest ( "emulation.spec" , "Emulation Page.viewport" , "should update media queries when resoltion changes" ) ]
100+ public async Task ShouldUpdateMediaQueriesWhenResolutionChanges ( )
101+ {
102+ foreach ( var dpr in new [ ] { 1 , 2 , 3 } )
103+ {
104+ await Page . SetViewportAsync ( new ViewPortOptions { Width = 800 , Height = 600 , DeviceScaleFactor = dpr } ) ;
105+
106+ await Page . GoToAsync ( TestConstants . ServerUrl + "/resolution.html" ) ;
107+ Assert . AreEqual ( dpr , await GetFontSizeAsync ( ) ) ;
108+ var screenshot = await Page . ScreenshotDataAsync ( new ScreenshotOptions ( ) { FullPage = false } ) ;
109+ Assert . True ( ScreenshotHelper . PixelMatch ( $ "device-pixel-ratio{ dpr } .png", screenshot ) ) ;
110+ }
111+ }
112+
113+ [ Test , Retry ( 2 ) , PuppeteerTest ( "emulation.spec" , "Emulation Page.viewport" , "should load correct pictures when emulation dpr" ) ]
114+ public async Task ShouldLoadCorrectPicturesWhenEmulationDpr ( )
115+ {
116+ foreach ( var dpr in new [ ] { 1 , 2 , 3 } )
117+ {
118+ await Page . SetViewportAsync ( new ViewPortOptions { Width = 800 , Height = 600 , DeviceScaleFactor = dpr } ) ;
119+
120+ await Page . GoToAsync ( TestConstants . ServerUrl + "/picture.html" ) ;
121+ StringAssert . EndsWith ( $ "logo-{ dpr } x.png", await GetCurrentSrc ( ) ) ;
122+
123+ }
124+ }
125+
126+ private Task < int > GetFontSizeAsync ( )
127+ => Page . EvaluateFunctionAsync < int > ( @"() => {
128+ return parseInt(window.getComputedStyle(document.querySelector('p')).fontSize, 10);
129+ }" ) ;
130+
131+ private Task < string > GetCurrentSrc ( )
132+ => Page . EvaluateFunctionAsync < string > ( @"() => {
133+ return document.querySelector('img').currentSrc;
134+ }" ) ;
102135 }
103136}
0 commit comments