зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1581278 part 3. Stop incorrectly rejecting promises in storage manager. r=janv
Differential Revision: https://phabricator.services.mozilla.com/D46384 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e44e36a681
Коммит
2e33a36d6f
|
@ -250,7 +250,21 @@ already_AddRefed<Promise> ExecuteOpOnMainOrWorkerThread(
|
|||
// Storage Standard 7. API
|
||||
// If origin is an opaque origin, then reject promise with a TypeError.
|
||||
if (principal->GetIsNullPrincipal()) {
|
||||
promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR);
|
||||
switch (aType) {
|
||||
case RequestResolver::Type::Persisted:
|
||||
promise->MaybeRejectWithTypeError(
|
||||
u"persisted() called for opaque origin");
|
||||
break;
|
||||
case RequestResolver::Type::Persist:
|
||||
promise->MaybeRejectWithTypeError(
|
||||
u"persist() called for opaque origin");
|
||||
break;
|
||||
case RequestResolver::Type::Estimate:
|
||||
promise->MaybeRejectWithTypeError(
|
||||
u"estimate() called for opaque origin");
|
||||
break;
|
||||
}
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
|
@ -381,7 +395,8 @@ void RequestResolver::ResolveOrReject() {
|
|||
if (NS_SUCCEEDED(mResultCode)) {
|
||||
promise->MaybeResolve(mStorageEstimate);
|
||||
} else {
|
||||
promise->MaybeReject(NS_ERROR_DOM_TYPE_ERR);
|
||||
promise->MaybeRejectWithTypeError(
|
||||
u"Internal error while estimating storage usage");
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
|
@ -2,31 +2,11 @@
|
|||
expected:
|
||||
if os == "android": OK
|
||||
TIMEOUT
|
||||
[navigator.storage.estimate() in non-sandboxed iframe should not reject]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
NOTRUN
|
||||
|
||||
[navigator.storage.estimate() in sandboxed iframe should reject with TypeError]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
NOTRUN
|
||||
|
||||
[navigator.storage.persist() in non-sandboxed iframe should not reject]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
TIMEOUT
|
||||
|
||||
[navigator.storage.persisted() in sandboxed iframe should reject with TypeError]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
NOTRUN
|
||||
|
||||
[navigator.storage.persisted() in non-sandboxed iframe should not reject]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
NOTRUN
|
||||
|
||||
[navigator.storage.persist() in sandboxed iframe should reject with TypeError]
|
||||
expected:
|
||||
if os == "android": PASS
|
||||
|
|
|
@ -15,7 +15,7 @@ function load_iframe(src, sandbox) {
|
|||
function wait_for_message(iframe) {
|
||||
return new Promise(resolve => {
|
||||
self.addEventListener('message', function listener(e) {
|
||||
if (e.source === iframe.contentWindow) {
|
||||
if (e.source === iframe.contentWindow && "result" in e.data) {
|
||||
resolve(e.data);
|
||||
self.removeEventListener('message', listener);
|
||||
}
|
||||
|
@ -24,7 +24,8 @@ function wait_for_message(iframe) {
|
|||
}
|
||||
|
||||
function make_script(snippet) {
|
||||
return '<script>' +
|
||||
return '<script src="/resources/testharness.js"></script>' +
|
||||
'<script>' +
|
||||
' window.onmessage = () => {' +
|
||||
' try {' +
|
||||
' (' + snippet + ')' +
|
||||
|
@ -33,19 +34,25 @@ function make_script(snippet) {
|
|||
' window.parent.postMessage({result: "no rejection"}, "*");' +
|
||||
' }, ' +
|
||||
' error => {' +
|
||||
' window.parent.postMessage({result: error.name}, "*");' +
|
||||
' try {' +
|
||||
' assert_throws_js(TypeError, () => { throw error; });' +
|
||||
' window.parent.postMessage({result: "correct rejection"}, "*");' +
|
||||
' } catch (e) {' +
|
||||
' window.parent.postMessage({result: "incorrect rejection"}, "*");' +
|
||||
' }' +
|
||||
' });' +
|
||||
' } catch (ex) {' +
|
||||
// Report if not implemented/exposed, rather than time out.
|
||||
' window.parent.postMessage({result: ex.message}, "*");' +
|
||||
' window.parent.postMessage({result: "API access threw"}, "*");' +
|
||||
' }' +
|
||||
' };' +
|
||||
'<\/script>';
|
||||
}
|
||||
|
||||
['navigator.storage.persist()',
|
||||
'navigator.storage.persisted()',
|
||||
'navigator.storage.estimate()'
|
||||
['navigator.storage.persisted()',
|
||||
'navigator.storage.estimate()',
|
||||
// persist() can prompt, so make sure we test that last
|
||||
'navigator.storage.persist()',
|
||||
].forEach(snippet => {
|
||||
promise_test(t => {
|
||||
return load_iframe(make_script(snippet))
|
||||
|
@ -66,7 +73,7 @@ function make_script(snippet) {
|
|||
return wait_for_message(iframe);
|
||||
})
|
||||
.then(message => {
|
||||
assert_equals(message.result, 'TypeError',
|
||||
assert_equals(message.result, 'correct rejection',
|
||||
`${snippet} should reject with TypeError`);
|
||||
});
|
||||
}, `${snippet} in sandboxed iframe should reject with TypeError`);
|
||||
|
|
Загрузка…
Ссылка в новой задаче