summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/credential-management/credentialscontainer-create-basics.https.html
blob: ea2326c4ae48d987f233f057a42fcf08eec6dd01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<title>Credential Management API: create() basics.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(function(t) {
    return promise_rejects_dom(t, "NotSupportedError",
            navigator.credentials.create());
}, "navigator.credentials.create() with no argument.");

promise_test(function(t) {
    return promise_rejects_dom(t, "NotSupportedError",
            navigator.credentials.create({}));
}, "navigator.credentials.create() with empty argument.");

promise_test(function(t) {
    var credential_data = {
        id: 'id',
        password: 'pencil',
    };

    return navigator.credentials.create({password: credential_data})
        .then(function(credential) {
            assert_equals(credential.id, 'id');
            assert_equals(credential.name, '');
            assert_equals(credential.iconURL, '');
            assert_equals(credential.type, 'password');
            assert_equals(credential.password, 'pencil');
        });
}, "navigator.credentials.create() with valid PasswordCredentialData");

promise_test(function(t) {
    var f = document.createElement('form');
    f.innerHTML = "<input type='text' name='theId' value='musterman' autocomplete='username'>"
        + "<input type='text' name='thePassword' value='sekrit' autocomplete='current-password'>"
        + "<input type='text' name='theIcon' value='https://example.com/photo' autocomplete='photo'>"
        + "<input type='text' name='theExtraField' value='extra'>"
        + "<input type='text' name='theName' value='friendly name' autocomplete='name'>";

    return navigator.credentials.create({password: f})
        .then(function(credential) {
            assert_equals(credential.id, 'musterman');
            assert_equals(credential.name, 'friendly name');
            assert_equals(credential.iconURL, 'https://example.com/photo');
            assert_equals(credential.type, 'password');
            assert_equals(credential.password, 'sekrit');
        });
}, "navigator.credentials.create() with valid HTMLFormElement");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({password: "bogus password data"}));
}, "navigator.credentials.create() with bogus password data");

promise_test(function(t) {
    var federated_data = {
        id: 'id',
        provider: 'https://example.com/',
    };

    return navigator.credentials.create({federated: federated_data})
        .then(function(credential) {
            assert_equals(credential.id, 'id');
            assert_equals(credential.name, '');
            assert_equals(credential.iconURL, '');
            assert_equals(credential.type, 'federated');
        });
}, "navigator.credentials.create() with valid FederatedCredentialData");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({federated: "bogus federated data"}));
}, "navigator.credentials.create() with bogus federated data");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({publicKey: "bogus publicKey data"}));
}, "navigator.credentials.create() with bogus publicKey data");

promise_test(function(t) {
    var credential_data = {
        id: 'id',
        password: 'pencil',
    };

    var federated_data = {
        id: 'id',
        provider: 'https://example.com/',
    };

    return promise_rejects_dom(t, "NotSupportedError",
            navigator.credentials.create({
                password: credential_data,
                federated: federated_data,
            }));
}, "navigator.credentials.create() with both PasswordCredentialData and FederatedCredentialData");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({
                password: "bogus password data",
                federated: "bogus federated data",
            }));
}, "navigator.credentials.create() with bogus password and federated data");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({
                federated: "bogus federated data",
                publicKey: "bogus publicKey data",
            }));
}, "navigator.credentials.create() with bogus federated and publicKey data");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({
                password: "bogus password data",
                publicKey: "bogus publicKey data",
            }));
}, "navigator.credentials.create() with bogus password and publicKey data");

promise_test(function(t) {
    return promise_rejects_js(t, TypeError,
            navigator.credentials.create({
                password: "bogus password data",
                federated: "bogus federated data",
                publicKey: "bogus publicKey data",
            }));
}, "navigator.credentials.create() with bogus password, federated, and publicKey data");

promise_test(function(t) {
    return promise_rejects_dom(t, "NotSupportedError",
            navigator.credentials.create({bogus_key: "bogus data"}));
}, "navigator.credentials.create() with bogus data");
</script>