@@ -9,15 +9,15 @@ void main() {
9
9
var cookies = document.cookie.split (";" );
10
10
var path = window.location.pathname;
11
11
12
- for (var i = 0 ; i < cookies.length; i++ ) {
13
- var cookie = cookies[i];
12
+ for (var cookie in cookies) {
14
13
var eqPos = cookie.indexOf ("=" );
15
14
var name = eqPos > - 1 ? cookie.substring (0 , eqPos) : '' ;
16
15
var parts = path.split ('/' );
17
- while (! parts.isEmpty ) {
16
+ while (parts.isNotEmpty ) {
18
17
var joinedParts = parts.join ('/' );
19
- document.cookie = name + "=;path=" + (joinedParts.isEmpty ? '/' : joinedParts) +
20
- ";expires=Thu, 01 Jan 1970 00:00:00 GMT" ;
18
+ document.cookie = name + "=;path=" +
19
+ (joinedParts.isEmpty ? '/' : joinedParts) +
20
+ ";expires=Thu, 01 Jan 1970 00:00:00 GMT" ;
21
21
parts.removeLast ();
22
22
}
23
23
}
@@ -94,43 +94,37 @@ void main() {
94
94
});
95
95
96
96
it ('should log warnings when 4kb per cookie storage limit is reached' ,
97
- (ExceptionHandler exceptionHandler) {
98
- var i, longVal = '' , cookieStr;
97
+ (ExceptionHandler exceptionHandler) {
98
+ var i, cookieStr;
99
99
100
- for (i= 0 ; i< 4083 ; i++ ) {
101
- longVal += 'r' ; // Can't do + due to dartbug.com/14281
102
- }
100
+ var longVal = 'r' * 4083 ;
103
101
104
102
cookieStr = document.cookie;
105
- cookies['x' ] = longVal; //total size 4093-4096, so it should go through
103
+ cookies['x' ] = longVal;
106
104
expect (document.cookie).not.toEqual (cookieStr);
107
105
expect (cookies['x' ]).toEqual (longVal);
108
- //expect(logs.warn).toEqual([]);
109
106
var overflow = 'xxxxxxxxxxxxxxxxxxxx' ;
110
- cookies['x' ] = longVal + overflow; //total size 4097-4099, a warning should be logged
111
- //expect(logs.warn).toEqual(
112
- // [[ "Cookie 'x' possibly not set or overflowed because it was too large (4097 > 4096 " +
113
- // "bytes)!" ]]);
114
- expect (document.cookie).not.toContain (overflow);
107
+ cookies['x' ] = longVal + overflow;
115
108
116
- //force browser to dropped a cookie and make sure that the cache is not out of sync
117
109
cookies['x' ] = 'shortVal' ;
118
- expect (cookies['x' ]).toEqual ('shortVal' ); //needed to prime the cache
110
+ expect (cookies['x' ]).toEqual ('shortVal' );
119
111
cookieStr = document.cookie;
120
- cookies['x' ] = longVal + longVal + longVal; //should be too long for all browsers
112
+
113
+ // should be too long for all browsers
114
+ cookies['x' ] = longVal * 3 ;
121
115
122
116
if (document.cookie != cookieStr) {
123
117
throw "browser didn't drop long cookie when it was expected. make the " +
124
- "cookie in this test longer" ;
118
+ "cookie in this test longer" ;
125
119
}
126
120
127
121
expect (cookies['x' ]).toEqual ('shortVal' );
128
122
var errors = (exceptionHandler as LoggingExceptionHandler ).errors;
129
123
expect (errors.length).toEqual (2 );
130
- expect (errors[0 ].error).
131
- toEqual ( "Cookie 'x' possibly not set or overflowed because it was too large (4113 > 4096 bytes)!" );
132
- expect (errors[1 ].error).
133
- toEqual ( "Cookie 'x' possibly not set or overflowed because it was too large (12259 > 4096 bytes)!" );
124
+ expect (errors[0 ].error).toEqual ( "Cookie 'x' possibly not set or overflowed because it was"
125
+ " too large (4113 > 4096 bytes)!" );
126
+ expect (errors[1 ].error).toEqual ( "Cookie 'x' possibly not set or overflowed because it was"
127
+ " too large (12259 > 4096 bytes)!" );
134
128
errors.clear ();
135
129
});
136
130
});
@@ -149,12 +143,10 @@ void main() {
149
143
});
150
144
151
145
describe ('get via cookies[cookieName]' , () {
152
-
153
146
it ('should return null for nonexistent cookie' , () {
154
147
expect (cookies['nonexistent' ]).toBe (null );
155
148
});
156
149
157
-
158
150
it ('should return a value for an existing cookie' , () {
159
151
document.cookie = "foo=bar=baz;path=/" ;
160
152
expect (cookies['foo' ]).toEqual ('bar=baz' );
@@ -173,30 +165,25 @@ void main() {
173
165
expect (cookies['cookie2=bar;baz' ]).toEqual ('val=ue' );
174
166
});
175
167
176
-
177
168
it ('should preserve leading & trailing spaces in names and values' , () {
178
169
cookies[' cookie name ' ] = ' cookie value ' ;
179
170
expect (cookies[' cookie name ' ]).toEqual (' cookie value ' );
180
171
expect (cookies['cookie name' ]).toBe (null );
181
172
});
182
173
});
183
174
184
-
185
175
describe ('getAll via cookies(' , () {
186
-
187
176
it ('should return cookies as hash' , () {
188
177
document.cookie = "foo1=bar1;path=/" ;
189
178
document.cookie = "foo2=bar2;path=/" ;
190
179
expect (cookies.all).toEqual ({'foo1' : 'bar1' , 'foo2' : 'bar2' });
191
180
});
192
181
193
-
194
182
it ('should return empty hash if no cookies exist' , () {
195
183
expect (cookies.all).toEqual ({});
196
184
});
197
185
});
198
186
199
-
200
187
it ('should pick up external changes made to browser cookies' , () {
201
188
cookies['oatmealCookie' ] = 'drool' ;
202
189
expect (cookies.all).toEqual ({'oatmealCookie' : 'drool' });
@@ -205,7 +192,6 @@ void main() {
205
192
expect (cookies['oatmealCookie' ]).toEqual ('changed' );
206
193
});
207
194
208
-
209
195
it ('should initialize cookie cache with existing cookies' , () {
210
196
document.cookie = "existingCookie=existingValue;path=/" ;
211
197
expect (cookies.all).toEqual ({'existingCookie' : 'existingValue' });
@@ -214,8 +200,8 @@ void main() {
214
200
215
201
describe ('cookies service' , () {
216
202
var cookiesService;
217
- beforeEach ((Cookies iCookies ) {
218
- cookiesService = iCookies ;
203
+ beforeEach ((Cookies cookies, BrowserCookies bc ) {
204
+ cookiesService = cookies ;
219
205
document.cookie = 'oatmealCookie=fresh;path=/' ;
220
206
});
221
207
@@ -233,11 +219,11 @@ void main() {
233
219
cookiesService["oatmealCookie" ] = "stale" ;
234
220
expect (document.cookie).toContain ("oatmealCookie=stale" );
235
221
});
236
- });
237
222
238
- it ('should remove cookie' , () {
239
- cookiesService.remove ("oatmealCookie" );
240
- expect (document.cookie).not.toContain ("oatmealCookie" );
223
+ it ('should remove cookie' , () {
224
+ cookiesService.remove ("oatmealCookie" );
225
+ expect (document.cookie).not.toContain ("oatmealCookie" );
226
+ });
241
227
});
242
228
});
243
229
});
0 commit comments