| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Credential Manager: PasswordCredential basics.</title> | 2 <title>Credential Manager: PasswordCredential basics.</title> |
| 3 <script src="../resources/testharness.js"></script> | 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> | 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="/serviceworker/resources/interfaces.js"></script> | 5 <script src="/serviceworker/resources/interfaces.js"></script> |
| 6 <script> | 6 <script> |
| 7 test(function() { | 7 test(function() { |
| 8 var credential = new PasswordCredential({ | 8 var credential = new PasswordCredential({ |
| 9 id: 'id', | 9 id: 'id', |
| 10 password: 'pencil', | 10 password: 'pencil', |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 assert_throws(new TypeError(), | 102 assert_throws(new TypeError(), |
| 103 () => { new PasswordCredential({ 'password': '' }); }); | 103 () => { new PasswordCredential({ 'password': '' }); }); |
| 104 assert_throws(new TypeError(), | 104 assert_throws(new TypeError(), |
| 105 () => { new PasswordCredential({ 'id': undefined, 'password':
undefined }); }); | 105 () => { new PasswordCredential({ 'id': undefined, 'password':
undefined }); }); |
| 106 assert_throws(new TypeError(), | 106 assert_throws(new TypeError(), |
| 107 () => { new PasswordCredential({ 'id': undefined, 'password':
'' }); }); | 107 () => { new PasswordCredential({ 'id': undefined, 'password':
'' }); }); |
| 108 assert_throws(new TypeError(), | 108 assert_throws(new TypeError(), |
| 109 () => { new PasswordCredential({ 'id': undefined, 'password':
undefined }); }); | 109 () => { new PasswordCredential({ 'id': undefined, 'password':
undefined }); }); |
| 110 }, 'PasswordCredential objects require IDs and Passwords'); | 110 }, 'PasswordCredential objects require IDs and Passwords'); |
| 111 | 111 |
| 112 test(function () { | 112 function verify_form_credential(f, credential) { |
| 113 var f = document.createElement('form'); | |
| 114 f.innerHTML = "<input type='text' name='theId' value='musterman' autocomplet
e='username'>" | |
| 115 + "<input type='text' name='thePassword' value='sekrit' autocomplete='cu
rrent-password'>" | |
| 116 + "<input type='text' name='theIcon' value='https://example.com/photo' a
utocomplete='photo'>" | |
| 117 + "<input type='text' name='theExtraField' value='extra'>" | |
| 118 + "<input type='text' name='theName' value='friendly name' autocomplete=
'name'>"; | |
| 119 | |
| 120 var credential = new PasswordCredential(f); | |
| 121 assert_equals(credential.id, 'musterman'); | 113 assert_equals(credential.id, 'musterman'); |
| 122 assert_equals(credential.name, 'friendly name'); | 114 assert_equals(credential.name, 'friendly name'); |
| 123 assert_equals(credential.iconURL, 'https://example.com/photo'); | 115 assert_equals(credential.iconURL, 'https://example.com/photo'); |
| 124 assert_equals(credential.idName, 'theId'); | 116 assert_equals(credential.idName, 'theId'); |
| 125 assert_equals(credential.passwordName, 'thePassword'); | 117 assert_equals(credential.passwordName, 'thePassword'); |
| 126 assert_equals(credential.type, 'password'); | 118 assert_equals(credential.type, 'password'); |
| 127 | 119 |
| 128 assert_equals(credential.additionalData.get('theId'), 'musterman'); | 120 assert_equals(credential.additionalData.get('theId'), 'musterman'); |
| 129 assert_equals(credential.additionalData.get('thePassword'), 'sekrit'); | 121 assert_equals(credential.additionalData.get('thePassword'), 'sekrit'); |
| 130 assert_equals(credential.additionalData.get('theIcon'), 'https://example.com
/photo'); | 122 assert_equals(credential.additionalData.get('theIcon'), 'https://example.com
/photo'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 f.appendChild(password); | 133 f.appendChild(password); |
| 142 password.value = "sekrit"; | 134 password.value = "sekrit"; |
| 143 credential = new PasswordCredential(f); | 135 credential = new PasswordCredential(f); |
| 144 assert_true(credential instanceof PasswordCredential); | 136 assert_true(credential instanceof PasswordCredential); |
| 145 | 137 |
| 146 var id = f.querySelector('[name=theId]'); | 138 var id = f.querySelector('[name=theId]'); |
| 147 id.value = ""; | 139 id.value = ""; |
| 148 assert_throws(new TypeError(), _ => new PasswordCredential(f)); | 140 assert_throws(new TypeError(), _ => new PasswordCredential(f)); |
| 149 f.removeChild(id); | 141 f.removeChild(id); |
| 150 assert_throws(new TypeError(), _ => new PasswordCredential(f)); | 142 assert_throws(new TypeError(), _ => new PasswordCredential(f)); |
| 151 }, 'PasswordCredential creation from `HTMLFormElement`'); | 143 } |
| 144 |
| 145 test(_ => { |
| 146 var f = document.createElement('form'); |
| 147 f.enctype = 'mUlTiPaRt/fOrm-dAtA'; |
| 148 f.innerHTML = "<input type='text' name='theId' value='musterman' autocomplet
e='username'>" |
| 149 + "<input type='text' name='thePassword' value='sekrit' autocomplete='cu
rrent-password'>" |
| 150 + "<input type='text' name='theIcon' value='https://example.com/photo' a
utocomplete='photo'>" |
| 151 + "<input type='text' name='theExtraField' value='extra'>" |
| 152 + "<input type='text' name='theName' value='friendly name' autocomplete=
'name'>"; |
| 153 |
| 154 var credential = new PasswordCredential(f); |
| 155 assert_true(credential.additionalData instanceof FormData); |
| 156 verify_form_credential(f, credential); |
| 157 }, 'PasswordCredential creation from `HTMLFormElement` with a multipart enctype'
); |
| 158 |
| 159 test(_ => { |
| 160 var f = document.createElement('form'); |
| 161 f.enctype = 'aPplIcaTion/X-wWw-form-urLencoded'; |
| 162 f.innerHTML = "<input type='text' name='theId' value='musterman' autocomplet
e='username'>" |
| 163 + "<input type='text' name='thePassword' value='sekrit' autocomplete='cu
rrent-password'>" |
| 164 + "<input type='text' name='theIcon' value='https://example.com/photo' a
utocomplete='photo'>" |
| 165 + "<input type='text' name='theExtraField' value='extra'>" |
| 166 + "<input type='text' name='theName' value='friendly name' autocomplete=
'name'>"; |
| 167 |
| 168 var credential = new PasswordCredential(f); |
| 169 assert_true(credential.additionalData instanceof URLSearchParams); |
| 170 verify_form_credential(f, credential); |
| 171 }, 'PasswordCredential creation from `HTMLFormElement` with a urlencoded enctype
'); |
| 172 |
| 173 test(_ => { |
| 174 var f = document.createElement('form'); |
| 175 f.innerHTML = "<input type='text' name='theId' value='musterman' autocomplet
e='username'>" |
| 176 + "<input type='text' name='thePassword' value='sekrit' autocomplete='cu
rrent-password'>" |
| 177 + "<input type='text' name='theIcon' value='https://example.com/photo' a
utocomplete='photo'>" |
| 178 + "<input type='text' name='theExtraField' value='extra'>" |
| 179 + "<input type='text' name='theName' value='friendly name' autocomplete=
'name'>"; |
| 180 |
| 181 var credential = new PasswordCredential(f); |
| 182 assert_true(credential.additionalData instanceof URLSearchParams); |
| 183 verify_form_credential(f, credential); |
| 184 }, 'PasswordCredential creation from `HTMLFormElement` with no enctype'); |
| 152 </script> | 185 </script> |
| OLD | NEW |