@@ -680,7 +680,6 @@ describe('Remote Frame Buffer protocol client', function () {
680680 // The resize will cause scrollbars on the container, this causes a
681681 // resize observation in the browsers
682682 fakeResizeObserver . fire ( ) ;
683- clock . tick ( 1000 ) ;
684683
685684 // FIXME: Display implicitly calls viewportChangeSize() when
686685 // resizing the framebuffer, hence calledTwice.
@@ -1042,7 +1041,6 @@ describe('Remote Frame Buffer protocol client', function () {
10421041 // The resize will cause scrollbars on the container, this causes a
10431042 // resize observation in the browsers
10441043 fakeResizeObserver . fire ( ) ;
1045- clock . tick ( 1000 ) ;
10461044
10471045 expect ( client . _display . autoscale ) . to . have . been . calledOnce ;
10481046 expect ( client . _display . autoscale ) . to . have . been . calledWith ( 70 , 80 ) ;
@@ -1079,6 +1077,7 @@ describe('Remote Frame Buffer protocol client', function () {
10791077 let height = RFB . messages . setDesktopSize . args [ 0 ] [ 2 ] ;
10801078 sendExtendedDesktopSize ( client , 1 , 0 , width , height , 0x7890abcd , 0x12345678 ) ;
10811079 RFB . messages . setDesktopSize . resetHistory ( ) ;
1080+ clock . tick ( 10000 ) ;
10821081 }
10831082 } ) ;
10841083
@@ -1093,7 +1092,6 @@ describe('Remote Frame Buffer protocol client', function () {
10931092 container . style . width = '40px' ;
10941093 container . style . height = '50px' ;
10951094 fakeResizeObserver . fire ( ) ;
1096- clock . tick ( 1000 ) ;
10971095 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
10981096
10991097 client . resizeSession = true ;
@@ -1132,7 +1130,6 @@ describe('Remote Frame Buffer protocol client', function () {
11321130 container . style . width = '40px' ;
11331131 container . style . height = '50px' ;
11341132 fakeResizeObserver . fire ( ) ;
1135- clock . tick ( 1000 ) ;
11361133
11371134 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
11381135 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
@@ -1143,21 +1140,19 @@ describe('Remote Frame Buffer protocol client', function () {
11431140 container . style . width = '40px' ;
11441141 container . style . height = '50px' ;
11451142 fakeResizeObserver . fire ( ) ;
1146- clock . tick ( 1000 ) ;
11471143
11481144 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
11491145 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
11501146 sinon . match . object , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
11511147
11521148 // Server responds with the requested size 40x50
11531149 sendExtendedDesktopSize ( client , 1 , 0 , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
1154- clock . tick ( 1000 ) ;
11551150
11561151 RFB . messages . setDesktopSize . resetHistory ( ) ;
11571152
11581153 // size is still 40x50
1159- fakeResizeObserver . fire ( ) ;
11601154 clock . tick ( 1000 ) ;
1155+ fakeResizeObserver . fire ( ) ;
11611156
11621157 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
11631158 } ) ;
@@ -1166,7 +1161,6 @@ describe('Remote Frame Buffer protocol client', function () {
11661161 container . style . width = '40px' ;
11671162 container . style . height = '50px' ;
11681163 fakeResizeObserver . fire ( ) ;
1169- clock . tick ( 1000 ) ;
11701164
11711165 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
11721166 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
@@ -1175,45 +1169,135 @@ describe('Remote Frame Buffer protocol client', function () {
11751169 sendExtendedDesktopSize ( client , 1 , 0 , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
11761170 RFB . messages . setDesktopSize . resetHistory ( ) ;
11771171
1172+ clock . tick ( 1000 ) ;
11781173 container . style . width = '70px' ;
11791174 container . style . height = '80px' ;
11801175 fakeResizeObserver . fire ( ) ;
1181- clock . tick ( 1000 ) ;
11821176
11831177 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
11841178 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
11851179 sinon . match . object , 70 , 80 , 0x7890abcd , 0x12345678 ) ;
11861180 } ) ;
11871181
1188- it ( 'should not resize until the container size is stable ' , function ( ) {
1182+ it ( 'should rate limit resizes ' , function ( ) {
11891183 container . style . width = '20px' ;
11901184 container . style . height = '30px' ;
11911185 fakeResizeObserver . fire ( ) ;
1192- clock . tick ( 400 ) ;
1186+
1187+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1188+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
1189+ sinon . match . object , 20 , 30 , 0x7890abcd , 0x12345678 ) ;
1190+
1191+ sendExtendedDesktopSize ( client , 1 , 0 , 20 , 30 , 0x7890abcd , 0x12345678 ) ;
1192+ RFB . messages . setDesktopSize . resetHistory ( ) ;
1193+
1194+ clock . tick ( 20 ) ;
1195+
1196+ container . style . width = '30px' ;
1197+ container . style . height = '40px' ;
1198+ fakeResizeObserver . fire ( ) ;
11931199
11941200 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
11951201
1202+ clock . tick ( 20 ) ;
1203+
11961204 container . style . width = '40px' ;
11971205 container . style . height = '50px' ;
11981206 fakeResizeObserver . fire ( ) ;
1199- clock . tick ( 400 ) ;
12001207
12011208 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
12021209
1203- clock . tick ( 200 ) ;
1210+ clock . tick ( 80 ) ;
12041211
12051212 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
12061213 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
12071214 sinon . match . object , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
12081215 } ) ;
12091216
1217+ it ( 'should not have overlapping resize requests' , function ( ) {
1218+ container . style . width = '40px' ;
1219+ container . style . height = '50px' ;
1220+ fakeResizeObserver . fire ( ) ;
1221+
1222+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1223+
1224+ RFB . messages . setDesktopSize . resetHistory ( ) ;
1225+
1226+ clock . tick ( 1000 ) ;
1227+ container . style . width = '20px' ;
1228+ container . style . height = '30px' ;
1229+ fakeResizeObserver . fire ( ) ;
1230+
1231+ expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
1232+ } ) ;
1233+
1234+ it ( 'should finalize any pending resizes' , function ( ) {
1235+ container . style . width = '40px' ;
1236+ container . style . height = '50px' ;
1237+ fakeResizeObserver . fire ( ) ;
1238+
1239+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1240+
1241+ RFB . messages . setDesktopSize . resetHistory ( ) ;
1242+
1243+ clock . tick ( 1000 ) ;
1244+ container . style . width = '20px' ;
1245+ container . style . height = '30px' ;
1246+ fakeResizeObserver . fire ( ) ;
1247+
1248+ expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
1249+
1250+ // Server responds with the requested size 40x50
1251+ sendExtendedDesktopSize ( client , 1 , 0 , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
1252+
1253+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1254+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
1255+ sinon . match . object , 20 , 30 , 0x7890abcd , 0x12345678 ) ;
1256+ } ) ;
1257+
1258+ it ( 'should not finalize any pending resize if not needed' , function ( ) {
1259+ container . style . width = '40px' ;
1260+ container . style . height = '50px' ;
1261+ fakeResizeObserver . fire ( ) ;
1262+
1263+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1264+
1265+ RFB . messages . setDesktopSize . resetHistory ( ) ;
1266+
1267+ // Server responds with the requested size 40x50
1268+ sendExtendedDesktopSize ( client , 1 , 0 , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
1269+
1270+ expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
1271+ } ) ;
1272+
1273+ it ( 'should not finalize any pending resizes on errors' , function ( ) {
1274+ container . style . width = '40px' ;
1275+ container . style . height = '50px' ;
1276+ fakeResizeObserver . fire ( ) ;
1277+
1278+ expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
1279+
1280+ RFB . messages . setDesktopSize . resetHistory ( ) ;
1281+
1282+ clock . tick ( 1000 ) ;
1283+ container . style . width = '20px' ;
1284+ container . style . height = '30px' ;
1285+ fakeResizeObserver . fire ( ) ;
1286+
1287+ expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
1288+
1289+ // Server failed the requested size 40x50
1290+ sendExtendedDesktopSize ( client , 1 , 1 , 40 , 50 , 0x7890abcd , 0x12345678 ) ;
1291+
1292+ expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
1293+ } ) ;
1294+
12101295 it ( 'should not resize when resize is disabled' , function ( ) {
12111296 client . _resizeSession = false ;
12121297
12131298 container . style . width = '40px' ;
12141299 container . style . height = '50px' ;
12151300 fakeResizeObserver . fire ( ) ;
1216- clock . tick ( 1000 ) ;
12171301
12181302 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
12191303 } ) ;
@@ -1224,7 +1308,6 @@ describe('Remote Frame Buffer protocol client', function () {
12241308 container . style . width = '40px' ;
12251309 container . style . height = '50px' ;
12261310 fakeResizeObserver . fire ( ) ;
1227- clock . tick ( 1000 ) ;
12281311
12291312 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
12301313 } ) ;
@@ -1235,7 +1318,6 @@ describe('Remote Frame Buffer protocol client', function () {
12351318 container . style . width = '40px' ;
12361319 container . style . height = '50px' ;
12371320 fakeResizeObserver . fire ( ) ;
1238- clock . tick ( 1000 ) ;
12391321
12401322 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
12411323 } ) ;
@@ -1248,15 +1330,13 @@ describe('Remote Frame Buffer protocol client', function () {
12481330 sendExtendedDesktopSize ( client , 0 , 0 , 100 , 100 , 0xabababab , 0x11223344 ) ;
12491331 // The scrollbars cause the ResizeObserver to fire
12501332 fakeResizeObserver . fire ( ) ;
1251- clock . tick ( 1000 ) ;
12521333
12531334 expect ( RFB . messages . setDesktopSize ) . to . not . have . been . called ;
12541335
12551336 // An actual size change must not be ignored afterwards
12561337 container . style . width = '120px' ;
12571338 container . style . height = '130px' ;
12581339 fakeResizeObserver . fire ( ) ;
1259- clock . tick ( 1000 ) ;
12601340
12611341 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledOnce ;
12621342 expect ( RFB . messages . setDesktopSize ) . to . have . been . calledWith (
0 commit comments