@@ -152,27 +152,39 @@ describe('browser', function(){
152152 } ) ;
153153
154154 it ( 'should log warnings when 4kb per cookie storage limit is reached' , function ( ) {
155- var i , longVal = '' , cookieString ;
155+ var i , longVal = '' , cookieStr ;
156156
157157 for ( i = 0 ; i < 4092 ; i ++ ) {
158158 longVal += '+' ;
159159 }
160160
161- cookieString = document . cookie ;
161+ cookieStr = document . cookie ;
162162 browser . cookies ( 'x' , longVal ) ; //total size 4094-4096, so it should go through
163- expect ( document . cookie ) . not . toEqual ( cookieString ) ;
163+ expect ( document . cookie ) . not . toEqual ( cookieStr ) ;
164164 expect ( browser . cookies ( ) [ 'x' ] ) . toEqual ( longVal ) ;
165165 expect ( logs . warn ) . toEqual ( [ ] ) ;
166166
167- browser . cookies ( 'x' , longVal + 'xxx' ) //total size 4097-4099, a warning should be logged
168- //browser behavior is undefined, so we test for existance of warning logs only
167+ browser . cookies ( 'x' , longVal + 'xxx' ) ; //total size 4097-4099, a warning should be logged
169168 expect ( logs . warn ) . toEqual (
170169 [ [ "Cookie 'x' possibly not set or overflowed because it was too large (4097 > 4096 " +
171170 "bytes)!" ] ] ) ;
171+
172+ //force browser to dropped a cookie and make sure that the cache is not out of sync
173+ browser . cookies ( 'x' , 'shortVal' ) ;
174+ expect ( browser . cookies ( ) . x ) . toEqual ( 'shortVal' ) ; //needed to prime the cache
175+ cookieStr = document . cookie ;
176+ browser . cookies ( 'x' , longVal + longVal + longVal ) ; //should be too long for all browsers
177+
178+ if ( document . cookie !== cookieStr ) {
179+ fail ( "browser didn't drop long cookie when it was expected. make the cookie in this " +
180+ "test longer" ) ;
181+ }
182+
183+ expect ( browser . cookies ( ) . x ) . toEqual ( 'shortVal' ) ;
172184 } ) ;
173185
174186 it ( 'should log warnings when 20 cookies per domain storage limit is reached' , function ( ) {
175- var i , str ;
187+ var i , str , cookieStr ;
176188
177189 for ( i = 0 ; i < 20 ; i ++ ) {
178190 str = '' + i ;
@@ -185,12 +197,18 @@ describe('browser', function(){
185197 }
186198 expect ( i ) . toEqual ( 20 ) ;
187199 expect ( logs . warn ) . toEqual ( [ ] ) ;
200+ cookieStr = document . cookie ;
188201
189202 browser . cookies ( 'one' , 'more' ) ;
190- //browser behavior is undefined, so we test for existance of warning logs only
191203 expect ( logs . warn ) . toEqual ( [ ] ) ;
192- } ) ;
193204
205+ //if browser dropped a cookie (very likely), make sure that the cache is not out of sync
206+ if ( document . cookie === cookieStr ) {
207+ expect ( size ( browser . cookies ( ) ) ) . toEqual ( 20 ) ;
208+ } else {
209+ expect ( size ( browser . cookies ( ) ) ) . toEqual ( 21 ) ;
210+ }
211+ } ) ;
194212 } ) ;
195213
196214
0 commit comments