gecko/dom/tests/mochitest/localstorage/test_localStorageQuotaSessionOnly.html
Honza Bambas 1027f32e5c Bug 487695 - Decide on localStorage behavior in session-only cookies or private-browsing mode, r+sr=jst
--HG--
rename : dom/src/storage/nsDOMStorageDB.cpp => dom/src/storage/nsDOMStoragePersistentDB.cpp
rename : dom/src/storage/nsDOMStorageDB.h => dom/src/storage/nsDOMStoragePersistentDB.h
2009-05-18 10:12:14 +02:00

137 lines
4.5 KiB
HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>localStorage and DOM quota test</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="interOriginTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var currentTest = 1;
var prefs = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
var io = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var uri = io.newURI(window.location, "", null);
var cp = Components.classes["@mozilla.org/cookie/permission;1"]
.getService(Components.interfaces.nsICookiePermission);
cp.setAccess(uri, Components.interfaces.nsICookiePermission.ACCESS_SESSION);
var quota;
function doNextTest()
{
slave = frame;
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
switch (currentTest)
{
// Initialy setup the quota to testing value of 1024B and
// set a 500 bytes key with name length 1 (allocate 501 bytes)
case 1:
try {
quota = prefs.getIntPref("dom.storage.default_quota");
} catch (ex) {
quota = 5*1024;
}
prefs.setIntPref("dom.storage.default_quota", 1);
slaveOrigin = "http://example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&A&success";
break;
// In subdomain now set another key with length 500 bytes, i.e.
// allocate 501 bytes
case 2:
slaveOrigin = "http://test1.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success";
break;
// Try to set the same key value again to check we don't fail
// even 1002 bytes has already been exhausted from the quota
// We just change the value of an existing key.
case 3:
slaveOrigin = "http://test1.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&B&success";
break;
// Try to set the same key to a larger value that would lead to
// quota reach and check that the value is still the old one
case 4:
slaveOrigin = "http://test1.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add2&B&failure";
break;
// In a different subdomain try to set a new 500 bytes key
// and check we fail because we are over the quota
case 5:
slaveOrigin = "https://test2.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&failure";
break;
// Remove from the second subdomain the second key, it must not fail
// This should release the allocated space of the quota assigned to
// example.com.
case 6:
slaveOrigin = "http://test1.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?remove&B&success";
break;
// Now try again to set 500 bytes key, it must succeed.
case 7:
slaveOrigin = "https://test2.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?add&C&success";
break;
case 8:
// Do a clean up...
// TODO Bug 455070, use just ?clear what invokes call
// of clear() in the target frame. W/o clear method we must
// call clear implemented as removeItem for each item in
// the localStorage.
slaveOrigin = "http://example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear&A&";
break;
case 9:
// Do a clean up...
slaveOrigin = "http://test1.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear&B&";
break;
case 10:
// Do a clean up...
slaveOrigin = "https://test2.example.com";
slave.location = slaveOrigin + slavePath + "frameQuotaSessionOnly.html?clear&C&";
break;
case 11:
prefs.setIntPref("dom.storage.default_quota", quota);
cp.setAccess(uri, Components.interfaces.nsICookiePermission.ACCESS_DEFAULT);
SimpleTest.finish();
}
++currentTest;
}
function doStep()
{
}
SimpleTest.waitForExplicitFinish();
</script>
</head>
<body onload="doNextTest();">
<iframe src="" name="frame"></iframe>
</body>
</html>