Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @fileoverview Runs the Polymer Password Settings tests. */ | 5 /** @fileoverview Runs the Polymer Password Settings tests. */ |
| 6 | 6 |
| 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ | 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ |
| 8 var ROOT_PATH = '../../../../../'; | 8 var ROOT_PATH = '../../../../../'; |
| 9 | 9 |
| 10 // Polymer BrowserTest fixture. | 10 // Polymer BrowserTest fixture. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 * @private | 48 * @private |
| 49 */ | 49 */ |
| 50 validatePasswordList: function(listElement, passwordList) { | 50 validatePasswordList: function(listElement, passwordList) { |
| 51 assertEquals(passwordList.length, listElement.items.length); | 51 assertEquals(passwordList.length, listElement.items.length); |
| 52 if (passwordList.length > 0) { | 52 if (passwordList.length > 0) { |
| 53 // The first child is a template, skip and get the real 'first child'. | 53 // The first child is a template, skip and get the real 'first child'. |
| 54 var node = Polymer.dom(listElement).children[1]; | 54 var node = Polymer.dom(listElement).children[1]; |
| 55 assert(node); | 55 assert(node); |
| 56 var passwordInfo = passwordList[0]; | 56 var passwordInfo = passwordList[0]; |
| 57 assertEquals(passwordInfo.loginPair.originUrl, | 57 assertEquals(passwordInfo.loginPair.originUrl, |
| 58 node.querySelector('#originUrl').textContent); | 58 node.querySelector('#originUrl').textContent.trim()); |
| 59 assertEquals(passwordInfo.linkUrl, | 59 assertEquals(passwordInfo.linkUrl, |
| 60 node.querySelector('#originUrl').href); | 60 node.querySelector('#originUrl').href); |
| 61 assertEquals(passwordInfo.loginPair.username, | 61 assertEquals(passwordInfo.loginPair.username, |
| 62 node.querySelector('#username').textContent); | 62 node.querySelector('#username').textContent); |
| 63 assertEquals(passwordInfo.numCharactersInPassword, | 63 assertEquals(passwordInfo.numCharactersInPassword, |
| 64 node.querySelector('#password').value.length); | 64 node.querySelector('#password').value.length); |
| 65 } | 65 } |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 /** | 68 /** |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 79 var node = nodes[index]; | 79 var node = nodes[index]; |
| 80 var exception = exceptionList[index]; | 80 var exception = exceptionList[index]; |
| 81 assertEquals(exception.exceptionUrl, | 81 assertEquals(exception.exceptionUrl, |
| 82 node.querySelector('#exception').textContent); | 82 node.querySelector('#exception').textContent); |
| 83 assertEquals(exception.linkUrl, | 83 assertEquals(exception.linkUrl, |
| 84 node.querySelector('#exception').href); | 84 node.querySelector('#exception').href); |
| 85 } | 85 } |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Helper method that validates that origin eliding from the left is done | |
| 90 * correctly. | |
| 91 * @param {!Element} listElement The iron-list element that will be checked. | |
| 92 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList The | |
| 93 * expected data. | |
| 94 * @private | |
| 95 */ | |
| 96 validateElideOriginUrlFromLeft: function(listElement, passwordList) { | |
| 97 // The first child is a template, skip it and get the remaining children. | |
| 98 var children = Polymer.dom(listElement).children.slice(1); | |
| 99 for (var i = 0; i < children.length; ++i) { | |
|
hcarmona
2016/10/25 17:05:31
iron-list will only create enough children to fill
| |
| 100 var longOriginUrl = passwordList[i].loginPair.originUrl; | |
| 101 var websiteColumn = children[i].querySelector('.website-column'); | |
| 102 assertEquals(this.elideOriginUrlFromLeft_(longOriginUrl, websiteColumn), | |
| 103 websiteColumn.textContent.trim()); | |
| 104 } | |
| 105 }, | |
| 106 | |
| 107 /** | |
| 108 * Helper method that replicates a logic done in the passwords section, but | |
| 109 * replaces the binary search with a linear search. | |
|
Dan Beam
2016/10/25 23:37:32
waiiiiiit, what? don't do this. you're not testi
| |
| 110 * @param {string} originUrl The original origin URL. | |
| 111 * @param {!Element} websiteColumn The div that contains the URL. | |
| 112 * @return {string} | |
| 113 * @private | |
| 114 */ | |
| 115 elideOriginUrlFromLeft_: function(originUrl, websiteColumn) { | |
| 116 var computedStyle = window.getComputedStyle(websiteColumn); | |
| 117 var columnWidth = websiteColumn.offsetWidth - | |
| 118 parseInt(computedStyle.webkitMarginStart, 10) - | |
| 119 parseInt(computedStyle.webkitPaddingStart, 10); | |
| 120 | |
| 121 var canvas = document.createElement('canvas'); | |
| 122 var ctx = canvas.getContext('2d'); | |
| 123 ctx.font = computedStyle.font; | |
| 124 | |
| 125 if (ctx.measureText(originUrl).width <= columnWidth) | |
| 126 return originUrl; | |
| 127 | |
| 128 var dots = '\u2026'; // HORIZONTAL ELLIPSIS | |
| 129 assert(ctx.measureText(dots).width <= columnWidth); | |
| 130 | |
| 131 var index = 0; | |
| 132 while (ctx.measureText(dots + originUrl.substr(index)).width > columnWidth) | |
| 133 ++index; | |
| 134 | |
| 135 return dots + originUrl.substr(index); | |
| 136 }, | |
| 137 | |
| 138 /** | |
| 89 * Returns all children of an element that has children added by a dom-repeat. | 139 * Returns all children of an element that has children added by a dom-repeat. |
| 90 * @param {!Element} element | 140 * @param {!Element} element |
| 91 * @return {!Array<!Element>} | 141 * @return {!Array<!Element>} |
| 92 * @private | 142 * @private |
| 93 */ | 143 */ |
| 94 getDomRepeatChildren_: function(element) { | 144 getDomRepeatChildren_: function(element) { |
| 95 var template = element.children[element.children.length - 1]; | 145 var template = element.children[element.children.length - 1]; |
| 96 assertEquals('TEMPLATE', template.tagName); | 146 assertEquals('TEMPLATE', template.tagName); |
| 97 // The template is at the end of the list of children and should be skipped. | 147 // The template is at the end of the list of children and should be skipped. |
| 98 return Array.prototype.slice.call(element.children, 0, -1); | 148 return Array.prototype.slice.call(element.children, 0, -1); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // Assert that the data is passed into the iron list. If this fails, | 249 // Assert that the data is passed into the iron list. If this fails, |
| 200 // then other expectations will also fail. | 250 // then other expectations will also fail. |
| 201 assertEquals(passwordList, passwordsSection.$.passwordList.items); | 251 assertEquals(passwordList, passwordsSection.$.passwordList.items); |
| 202 | 252 |
| 203 self.validatePasswordList(passwordsSection.$.passwordList, passwordList); | 253 self.validatePasswordList(passwordsSection.$.passwordList, passwordList); |
| 204 | 254 |
| 205 assertTrue(passwordsSection.$.noPasswordsLabel.hidden); | 255 assertTrue(passwordsSection.$.noPasswordsLabel.hidden); |
| 206 assertFalse(passwordsSection.$.savedPasswordsHeading.hidden); | 256 assertFalse(passwordsSection.$.savedPasswordsHeading.hidden); |
| 207 }); | 257 }); |
| 208 | 258 |
| 259 test('verifyElidedOrigins', function() { | |
| 260 var passwordList = [ | |
| 261 FakeDataMaker.passwordEntry( | |
| 262 'this.is.an.extremely.long.origin.that.should.be.elided.com'), | |
| 263 FakeDataMaker.passwordEntry( | |
| 264 'another.very.long.and.completely.unrealistic.website.name.com'), | |
| 265 FakeDataMaker.passwordEntry('this.is.rather.short.com'), | |
| 266 FakeDataMaker.passwordEntry('also.short.com'), | |
| 267 ]; | |
| 268 | |
| 269 var passwordsSection = self.createPasswordsSection_(passwordList, []); | |
|
hcarmona
2016/10/25 17:05:31
Can we simplify the test by calling |elideOriginUr
| |
| 270 self.validateElideOriginUrlFromLeft(passwordsSection.$.passwordList, | |
| 271 passwordList); | |
| 272 }); | |
| 273 | |
| 209 // Test verifies that removing a password will update the elements. | 274 // Test verifies that removing a password will update the elements. |
| 210 test('verifyPasswordListRemove', function() { | 275 test('verifyPasswordListRemove', function() { |
| 211 var passwordList = [ | 276 var passwordList = [ |
| 212 FakeDataMaker.passwordEntry('anotherwebsite.com', 'luigi', 1), | 277 FakeDataMaker.passwordEntry('anotherwebsite.com', 'luigi', 1), |
| 213 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), | 278 FakeDataMaker.passwordEntry('longwebsite.com', 'peach', 7), |
| 214 FakeDataMaker.passwordEntry('website.com', 'mario', 70) | 279 FakeDataMaker.passwordEntry('website.com', 'mario', 70) |
| 215 ]; | 280 ]; |
| 216 | 281 |
| 217 var passwordsSection = self.createPasswordsSection_(passwordList, []); | 282 var passwordsSection = self.createPasswordsSection_(passwordList, []); |
| 218 | 283 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 assertEquals(item.loginPair.username, event.detail.username); | 507 assertEquals(item.loginPair.username, event.detail.username); |
| 443 done(); | 508 done(); |
| 444 }); | 509 }); |
| 445 | 510 |
| 446 MockInteractions.tap(passwordDialog.$.showPasswordButton); | 511 MockInteractions.tap(passwordDialog.$.showPasswordButton); |
| 447 }); | 512 }); |
| 448 }); | 513 }); |
| 449 | 514 |
| 450 mocha.run(); | 515 mocha.run(); |
| 451 }); | 516 }); |
| OLD | NEW |