| 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 22 matching lines...) Expand all Loading... |
| 33 /** | 33 /** |
| 34 * A Task that waits for the results of an HSTS query. Once the results are | 34 * A Task that waits for the results of an HSTS query. Once the results are |
| 35 * received, checks them before completing. Does not initiate the query. | 35 * received, checks them before completing. Does not initiate the query. |
| 36 * @param {string} domain The domain expected in the returned results. | 36 * @param {string} domain The domain expected in the returned results. |
| 37 * @param {bool} stsSubdomains Whether or not the stsSubdomains flag is expected | 37 * @param {bool} stsSubdomains Whether or not the stsSubdomains flag is expected |
| 38 * to be set in the returned results. Ignored on error and not found | 38 * to be set in the returned results. Ignored on error and not found |
| 39 * results. | 39 * results. |
| 40 * @param {bool} pkpSubdomains Whether or not the pkpSubdomains flag is expected | 40 * @param {bool} pkpSubdomains Whether or not the pkpSubdomains flag is expected |
| 41 * to be set in the returned results. Ignored on error and not found | 41 * to be set in the returned results. Ignored on error and not found |
| 42 * results. | 42 * results. |
| 43 * @param {number} stsObserved The time the STS policy was observed. |
| 44 * @param {number} pkpObserved The time the PKP policy was observed. |
| 43 * @param {string} publicKeyHashes Expected public key hashes. Ignored on error | 45 * @param {string} publicKeyHashes Expected public key hashes. Ignored on error |
| 44 * error and not found results. | 46 * error and not found results. |
| 45 * @param {QueryResultType} queryResultType The expected result type of the | 47 * @param {QueryResultType} queryResultType The expected result type of the |
| 46 * results of the query. | 48 * results of the query. |
| 47 * @extends {NetInternalsTest.Task} | 49 * @extends {NetInternalsTest.Task} |
| 48 */ | 50 */ |
| 49 function CheckQueryResultTask(domain, stsSubdomains, pkpSubdomains, | 51 function CheckQueryResultTask(domain, stsSubdomains, pkpSubdomains, |
| 50 publicKeyHashes, queryResultType) { | 52 stsObserved, pkpObserved, publicKeyHashes, |
| 53 queryResultType) { |
| 51 this.domain_ = domain; | 54 this.domain_ = domain; |
| 52 this.stsSubdomains_ = stsSubdomains; | 55 this.stsSubdomains_ = stsSubdomains; |
| 53 this.pkpSubdomains_ = pkpSubdomains; | 56 this.pkpSubdomains_ = pkpSubdomains; |
| 57 this.stsObserved_ = stsObserved; |
| 58 this.pkpObserved_ = pkpObserved; |
| 54 this.publicKeyHashes_ = publicKeyHashes; | 59 this.publicKeyHashes_ = publicKeyHashes; |
| 55 this.queryResultType_ = queryResultType; | 60 this.queryResultType_ = queryResultType; |
| 56 NetInternalsTest.Task.call(this); | 61 NetInternalsTest.Task.call(this); |
| 57 } | 62 } |
| 58 | 63 |
| 59 CheckQueryResultTask.prototype = { | 64 CheckQueryResultTask.prototype = { |
| 60 __proto__: NetInternalsTest.Task.prototype, | 65 __proto__: NetInternalsTest.Task.prototype, |
| 61 | 66 |
| 62 /** | 67 /** |
| 63 * Starts watching for the query results. | 68 * Starts watching for the query results. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 }, | 117 }, |
| 113 | 118 |
| 114 /** | 119 /** |
| 115 * Checks successful results. | 120 * Checks successful results. |
| 116 * @param {object} result Results from the query. | 121 * @param {object} result Results from the query. |
| 117 */ | 122 */ |
| 118 checkSuccess_: function(result) { | 123 checkSuccess_: function(result) { |
| 119 expectEquals(QueryResultType.SUCCESS, this.queryResultType_); | 124 expectEquals(QueryResultType.SUCCESS, this.queryResultType_); |
| 120 expectEquals(this.stsSubdomains_, result.sts_subdomains); | 125 expectEquals(this.stsSubdomains_, result.sts_subdomains); |
| 121 expectEquals(this.pkpSubdomains_, result.pkp_subdomains); | 126 expectEquals(this.pkpSubdomains_, result.pkp_subdomains); |
| 127 expectEquals(this.stsObserved_, result.sts_observed); |
| 128 expectEquals(this.pkpObserved_, result.pkp_observed); |
| 122 | 129 |
| 123 // |public_key_hashes| is an old synonym for what is now | 130 // |public_key_hashes| is an old synonym for what is now |
| 124 // |preloaded_spki_hashes|, which in turn is a legacy synonym for | 131 // |preloaded_spki_hashes|, which in turn is a legacy synonym for |
| 125 // |static_spki_hashes|. Look for all three, and also for | 132 // |static_spki_hashes|. Look for all three, and also for |
| 126 // |dynamic_spki_hashes|. | 133 // |dynamic_spki_hashes|. |
| 127 if (typeof result.public_key_hashes === 'undefined') | 134 if (typeof result.public_key_hashes === 'undefined') |
| 128 result.public_key_hashes = ''; | 135 result.public_key_hashes = ''; |
| 129 if (typeof result.preloaded_spki_hashes === 'undefined') | 136 if (typeof result.preloaded_spki_hashes === 'undefined') |
| 130 result.preloaded_spki_hashes = ''; | 137 result.preloaded_spki_hashes = ''; |
| 131 if (typeof result.static_spki_hashes === 'undefined') | 138 if (typeof result.static_spki_hashes === 'undefined') |
| (...skipping 23 matching lines...) Expand all Loading... |
| 155 * A Task to try and add an HSTS domain via the HTML form. The task will wait | 162 * A Task to try and add an HSTS domain via the HTML form. The task will wait |
| 156 * until the results from the automatically sent query have been received, and | 163 * until the results from the automatically sent query have been received, and |
| 157 * then checks them against the expected values. | 164 * then checks them against the expected values. |
| 158 * @param {string} domain The domain to send and expected to be returned. | 165 * @param {string} domain The domain to send and expected to be returned. |
| 159 * @param {bool} stsSubdomains Whether the HSTS subdomain checkbox should be | 166 * @param {bool} stsSubdomains Whether the HSTS subdomain checkbox should be |
| 160 * selected. Also the corresponding expected return value, in the success | 167 * selected. Also the corresponding expected return value, in the success |
| 161 * case. | 168 * case. |
| 162 * @param {bool} pkpSubdomains Whether the pinning subdomain checkbox should be | 169 * @param {bool} pkpSubdomains Whether the pinning subdomain checkbox should be |
| 163 * selected. Also the corresponding expected return value, in the success | 170 * selected. Also the corresponding expected return value, in the success |
| 164 * case. | 171 * case. |
| 172 * @param {number} stsObserved The time the STS policy was observed. |
| 173 * @param {number} pkpObserved The time the PKP policy was observed. |
| 165 * @param {string} publicKeyHashes Public key hash to send. Also the | 174 * @param {string} publicKeyHashes Public key hash to send. Also the |
| 166 * corresponding expected return value, on success. When this is the string | 175 * corresponding expected return value, on success. When this is the string |
| 167 * INVALID_HASH, an empty string is expected to be received instead. | 176 * INVALID_HASH, an empty string is expected to be received instead. |
| 168 * @param {QueryResultType} queryResultType Expected result type. | 177 * @param {QueryResultType} queryResultType Expected result type. |
| 169 * @extends {CheckQueryResultTask} | 178 * @extends {CheckQueryResultTask} |
| 170 */ | 179 */ |
| 171 function AddTask(domain, stsSubdomains, pkpSubdomains, publicKeyHashes, | 180 function AddTask(domain, stsSubdomains, pkpSubdomains, publicKeyHashes, |
| 172 queryResultType) { | 181 stsObserved, pkpObserved, queryResultType) { |
| 173 this.requestedPublicKeyHashes_ = publicKeyHashes; | 182 this.requestedPublicKeyHashes_ = publicKeyHashes; |
| 174 if (publicKeyHashes == INVALID_HASH) | 183 if (publicKeyHashes == INVALID_HASH) |
| 175 publicKeyHashes = ''; | 184 publicKeyHashes = ''; |
| 176 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, | 185 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, |
| 177 publicKeyHashes, queryResultType); | 186 stsObserved, pkpObserved, publicKeyHashes, |
| 187 queryResultType); |
| 178 } | 188 } |
| 179 | 189 |
| 180 AddTask.prototype = { | 190 AddTask.prototype = { |
| 181 __proto__: CheckQueryResultTask.prototype, | 191 __proto__: CheckQueryResultTask.prototype, |
| 182 | 192 |
| 183 /** | 193 /** |
| 184 * Fills out the add form, simulates a click to submit it, and starts | 194 * Fills out the add form, simulates a click to submit it, and starts |
| 185 * listening for the results of the query that is automatically submitted. | 195 * listening for the results of the query that is automatically submitted. |
| 186 */ | 196 */ |
| 187 start: function() { | 197 start: function() { |
| 188 $(HSTSView.ADD_INPUT_ID).value = this.domain_; | 198 $(HSTSView.ADD_INPUT_ID).value = this.domain_; |
| 189 $(HSTSView.ADD_STS_CHECK_ID).checked = this.stsSubdomains_; | 199 $(HSTSView.ADD_STS_CHECK_ID).checked = this.stsSubdomains_; |
| 190 $(HSTSView.ADD_PKP_CHECK_ID).checked = this.pkpSubdomains_; | 200 $(HSTSView.ADD_PKP_CHECK_ID).checked = this.pkpSubdomains_; |
| 191 $(HSTSView.ADD_PINS_ID).value = this.requestedPublicKeyHashes_; | 201 $(HSTSView.ADD_PINS_ID).value = this.requestedPublicKeyHashes_; |
| 192 $(HSTSView.ADD_SUBMIT_ID).click(); | 202 $(HSTSView.ADD_SUBMIT_ID).click(); |
| 193 CheckQueryResultTask.prototype.start.call(this); | 203 CheckQueryResultTask.prototype.start.call(this); |
| 194 } | 204 } |
| 195 }; | 205 }; |
| 196 | 206 |
| 197 /** | 207 /** |
| 198 * A Task to query a domain and wait for the results. Parameters mirror those | 208 * A Task to query a domain and wait for the results. Parameters mirror those |
| 199 * of CheckQueryResultTask, except |domain| is also the name of the domain to | 209 * of CheckQueryResultTask, except |domain| is also the name of the domain to |
| 200 * query. | 210 * query. |
| 201 * @extends {CheckQueryResultTask} | 211 * @extends {CheckQueryResultTask} |
| 202 */ | 212 */ |
| 203 function QueryTask(domain, stsSubdomains, pkpSubdomains, publicKeyHashes, | 213 function QueryTask(domain, stsSubdomains, pkpSubdomains, stsObserved, |
| 204 queryResultType) { | 214 pkpObserved, publicKeyHashes, queryResultType) { |
| 205 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, | 215 CheckQueryResultTask.call(this, domain, stsSubdomains, pkpSubdomains, |
| 206 publicKeyHashes, queryResultType); | 216 stsObserved, pkpObserved, publicKeyHashes, |
| 217 queryResultType); |
| 207 } | 218 } |
| 208 | 219 |
| 209 QueryTask.prototype = { | 220 QueryTask.prototype = { |
| 210 __proto__: CheckQueryResultTask.prototype, | 221 __proto__: CheckQueryResultTask.prototype, |
| 211 | 222 |
| 212 /** | 223 /** |
| 213 * Fills out the query form, simulates a click to submit it, and starts | 224 * Fills out the query form, simulates a click to submit it, and starts |
| 214 * listening for the results. | 225 * listening for the results. |
| 215 */ | 226 */ |
| 216 start: function() { | 227 start: function() { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 QueryResultType.SUCCESS)); | 379 QueryResultType.SUCCESS)); |
| 369 taskQueue.addTask(new DeleteTask('somewhere.com', QueryResultType.NOT_FOUND)); | 380 taskQueue.addTask(new DeleteTask('somewhere.com', QueryResultType.NOT_FOUND)); |
| 370 taskQueue.addTask(new QueryTask('somewhereelse.com', true, true, '', | 381 taskQueue.addTask(new QueryTask('somewhereelse.com', true, true, '', |
| 371 QueryResultType.SUCCESS)); | 382 QueryResultType.SUCCESS)); |
| 372 taskQueue.addTask(new DeleteTask('somewhereelse.com', | 383 taskQueue.addTask(new DeleteTask('somewhereelse.com', |
| 373 QueryResultType.NOT_FOUND)); | 384 QueryResultType.NOT_FOUND)); |
| 374 taskQueue.run(true); | 385 taskQueue.run(true); |
| 375 }); | 386 }); |
| 376 | 387 |
| 377 })(); // Anonymous namespace | 388 })(); // Anonymous namespace |
| OLD | NEW |