OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Include test fixture. | 5 // Include test fixture. |
6 GEN_INCLUDE(['net_internals_test.js']); | 6 GEN_INCLUDE(['net_internals_test.js']); |
7 | 7 |
8 // Anonymous namespace | 8 // Anonymous namespace |
9 (function() { | 9 (function() { |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 /** | 162 /** |
163 * A Task to try and add an HSTS domain via the HTML form. The task will wait | 163 * A Task to try and add an HSTS domain via the HTML form. The task will wait |
164 * until the results from the automatically sent query have been received, and | 164 * until the results from the automatically sent query have been received, and |
165 * then checks them against the expected values. | 165 * then checks them against the expected values. |
166 * @param {string} domain The domain to send and expected to be returned. | 166 * @param {string} domain The domain to send and expected to be returned. |
167 * @param {bool} stsSubdomains Whether the HSTS subdomain checkbox should be | 167 * @param {bool} stsSubdomains Whether the HSTS subdomain checkbox should be |
168 * selected. Also the corresponding expected return value, in the success | 168 * selected. Also the corresponding expected return value, in the success |
169 * case. | 169 * case. |
170 * @param {bool} pkpSubdomains Whether the pinning subdomain checkbox should be | 170 * @param {bool} pkpSubdomains Whether the pinning subdomain checkbox should be |
171 * selected. Also the corresponding expected return value, in the success | 171 * selected. Also the corresponding expected return value, in the success |
172 * case. | 172 * case. When publicKeyHashes is INVALID_HASH, the expected return value |
| 173 * is false. |
173 * @param {number} stsObserved The time the STS policy was observed. | 174 * @param {number} stsObserved The time the STS policy was observed. |
174 * @param {number} pkpObserved The time the PKP policy was observed. | 175 * @param {number} pkpObserved The time the PKP policy was observed. |
175 * @param {string} publicKeyHashes Public key hash to send. Also the | 176 * @param {string} publicKeyHashes Public key hash to send. Also the |
176 * corresponding expected return value, on success. When this is the string | 177 * corresponding expected return value, on success. When this is the string |
177 * INVALID_HASH, an empty string is expected to be received instead. | 178 * INVALID_HASH, an empty string is expected to be received instead. |
178 * @param {QueryResultType} queryResultType Expected result type. | 179 * @param {QueryResultType} queryResultType Expected result type. |
179 * @extends {CheckQueryResultTask} | 180 * @extends {CheckQueryResultTask} |
180 */ | 181 */ |
181 function AddTask(domain, stsSubdomains, pkpSubdomains, publicKeyHashes, | 182 function AddTask(domain, stsSubdomains, pkpSubdomains, publicKeyHashes, |
182 stsObserved, pkpObserved, queryResultType) { | 183 stsObserved, pkpObserved, queryResultType) { |
183 this.requestedPublicKeyHashes_ = publicKeyHashes; | 184 this.requestedPublicKeyHashes_ = publicKeyHashes; |
184 if (publicKeyHashes == INVALID_HASH) | 185 this.requestedPkpSubdomains_ = pkpSubdomains; |
| 186 if (publicKeyHashes == INVALID_HASH) { |
| 187 pkpSubdomains = false; |
185 publicKeyHashes = ''; | 188 publicKeyHashes = ''; |
| 189 } |
186 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, | 190 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, |
187 stsObserved, pkpObserved, publicKeyHashes, | 191 stsObserved, pkpObserved, publicKeyHashes, |
188 queryResultType); | 192 queryResultType); |
189 } | 193 } |
190 | 194 |
191 AddTask.prototype = { | 195 AddTask.prototype = { |
192 __proto__: CheckQueryResultTask.prototype, | 196 __proto__: CheckQueryResultTask.prototype, |
193 | 197 |
194 /** | 198 /** |
195 * Fills out the add form, simulates a click to submit it, and starts | 199 * Fills out the add form, simulates a click to submit it, and starts |
196 * listening for the results of the query that is automatically submitted. | 200 * listening for the results of the query that is automatically submitted. |
197 */ | 201 */ |
198 start: function() { | 202 start: function() { |
199 $(HSTSView.ADD_INPUT_ID).value = this.domain_; | 203 $(HSTSView.ADD_INPUT_ID).value = this.domain_; |
200 $(HSTSView.ADD_STS_CHECK_ID).checked = this.stsSubdomains_; | 204 $(HSTSView.ADD_STS_CHECK_ID).checked = this.stsSubdomains_; |
201 $(HSTSView.ADD_PKP_CHECK_ID).checked = this.pkpSubdomains_; | 205 $(HSTSView.ADD_PKP_CHECK_ID).checked = this.requestedPkpSubdomains_; |
202 $(HSTSView.ADD_PINS_ID).value = this.requestedPublicKeyHashes_; | 206 $(HSTSView.ADD_PINS_ID).value = this.requestedPublicKeyHashes_; |
203 $(HSTSView.ADD_SUBMIT_ID).click(); | 207 $(HSTSView.ADD_SUBMIT_ID).click(); |
204 CheckQueryResultTask.prototype.start.call(this); | 208 CheckQueryResultTask.prototype.start.call(this); |
205 } | 209 } |
206 }; | 210 }; |
207 | 211 |
208 /** | 212 /** |
209 * A Task to query a domain and wait for the results. Parameters mirror those | 213 * A Task to query a domain and wait for the results. Parameters mirror those |
210 * of CheckQueryResultTask, except |domain| is also the name of the domain to | 214 * of CheckQueryResultTask, except |domain| is also the name of the domain to |
211 * query. | 215 * query. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 * Adds two different domains and then deletes them. | 380 * Adds two different domains and then deletes them. |
377 */ | 381 */ |
378 TEST_F('NetInternalsTest', 'netInternalsHSTSViewAddTwice', function() { | 382 TEST_F('NetInternalsTest', 'netInternalsHSTSViewAddTwice', function() { |
379 NetInternalsTest.switchToView('hsts'); | 383 NetInternalsTest.switchToView('hsts'); |
380 taskQueue = new NetInternalsTest.TaskQueue(true); | 384 taskQueue = new NetInternalsTest.TaskQueue(true); |
381 var now = new Date().getTime() / 1000.0; | 385 var now = new Date().getTime() / 1000.0; |
382 taskQueue.addTask(new AddTask('somewhere.com', false, false, VALID_HASH, | 386 taskQueue.addTask(new AddTask('somewhere.com', false, false, VALID_HASH, |
383 now, now, QueryResultType.SUCCESS)); | 387 now, now, QueryResultType.SUCCESS)); |
384 taskQueue.addTask(new QueryTask('somewhereelse.com', false, false, now, now, | 388 taskQueue.addTask(new QueryTask('somewhereelse.com', false, false, now, now, |
385 '', QueryResultType.NOT_FOUND)); | 389 '', QueryResultType.NOT_FOUND)); |
386 taskQueue.addTask(new AddTask('somewhereelse.com', true, true, '', | 390 taskQueue.addTask(new AddTask('somewhereelse.com', true, false, '', |
387 now, now, QueryResultType.SUCCESS)); | 391 now, now, QueryResultType.SUCCESS)); |
388 taskQueue.addTask(new QueryTask('somewhere.com', false, false, now, now, | 392 taskQueue.addTask(new QueryTask('somewhere.com', false, false, now, now, |
389 VALID_HASH, QueryResultType.SUCCESS)); | 393 VALID_HASH, QueryResultType.SUCCESS)); |
390 taskQueue.addTask(new DeleteTask('somewhere.com', QueryResultType.NOT_FOUND)); | 394 taskQueue.addTask(new DeleteTask('somewhere.com', QueryResultType.NOT_FOUND)); |
391 taskQueue.addTask(new QueryTask('somewhereelse.com', true, true, now, now, '', | 395 taskQueue.addTask(new QueryTask('somewhereelse.com', true, false, now, now, |
392 QueryResultType.SUCCESS)); | 396 '', QueryResultType.SUCCESS)); |
393 taskQueue.addTask(new DeleteTask('somewhereelse.com', | 397 taskQueue.addTask(new DeleteTask('somewhereelse.com', |
394 QueryResultType.NOT_FOUND)); | 398 QueryResultType.NOT_FOUND)); |
395 taskQueue.run(true); | 399 taskQueue.run(true); |
396 }); | 400 }); |
397 | 401 |
398 })(); // Anonymous namespace | 402 })(); // Anonymous namespace |
OLD | NEW |