Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/credentialmanager/passwordcredential-fetch.html

Issue 1446963002: CREDENTIAL: Teach Fetch to handle PasswordCredential objects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@opaque
Patch Set: Better Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 async_test(function(t) {
philipj_slow 2015/11/17 15:53:59 I don't know if it will simplify or not, but there
Mike West 2015/11/18 09:12:51 Looks like a pretty reasonable simplification.
philipj_slow 2015/11/18 10:00:05 Yep, it turned out pretty nice!
8 var credential = new PasswordCredential({
9 id: 'id',
10 password: 'pencil',
11 name: 'name',
12 iconURL: 'https://example.com/icon.png'
13 });
14
15 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
16 t.step_func(function (r) {
17 r.json().then(
philipj_slow 2015/11/17 15:53:59 I think you could also flatten this kind of struct
Mike West 2015/11/18 09:12:50 This looks pretty cool to me!
18 t.step_func_done(function (j) {
19 assert_equals(j.username, 'id');
20 assert_equals(j.password, 'pencil');
21 }),
22 t.unreached_func("Should be able to read the body."));
23 }),
24 t.unreached_func("Should not reject")
25 );
26 }, "Simple Fetch");
27
28 async_test(function(t) {
29 var credential = new PasswordCredential({
30 id: 'id',
31 password: 'pencil',
32 name: 'name',
33 iconURL: 'https://example.com/icon.png'
34 });
35
36 credential.idName = "notUsername";
37 credential.passwordName = "notPassword";
38
39 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
40 t.step_func(function (r) {
41 r.json().then(
42 t.step_func_done(function (j) {
43 assert_equals(j.username, undefined);
44 assert_equals(j.password, undefined);
45 assert_equals(j.notUsername, 'id');
46 assert_equals(j.notPassword, 'pencil');
47 }),
48 t.unreached_func("Should be able to read the body."));
49 }),
50 t.unreached_func("Should not reject")
51 );
52 }, "'idName' and 'passwordName'");
53
54 async_test(function(t) {
55 var credential = new PasswordCredential({
56 id: 'id',
57 password: 'pencil',
58 name: 'name',
59 iconURL: 'https://example.com/icon.png'
60 });
61
62 var fd = new FormData();
63 credential.additionalData = fd;
64
65 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
66 t.step_func(function (r) {
67 r.json().then(
68 t.step_func_done(function (j) {
69 assert_equals(j.username, 'id');
70 assert_equals(j.password, 'pencil');
71 }),
72 t.unreached_func("Should be able to read the body."));
73 }),
74 t.unreached_func("Should not reject")
75 );
76 }, "'additionalData': Empty FormData has no effect.");
77
78 async_test(function(t) {
79 var credential = new PasswordCredential({
80 id: 'id',
81 password: 'pencil',
82 name: 'name',
83 iconURL: 'https://example.com/icon.png'
84 });
85
86 var fd = new FormData();
87 fd.append("excitingData", "exciting value");
88 fd.append("csrf", "[randomness]");
89 credential.additionalData = fd;
90
91 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
92 t.step_func(function (r) {
93 r.json().then(
94 t.step_func_done(function (j) {
95 assert_equals(j.username, 'id');
96 assert_equals(j.password, 'pencil');
97 assert_equals(j.excitingData, 'exciting value');
98 assert_equals(j.csrf, '[randomness]');
99 }),
100 t.unreached_func("Should be able to read the body."));
101 }),
102 t.unreached_func("Should not reject")
103 );
104 }, "'additionalData': FormData properties are properly injected.");
philipj_slow 2015/11/17 15:53:59 The spec requires a specific order (idName+passwor
Mike West 2015/11/18 09:12:51 This is going to be difficult to do with FormData.
philipj_slow 2015/11/18 10:00:05 Fair enough :)
105
106 async_test(function(t) {
107 var credential = new PasswordCredential({
108 id: 'id',
109 password: 'pencil',
110 name: 'name',
111 iconURL: 'https://example.com/icon.png'
112 });
113
114 var params = new URLSearchParams();
115 credential.additionalData = params;
116
117 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
118 t.step_func(function (r) {
119 r.json().then(
120 t.step_func_done(function (j) {
121 assert_equals(j.username, 'id');
122 assert_equals(j.password, 'pencil');
123 }),
124 t.unreached_func("Should be able to read the body."));
125 }),
126 t.unreached_func("Should not reject")
127 );
128 }, "'additionalData': Empty URLSearchParams has no effect.");
129
130 async_test(function(t) {
131 var credential = new PasswordCredential({
132 id: 'id',
133 password: 'pencil',
134 name: 'name',
135 iconURL: 'https://example.com/icon.png'
136 });
137
138 var params = new URLSearchParams();
139 params.append("excitingData", "exciting value");
140 params.append("csrf", "[randomness]");
141 credential.additionalData = params;
142
143 fetch("./resources/echo-post.php", { body: credential, method: "POST" }).the n(
144 t.step_func(function (r) {
145 r.json().then(
146 t.step_func_done(function (j) {
147 assert_equals(j.username, 'id');
148 assert_equals(j.password, 'pencil');
149 assert_equals(j.excitingData, 'exciting value');
150 assert_equals(j.csrf, '[randomness]');
151 }),
152 t.unreached_func("Should be able to read the body."));
153 }),
154 t.unreached_func("Should not reject")
155 );
156 }, "'additionalData': URLSearchParams properties are properly injected.");
philipj_slow 2015/11/17 15:53:59 Same question about order.
Mike West 2015/11/18 09:12:51 This will be simpler. :)
157 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698