browser_sections_by_name.js (9725B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /* global add_heuristic_tests */ 5 6 "use strict"; 7 8 // The following are included in this test 9 // - One named billing section 10 // - One named billing section and one named shipping section 11 // - One named billing section and one section without name 12 // - Fields without section name are merged to a section with section name 13 // - Two sections without name 14 15 add_heuristic_tests([ 16 { 17 description: `One named billing section`, 18 fixtureData: ` 19 <html><body> 20 <input id="street-address" autocomplete="billing street-address"> 21 <input id="postal-code" autocomplete="billing postal-code"> 22 <input id="country" autocomplete="billing country"> 23 </body></html> 24 `, 25 expectedResult: [ 26 { 27 default: { 28 reason: "autocomplete", 29 addressType: "billing", 30 }, 31 fields: [ 32 { fieldName: "street-address" }, 33 { fieldName: "postal-code" }, 34 { fieldName: "country" }, 35 ], 36 }, 37 ], 38 }, 39 { 40 description: `One billing section and one shipping section`, 41 fixtureData: ` 42 <html><body> 43 <input id="street-address" autocomplete="billing street-address"> 44 <input id="postal-code" autocomplete="billing postal-code"> 45 <input id="country" autocomplete="billing country"> 46 <input id="street-address" autocomplete="shipping street-address"> 47 <input id="postal-code" autocomplete="shipping postal-code"> 48 <input id="country" autocomplete="shipping country"> 49 </body></html> 50 `, 51 expectedResult: [ 52 { 53 default: { 54 reason: "autocomplete", 55 addressType: "billing", 56 }, 57 fields: [ 58 { fieldName: "street-address" }, 59 { fieldName: "postal-code" }, 60 { fieldName: "country" }, 61 ], 62 }, 63 { 64 default: { 65 reason: "autocomplete", 66 addressType: "shipping", 67 }, 68 fields: [ 69 { fieldName: "street-address" }, 70 { fieldName: "postal-code" }, 71 { fieldName: "country" }, 72 ], 73 }, 74 ], 75 }, 76 { 77 description: `One billing section, one shipping section, and then billing section`, 78 fixtureData: ` 79 <html><body> 80 <input id="street-address" autocomplete="billing street-address"> 81 <input id="postal-code" autocomplete="billing postal-code"> 82 <input id="street-address" autocomplete="shipping street-address"> 83 <input id="postal-code" autocomplete="shipping postal-code"> 84 <input id="country" autocomplete="shipping country"> 85 <input id="country" autocomplete="billing country"> 86 </body></html> 87 `, 88 expectedResult: [ 89 { 90 default: { 91 reason: "autocomplete", 92 addressType: "billing", 93 }, 94 fields: [ 95 { fieldName: "street-address" }, 96 { fieldName: "postal-code" }, 97 { fieldName: "country" }, 98 ], 99 }, 100 { 101 default: { 102 reason: "autocomplete", 103 addressType: "shipping", 104 }, 105 fields: [ 106 { fieldName: "street-address" }, 107 { fieldName: "postal-code" }, 108 { fieldName: "country" }, 109 ], 110 }, 111 ], 112 }, 113 { 114 description: `one section without a name and one billing section`, 115 fixtureData: ` 116 <html><body> 117 <input id="street-address" autocomplete="street-address"> 118 <input id="postal-code" autocomplete="postal-code"> 119 <input id="country" autocomplete="country"> 120 <input id="street-address" autocomplete="billing street-address"> 121 <input id="postal-code" autocomplete="billing postal-code"> 122 <input id="country" autocomplete="billing country"> 123 </body></html> 124 `, 125 expectedResult: [ 126 { 127 default: { 128 reason: "autocomplete", 129 }, 130 fields: [ 131 { fieldName: "street-address" }, 132 { fieldName: "postal-code" }, 133 { fieldName: "country" }, 134 ], 135 }, 136 { 137 default: { 138 reason: "autocomplete", 139 addressType: "billing", 140 }, 141 fields: [ 142 { fieldName: "street-address" }, 143 { fieldName: "postal-code" }, 144 { fieldName: "country" }, 145 ], 146 }, 147 ], 148 }, 149 { 150 description: `One billing section and one section without a name`, 151 fixtureData: ` 152 <html><body> 153 <input id="street-address" autocomplete="billing street-address"> 154 <input id="postal-code" autocomplete="billing postal-code"> 155 <input id="country" autocomplete="billing country"> 156 <input id="street-address" autocomplete="street-address"> 157 <input id="postal-code" autocomplete="postal-code"> 158 <input id="country" autocomplete="country"> 159 </body></html> 160 `, 161 expectedResult: [ 162 { 163 default: { 164 reason: "autocomplete", 165 addressType: "billing", 166 }, 167 fields: [ 168 { fieldName: "street-address" }, 169 { fieldName: "postal-code" }, 170 { fieldName: "country" }, 171 ], 172 }, 173 { 174 default: { 175 reason: "autocomplete", 176 }, 177 fields: [ 178 { fieldName: "street-address" }, 179 { fieldName: "postal-code" }, 180 { fieldName: "country" }, 181 ], 182 }, 183 ], 184 }, 185 { 186 description: `Fields without section name are merged (test both before and after the section with a name)`, 187 fixtureData: ` 188 <html><body> 189 <input id="name" autocomplete="name"> 190 <input id="street-address" autocomplete="billing street-address"> 191 <input id="postal-code" autocomplete="billing postal-code"> 192 <input id="country" autocomplete="billing country"> 193 <input id="street-address" autocomplete="shipping street-address"> 194 <input id="postal-code" autocomplete="shipping postal-code"> 195 <input id="country" autocomplete="shipping country"> 196 <input id="name" autocomplete="name"> 197 </body></html> 198 `, 199 expectedResult: [ 200 { 201 default: { 202 reason: "autocomplete", 203 addressType: "billing", 204 }, 205 fields: [ 206 { fieldName: "name", addressType: "" }, 207 { fieldName: "street-address" }, 208 { fieldName: "postal-code" }, 209 { fieldName: "country" }, 210 ], 211 }, 212 { 213 default: { 214 reason: "autocomplete", 215 addressType: "shipping", 216 }, 217 fields: [ 218 { fieldName: "street-address" }, 219 { fieldName: "postal-code" }, 220 { fieldName: "country" }, 221 { fieldName: "name", addressType: "" }, 222 ], 223 }, 224 ], 225 }, 226 { 227 description: `Fields without section name are merged, but do not merge if the field already exists`, 228 fixtureData: ` 229 <html><body> 230 <input id="name" autocomplete="name"> 231 <input id="street-address" autocomplete="billing street-address"> 232 <input id="postal-code" autocomplete="billing postal-code"> 233 <input id="country" autocomplete="billing country"> 234 <input id="name" autocomplete="name"> 235 </body></html> 236 `, 237 expectedResult: [ 238 { 239 default: { 240 reason: "autocomplete", 241 addressType: "billing", 242 }, 243 fields: [ 244 { fieldName: "name", addressType: "" }, 245 { fieldName: "street-address" }, 246 { fieldName: "postal-code" }, 247 { fieldName: "country" }, 248 ], 249 }, 250 { 251 fields: [{ fieldName: "name", reason: "autocomplete" }], 252 }, 253 ], 254 }, 255 { 256 description: `Fields without section name are merged (multi-fields)`, 257 fixtureData: ` 258 <html><body> 259 <input id="street-address" autocomplete="billing street-address"> 260 <input id="postal-code" autocomplete="billing postal-code"> 261 <input id="country" autocomplete="billing country"> 262 <input id="email" autocomplete="email"> 263 <input id="email" autocomplete="email"> 264 </body></html> 265 `, 266 expectedResult: [ 267 { 268 default: { 269 reason: "autocomplete", 270 addressType: "billing", 271 }, 272 fields: [ 273 { fieldName: "street-address" }, 274 { fieldName: "postal-code" }, 275 { fieldName: "country" }, 276 { fieldName: "email", addressType: "" }, 277 { fieldName: "email", addressType: "" }, 278 ], 279 }, 280 ], 281 }, 282 { 283 description: `Two sections without name`, 284 fixtureData: ` 285 <html><body> 286 <input id="street-address" autocomplete="street-address"> 287 <input id="postal-code" autocomplete="postal-code"> 288 <input id="country" autocomplete="country"> 289 <input id="street-address" autocomplete="street-address"> 290 <input id="postal-code" autocomplete="postal-code"> 291 <input id="country" autocomplete="country"> 292 </body></html> 293 `, 294 expectedResult: [ 295 { 296 default: { 297 reason: "autocomplete", 298 }, 299 fields: [ 300 { fieldName: "street-address" }, 301 { fieldName: "postal-code" }, 302 { fieldName: "country" }, 303 ], 304 }, 305 { 306 default: { 307 reason: "autocomplete", 308 }, 309 fields: [ 310 { fieldName: "street-address" }, 311 { fieldName: "postal-code" }, 312 { fieldName: "country" }, 313 ], 314 }, 315 ], 316 }, 317 ]);