1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Daniel Witte (dwitte@stanford.edu)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "TestCommon.h"
40 #include "nsIServiceManager.h"
41 #include "nsICookieService.h"
42 #include "nsICookieManager.h"
43 #include "nsICookieManager2.h"
44 #include "nsICookie2.h"
48 #include "nsNetUtil.h"
50 #include "nsStringAPI.h"
51 #include "nsIPrefBranch.h"
52 #include "nsIPrefService.h"
54 static NS_DEFINE_CID(kCookieServiceCID
, NS_COOKIESERVICE_CID
);
55 static NS_DEFINE_CID(kPrefServiceCID
, NS_PREFSERVICE_CID
);
57 // various pref strings
58 static const char kCookiesPermissions
[] = "network.cookie.cookieBehavior";
59 static const char kCookiesDisabledForMailNews
[] = "network.cookie.disableCookieForMailNews";
60 static const char kCookiesLifetimeEnabled
[] = "network.cookie.lifetime.enabled";
61 static const char kCookiesLifetimeDays
[] = "network.cookie.lifetime.days";
62 static const char kCookiesLifetimeCurrentSession
[] = "network.cookie.lifetime.behavior";
63 static const char kCookiesP3PString
[] = "network.cookie.p3p";
64 static const char kCookiesAskPermission
[] = "network.cookie.warnAboutCookies";
67 SetACookie(nsICookieService
*aCookieService
, const char *aSpec1
, const char *aSpec2
, const char* aCookieString
, const char *aServerTime
)
69 nsCOMPtr
<nsIURI
> uri1
, uri2
;
70 NS_NewURI(getter_AddRefs(uri1
), aSpec1
);
72 NS_NewURI(getter_AddRefs(uri2
), aSpec2
);
74 printf(" for host \"%s\": SET ", aSpec1
);
75 nsresult rv
= aCookieService
->SetCookieStringFromHttp(uri1
, uri2
, nsnull
, (char *)aCookieString
, aServerTime
, nsnull
);
76 // the following code is useless. the cookieservice blindly returns NS_OK
77 // from SetCookieString. we have to call GetCookie to see if the cookie was
82 printf("\"%s\"\n", aCookieString
);
88 SetACookieNoHttp(nsICookieService
*aCookieService
, const char *aSpec
, const char* aCookieString
)
91 NS_NewURI(getter_AddRefs(uri
), aSpec
);
93 printf(" for host \"%s\": SET ", aSpec
);
94 nsresult rv
= aCookieService
->SetCookieString(uri
, nsnull
, (char *)aCookieString
, nsnull
);
95 // the following code is useless. the cookieservice blindly returns NS_OK
96 // from SetCookieString. we have to call GetCookie to see if the cookie was
101 printf("\"%s\"\n", aCookieString
);
106 // returns PR_TRUE if cookie(s) for the given host were found; else PR_FALSE.
107 // the cookie string is returned via aCookie.
109 GetACookie(nsICookieService
*aCookieService
, const char *aSpec1
, const char *aSpec2
, char **aCookie
)
111 nsCOMPtr
<nsIURI
> uri1
, uri2
;
112 NS_NewURI(getter_AddRefs(uri1
), aSpec1
);
114 NS_NewURI(getter_AddRefs(uri2
), aSpec2
);
116 printf(" \"%s\": GOT ", aSpec1
);
117 nsresult rv
= aCookieService
->GetCookieStringFromHttp(uri1
, uri2
, nsnull
, aCookie
);
118 if (NS_FAILED(rv
)) printf("XXX GetCookieString() failed!\n");
122 printf("\"%s\"\n", *aCookie
);
124 return *aCookie
!= nsnull
;
127 // returns PR_TRUE if cookie(s) for the given host were found; else PR_FALSE.
128 // the cookie string is returned via aCookie.
130 GetACookieNoHttp(nsICookieService
*aCookieService
, const char *aSpec
, char **aCookie
)
132 nsCOMPtr
<nsIURI
> uri
;
133 NS_NewURI(getter_AddRefs(uri
), aSpec
);
135 printf(" \"%s\": GOT ", aSpec
);
136 nsresult rv
= aCookieService
->GetCookieString(uri
, nsnull
, aCookie
);
137 if (NS_FAILED(rv
)) printf("XXX GetCookieString() failed!\n");
141 printf("\"%s\"\n", *aCookie
);
143 return *aCookie
!= nsnull
;
146 // some #defines for comparison rules
147 #define MUST_BE_NULL 0
149 #define MUST_CONTAIN 2
150 #define MUST_NOT_CONTAIN 3
151 #define MUST_NOT_EQUAL 4
153 // a simple helper function to improve readability:
154 // takes one of the #defined rules above, and performs the appropriate test.
155 // PR_TRUE means the test passed; PR_FALSE means the test failed.
157 CheckResult(const char *aLhs
, PRUint32 aRule
, const char *aRhs
= nsnull
)
161 return !aLhs
|| !*aLhs
;
164 return !PL_strcmp(aLhs
, aRhs
);
167 return PL_strcmp(aLhs
, aRhs
);
170 return PL_strstr(aLhs
, aRhs
) != nsnull
;
172 case MUST_NOT_CONTAIN
:
173 return PL_strstr(aLhs
, aRhs
) == nsnull
;
176 return PR_FALSE
; // failure
180 // helper function that ensures the first aSize elements of aResult are
181 // PR_TRUE (i.e. all tests succeeded). prints the result of the tests (if any
182 // tests failed, it prints the zero-based index of each failed test).
184 PrintResult(const PRBool aResult
[], PRUint32 aSize
)
186 PRBool failed
= PR_FALSE
;
187 printf("*** tests ");
188 for (PRUint32 i
= 0; i
< aSize
; ++i
) {
195 printf("FAILED!\a\n");
203 InitPrefs(nsIPrefBranch
*aPrefBranch
)
205 // init some relevant prefs, so the tests don't go awry.
206 // we use the most restrictive set of prefs we can;
207 // however, we don't test third party blocking here.
208 aPrefBranch
->SetIntPref(kCookiesPermissions
, 0); // accept all
209 aPrefBranch
->SetBoolPref(kCookiesDisabledForMailNews
, PR_TRUE
);
210 aPrefBranch
->SetBoolPref(kCookiesLifetimeEnabled
, PR_TRUE
);
211 aPrefBranch
->SetIntPref(kCookiesLifetimeCurrentSession
, 0);
212 aPrefBranch
->SetIntPref(kCookiesLifetimeDays
, 1);
213 aPrefBranch
->SetBoolPref(kCookiesAskPermission
, PR_FALSE
);
219 ScopedXPCOM() : rv(NS_InitXPCOM2(nsnull
, nsnull
, nsnull
)) { }
222 if (NS_SUCCEEDED(rv
))
223 NS_ShutdownXPCOM(nsnull
);
230 main(PRInt32 argc
, char *argv
[])
232 if (test_common_init(&argc
, &argv
) != 0)
235 PRBool allTestsPassed
= PR_TRUE
;
238 if (NS_FAILED(xpcom
.rv
))
244 nsCOMPtr
<nsICookieService
> cookieService
=
245 do_GetService(kCookieServiceCID
, &rv0
);
246 if (NS_FAILED(rv0
)) return -1;
248 nsCOMPtr
<nsIPrefBranch
> prefBranch
=
249 do_GetService(kPrefServiceCID
, &rv0
);
250 if (NS_FAILED(rv0
)) return -1;
252 InitPrefs(prefBranch
);
257 // call NS_NewURI just to force chrome registrations, so all our
258 // printf'ed messages are together.
260 nsCOMPtr
<nsIURI
> foo
;
261 NS_NewURI(getter_AddRefs(foo
), "http://foo.com");
266 /* The basic idea behind these tests is the following:
268 * we set() some cookie, then try to get() it in various ways. we have
269 * several possible tests we perform on the cookie string returned from
272 * a) check whether the returned string is null (i.e. we got no cookies
273 * back). this is used e.g. to ensure a given cookie was deleted
274 * correctly, or to ensure a certain cookie wasn't returned to a given
276 * b) check whether the returned string exactly matches a given string.
277 * this is used where we want to make sure our cookie service adheres to
278 * some strict spec (e.g. ordering of multiple cookies), or where we
279 * just know exactly what the returned string should be.
280 * c) check whether the returned string contains/does not contain a given
281 * string. this is used where we don't know/don't care about the
282 * ordering of multiple cookies - we just want to make sure the cookie
283 * string contains them all, in some order.
285 * the results of each individual testing operation from CheckResult() is
286 * stored in an array of bools, which is then checked against the expected
287 * outcomes (all successes), by PrintResult(). the overall result of all
288 * tests to date is kept in |allTestsPassed|, for convenient display at the
291 * Interpreting the output:
292 * each setting/getting operation will print output saying exactly what
293 * it's doing and the outcome, respectively. this information is only
294 * useful for debugging purposes; the actual result of the tests is
295 * printed at the end of each block of tests. this will either be "all
296 * tests passed" or "tests X Y Z failed", where X, Y, Z are the indexes
297 * of rv (i.e. zero-based). at the conclusion of all tests, the overall
298 * passed/failed result is printed.
300 * NOTE: this testsuite is not yet comprehensive or complete, and is
301 * somewhat contrived - still under development, and needs improving!
305 printf("*** Beginning basic tests...\n");
307 // test some basic variations of the domain & path
308 SetACookie(cookieService
, "http://www.basic.com", nsnull
, "test=basic", nsnull
);
309 GetACookie(cookieService
, "http://www.basic.com", nsnull
, getter_Copies(cookie
));
310 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=basic");
311 GetACookie(cookieService
, "http://www.basic.com/testPath/testfile.txt", nsnull
, getter_Copies(cookie
));
312 rv
[1] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=basic");
313 GetACookie(cookieService
, "http://www.basic.com./", nsnull
, getter_Copies(cookie
));
314 rv
[2] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=basic");
315 GetACookie(cookieService
, "http://www.basic.com.", nsnull
, getter_Copies(cookie
));
316 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=basic");
317 GetACookie(cookieService
, "http://www.basic.com./testPath/testfile.txt", nsnull
, getter_Copies(cookie
));
318 rv
[4] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=basic");
319 GetACookie(cookieService
, "http://www.basic2.com/", nsnull
, getter_Copies(cookie
));
320 rv
[5] = CheckResult(cookie
.get(), MUST_BE_NULL
);
321 SetACookie(cookieService
, "http://www.basic.com", nsnull
, "test=basic; max-age=-1", nsnull
);
322 GetACookie(cookieService
, "http://www.basic.com/", nsnull
, getter_Copies(cookie
));
323 rv
[6] = CheckResult(cookie
.get(), MUST_BE_NULL
);
325 allTestsPassed
= PrintResult(rv
, 7) && allTestsPassed
;
329 printf("*** Beginning domain tests...\n");
331 // test some variations of the domain & path, for different domains of
333 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=domain.com", nsnull
);
334 GetACookie(cookieService
, "http://domain.com", nsnull
, getter_Copies(cookie
));
335 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
336 GetACookie(cookieService
, "http://domain.com.", nsnull
, getter_Copies(cookie
));
337 rv
[1] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
338 GetACookie(cookieService
, "http://www.domain.com", nsnull
, getter_Copies(cookie
));
339 rv
[2] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
340 GetACookie(cookieService
, "http://foo.domain.com", nsnull
, getter_Copies(cookie
));
341 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
342 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=domain.com; max-age=-1", nsnull
);
343 GetACookie(cookieService
, "http://domain.com", nsnull
, getter_Copies(cookie
));
344 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
346 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=.domain.com", nsnull
);
347 GetACookie(cookieService
, "http://domain.com", nsnull
, getter_Copies(cookie
));
348 rv
[5] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
349 GetACookie(cookieService
, "http://www.domain.com", nsnull
, getter_Copies(cookie
));
350 rv
[6] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
351 GetACookie(cookieService
, "http://bah.domain.com", nsnull
, getter_Copies(cookie
));
352 rv
[7] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=domain");
353 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=.domain.com; max-age=-1", nsnull
);
354 GetACookie(cookieService
, "http://domain.com", nsnull
, getter_Copies(cookie
));
355 rv
[8] = CheckResult(cookie
.get(), MUST_BE_NULL
);
357 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=.foo.domain.com", nsnull
);
358 GetACookie(cookieService
, "http://foo.domain.com", nsnull
, getter_Copies(cookie
));
359 rv
[9] = CheckResult(cookie
.get(), MUST_BE_NULL
);
361 SetACookie(cookieService
, "http://www.domain.com", nsnull
, "test=domain; domain=moose.com", nsnull
);
362 GetACookie(cookieService
, "http://foo.domain.com", nsnull
, getter_Copies(cookie
));
363 rv
[10] = CheckResult(cookie
.get(), MUST_BE_NULL
);
365 allTestsPassed
= PrintResult(rv
, 11) && allTestsPassed
;
369 printf("*** Beginning path tests...\n");
371 // test some variations of the domain & path, for different paths of
373 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/path", nsnull
);
374 GetACookie(cookieService
, "http://path.net/path", nsnull
, getter_Copies(cookie
));
375 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
376 GetACookie(cookieService
, "http://path.net/path/", nsnull
, getter_Copies(cookie
));
377 rv
[1] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
378 GetACookie(cookieService
, "http://path.net/path/hithere.foo", nsnull
, getter_Copies(cookie
));
379 rv
[2] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
380 GetACookie(cookieService
, "http://path.net/path?hithere/foo", nsnull
, getter_Copies(cookie
));
381 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
382 GetACookie(cookieService
, "http://path.net/path2", nsnull
, getter_Copies(cookie
));
383 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
384 GetACookie(cookieService
, "http://path.net/path2/", nsnull
, getter_Copies(cookie
));
385 rv
[5] = CheckResult(cookie
.get(), MUST_BE_NULL
);
386 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/path; max-age=-1", nsnull
);
387 GetACookie(cookieService
, "http://path.net/path/", nsnull
, getter_Copies(cookie
));
388 rv
[6] = CheckResult(cookie
.get(), MUST_BE_NULL
);
390 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/path/", nsnull
);
391 GetACookie(cookieService
, "http://path.net/path", nsnull
, getter_Copies(cookie
));
392 rv
[7] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
393 GetACookie(cookieService
, "http://path.net/path/", nsnull
, getter_Copies(cookie
));
394 rv
[8] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
395 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/path/; max-age=-1", nsnull
);
396 GetACookie(cookieService
, "http://path.net/path/", nsnull
, getter_Copies(cookie
));
397 rv
[9] = CheckResult(cookie
.get(), MUST_BE_NULL
);
399 // note that a site can set a cookie for a path it's not on.
400 // this is an intentional deviation from spec (see comments in
401 // nsCookieService::CheckPath()), so we test this functionality too
402 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/foo/", nsnull
);
403 GetACookie(cookieService
, "http://path.net/path", nsnull
, getter_Copies(cookie
));
404 rv
[10] = CheckResult(cookie
.get(), MUST_BE_NULL
);
405 GetACookie(cookieService
, "http://path.net/foo", nsnull
, getter_Copies(cookie
));
406 rv
[11] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=path");
407 SetACookie(cookieService
, "http://path.net/path/file", nsnull
, "test=path; path=/foo/; max-age=-1", nsnull
);
408 GetACookie(cookieService
, "http://path.net/foo/", nsnull
, getter_Copies(cookie
));
409 rv
[12] = CheckResult(cookie
.get(), MUST_BE_NULL
);
411 // bug 373228: make sure cookies with paths longer than 1024 bytes,
412 // and cookies with paths or names containing tabs, are rejected.
413 // the following cookie has a path > 1024 bytes explicitly specified in the cookie
414 SetACookie(cookieService
, "http://path.net/", nsnull
, "test=path; path=/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/", nsnull
);
415 GetACookie(cookieService
, "http://path.net/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", nsnull
, getter_Copies(cookie
));
416 rv
[13] = CheckResult(cookie
.get(), MUST_BE_NULL
);
417 // the following cookie has a path > 1024 bytes implicitly specified by the uri path
418 SetACookie(cookieService
, "http://path.net/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/", nsnull
, "test=path", nsnull
);
419 GetACookie(cookieService
, "http://path.net/1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890/", nsnull
, getter_Copies(cookie
));
420 rv
[14] = CheckResult(cookie
.get(), MUST_BE_NULL
);
421 // the following cookie includes a tab in the path
422 SetACookie(cookieService
, "http://path.net/", nsnull
, "test=path; path=/foo\tbar/", nsnull
);
423 GetACookie(cookieService
, "http://path.net/foo\tbar/", nsnull
, getter_Copies(cookie
));
424 rv
[15] = CheckResult(cookie
.get(), MUST_BE_NULL
);
425 // the following cookie includes a tab in the name
426 SetACookie(cookieService
, "http://path.net/", nsnull
, "test\ttabs=tab", nsnull
);
427 GetACookie(cookieService
, "http://path.net/", nsnull
, getter_Copies(cookie
));
428 rv
[16] = CheckResult(cookie
.get(), MUST_BE_NULL
);
429 // the following cookie includes a tab in the value - allowed
430 SetACookie(cookieService
, "http://path.net/", nsnull
, "test=tab\ttest", nsnull
);
431 GetACookie(cookieService
, "http://path.net/", nsnull
, getter_Copies(cookie
));
432 rv
[17] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=tab\ttest");
433 SetACookie(cookieService
, "http://path.net/", nsnull
, "test=tab\ttest; max-age=-1", nsnull
);
434 GetACookie(cookieService
, "http://path.net/", nsnull
, getter_Copies(cookie
));
435 rv
[18] = CheckResult(cookie
.get(), MUST_BE_NULL
);
437 allTestsPassed
= PrintResult(rv
, 19) && allTestsPassed
;
440 // *** expiry & deletion tests
441 // XXX add server time str parsing tests here
442 printf("*** Beginning expiry & deletion tests...\n");
444 // test some variations of the expiry time,
445 // and test deletion of previously set cookies
446 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=-1", nsnull
);
447 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
448 rv
[0] = CheckResult(cookie
.get(), MUST_BE_NULL
);
449 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=0", nsnull
);
450 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
451 rv
[1] = CheckResult(cookie
.get(), MUST_BE_NULL
);
452 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull
);
453 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
454 rv
[2] = CheckResult(cookie
.get(), MUST_BE_NULL
);
456 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=60", nsnull
);
457 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
458 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=expiry");
459 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=-20", nsnull
);
460 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
461 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
462 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=60", nsnull
);
463 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
464 rv
[5] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=expiry");
465 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull
);
466 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
467 rv
[6] = CheckResult(cookie
.get(), MUST_BE_NULL
);
468 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=expiry; max-age=60", nsnull
);
469 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "newtest=expiry; max-age=60", nsnull
);
470 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
471 rv
[7] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test=expiry");
472 rv
[8] = CheckResult(cookie
.get(), MUST_CONTAIN
, "newtest=expiry");
473 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "test=differentvalue; max-age=0", nsnull
);
474 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
475 rv
[9] = CheckResult(cookie
.get(), MUST_EQUAL
, "newtest=expiry");
476 SetACookie(cookieService
, "http://expireme.org/", nsnull
, "newtest=evendifferentvalue; max-age=0", nsnull
);
477 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
478 rv
[10] = CheckResult(cookie
.get(), MUST_BE_NULL
);
480 SetACookie(cookieService
, "http://foo.expireme.org/", nsnull
, "test=expiry; domain=.expireme.org; max-age=60", nsnull
);
481 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
482 rv
[11] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=expiry");
483 SetACookie(cookieService
, "http://bar.expireme.org/", nsnull
, "test=differentvalue; domain=.expireme.org; max-age=0", nsnull
);
484 GetACookie(cookieService
, "http://expireme.org/", nsnull
, getter_Copies(cookie
));
485 rv
[12] = CheckResult(cookie
.get(), MUST_BE_NULL
);
487 allTestsPassed
= PrintResult(rv
, 13) && allTestsPassed
;
490 // *** multiple cookie tests
491 printf("*** Beginning multiple cookie tests...\n");
493 // test the setting of multiple cookies, and test the order of precedence
494 // (a later cookie overwriting an earlier one, in the same header string)
495 SetACookie(cookieService
, "http://multiple.cookies/", nsnull
, "test=multiple; domain=.multiple.cookies \n test=different \n test=same; domain=.multiple.cookies \n newtest=ciao \n newtest=foo; max-age=-6 \n newtest=reincarnated", nsnull
);
496 GetACookie(cookieService
, "http://multiple.cookies/", nsnull
, getter_Copies(cookie
));
497 rv
[0] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "test=multiple");
498 rv
[1] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test=different");
499 rv
[2] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test=same");
500 rv
[3] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "newtest=ciao");
501 rv
[4] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "newtest=foo");
502 rv
[5] = CheckResult(cookie
.get(), MUST_CONTAIN
, "newtest=reincarnated") != nsnull
;
503 SetACookie(cookieService
, "http://multiple.cookies/", nsnull
, "test=expiry; domain=.multiple.cookies; max-age=0", nsnull
);
504 GetACookie(cookieService
, "http://multiple.cookies/", nsnull
, getter_Copies(cookie
));
505 rv
[6] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "test=same");
506 SetACookie(cookieService
, "http://multiple.cookies/", nsnull
, "\n test=different; max-age=0 \n", nsnull
);
507 GetACookie(cookieService
, "http://multiple.cookies/", nsnull
, getter_Copies(cookie
));
508 rv
[7] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "test=different");
509 SetACookie(cookieService
, "http://multiple.cookies/", nsnull
, "newtest=dead; max-age=0", nsnull
);
510 GetACookie(cookieService
, "http://multiple.cookies/", nsnull
, getter_Copies(cookie
));
511 rv
[8] = CheckResult(cookie
.get(), MUST_BE_NULL
);
513 allTestsPassed
= PrintResult(rv
, 9) && allTestsPassed
;
517 printf("*** Beginning parser tests...\n");
519 // test the cookie header parser, under various circumstances.
520 SetACookie(cookieService
, "http://parser.test/", nsnull
, "test=parser; domain=.parser.test; ;; ;=; ,,, ===,abc,=; abracadabra! max-age=20;=;;", nsnull
);
521 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
522 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=parser");
523 SetACookie(cookieService
, "http://parser.test/", nsnull
, "test=parser; domain=.parser.test; max-age=0", nsnull
);
524 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
525 rv
[1] = CheckResult(cookie
.get(), MUST_BE_NULL
);
526 SetACookie(cookieService
, "http://parser.test/", nsnull
, "test=\"fubar! = foo;bar\\\";\" parser; domain=.parser.test; max-age=6\nfive; max-age=2.63,", nsnull
);
527 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
528 rv
[2] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test=\"fubar! = foo;bar\\\";\"");
529 rv
[3] = CheckResult(cookie
.get(), MUST_CONTAIN
, "five");
530 SetACookie(cookieService
, "http://parser.test/", nsnull
, "test=kill; domain=.parser.test; max-age=0 \n five; max-age=0", nsnull
);
531 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
532 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
534 // test the handling of VALUE-only cookies (see bug 169091),
535 // i.e. "six" should assume an empty NAME, which allows other VALUE-only
536 // cookies to overwrite it
537 SetACookie(cookieService
, "http://parser.test/", nsnull
, "six", nsnull
);
538 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
539 rv
[5] = CheckResult(cookie
.get(), MUST_EQUAL
, "six");
540 SetACookie(cookieService
, "http://parser.test/", nsnull
, "seven", nsnull
);
541 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
542 rv
[6] = CheckResult(cookie
.get(), MUST_EQUAL
, "seven");
543 SetACookie(cookieService
, "http://parser.test/", nsnull
, " =eight", nsnull
);
544 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
545 rv
[7] = CheckResult(cookie
.get(), MUST_EQUAL
, "eight");
546 SetACookie(cookieService
, "http://parser.test/", nsnull
, "test=six", nsnull
);
547 GetACookie(cookieService
, "http://parser.test/", nsnull
, getter_Copies(cookie
));
548 rv
[9] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test=six");
550 allTestsPassed
= PrintResult(rv
, 10) && allTestsPassed
;
553 // *** mailnews tests
554 printf("*** Beginning mailnews tests...\n");
556 // test some mailnews cookies to ensure blockage.
557 // we use null firstURI's deliberately, since we have hacks to deal with
559 SetACookie(cookieService
, "mailbox://mail.co.uk/", nsnull
, "test=mailnews", nsnull
);
560 GetACookie(cookieService
, "mailbox://mail.co.uk/", nsnull
, getter_Copies(cookie
));
561 rv
[0] = CheckResult(cookie
.get(), MUST_BE_NULL
);
562 GetACookie(cookieService
, "http://mail.co.uk/", nsnull
, getter_Copies(cookie
));
563 rv
[1] = CheckResult(cookie
.get(), MUST_BE_NULL
);
564 SetACookie(cookieService
, "http://mail.co.uk/", nsnull
, "test=mailnews", nsnull
);
565 GetACookie(cookieService
, "mailbox://mail.co.uk/", nsnull
, getter_Copies(cookie
));
566 rv
[2] = CheckResult(cookie
.get(), MUST_BE_NULL
);
567 GetACookie(cookieService
, "http://mail.co.uk/", nsnull
, getter_Copies(cookie
));
568 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=mailnews");
569 SetACookie(cookieService
, "http://mail.co.uk/", nsnull
, "test=mailnews; max-age=0", nsnull
);
570 GetACookie(cookieService
, "http://mail.co.uk/", nsnull
, getter_Copies(cookie
));
571 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
573 allTestsPassed
= PrintResult(rv
, 5) && allTestsPassed
;
576 // *** path ordering tests
577 printf("*** Beginning path ordering tests...\n");
579 // test that cookies are returned in path order - longest to shortest.
580 // if the header doesn't specify a path, it's taken from the host URI.
581 SetACookie(cookieService
, "http://multi.path.tests/", nsnull
, "test1=path; path=/one/two/three", nsnull
);
582 SetACookie(cookieService
, "http://multi.path.tests/", nsnull
, "test2=path; path=/one \n test3=path; path=/one/two/three/four \n test4=path; path=/one/two \n test5=path; path=/one/two/", nsnull
);
583 SetACookie(cookieService
, "http://multi.path.tests/one/two/three/four/five/", nsnull
, "test6=path", nsnull
);
584 SetACookie(cookieService
, "http://multi.path.tests/one/two/three/four/five/six/", nsnull
, "test7=path; path=", nsnull
);
585 SetACookie(cookieService
, "http://multi.path.tests/", nsnull
, "test8=path; path=/", nsnull
);
586 GetACookie(cookieService
, "http://multi.path.tests/one/two/three/four/five/six/", nsnull
, getter_Copies(cookie
));
587 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, "test7=path; test6=path; test3=path; test1=path; test5=path; test4=path; test2=path; test8=path");
589 allTestsPassed
= PrintResult(rv
, 1) && allTestsPassed
;
592 // *** httponly tests
593 printf("*** Beginning httponly tests...\n");
595 // Since this cookie is NOT set via http, setting it fails
596 SetACookieNoHttp(cookieService
, "http://httponly.test/", "test=httponly; httponly");
597 GetACookie(cookieService
, "http://httponly.test/", nsnull
, getter_Copies(cookie
));
598 rv
[0] = CheckResult(cookie
.get(), MUST_BE_NULL
);
599 // Since this cookie is set via http, it can be retrieved
600 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=httponly; httponly", nsnull
);
601 GetACookie(cookieService
, "http://httponly.test/", nsnull
, getter_Copies(cookie
));
602 rv
[1] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=httponly");
603 // ... but not by web content
604 GetACookieNoHttp(cookieService
, "http://httponly.test/", getter_Copies(cookie
));
605 rv
[2] = CheckResult(cookie
.get(), MUST_BE_NULL
);
606 // Non-Http cookies should not replace HttpOnly cookies
607 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=httponly; httponly", nsnull
);
608 SetACookieNoHttp(cookieService
, "http://httponly.test/", "test=not-httponly");
609 GetACookie(cookieService
, "http://httponly.test/", nsnull
, getter_Copies(cookie
));
610 rv
[3] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=httponly");
611 // ... and, if an HttpOnly cookie already exists, should not be set at all
612 GetACookieNoHttp(cookieService
, "http://httponly.test/", getter_Copies(cookie
));
613 rv
[4] = CheckResult(cookie
.get(), MUST_BE_NULL
);
614 // Non-Http cookies should not delete HttpOnly cookies
615 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=httponly; httponly", nsnull
);
616 SetACookieNoHttp(cookieService
, "http://httponly.test/", "test=httponly; max-age=-1");
617 GetACookie(cookieService
, "http://httponly.test/", nsnull
, getter_Copies(cookie
));
618 rv
[5] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=httponly");
619 // ... but HttpOnly cookies should
620 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=httponly; httponly; max-age=-1", nsnull
);
621 GetACookie(cookieService
, "http://httponly.test/", nsnull
, getter_Copies(cookie
));
622 rv
[6] = CheckResult(cookie
.get(), MUST_BE_NULL
);
623 // Non-Httponly cookies can replace HttpOnly cookies when set over http
624 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=httponly; httponly", nsnull
);
625 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=not-httponly", nsnull
);
626 GetACookieNoHttp(cookieService
, "http://httponly.test/", getter_Copies(cookie
));
627 rv
[7] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=not-httponly");
628 // scripts should not be able to set httponly cookies by replacing an existing non-httponly cookie
629 SetACookie(cookieService
, "http://httponly.test/", nsnull
, "test=not-httponly", nsnull
);
630 SetACookieNoHttp(cookieService
, "http://httponly.test/", "test=httponly; httponly");
631 GetACookieNoHttp(cookieService
, "http://httponly.test/", getter_Copies(cookie
));
632 rv
[8] = CheckResult(cookie
.get(), MUST_EQUAL
, "test=not-httponly");
634 allTestsPassed
= PrintResult(rv
, 9) && allTestsPassed
;
637 // *** nsICookieManager{2} interface tests
638 printf("*** Beginning nsICookieManager{2} interface tests...\n");
639 nsCOMPtr
<nsICookieManager
> cookieMgr
= do_GetService(NS_COOKIEMANAGER_CONTRACTID
, &rv0
);
640 if (NS_FAILED(rv0
)) return -1;
641 nsCOMPtr
<nsICookieManager2
> cookieMgr2
= do_QueryInterface(cookieMgr
);
642 if (!cookieMgr2
) return -1;
644 // first, ensure a clean slate
645 rv
[0] = NS_SUCCEEDED(cookieMgr
->RemoveAll());
647 rv
[1] = NS_SUCCEEDED(cookieMgr2
->Add(NS_LITERAL_CSTRING("cookiemgr.test"), // domain
648 NS_LITERAL_CSTRING("/foo"), // path
649 NS_LITERAL_CSTRING("test1"), // name
650 NS_LITERAL_CSTRING("yes"), // value
651 PR_FALSE
, // is secure
652 PR_FALSE
, // is httponly
653 PR_TRUE
, // is session
654 LL_MAXINT
)); // expiry time
655 rv
[2] = NS_SUCCEEDED(cookieMgr2
->Add(NS_LITERAL_CSTRING("cookiemgr.test"), // domain
656 NS_LITERAL_CSTRING("/foo"), // path
657 NS_LITERAL_CSTRING("test2"), // name
658 NS_LITERAL_CSTRING("yes"), // value
659 PR_FALSE
, // is secure
660 PR_TRUE
, // is httponly
661 PR_TRUE
, // is session
662 PR_Now() / PR_USEC_PER_SEC
+ 2)); // expiry time
663 rv
[3] = NS_SUCCEEDED(cookieMgr2
->Add(NS_LITERAL_CSTRING("new.domain"), // domain
664 NS_LITERAL_CSTRING("/rabbit"), // path
665 NS_LITERAL_CSTRING("test3"), // name
666 NS_LITERAL_CSTRING("yes"), // value
667 PR_FALSE
, // is secure
668 PR_FALSE
, // is httponly
669 PR_TRUE
, // is session
670 LL_MAXINT
)); // expiry time
671 // confirm using enumerator
672 nsCOMPtr
<nsISimpleEnumerator
> enumerator
;
673 rv
[4] = NS_SUCCEEDED(cookieMgr
->GetEnumerator(getter_AddRefs(enumerator
)));
676 nsCOMPtr
<nsICookie2
> expiredCookie
, newDomainCookie
;
677 while (NS_SUCCEEDED(enumerator
->HasMoreElements(&more
)) && more
) {
678 nsCOMPtr
<nsISupports
> cookie
;
679 if (NS_FAILED(enumerator
->GetNext(getter_AddRefs(cookie
)))) break;
682 // keep tabs on the second and third cookies, so we can check them later
683 nsCOMPtr
<nsICookie2
> cookie2(do_QueryInterface(cookie
));
686 cookie2
->GetName(name
);
687 if (name
== NS_LITERAL_CSTRING("test2"))
688 expiredCookie
= cookie2
;
689 else if (name
== NS_LITERAL_CSTRING("test3"))
690 newDomainCookie
= cookie2
;
693 // check the httpOnly attribute of the second cookie is honored
694 GetACookie(cookieService
, "http://cookiemgr.test/foo/", nsnull
, getter_Copies(cookie
));
695 rv
[6] = CheckResult(cookie
.get(), MUST_CONTAIN
, "test2=yes");
696 GetACookieNoHttp(cookieService
, "http://cookiemgr.test/foo/", getter_Copies(cookie
));
697 rv
[7] = CheckResult(cookie
.get(), MUST_NOT_CONTAIN
, "test2=yes");
698 // check CountCookiesFromHost()
699 PRUint32 hostCookies
= 0;
700 rv
[8] = NS_SUCCEEDED(cookieMgr2
->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies
)) &&
702 // check CookieExists() using the third cookie
704 rv
[9] = NS_SUCCEEDED(cookieMgr2
->CookieExists(newDomainCookie
, &found
)) && found
;
705 // remove the cookie, block it, and ensure it can't be added again
706 rv
[10] = NS_SUCCEEDED(cookieMgr
->Remove(NS_LITERAL_CSTRING("new.domain"), // domain
707 NS_LITERAL_CSTRING("test3"), // name
708 NS_LITERAL_CSTRING("/rabbit"), // path
709 PR_TRUE
)); // is blocked
710 rv
[11] = NS_SUCCEEDED(cookieMgr2
->CookieExists(newDomainCookie
, &found
)) && !found
;
711 rv
[12] = NS_SUCCEEDED(cookieMgr2
->Add(NS_LITERAL_CSTRING("new.domain"), // domain
712 NS_LITERAL_CSTRING("/rabbit"), // path
713 NS_LITERAL_CSTRING("test3"), // name
714 NS_LITERAL_CSTRING("yes"), // value
715 PR_FALSE
, // is secure
716 PR_FALSE
, // is httponly
717 PR_TRUE
, // is session
718 LL_MININT
)); // expiry time
719 rv
[13] = NS_SUCCEEDED(cookieMgr2
->CookieExists(newDomainCookie
, &found
)) && !found
;
720 // sleep four seconds, to make sure the second cookie has expired
721 PR_Sleep(4 * PR_TicksPerSecond());
722 // check CountCookiesFromHost() and CookieExists() don't count the expired cookie
723 rv
[14] = NS_SUCCEEDED(cookieMgr2
->CountCookiesFromHost(NS_LITERAL_CSTRING("cookiemgr.test"), &hostCookies
)) &&
725 rv
[15] = NS_SUCCEEDED(cookieMgr2
->CookieExists(expiredCookie
, &found
)) && !found
;
726 // double-check RemoveAll() using the enumerator
727 rv
[16] = NS_SUCCEEDED(cookieMgr
->RemoveAll());
728 rv
[17] = NS_SUCCEEDED(cookieMgr
->GetEnumerator(getter_AddRefs(enumerator
))) &&
729 NS_SUCCEEDED(enumerator
->HasMoreElements(&more
)) &&
732 allTestsPassed
= PrintResult(rv
, 18) && allTestsPassed
;
735 // *** eviction and creation ordering tests
736 printf("*** Beginning eviction and creation ordering tests...\n");
738 // test that cookies are
739 // a) returned by order of creation time (oldest first, newest last)
740 // b) evicted by order of lastAccessed time, if the limit on cookies per host (50) is reached
742 nsCAutoString expected
;
743 for (PRInt32 i
= 0; i
< 60; ++i
) {
744 name
= NS_LITERAL_CSTRING("test");
746 name
+= NS_LITERAL_CSTRING("=creation");
747 SetACookie(cookieService
, "http://creation.ordering.tests/", nsnull
, name
.get(), nsnull
);
750 // sleep a couple of seconds, to make sure the first 10 cookies are older than
751 // subsequent ones (timer resolution varies on different platforms).
752 PR_Sleep(2 * PR_TicksPerSecond());
758 expected
+= NS_LITERAL_CSTRING("; ");
761 GetACookie(cookieService
, "http://creation.ordering.tests/", nsnull
, getter_Copies(cookie
));
762 rv
[0] = CheckResult(cookie
.get(), MUST_EQUAL
, expected
.get());
764 // test that cookies are evicted by order of lastAccessed time, if the limit on total cookies
767 for (PRInt32 i
= 0; i
< 1010; ++i
) {
768 host
= NS_LITERAL_CSTRING("http://eviction.");
770 host
+= NS_LITERAL_CSTRING(".tests/");
771 SetACookie(cookieService
, host
.get(), nsnull
, "test=eviction", nsnull
);
774 // sleep a couple of seconds, to make sure the first 10 cookies are older than
775 // subsequent ones (timer resolution varies on different platforms).
776 PR_Sleep(2 * PR_TicksPerSecond());
779 rv
[1] = NS_SUCCEEDED(cookieMgr
->GetEnumerator(getter_AddRefs(enumerator
)));
781 rv
[2] = PR_FALSE
; // init to failure in case we break from the while loop
782 while (NS_SUCCEEDED(enumerator
->HasMoreElements(&more
)) && more
) {
783 nsCOMPtr
<nsISupports
> cookie
;
784 if (NS_FAILED(enumerator
->GetNext(getter_AddRefs(cookie
)))) break;
787 // keep tabs on the third cookie, so we can check it later
788 nsCOMPtr
<nsICookie2
> cookie2(do_QueryInterface(cookie
));
790 nsCAutoString domain
;
791 cookie2
->GetRawHost(domain
);
793 PRInt32 numInts
= PR_sscanf(domain
.get(), "eviction.%ld.tests", &hostNumber
);
794 if (numInts
!= 1 || hostNumber
< 10) break;
798 allTestsPassed
= PrintResult(rv
, 3) && allTestsPassed
;
801 // XXX the following are placeholders: add these tests please!
802 // *** "noncompliant cookie" tests
803 // *** IP address tests
807 printf("\n*** Result: %s!\n\n", allTestsPassed
? "all tests passed" : "TEST(S) FAILED");
811 return allTestsPassed
? 0 : 1;