2009-08-06 16:43:53 -07:00
|
|
|
var gExpectedCookies;
|
|
|
|
var gExpectedLoads;
|
2008-03-12 00:53:50 -07:00
|
|
|
|
2009-08-06 16:43:53 -07:00
|
|
|
var gPopup;
|
2008-03-12 00:53:50 -07:00
|
|
|
|
|
|
|
var gLoads = 0;
|
|
|
|
|
|
|
|
function setupTest(uri, cookies, loads) {
|
2009-08-06 16:43:53 -07:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2008-03-12 00:53:50 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
|
2009-07-24 18:16:33 -07:00
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch)
|
|
|
|
.setIntPref("network.cookie.cookieBehavior", 1);
|
2008-03-12 00:53:50 -07:00
|
|
|
|
|
|
|
var cs = Components.classes["@mozilla.org/cookiemanager;1"]
|
2009-07-24 18:16:33 -07:00
|
|
|
.getService(Components.interfaces.nsICookieManager2);
|
2008-03-12 00:53:50 -07:00
|
|
|
cs.removeAll();
|
|
|
|
|
|
|
|
gExpectedCookies = cookies;
|
|
|
|
gExpectedLoads = loads;
|
|
|
|
|
2009-08-06 16:43:53 -07:00
|
|
|
// Listen for MessageEvents.
|
|
|
|
window.addEventListener("message", messageReceiver, false);
|
|
|
|
|
2008-03-12 00:53:50 -07:00
|
|
|
// load a window which contains an iframe; each will attempt to set
|
|
|
|
// cookies from their respective domains.
|
|
|
|
gPopup = window.open(uri, 'hai', 'width=100,height=100');
|
|
|
|
}
|
|
|
|
|
2010-01-21 11:11:49 -08:00
|
|
|
function finishTest()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch)
|
|
|
|
.clearUserPref("network.cookie.cookieBehavior");
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
2009-07-24 18:16:33 -07:00
|
|
|
|
2008-03-12 00:53:50 -07:00
|
|
|
/** Receives MessageEvents to this window. */
|
2009-08-06 16:43:53 -07:00
|
|
|
// Count and check loads.
|
2008-03-12 00:53:50 -07:00
|
|
|
function messageReceiver(evt)
|
|
|
|
{
|
2009-08-06 16:43:53 -07:00
|
|
|
is(evt.data, "message", "message data received from popup");
|
2009-07-24 18:16:33 -07:00
|
|
|
if (evt.data != "message") {
|
2009-08-06 16:43:53 -07:00
|
|
|
gPopup.close();
|
2009-07-24 18:16:33 -07:00
|
|
|
window.removeEventListener("message", messageReceiver, false);
|
|
|
|
|
2010-01-21 11:11:49 -08:00
|
|
|
finishTest();
|
2009-07-24 18:16:33 -07:00
|
|
|
return;
|
2008-03-12 00:53:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// only run the test when all our children are done loading & setting cookies
|
2009-07-24 18:16:33 -07:00
|
|
|
if (++gLoads == gExpectedLoads) {
|
2009-08-06 16:43:53 -07:00
|
|
|
gPopup.close();
|
2009-07-24 18:16:33 -07:00
|
|
|
window.removeEventListener("message", messageReceiver, false);
|
|
|
|
|
2008-03-12 00:53:50 -07:00
|
|
|
runTest();
|
2009-07-24 18:16:33 -07:00
|
|
|
}
|
2008-03-12 00:53:50 -07:00
|
|
|
}
|
|
|
|
|
2009-08-06 16:43:53 -07:00
|
|
|
// runTest() is run by messageReceiver().
|
|
|
|
// Count and check cookies.
|
2008-03-12 00:53:50 -07:00
|
|
|
function runTest() {
|
|
|
|
// set a cookie from a domain of "localhost"
|
|
|
|
document.cookie = "oh=hai";
|
|
|
|
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
2009-07-24 18:16:33 -07:00
|
|
|
|
2008-03-12 00:53:50 -07:00
|
|
|
var cs = Components.classes["@mozilla.org/cookiemanager;1"]
|
|
|
|
.getService(Components.interfaces.nsICookieManager);
|
|
|
|
var count = 0;
|
2009-08-06 16:43:53 -07:00
|
|
|
for(var list = cs.enumerator; list.hasMoreElements(); list.getNext())
|
|
|
|
++count;
|
|
|
|
is(count, gExpectedCookies, "total number of cookies");
|
2009-07-24 18:16:33 -07:00
|
|
|
cs.removeAll();
|
2008-03-12 00:53:50 -07:00
|
|
|
|
2010-01-21 11:11:49 -08:00
|
|
|
finishTest();
|
2008-03-12 00:53:50 -07:00
|
|
|
}
|