Bug 1439805 - Implement CredentialsContainer.preventSilentAccess() r=jcj,smaug

Reviewers: jcj, smaug

Reviewed By: jcj, smaug

Bug #: 1439805

Differential Revision: https://phabricator.services.mozilla.com/D629
This commit is contained in:
Tim Taubert 2018-02-22 14:36:08 +01:00
parent 14fc881f71
commit e7bbf534a6
5 changed files with 41 additions and 9 deletions

View File

@ -143,5 +143,23 @@ CredentialsContainer::Store(const Credential& aCredential, ErrorResult& aRv)
return mManager->Store(aCredential);
}
already_AddRefed<Promise>
CredentialsContainer::PreventSilentAccess(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mParent);
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
promise->MaybeResolveWithUndefined();
return promise.forget();
}
} // namespace dom
} // namespace mozilla

View File

@ -41,6 +41,9 @@ public:
already_AddRefed<Promise>
Store(const Credential& aCredential, ErrorResult& aRv);
already_AddRefed<Promise>
PreventSilentAccess(ErrorResult& aRv);
private:
~CredentialsContainer();

View File

@ -42,6 +42,15 @@ function testSameOrigin() {
.catch(function sameOriginCatch(aResult) {
local_ok(false, "Should not have failed " + aResult);
})
.then(function sameOriginPreventSilentAccess() {
return navigator.credentials.preventSilentAccess();
})
.then(function sameOriginPreventSilentAccessThen(aResult) {
local_ok(aResult == undefined, "PreventSilentAccess worked " + aResult);
})
.catch(function sameOriginPreventSilentAccessCatch(aResult) {
local_ok(false, "Should not have failed " + aResult);
})
.then(function() {
local_finished();
});
@ -58,6 +67,15 @@ function testCrossOrigin() {
local_ok(aResult.toString().startsWith("NotAllowedError"),
"Expecting a NotAllowedError, received " + aResult);
})
.then(function crossOriginPreventSilentAccess() {
return navigator.credentials.preventSilentAccess();
})
.then(function crossOriginPreventSilentAccessThen(aResult) {
local_ok(aResult == undefined, "PreventSilentAccess worked " + aResult);
})
.catch(function crossOriginPreventSilentAccessCatch(aResult) {
local_ok(false, "Should not have failed " + aResult);
})
.then(function() {
local_finished();
});

View File

@ -21,6 +21,8 @@ interface CredentialsContainer {
Promise<Credential?> create(optional CredentialCreationOptions options);
[Throws]
Promise<Credential> store(Credential credential);
[Throws]
Promise<void> preventSilentAccess();
};
dictionary CredentialRequestOptions {

View File

@ -108,21 +108,12 @@
[Credential interface: new FederatedCredential({ id: "id", provider: "https://example.com", iconURL: "https://example.com/", name: "name" }) must inherit property "type" with the proper type (1)]
expected: FAIL
[CredentialsContainer interface: operation preventSilentAccess()]
expected: FAIL
[CredentialsContainer interface: navigator.credentials must inherit property "preventSilentAccess" with the proper type (3)]
expected: FAIL
[PasswordCredential interface: attribute password]
expected: FAIL
[PasswordCredential interface: new PasswordCredential({ id: "id", password: "pencil", iconURL: "https://example.com/", name: "name" }) must inherit property "password" with the proper type (0)]
expected: FAIL
[CredentialsContainer interface: navigator.credentials must inherit property "preventSilentAccess()" with the proper type]
expected: FAIL
[PasswordCredential interface: new PasswordCredential({ id: "id", password: "pencil", iconURL: "https://example.com/", name: "name" }) must inherit property "password" with the proper type]
expected: FAIL