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('id', 'pencil', 'name', 'https://exa
mple.com/icon.png'); | 8 var credential = new PasswordCredential({ |
| 9 id: 'id', |
| 10 password: 'pencil', |
| 11 name: 'name', |
| 12 iconURL: 'https://example.com/icon.png' |
| 13 }); |
9 | 14 |
10 verify_interface('PasswordCredential', credential, { | 15 verify_interface('PasswordCredential', credential, { |
11 id: 'string', | 16 id: 'string', |
12 name: 'string', | 17 name: 'string', |
13 iconURL: 'string', | 18 iconURL: 'string', |
14 type: 'string' | 19 type: 'string' |
15 }); | 20 }); |
16 | 21 |
17 assert_equals(credential.id, 'id'); | 22 assert_equals(credential.id, 'id'); |
18 assert_equals(credential.name, 'name'); | 23 assert_equals(credential.name, 'name'); |
19 assert_equals(credential.iconURL, 'https://example.com/icon.png'); | 24 assert_equals(credential.iconURL, 'https://example.com/icon.png'); |
20 assert_equals(credential.type, 'password'); | 25 assert_equals(credential.type, 'password'); |
21 | 26 |
22 assert_true(credential.toFormData() instanceof FormData); | 27 assert_true(credential.toFormData() instanceof FormData); |
23 }, 'Interfaces and attributes of PasswordCredential'); | 28 }, 'Interfaces and attributes of PasswordCredential'); |
24 | 29 |
25 test(function() { | 30 test(function() { |
26 assert_throws(new SyntaxError(), function () { | 31 assert_throws(new SyntaxError(), function () { |
27 var credential = new PasswordCredential('id', 'pencil', 'name', '-'); | 32 var credential = new PasswordCredential({ |
| 33 id: 'id', |
| 34 password: 'pencil', |
| 35 name: 'name', |
| 36 iconURL: '-' |
| 37 }); |
28 }); | 38 }); |
29 }, 'Construct a PasswordCredential with an invalid icon URL.'); | 39 }, 'Construct a PasswordCredential with an invalid icon URL.'); |
30 | 40 |
31 test(function() { | 41 test(function() { |
32 var credential = new PasswordCredential('id', 'pencil', 'name'); | 42 var credential = new PasswordCredential({ |
| 43 id: 'id', |
| 44 password: 'pencil', |
| 45 name: 'name', |
| 46 }); |
33 | 47 |
34 assert_equals(credential.id, 'id'); | 48 assert_equals(credential.id, 'id'); |
35 assert_equals(credential.name, 'name'); | 49 assert_equals(credential.name, 'name'); |
36 assert_equals(credential.iconURL, ''); | 50 assert_equals(credential.iconURL, ''); |
37 assert_equals(credential.type, 'password'); | 51 assert_equals(credential.type, 'password'); |
38 assert_true(credential.toFormData() instanceof FormData); | 52 assert_true(credential.toFormData() instanceof FormData); |
39 | 53 |
40 }, 'Construct a PasswordCredential with an empty icon URL.'); | 54 }, 'Construct a PasswordCredential with an empty icon URL.'); |
41 | 55 |
42 test(function() { | 56 test(function() { |
43 var credential = new PasswordCredential('id', 'pencil'); | 57 var credential = new PasswordCredential({ |
| 58 id: 'id', |
| 59 password: 'pencil', |
| 60 }); |
44 | 61 |
45 assert_equals(credential.id, 'id'); | 62 assert_equals(credential.id, 'id'); |
46 assert_equals(credential.name, ''); | 63 assert_equals(credential.name, ''); |
47 assert_equals(credential.iconURL, ''); | 64 assert_equals(credential.iconURL, ''); |
48 assert_equals(credential.type, 'password'); | 65 assert_equals(credential.type, 'password'); |
49 assert_true(credential.toFormData() instanceof FormData); | 66 assert_true(credential.toFormData() instanceof FormData); |
50 }, 'Construct a PasswordCredential with an empty name and icon URL.'); | 67 }, 'Construct a PasswordCredential with an empty name and icon URL.'); |
51 | 68 |
52 test(function() { | 69 test(function() { |
53 var credential = new PasswordCredential('id', 'pencil'); | 70 var credential = new PasswordCredential({ |
| 71 id: 'id', |
| 72 password: 'pencil', |
| 73 }); |
54 | 74 |
55 var fd = credential.toFormData(); | 75 var fd = credential.toFormData(); |
56 fd.append('n1', 'v1'); | 76 fd.append('n1', 'v1'); |
57 fd.append('n2', 'v2'); | 77 fd.append('n2', 'v2'); |
58 fd.append('n3', 'v3'); | 78 fd.append('n3', 'v3'); |
59 fd.append('n1', 'v4'); | 79 fd.append('n1', 'v4'); |
60 fd.append('n2', 'v5'); | 80 fd.append('n2', 'v5'); |
61 fd.append('n3', 'v6'); | 81 fd.append('n3', 'v6'); |
62 | 82 |
63 assert_equals(fd.get('n1'), null); | 83 assert_equals(fd.get('n1'), null); |
(...skipping 15 matching lines...) Expand all Loading... |
79 | 99 |
80 function verifyBodyMethodBehavior(t, req, methodName) { | 100 function verifyBodyMethodBehavior(t, req, methodName) { |
81 req[methodName]().then( | 101 req[methodName]().then( |
82 t.unreached_func("The 'Body::" + methodName + "()' method should reject.
"), | 102 t.unreached_func("The 'Body::" + methodName + "()' method should reject.
"), |
83 t.step_func_done(function (e) { assert_equals(e.name, "TypeError"); })); | 103 t.step_func_done(function (e) { assert_equals(e.name, "TypeError"); })); |
84 } | 104 } |
85 | 105 |
86 // TODO(mkwst): 'Body' doesn't yet implement 'formData()'. | 106 // TODO(mkwst): 'Body' doesn't yet implement 'formData()'. |
87 ['arrayBuffer', 'blob', 'json', 'text'].forEach(function (methodName) { | 107 ['arrayBuffer', 'blob', 'json', 'text'].forEach(function (methodName) { |
88 async_test(function (t) { | 108 async_test(function (t) { |
89 var credential = new PasswordCredential('id', 'pencil'); | 109 var credential = new PasswordCredential({ |
| 110 id: 'id', |
| 111 password: 'pencil', |
| 112 }); |
90 var fd = credential.toFormData(); | 113 var fd = credential.toFormData(); |
91 fd.append('n1', 'v1'); | 114 fd.append('n1', 'v1'); |
92 fd.append('n2', 'v2'); | 115 fd.append('n2', 'v2'); |
93 fd.append('n3', 'v3'); | 116 fd.append('n3', 'v3'); |
94 fd.append('n1', 'v4'); | 117 fd.append('n1', 'v4'); |
95 fd.append('n2', 'v5'); | 118 fd.append('n2', 'v5'); |
96 fd.append('n3', 'v6'); | 119 fd.append('n3', 'v6'); |
97 | 120 |
98 t.step(function () { | 121 t.step(function () { |
99 var r = new Request("http://127.0.0.1:8000", { body: fd, method: "PO
ST" }); | 122 var r = new Request("http://127.0.0.1:8000", { body: fd, method: "PO
ST" }); |
100 verifyBodyMethodBehavior(t, r, methodName); | 123 verifyBodyMethodBehavior(t, r, methodName); |
101 }); | 124 }); |
102 | 125 |
103 }, "Verify behavior of 'Body::" + methodName + "()' for opaque Requests."); | 126 }, "Verify behavior of 'Body::" + methodName + "()' for opaque Requests."); |
104 }); | 127 }); |
105 </script> | 128 </script> |
OLD | NEW |