зеркало из https://github.com/mozilla/pjs.git
Bug 327168 - test holds COMPtrs past XPCOM shutdown, r=darin
This commit is contained in:
Родитель
d678525b78
Коммит
cbd506e74c
|
@ -166,404 +166,422 @@ InitPrefs(nsIPrefBranch *aPrefBranch)
|
|||
aPrefBranch->SetBoolPref(kCookiesAskPermission, PR_FALSE);
|
||||
}
|
||||
|
||||
class ScopedXPCOM
|
||||
{
|
||||
public:
|
||||
ScopedXPCOM() : rv(NS_InitXPCOM2(nsnull, nsnull, nsnull)) { }
|
||||
~ScopedXPCOM()
|
||||
{
|
||||
if (NS_SUCCEEDED(rv))
|
||||
NS_ShutdownXPCOM(nsnull);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
};
|
||||
|
||||
int
|
||||
main(PRInt32 argc, char *argv[])
|
||||
{
|
||||
if (test_common_init(&argc, &argv) != 0)
|
||||
return -1;
|
||||
|
||||
nsresult rv0 = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
||||
if (NS_FAILED(rv0)) return -1;
|
||||
|
||||
nsCOMPtr<nsICookieService> cookieService =
|
||||
do_GetService(kCookieServiceCID, &rv0);
|
||||
if (NS_FAILED(rv0)) return -1;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch =
|
||||
do_GetService(kPrefServiceCID, &rv0);
|
||||
if (NS_FAILED(rv0)) return -1;
|
||||
|
||||
InitPrefs(prefBranch);
|
||||
|
||||
PRBool allTestsPassed = PR_TRUE;
|
||||
PRBool rv[20];
|
||||
nsCString cookie;
|
||||
|
||||
// call NS_NewURI just to force chrome registrations, so all our
|
||||
// printf'ed messages are together.
|
||||
ScopedXPCOM xpcom;
|
||||
if (NS_FAILED(xpcom.rv))
|
||||
return -1;
|
||||
|
||||
{
|
||||
nsresult rv0;
|
||||
|
||||
nsCOMPtr<nsICookieService> cookieService =
|
||||
do_GetService(kCookieServiceCID, &rv0);
|
||||
if (NS_FAILED(rv0)) return -1;
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch =
|
||||
do_GetService(kPrefServiceCID, &rv0);
|
||||
if (NS_FAILED(rv0)) return -1;
|
||||
|
||||
InitPrefs(prefBranch);
|
||||
|
||||
PRBool rv[20];
|
||||
nsCString cookie;
|
||||
|
||||
// call NS_NewURI just to force chrome registrations, so all our
|
||||
// printf'ed messages are together.
|
||||
{
|
||||
nsCOMPtr<nsIURI> foo;
|
||||
NS_NewURI(getter_AddRefs(foo), "http://foo.com");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
/* The basic idea behind these tests is the following:
|
||||
*
|
||||
* we set() some cookie, then try to get() it in various ways. we have
|
||||
* several possible tests we perform on the cookie string returned from
|
||||
* get():
|
||||
*
|
||||
* a) check whether the returned string is null (i.e. we got no cookies
|
||||
* back). this is used e.g. to ensure a given cookie was deleted
|
||||
* correctly, or to ensure a certain cookie wasn't returned to a given
|
||||
* host.
|
||||
* b) check whether the returned string exactly matches a given string.
|
||||
* this is used where we want to make sure our cookie service adheres to
|
||||
* some strict spec (e.g. ordering of multiple cookies), or where we
|
||||
* just know exactly what the returned string should be.
|
||||
* c) check whether the returned string contains/does not contain a given
|
||||
* string. this is used where we don't know/don't care about the
|
||||
* ordering of multiple cookies - we just want to make sure the cookie
|
||||
* string contains them all, in some order.
|
||||
*
|
||||
* the results of each individual testing operation from CheckResult() is
|
||||
* stored in an array of bools, which is then checked against the expected
|
||||
* outcomes (all successes), by PrintResult()). the overall result of all
|
||||
* tests to date is kept in |allTestsPassed|, for convenient display at the
|
||||
* end.
|
||||
*
|
||||
* Interpreting the output:
|
||||
* each setting/getting operation will print output saying exactly what
|
||||
* it's doing and the outcome, respectively. this information is only
|
||||
* useful for debugging purposes; the actual result of the tests is
|
||||
* printed at the end of each block of tests. this will either be "all
|
||||
* tests passed" or "tests X Y Z failed", where X, Y, Z are the indexes
|
||||
* of rv (i.e. zero-based). at the conclusion of all tests, the overall
|
||||
* passed/failed result is printed.
|
||||
*
|
||||
* NOTE: this testsuite is not yet comprehensive or complete, and is
|
||||
* somewhat contrived - still under development, and needs improving!
|
||||
*/
|
||||
|
||||
// *** basic tests
|
||||
printf("*** Beginning basic tests...\n");
|
||||
|
||||
// test some basic variations of the domain & path
|
||||
SetACookie(cookieService, "http://www.basic.com", nsnull, "test=basic", nsnull);
|
||||
GetACookie(cookieService, "http://www.basic.com", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com/testPath/testfile.txt", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com./", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com.", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com./testPath/testfile.txt", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic2.com/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://www.basic.com", nsnull, "test=basic; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://www.basic.com/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 7) && allTestsPassed;
|
||||
|
||||
|
||||
// *** domain tests
|
||||
printf("*** Beginning domain tests...\n");
|
||||
|
||||
// test some variations of the domain & path, for different domains of
|
||||
// a domain cookie
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://domain.com.", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://www.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=domain.com; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://www.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://bah.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.domain.com; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.foo.domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=moose.com", nsnull);
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 11) && allTestsPassed;
|
||||
|
||||
|
||||
// *** path tests
|
||||
printf("*** Beginning path tests...\n");
|
||||
|
||||
// test some variations of the domain & path, for different paths of
|
||||
// a path cookie
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/hithere.foo", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path?hithere/foo", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path2", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://path.net/path2/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path/", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path/; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// note that a site can set a cookie for a path it's not on.
|
||||
// this is an intentional deviation from spec (see comments in
|
||||
// nsCookieService::CheckPath()), so we test this functionality too
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/foo/", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://path.net/foo", nsnull, getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/foo/; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/foo/", nsnull, getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 13) && allTestsPassed;
|
||||
|
||||
|
||||
// *** expiry & deletion tests
|
||||
// XXX add server time str parsing tests here
|
||||
printf("*** Beginning expiry & deletion tests...\n");
|
||||
|
||||
// test some variations of the expiry time,
|
||||
// and test deletion of previously set cookies
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=-20", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "newtest=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_CONTAIN, "test=expiry");
|
||||
rv[8] = CheckResult(cookie.get(), MUST_CONTAIN, "newtest=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=differentvalue; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_EQUAL, "newtest=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "newtest=evendifferentvalue; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://foo.expireme.org/", nsnull, "test=expiry; domain=.expireme.org; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://bar.expireme.org/", nsnull, "test=differentvalue; domain=.expireme.org; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 13) && allTestsPassed;
|
||||
|
||||
|
||||
// *** multiple cookie tests
|
||||
printf("*** Beginning multiple cookie tests...\n");
|
||||
|
||||
// test the setting of multiple cookies, and test the order of precedence
|
||||
// (a later cookie overwriting an earlier one, in the same header string)
|
||||
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);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=multiple");
|
||||
rv[1] = CheckResult(cookie.get(), MUST_CONTAIN, "test=different");
|
||||
rv[2] = CheckResult(cookie.get(), MUST_CONTAIN, "test=same");
|
||||
rv[3] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "newtest=ciao");
|
||||
rv[4] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "newtest=foo");
|
||||
rv[5] = CheckResult(cookie.get(), MUST_CONTAIN, "newtest=reincarnated") != nsnull;
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "test=expiry; domain=.multiple.cookies; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=same");
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "\n test=different; max-age=0 \n", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=different");
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "newtest=dead; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 9) && allTestsPassed;
|
||||
|
||||
|
||||
// *** foreign cookie tests
|
||||
printf("*** Beginning foreign cookie tests...\n");
|
||||
|
||||
// test the blocking of foreign cookies, under various circumstances.
|
||||
// order of URI arguments is hostURI, firstURI
|
||||
SetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://weather.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://notweather.yahoo.com/", "http://sport.yahoo.com/", getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://moose.yahoo.com/", "http://canada.yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://sport.yahoo.com/", getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://sport.yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://jack.yahoo.com/", "http://jill.yahoo.com/", "test=foreign; domain=.yahoo.com; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://jane.yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://moose.yahoo.com/", "http://foo.moose.yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://foo.bar.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://foo.bar.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test handling of IP addresses by the foreign blocking algo
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", "test=foreign; domain=192.168.54.33", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33./", "http://.192.168.54.33../", getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33/", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://148.168.54.33", getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", "test=foreign; domain=192.168.54.33; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://148.168.54.33/", "test=foreign; domain=192.168.54.33", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[13] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 14) && allTestsPassed;
|
||||
|
||||
|
||||
// *** parser tests
|
||||
printf("*** Beginning parser tests...\n");
|
||||
|
||||
// test the cookie header parser, under various circumstances.
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=parser; domain=.parser.test; ;; ;=; ,,, ===,abc,=; abracadabra! max-age=20;=;;", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=parser");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=parser; domain=.parser.test; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=\"fubar! = foo;bar\\\";\" parser; domain=.parser.test; max-age=6\nfive; max-age=2.63,", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_CONTAIN, "test=\"fubar! = foo;bar\\\";\"");
|
||||
rv[3] = CheckResult(cookie.get(), MUST_CONTAIN, "five");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=kill; domain=.parser.test; max-age=0 \n five; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test the handling of VALUE-only cookies (see bug 169091),
|
||||
// i.e. "six" should assume an empty NAME, which allows other VALUE-only
|
||||
// cookies to overwrite it
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "six", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "six");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "seven", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "seven");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, " =eight", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "eight");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=six", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_CONTAIN, "test=six");
|
||||
|
||||
allTestsPassed = PrintResult(rv, 10) && allTestsPassed;
|
||||
|
||||
|
||||
// *** mailnews tests
|
||||
printf("*** Beginning mailnews tests...\n");
|
||||
|
||||
// test some mailnews cookies to ensure blockage.
|
||||
// we use null firstURI's deliberately, since we have hacks to deal with
|
||||
// this situation...
|
||||
SetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=mailnews");
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test non-null firstURI's, i) from mailnews ii) not from mailnews
|
||||
SetACookie(cookieService, "mailbox://mail.co.uk/", "http://mail.co.uk/", "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://mail.co.uk/", "mailbox://mail.co.uk/", "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 7) && allTestsPassed;
|
||||
|
||||
|
||||
// *** path ordering tests
|
||||
printf("*** Beginning path ordering tests...\n");
|
||||
|
||||
// test that cookies are returned in path order - longest to shortest.
|
||||
// if the header doesn't specify a path, it's taken from the host URI.
|
||||
SetACookie(cookieService, "http://multi.path.tests/", nsnull, "test1=path; path=/one/two/three", nsnull);
|
||||
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);
|
||||
SetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/", nsnull, "test6=path", nsnull);
|
||||
SetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/six/", nsnull, "test7=path; path=", nsnull);
|
||||
SetACookie(cookieService, "http://multi.path.tests/", nsnull, "test8=path; path=/", nsnull);
|
||||
GetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/six/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test7=path; test6=path; test3=path; test1=path; test5=path; test4=path; test2=path; test8=path");
|
||||
|
||||
allTestsPassed = PrintResult(rv, 1) && allTestsPassed;
|
||||
|
||||
// XXX the following are placeholders: add these tests please!
|
||||
// *** "noncompliant cookie" tests
|
||||
// *** IP address tests
|
||||
// *** speed tests
|
||||
|
||||
|
||||
printf("\n*** Result: %s!\n\n", allTestsPassed ? "all tests passed" : "TEST(S) FAILED");
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
/* The basic idea behind these tests is the following:
|
||||
*
|
||||
* we set() some cookie, then try to get() it in various ways. we have
|
||||
* several possible tests we perform on the cookie string returned from
|
||||
* get():
|
||||
*
|
||||
* a) check whether the returned string is null (i.e. we got no cookies
|
||||
* back). this is used e.g. to ensure a given cookie was deleted
|
||||
* correctly, or to ensure a certain cookie wasn't returned to a given
|
||||
* host.
|
||||
* b) check whether the returned string exactly matches a given string.
|
||||
* this is used where we want to make sure our cookie service adheres to
|
||||
* some strict spec (e.g. ordering of multiple cookies), or where we
|
||||
* just know exactly what the returned string should be.
|
||||
* c) check whether the returned string contains/does not contain a given
|
||||
* string. this is used where we don't know/don't care about the
|
||||
* ordering of multiple cookies - we just want to make sure the cookie
|
||||
* string contains them all, in some order.
|
||||
*
|
||||
* the results of each individual testing operation from CheckResult() is
|
||||
* stored in an array of bools, which is then checked against the expected
|
||||
* outcomes (all successes), by PrintResult()). the overall result of all
|
||||
* tests to date is kept in |allTestsPassed|, for convenient display at the
|
||||
* end.
|
||||
*
|
||||
* Interpreting the output:
|
||||
* each setting/getting operation will print output saying exactly what
|
||||
* it's doing and the outcome, respectively. this information is only
|
||||
* useful for debugging purposes; the actual result of the tests is
|
||||
* printed at the end of each block of tests. this will either be "all
|
||||
* tests passed" or "tests X Y Z failed", where X, Y, Z are the indexes
|
||||
* of rv (i.e. zero-based). at the conclusion of all tests, the overall
|
||||
* passed/failed result is printed.
|
||||
*
|
||||
* NOTE: this testsuite is not yet comprehensive or complete, and is
|
||||
* somewhat contrived - still under development, and needs improving!
|
||||
*/
|
||||
|
||||
// *** basic tests
|
||||
printf("*** Beginning basic tests...\n");
|
||||
|
||||
// test some basic variations of the domain & path
|
||||
SetACookie(cookieService, "http://www.basic.com", nsnull, "test=basic", nsnull);
|
||||
GetACookie(cookieService, "http://www.basic.com", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com/testPath/testfile.txt", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com./", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com.", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic.com./testPath/testfile.txt", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_EQUAL, "test=basic");
|
||||
GetACookie(cookieService, "http://www.basic2.com/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://www.basic.com", nsnull, "test=basic; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://www.basic.com/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 7) && allTestsPassed;
|
||||
|
||||
|
||||
// *** domain tests
|
||||
printf("*** Beginning domain tests...\n");
|
||||
|
||||
// test some variations of the domain & path, for different domains of
|
||||
// a domain cookie
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://domain.com.", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://www.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=domain.com; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://www.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
GetACookie(cookieService, "http://bah.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "test=domain");
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.domain.com; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=.foo.domain.com", nsnull);
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://www.domain.com", nsnull, "test=domain; domain=moose.com", nsnull);
|
||||
GetACookie(cookieService, "http://foo.domain.com", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 11) && allTestsPassed;
|
||||
|
||||
|
||||
// *** path tests
|
||||
printf("*** Beginning path tests...\n");
|
||||
|
||||
// test some variations of the domain & path, for different paths of
|
||||
// a path cookie
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/hithere.foo", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path?hithere/foo", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path2", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://path.net/path2/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path/", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/path/; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// note that a site can set a cookie for a path it's not on.
|
||||
// this is an intentional deviation from spec (see comments in
|
||||
// nsCookieService::CheckPath()), so we test this functionality too
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/foo/", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/path", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://path.net/foo", nsnull, getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_EQUAL, "test=path");
|
||||
SetACookie(cookieService, "http://path.net/path/file", nsnull, "test=path; path=/foo/; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://path.net/foo/", nsnull, getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 13) && allTestsPassed;
|
||||
|
||||
|
||||
// *** expiry & deletion tests
|
||||
// XXX add server time str parsing tests here
|
||||
printf("*** Beginning expiry & deletion tests...\n");
|
||||
|
||||
// test some variations of the expiry time,
|
||||
// and test deletion of previously set cookies
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=-1", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=-20", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; expires=Thu, 10 Apr 1980 16:33:12 GMT", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=expiry; max-age=60", nsnull);
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "newtest=expiry; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_CONTAIN, "test=expiry");
|
||||
rv[8] = CheckResult(cookie.get(), MUST_CONTAIN, "newtest=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "test=differentvalue; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_EQUAL, "newtest=expiry");
|
||||
SetACookie(cookieService, "http://expireme.org/", nsnull, "newtest=evendifferentvalue; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://foo.expireme.org/", nsnull, "test=expiry; domain=.expireme.org; max-age=60", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_EQUAL, "test=expiry");
|
||||
SetACookie(cookieService, "http://bar.expireme.org/", nsnull, "test=differentvalue; domain=.expireme.org; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://expireme.org/", nsnull, getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 13) && allTestsPassed;
|
||||
|
||||
|
||||
// *** multiple cookie tests
|
||||
printf("*** Beginning multiple cookie tests...\n");
|
||||
|
||||
// test the setting of multiple cookies, and test the order of precedence
|
||||
// (a later cookie overwriting an earlier one, in the same header string)
|
||||
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);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=multiple");
|
||||
rv[1] = CheckResult(cookie.get(), MUST_CONTAIN, "test=different");
|
||||
rv[2] = CheckResult(cookie.get(), MUST_CONTAIN, "test=same");
|
||||
rv[3] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "newtest=ciao");
|
||||
rv[4] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "newtest=foo");
|
||||
rv[5] = CheckResult(cookie.get(), MUST_CONTAIN, "newtest=reincarnated") != nsnull;
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "test=expiry; domain=.multiple.cookies; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=same");
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "\n test=different; max-age=0 \n", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_NOT_CONTAIN, "test=different");
|
||||
SetACookie(cookieService, "http://multiple.cookies/", nsnull, "newtest=dead; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://multiple.cookies/", nsnull, getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 9) && allTestsPassed;
|
||||
|
||||
|
||||
// *** foreign cookie tests
|
||||
printf("*** Beginning foreign cookie tests...\n");
|
||||
|
||||
// test the blocking of foreign cookies, under various circumstances.
|
||||
// order of URI arguments is hostURI, firstURI
|
||||
SetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://weather.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://notweather.yahoo.com/", "http://sport.yahoo.com/", getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://moose.yahoo.com/", "http://canada.yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://sport.yahoo.com/", getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://sport.yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://jack.yahoo.com/", "http://jill.yahoo.com/", "test=foreign; domain=.yahoo.com; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://jane.yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
SetACookie(cookieService, "http://moose.yahoo.com/", "http://foo.moose.yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://foo.bar.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
SetACookie(cookieService, "http://foo.bar.yahoo.com/", "http://yahoo.com/", "test=foreign; domain=.yahoo.com; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://yahoo.com/", "http://yahoo.com/", getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test handling of IP addresses by the foreign blocking algo
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", "test=foreign; domain=192.168.54.33", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[8] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33./", "http://.192.168.54.33../", getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33/", nsnull, getter_Copies(cookie));
|
||||
rv[10] = CheckResult(cookie.get(), MUST_EQUAL, "test=foreign");
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://148.168.54.33", getter_Copies(cookie));
|
||||
rv[11] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", "test=foreign; domain=192.168.54.33; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[12] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://192.168.54.33/", "http://148.168.54.33/", "test=foreign; domain=192.168.54.33", nsnull);
|
||||
GetACookie(cookieService, "http://192.168.54.33/", "http://192.168.54.33/", getter_Copies(cookie));
|
||||
rv[13] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 14) && allTestsPassed;
|
||||
|
||||
|
||||
// *** parser tests
|
||||
printf("*** Beginning parser tests...\n");
|
||||
|
||||
// test the cookie header parser, under various circumstances.
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=parser; domain=.parser.test; ;; ;=; ,,, ===,abc,=; abracadabra! max-age=20;=;;", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test=parser");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=parser; domain=.parser.test; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=\"fubar! = foo;bar\\\";\" parser; domain=.parser.test; max-age=6\nfive; max-age=2.63,", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_CONTAIN, "test=\"fubar! = foo;bar\\\";\"");
|
||||
rv[3] = CheckResult(cookie.get(), MUST_CONTAIN, "five");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=kill; domain=.parser.test; max-age=0 \n five; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test the handling of VALUE-only cookies (see bug 169091),
|
||||
// i.e. "six" should assume an empty NAME, which allows other VALUE-only
|
||||
// cookies to overwrite it
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "six", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_EQUAL, "six");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "seven", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_EQUAL, "seven");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, " =eight", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[7] = CheckResult(cookie.get(), MUST_EQUAL, "eight");
|
||||
SetACookie(cookieService, "http://parser.test/", nsnull, "test=six", nsnull);
|
||||
GetACookie(cookieService, "http://parser.test/", nsnull, getter_Copies(cookie));
|
||||
rv[9] = CheckResult(cookie.get(), MUST_CONTAIN, "test=six");
|
||||
|
||||
allTestsPassed = PrintResult(rv, 10) && allTestsPassed;
|
||||
|
||||
|
||||
// *** mailnews tests
|
||||
printf("*** Beginning mailnews tests...\n");
|
||||
|
||||
// test some mailnews cookies to ensure blockage.
|
||||
// we use null firstURI's deliberately, since we have hacks to deal with
|
||||
// this situation...
|
||||
SetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=mailnews");
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
// test non-null firstURI's, i) from mailnews ii) not from mailnews
|
||||
SetACookie(cookieService, "mailbox://mail.co.uk/", "http://mail.co.uk/", "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[5] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://mail.co.uk/", "mailbox://mail.co.uk/", "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[6] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 7) && allTestsPassed;
|
||||
|
||||
|
||||
// *** path ordering tests
|
||||
printf("*** Beginning path ordering tests...\n");
|
||||
|
||||
// test that cookies are returned in path order - longest to shortest.
|
||||
// if the header doesn't specify a path, it's taken from the host URI.
|
||||
SetACookie(cookieService, "http://multi.path.tests/", nsnull, "test1=path; path=/one/two/three", nsnull);
|
||||
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);
|
||||
SetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/", nsnull, "test6=path", nsnull);
|
||||
SetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/six/", nsnull, "test7=path; path=", nsnull);
|
||||
SetACookie(cookieService, "http://multi.path.tests/", nsnull, "test8=path; path=/", nsnull);
|
||||
GetACookie(cookieService, "http://multi.path.tests/one/two/three/four/five/six/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_EQUAL, "test7=path; test6=path; test3=path; test1=path; test5=path; test4=path; test2=path; test8=path");
|
||||
|
||||
allTestsPassed = PrintResult(rv, 1) && allTestsPassed;
|
||||
|
||||
// XXX the following are placeholders: add these tests please!
|
||||
// *** "noncompliant cookie" tests
|
||||
// *** IP address tests
|
||||
// *** speed tests
|
||||
|
||||
|
||||
printf("\n*** Result: %s!\n\n", allTestsPassed ? "all tests passed" : "TEST(S) FAILED");
|
||||
|
||||
NS_ShutdownXPCOM(nsnull);
|
||||
|
||||
return allTestsPassed ? 0 : 1;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче