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 promise_test(function() { | 7 promise_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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 var fd = new FormData(); | 77 var fd = new FormData(); |
78 fd.append("excitingData", "exciting value"); | 78 fd.append("excitingData", "exciting value"); |
79 fd.append("csrf", "[randomness]"); | 79 fd.append("csrf", "[randomness]"); |
80 credential.additionalData = fd; | 80 credential.additionalData = fd; |
81 | 81 |
82 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) | 82 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
83 .then(function (r) { | 83 .then(function (r) { |
84 return r.json(); | 84 return r.json(); |
85 }) | 85 }) |
86 then(function (j) { | 86 .then(function (j) { |
87 assert_equals(j.username, 'id'); | 87 assert_equals(j.username, 'id'); |
88 assert_equals(j.password, 'pencil'); | 88 assert_equals(j.password, 'pencil'); |
89 assert_equals(j.excitingData, 'exciting value'); | 89 assert_equals(j.excitingData, 'exciting value'); |
90 assert_equals(j.csrf, '[randomness]'); | 90 assert_equals(j.csrf, '[randomness]'); |
91 }); | 91 }); |
92 }, "'additionalData': FormData properties are properly injected."); | 92 }, "'additionalData': FormData properties are properly injected."); |
93 | 93 |
94 promise_test(function() { | 94 promise_test(function() { |
95 var credential = new PasswordCredential({ | 95 var credential = new PasswordCredential({ |
96 id: 'id', | 96 id: 'id', |
97 password: 'pencil', | 97 password: 'pencil', |
98 name: 'name', | 98 name: 'name', |
99 iconURL: 'https://example.com/icon.png' | 99 iconURL: 'https://example.com/icon.png' |
100 }); | 100 }); |
101 | 101 |
| 102 var fd = new FormData(); |
| 103 fd.append("username", "foo"); |
| 104 fd.append("password", "bar"); |
| 105 credential.additionalData = fd; |
| 106 |
| 107 // Use post-echo.cgi since PHP doesn't give us the raw data of a POST's |
| 108 // body if it's multipart/form-data. |
| 109 return fetch("/xmlhttprequest/resources/post-echo.cgi", { body: credential,
method: "POST" }) |
| 110 .then(function (r) { |
| 111 return r.text(); |
| 112 }) |
| 113 .then(function (t) { |
| 114 // Match "CRLF *OCTET CRLF". See RFC 2046 for the multipart |
| 115 // grammar. |
| 116 assert_false( |
| 117 /\r\nfoo\r\n/.test(t), |
| 118 "POST data should not contain the overridden value foo."); |
| 119 assert_false( |
| 120 /\r\nbar\r\n/.test(t), |
| 121 "POST data should not contain the overridden value bar."); |
| 122 }); |
| 123 }, "'additionalData': FormData properties are properly overridden."); |
| 124 |
| 125 promise_test(function() { |
| 126 var credential = new PasswordCredential({ |
| 127 id: 'id', |
| 128 password: 'pencil', |
| 129 name: 'name', |
| 130 iconURL: 'https://example.com/icon.png' |
| 131 }); |
| 132 |
102 var params = new URLSearchParams(); | 133 var params = new URLSearchParams(); |
103 credential.additionalData = params; | 134 credential.additionalData = params; |
104 | 135 |
105 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) | 136 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
106 .then(function (r) { | 137 .then(function (r) { |
107 return r.json(); | 138 return r.json(); |
108 }) | 139 }) |
109 .then(function (j) { | 140 .then(function (j) { |
110 assert_equals(j.username, 'id'); | 141 assert_equals(j.username, 'id'); |
111 assert_equals(j.password, 'pencil'); | 142 assert_equals(j.password, 'pencil'); |
(...skipping 27 matching lines...) Expand all Loading... |
139 | 170 |
140 promise_test(function() { | 171 promise_test(function() { |
141 var credential = new PasswordCredential({ | 172 var credential = new PasswordCredential({ |
142 id: 'id', | 173 id: 'id', |
143 password: 'pencil', | 174 password: 'pencil', |
144 name: 'name', | 175 name: 'name', |
145 iconURL: 'https://example.com/icon.png' | 176 iconURL: 'https://example.com/icon.png' |
146 }); | 177 }); |
147 | 178 |
148 var params = new URLSearchParams(); | 179 var params = new URLSearchParams(); |
| 180 params.append("username", "foo"); |
| 181 params.append("password", "bar"); |
| 182 credential.additionalData = params; |
| 183 |
| 184 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P
OST" }) |
| 185 .then(function (r) { |
| 186 return r.text(); |
| 187 }) |
| 188 .then(function (t) { |
| 189 assert_equals(t, 'username=id&password=pencil'); |
| 190 }); |
| 191 }, "'additionalData': URLSearchParams properties are properly overridden."); |
| 192 |
| 193 promise_test(function() { |
| 194 var credential = new PasswordCredential({ |
| 195 id: 'id', |
| 196 password: 'pencil', |
| 197 name: 'name', |
| 198 iconURL: 'https://example.com/icon.png' |
| 199 }); |
| 200 |
| 201 var params = new URLSearchParams(); |
149 params.append("a", "1"); | 202 params.append("a", "1"); |
150 params.append("a", "2"); | 203 params.append("a", "2"); |
151 params.append("a", "3"); | 204 params.append("a", "3"); |
152 credential.additionalData = params; | 205 credential.additionalData = params; |
153 | 206 |
154 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P
OST" }) | 207 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P
OST" }) |
155 .then(function (r) { | 208 .then(function (r) { |
156 return r.text(); | 209 return r.text(); |
157 }) | 210 }) |
158 .then(function (t) { | 211 .then(function (t) { |
159 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); | 212 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); |
160 }); | 213 }); |
161 }, "'additionalData': URLSearchParams properties are properly injected (ordering
matters)."); | 214 }, "'additionalData': URLSearchParams properties are properly injected (ordering
matters)."); |
162 </script> | 215 </script> |
OLD | NEW |