OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Credential Manager: PasswordCredential basics.</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharnessreport.js"></script> |
| 5 <script src="/serviceworker/resources/interfaces.js"></script> |
| 6 <script> |
| 7 promise_test(function() { |
| 8 var credential = new PasswordCredential({ |
| 9 id: 'id', |
| 10 password: 'pencil', |
| 11 name: 'name', |
| 12 iconURL: 'https://example.com/icon.png' |
| 13 }); |
| 14 |
| 15 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 16 .then(function (r) { |
| 17 return r.json(); |
| 18 }) |
| 19 .then(function (j) { |
| 20 assert_equals(j.username, 'id'); |
| 21 assert_equals(j.password, 'pencil'); |
| 22 }); |
| 23 }, "Simple Fetch"); |
| 24 |
| 25 promise_test(function() { |
| 26 var credential = new PasswordCredential({ |
| 27 id: 'id', |
| 28 password: 'pencil', |
| 29 name: 'name', |
| 30 iconURL: 'https://example.com/icon.png' |
| 31 }); |
| 32 |
| 33 credential.idName = "notUsername"; |
| 34 credential.passwordName = "notPassword"; |
| 35 |
| 36 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 37 .then(function (r) { |
| 38 return r.json() |
| 39 }) |
| 40 .then(function (j) { |
| 41 assert_equals(j.username, undefined); |
| 42 assert_equals(j.password, undefined); |
| 43 assert_equals(j.notUsername, 'id'); |
| 44 assert_equals(j.notPassword, 'pencil'); |
| 45 }); |
| 46 }, "'idName' and 'passwordName'"); |
| 47 |
| 48 promise_test(function() { |
| 49 var credential = new PasswordCredential({ |
| 50 id: 'id', |
| 51 password: 'pencil', |
| 52 name: 'name', |
| 53 iconURL: 'https://example.com/icon.png' |
| 54 }); |
| 55 |
| 56 var fd = new FormData(); |
| 57 credential.additionalData = fd; |
| 58 |
| 59 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 60 .then(function (r) { |
| 61 return r.json(); |
| 62 }) |
| 63 .then(function (j) { |
| 64 assert_equals(j.username, 'id'); |
| 65 assert_equals(j.password, 'pencil'); |
| 66 }); |
| 67 }, "'additionalData': Empty FormData has no effect."); |
| 68 |
| 69 promise_test(function() { |
| 70 var credential = new PasswordCredential({ |
| 71 id: 'id', |
| 72 password: 'pencil', |
| 73 name: 'name', |
| 74 iconURL: 'https://example.com/icon.png' |
| 75 }); |
| 76 |
| 77 var fd = new FormData(); |
| 78 fd.append("excitingData", "exciting value"); |
| 79 fd.append("csrf", "[randomness]"); |
| 80 credential.additionalData = fd; |
| 81 |
| 82 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 83 .then(function (r) { |
| 84 return r.json(); |
| 85 }) |
| 86 then(function (j) { |
| 87 assert_equals(j.username, 'id'); |
| 88 assert_equals(j.password, 'pencil'); |
| 89 assert_equals(j.excitingData, 'exciting value'); |
| 90 assert_equals(j.csrf, '[randomness]'); |
| 91 }); |
| 92 }, "'additionalData': FormData properties are properly injected."); |
| 93 |
| 94 promise_test(function() { |
| 95 var credential = new PasswordCredential({ |
| 96 id: 'id', |
| 97 password: 'pencil', |
| 98 name: 'name', |
| 99 iconURL: 'https://example.com/icon.png' |
| 100 }); |
| 101 |
| 102 var params = new URLSearchParams(); |
| 103 credential.additionalData = params; |
| 104 |
| 105 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 106 .then(function (r) { |
| 107 return r.json(); |
| 108 }) |
| 109 .then(function (j) { |
| 110 assert_equals(j.username, 'id'); |
| 111 assert_equals(j.password, 'pencil'); |
| 112 }); |
| 113 }, "'additionalData': Empty URLSearchParams has no effect."); |
| 114 |
| 115 promise_test(function() { |
| 116 var credential = new PasswordCredential({ |
| 117 id: 'id', |
| 118 password: 'pencil', |
| 119 name: 'name', |
| 120 iconURL: 'https://example.com/icon.png' |
| 121 }); |
| 122 |
| 123 var params = new URLSearchParams(); |
| 124 params.append("excitingData", "exciting value"); |
| 125 params.append("csrf", "[randomness]"); |
| 126 credential.additionalData = params; |
| 127 |
| 128 return fetch("./resources/echo-post.php", { body: credential, method: "POST"
}) |
| 129 .then(function (r) { |
| 130 return r.json(); |
| 131 }) |
| 132 .then(function (j) { |
| 133 assert_equals(j.username, 'id'); |
| 134 assert_equals(j.password, 'pencil'); |
| 135 assert_equals(j.excitingData, 'exciting value'); |
| 136 assert_equals(j.csrf, '[randomness]'); |
| 137 }); |
| 138 }, "'additionalData': URLSearchParams properties are properly injected."); |
| 139 |
| 140 promise_test(function() { |
| 141 var credential = new PasswordCredential({ |
| 142 id: 'id', |
| 143 password: 'pencil', |
| 144 name: 'name', |
| 145 iconURL: 'https://example.com/icon.png' |
| 146 }); |
| 147 |
| 148 var params = new URLSearchParams(); |
| 149 params.append("a", "1"); |
| 150 params.append("a", "2"); |
| 151 params.append("a", "3"); |
| 152 credential.additionalData = params; |
| 153 |
| 154 return fetch("./resources/echo-raw-post.php", { body: credential, method: "P
OST" }) |
| 155 .then(function (r) { |
| 156 return r.text(); |
| 157 }) |
| 158 .then(function (t) { |
| 159 assert_equals(t, 'a=1&a=2&a=3&username=id&password=pencil'); |
| 160 }); |
| 161 }, "'additionalData': URLSearchParams properties are properly injected (ordering
matters)."); |
| 162 </script> |
OLD | NEW |