Skip to content

Commit

Permalink
[FedCM] Add WPTs for loginHint
Browse files Browse the repository at this point in the history
The base::Feature needs to be enabled in order to allow the WPTs to be
run correctly. Note that the feature is still gated on the Blink
RuntimeEnabledFeature.

Bug: 1440192
Change-Id: I67a05889234451c126190c91030201dbfe5dbd60
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4595640
Reviewed-by: Christian Biesinger <[email protected]>
Reviewed-by: Rakina Zata Amni <[email protected]>
Commit-Queue: Nicolás Peña <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1154713}
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed Jun 8, 2023
1 parent 68792ad commit 8969965
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
33 changes: 33 additions & 0 deletions credential-management/fedcm-loginhint.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<title>Federated Credential Management API login hint tests.</title>
<link rel="help" href="https://fedidcg.github.io/FedCM">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
<body>

<script type="module">
import {fedcm_test,
request_options_with_login_hint,
select_manifest} from './support/fedcm-helper.sub.js';

fedcm_test(async t => {
let options = request_options_with_login_hint('manifest.py', 'nomatch');
const cred = navigator.credentials.get(options);
return promise_rejects_dom(t, "NetworkError", cred);
}, "No login hint matches an account.");

fedcm_test(async t => {
let options = request_options_with_login_hint('manifest.py', 'john_doe');
const cred = await navigator.credentials.get(options);
assert_equals(cred.token, 'token');
}, "Login hint matches an account.");

fedcm_test(async t => {
let options = request_options_with_login_hint('manifest_with_two_accounts.json', 'john_doe');
await select_manifest(t, options);

const cred = await navigator.credentials.get(options);
assert_equals(cred.token, 'account_id=john_doe');
}, "Login hint matches an account from two accounts.");
</script>
7 changes: 7 additions & 0 deletions credential-management/support/fedcm-helper.sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,10 @@ export function select_manifest(test, test_options) {
const manifest_url = test_options.identity.providers[0].configURL;
return select_manifest_impl(manifest_url);
}

export function request_options_with_login_hint(manifest_filename, login_hint) {
let options = request_options_with_mediation_required(manifest_filename);
options.identity.providers[0].loginHint = login_hint;

return options;
}
3 changes: 2 additions & 1 deletion credential-management/support/fedcm/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def main(request, response):
"name": "John Doe",
"email": "[email protected]",
"picture": "https://idp.example/profile/123",
"approved_clients": ["123", "456", "789"]
"approved_clients": ["123", "456", "789"],
"login_hints": ["john_doe"]
}]
}
"""
3 changes: 2 additions & 1 deletion credential-management/support/fedcm/two_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def main(request, response):
"name": "John Doe",
"email": "[email protected]",
"picture": "https://idp.example/profile/123",
"approved_clients": ["123", "456", "789"]
"approved_clients": ["123", "456", "789"],
"login_hints": ["john_doe"]
}
]
}
Expand Down

0 comments on commit 8969965

Please sign in to comment.