Bug 1482194. Throw the right exception when localStorage/sessionStorage quota is reached. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D3034

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Boris Zbarsky 2018-08-27 11:12:59 +00:00
parent 85db10cfb9
commit 951bba6efd
8 changed files with 10 additions and 21 deletions

View File

@ -98,7 +98,6 @@ DOM_MSG_DEF(NS_ERROR_DOM_PROP_ACCESS_DENIED, "Access to property denied")
DOM_MSG_DEF(NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED, "Access to XPConnect service denied") DOM_MSG_DEF(NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED, "Access to XPConnect service denied")
DOM_MSG_DEF(NS_ERROR_DOM_BAD_URI, "Access to restricted URI denied") DOM_MSG_DEF(NS_ERROR_DOM_BAD_URI, "Access to restricted URI denied")
DOM_MSG_DEF(NS_ERROR_DOM_RETVAL_UNDEFINED, "Return value is undefined") DOM_MSG_DEF(NS_ERROR_DOM_RETVAL_UNDEFINED, "Return value is undefined")
DOM_MSG_DEF(NS_ERROR_DOM_QUOTA_REACHED, "Persistent storage maximum size reached")
DOM4_MSG_DEF(NotFoundError, "File was not found", NS_ERROR_DOM_FILE_NOT_FOUND_ERR) DOM4_MSG_DEF(NotFoundError, "File was not found", NS_ERROR_DOM_FILE_NOT_FOUND_ERR)
DOM4_MSG_DEF(NotReadableError, "File could not be read", NS_ERROR_DOM_FILE_NOT_READABLE_ERR) DOM4_MSG_DEF(NotReadableError, "File could not be read", NS_ERROR_DOM_FILE_NOT_READABLE_ERR)

View File

@ -424,7 +424,7 @@ LocalStorageCache::SetItem(const LocalStorage* aStorage, const nsAString& aKey,
static_cast<int64_t>(aOld.Length()); static_cast<int64_t>(aOld.Length());
if (!ProcessUsageDelta(aStorage, delta, aSource)) { if (!ProcessUsageDelta(aStorage, delta, aSource)) {
return NS_ERROR_DOM_QUOTA_REACHED; return NS_ERROR_DOM_QUOTA_EXCEEDED_ERR;
} }
if (aValue == aOld && DOMStringIsNull(aValue) == DOMStringIsNull(aOld)) { if (aValue == aOld && DOMStringIsNull(aValue) == DOMStringIsNull(aOld)) {

View File

@ -104,7 +104,7 @@ SessionStorageCache::SetItem(DataSetType aDataSetType, const nsAString& aKey,
} }
if (!dataSet->ProcessUsageDelta(delta)) { if (!dataSet->ProcessUsageDelta(delta)) {
return NS_ERROR_DOM_QUOTA_REACHED; return NS_ERROR_DOM_QUOTA_EXCEEDED_ERR;
} }
dataSet->mKeys.Put(aKey, nsString(aValue)); dataSet->mKeys.Put(aKey, nsString(aValue));

View File

@ -5,7 +5,7 @@
<script type="text/javascript" src="interOriginFrame.js"></script> <script type="text/javascript" src="interOriginFrame.js"></script>
<script type="text/javascript"> <script type="text/javascript">
const DOM_QUOTA_REACHED = 2152924150; const DOM_QUOTA_EXCEEDED_ERR = 0x80530016;
function checkException(func, exc) function checkException(func, exc)
{ {
@ -61,10 +61,10 @@ function doStep()
{ {
case "add": case "add":
// Attempt to store 500 bytes long string that doens't // Attempt to store 500 bytes long string that doens't
// fit the quota, have to throw DOM_QUOTA_REACHED exception // fit the quota, have to throw DOM_QUOTA_EXCEEDED_ERR exception
checkException(function() { checkException(function() {
localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
}, DOM_QUOTA_REACHED); }, DOM_QUOTA_EXCEEDED_ERR);
is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored");
break; break;
@ -73,7 +73,7 @@ function doStep()
// check it fails and the old key value is still present. // check it fails and the old key value is still present.
checkException(function() { checkException(function() {
localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
}, DOM_QUOTA_REACHED); }, DOM_QUOTA_EXCEEDED_ERR);
is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged");
break; break;
} }

View File

@ -5,7 +5,7 @@
<script type="text/javascript" src="interOriginFrame.js"></script> <script type="text/javascript" src="interOriginFrame.js"></script>
<script type="text/javascript"> <script type="text/javascript">
const DOM_QUOTA_REACHED = 2152924150; const DOM_QUOTA_EXCEEDED_ERR = 0x80530016;
function checkException(func, exc) function checkException(func, exc)
{ {
@ -61,10 +61,10 @@ function doStep()
{ {
case "add": case "add":
// Attempt to store 500 bytes long string that doens't // Attempt to store 500 bytes long string that doens't
// fit the quota, have to throw DOM_QUOTA_REACHED exception // fit the quota, have to throw DOM_QUOTA_EXCEEDED_ERR exception
checkException(function() { checkException(function() {
localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); localStorage.setItem(keyName, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
}, DOM_QUOTA_REACHED); }, DOM_QUOTA_EXCEEDED_ERR);
is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored"); is(localStorage.getItem(keyName), null, "500 bytes key "+keyName+" is NOT stored");
break; break;
@ -73,7 +73,7 @@ function doStep()
// check it fails and the old key value is still present. // check it fails and the old key value is still present.
checkException(function() { checkException(function() {
localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); localStorage.setItem(keyName, "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
}, DOM_QUOTA_REACHED); }, DOM_QUOTA_EXCEEDED_ERR);
is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged"); is(localStorage.getItem(keyName), "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", "Key "+keyName+" left unchanged");
break; break;
} }

View File

@ -1,6 +0,0 @@
[storage_local_setitem_quotaexceedederr.html]
expected: TIMEOUT
disabled: true
[Web Storage]
expected: FAIL

View File

@ -1,3 +0,0 @@
[storage_session_setitem_quotaexceedederr.html]
expected: TIMEOUT
disabled: true

View File

@ -639,7 +639,6 @@ with modules["DOM"]:
errors["NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED"] = FAILURE(1011) errors["NS_ERROR_DOM_XPCONNECT_ACCESS_DENIED"] = FAILURE(1011)
errors["NS_ERROR_DOM_BAD_URI"] = FAILURE(1012) errors["NS_ERROR_DOM_BAD_URI"] = FAILURE(1012)
errors["NS_ERROR_DOM_RETVAL_UNDEFINED"] = FAILURE(1013) errors["NS_ERROR_DOM_RETVAL_UNDEFINED"] = FAILURE(1013)
errors["NS_ERROR_DOM_QUOTA_REACHED"] = FAILURE(1014)
# A way to represent uncatchable exceptions # A way to represent uncatchable exceptions
errors["NS_ERROR_UNCATCHABLE_EXCEPTION"] = FAILURE(1015) errors["NS_ERROR_UNCATCHABLE_EXCEPTION"] = FAILURE(1015)