| 1 |
const kFetchPriorityLowRequestFileNameAndSuffix = "dummy.js?1"; |
| 2 |
const kFetchPriorityHighRequestFileNameAndSuffix = "dummy.js?2"; |
| 3 |
const kFetchPriorityAutoRequestFileNameAndSuffix = "dummy.js?3"; |
| 4 |
const kNoFetchPriorityRequestFileNameAndSuffix = "dummy.js?4"; |
| 5 |
|
| 6 |
// Mapping fetchpriority's values to internal priorities is specified as |
| 7 |
// implementation-defined (https://fetch.spec.whatwg.org/#concept-fetch, step |
| 8 |
// 15). For web-compatibility, Chromium's desired mapping is chosen, see |
| 9 |
// <https://web.dev/articles/fetch-priority#browser_priority_and_fetchpriority>. |
| 10 |
// Exceptions are commented below. |
| 11 |
|
| 12 |
const kExpectedRequestsForScriptsInHead = [ |
| 13 |
{ fileNameAndSuffix: kFetchPriorityLowRequestFileNameAndSuffix, |
| 14 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 15 |
}, |
| 16 |
{ fileNameAndSuffix: kFetchPriorityHighRequestFileNameAndSuffix, |
| 17 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 18 |
}, |
| 19 |
{ fileNameAndSuffix: kFetchPriorityAutoRequestFileNameAndSuffix, |
| 20 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 21 |
}, |
| 22 |
{ fileNameAndSuffix: kNoFetchPriorityRequestFileNameAndSuffix, |
| 23 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 24 |
} |
| 25 |
]; |
| 26 |
|
| 27 |
const kExpectedRequestsForScriptsInHeadDisabled = [ |
| 28 |
{ fileNameAndSuffix: kFetchPriorityLowRequestFileNameAndSuffix, |
| 29 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 30 |
}, |
| 31 |
{ fileNameAndSuffix: kFetchPriorityHighRequestFileNameAndSuffix, |
| 32 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 33 |
}, |
| 34 |
{ fileNameAndSuffix: kFetchPriorityAutoRequestFileNameAndSuffix, |
| 35 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 36 |
}, |
| 37 |
{ fileNameAndSuffix: kNoFetchPriorityRequestFileNameAndSuffix, |
| 38 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 39 |
} |
| 40 |
]; |
| 41 |
|
| 42 |
// TODO(bug 1872654): Should we align on Chromium for "early" in-body scripts? |
| 43 |
const kExpectedRequestsForScriptsInBody = [ |
| 44 |
{ fileNameAndSuffix: "dummy.js?1", |
| 45 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 46 |
}, |
| 47 |
{ fileNameAndSuffix: "dummy.js?2", |
| 48 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 49 |
}, |
| 50 |
{ fileNameAndSuffix: "dummy.js?3", |
| 51 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 52 |
}, |
| 53 |
{ fileNameAndSuffix: "dummy.js?4", |
| 54 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 55 |
}, |
| 56 |
{ fileNameAndSuffix: "dummy.js?5", |
| 57 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 58 |
}, |
| 59 |
{ fileNameAndSuffix: "dummy.js?6", |
| 60 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 61 |
}, |
| 62 |
{ fileNameAndSuffix: "dummy.js?7", |
| 63 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 64 |
}, |
| 65 |
{ fileNameAndSuffix: "dummy.js?8", |
| 66 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 67 |
}, |
| 68 |
{ fileNameAndSuffix: "dummy.js?9", |
| 69 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 70 |
}, |
| 71 |
{ fileNameAndSuffix: "dummy.js?10", |
| 72 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 73 |
}, |
| 74 |
{ fileNameAndSuffix: "dummy.js?11", |
| 75 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 76 |
}, |
| 77 |
{ fileNameAndSuffix: "dummy.js?12", |
| 78 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 79 |
}, |
| 80 |
{ fileNameAndSuffix: "dummy.js?13", |
| 81 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 82 |
}, |
| 83 |
{ fileNameAndSuffix: "dummy.js?14", |
| 84 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 85 |
}, |
| 86 |
{ fileNameAndSuffix: "dummy.js?15", |
| 87 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 88 |
}, |
| 89 |
{ fileNameAndSuffix: "dummy.js?16", |
| 90 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 91 |
}, |
| 92 |
] |
| 93 |
|
| 94 |
const kExpectedRequestsForScriptsInBodyDisabled = [ |
| 95 |
{ fileNameAndSuffix: "dummy.js?1", |
| 96 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 97 |
}, |
| 98 |
{ fileNameAndSuffix: "dummy.js?2", |
| 99 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 100 |
}, |
| 101 |
{ fileNameAndSuffix: "dummy.js?3", |
| 102 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 103 |
}, |
| 104 |
{ fileNameAndSuffix: "dummy.js?4", |
| 105 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 106 |
}, |
| 107 |
{ fileNameAndSuffix: "dummy.js?5", |
| 108 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 109 |
}, |
| 110 |
{ fileNameAndSuffix: "dummy.js?6", |
| 111 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 112 |
}, |
| 113 |
{ fileNameAndSuffix: "dummy.js?7", |
| 114 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 115 |
}, |
| 116 |
{ fileNameAndSuffix: "dummy.js?8", |
| 117 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 118 |
}, |
| 119 |
{ fileNameAndSuffix: "dummy.js?9", |
| 120 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 121 |
}, |
| 122 |
{ fileNameAndSuffix: "dummy.js?10", |
| 123 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 124 |
}, |
| 125 |
{ fileNameAndSuffix: "dummy.js?11", |
| 126 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 127 |
}, |
| 128 |
{ fileNameAndSuffix: "dummy.js?12", |
| 129 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 130 |
}, |
| 131 |
{ fileNameAndSuffix: "dummy.js?13", |
| 132 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 133 |
}, |
| 134 |
{ fileNameAndSuffix: "dummy.js?14", |
| 135 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 136 |
}, |
| 137 |
{ fileNameAndSuffix: "dummy.js?15", |
| 138 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 139 |
}, |
| 140 |
{ fileNameAndSuffix: "dummy.js?16", |
| 141 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 142 |
}, |
| 143 |
] |
| 144 |
|
| 145 |
export const kTestFolderName = "script-tests"; |
| 146 |
|
| 147 |
const kExpectedRequestsForNonModuleAsyncAndDeferredScripts = [ |
| 148 |
{ fileNameAndSuffix: "dummy.js?1", |
| 149 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 150 |
}, |
| 151 |
{ fileNameAndSuffix: "dummy.js?2", |
| 152 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 153 |
}, |
| 154 |
{ fileNameAndSuffix: "dummy.js?3", |
| 155 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 156 |
}, |
| 157 |
{ fileNameAndSuffix: "dummy.js?4", |
| 158 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 159 |
}, |
| 160 |
{ fileNameAndSuffix: "dummy.js?5", |
| 161 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 162 |
}, |
| 163 |
{ fileNameAndSuffix: "dummy.js?6", |
| 164 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 165 |
}, |
| 166 |
{ fileNameAndSuffix: "dummy.js?7", |
| 167 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 168 |
}, |
| 169 |
{ fileNameAndSuffix: "dummy.js?8", |
| 170 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 171 |
}, |
| 172 |
] |
| 173 |
|
| 174 |
const kExpectedRequestsForNonModuleAsyncAndDeferredScriptsDisabled = [ |
| 175 |
{ fileNameAndSuffix: "dummy.js?1", |
| 176 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 177 |
}, |
| 178 |
{ fileNameAndSuffix: "dummy.js?2", |
| 179 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 180 |
}, |
| 181 |
{ fileNameAndSuffix: "dummy.js?3", |
| 182 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 183 |
}, |
| 184 |
{ fileNameAndSuffix: "dummy.js?4", |
| 185 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 186 |
}, |
| 187 |
{ fileNameAndSuffix: "dummy.js?5", |
| 188 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 189 |
}, |
| 190 |
{ fileNameAndSuffix: "dummy.js?6", |
| 191 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 192 |
}, |
| 193 |
{ fileNameAndSuffix: "dummy.js?7", |
| 194 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 195 |
}, |
| 196 |
{ fileNameAndSuffix: "dummy.js?8", |
| 197 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 198 |
}, |
| 199 |
] |
| 200 |
|
| 201 |
// Chromium's desired behavior is under discussion: |
| 202 |
// <https://bugs.chromium.org/p/chromium/issues/detail?id=1475635>. |
| 203 |
const kExpectedRequestsForModuleScripts = [ |
| 204 |
{ fileNameAndSuffix: "dummy.js?1", |
| 205 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 206 |
}, |
| 207 |
{ fileNameAndSuffix: "dummy.js?2", |
| 208 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 209 |
}, |
| 210 |
{ fileNameAndSuffix: "dummy.js?3", |
| 211 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 212 |
}, |
| 213 |
{ fileNameAndSuffix: "dummy.js?4", |
| 214 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 215 |
}, |
| 216 |
{ fileNameAndSuffix: "dummy.js?5", |
| 217 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_LOW |
| 218 |
}, |
| 219 |
{ fileNameAndSuffix: "dummy.js?6", |
| 220 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_HIGH |
| 221 |
}, |
| 222 |
{ fileNameAndSuffix: "dummy.js?7", |
| 223 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 224 |
}, |
| 225 |
{ fileNameAndSuffix: "dummy.js?8", |
| 226 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 227 |
}, |
| 228 |
] |
| 229 |
|
| 230 |
const kExpectedRequestsForModuleScriptsDisabled = [ |
| 231 |
{ fileNameAndSuffix: "dummy.js?1", |
| 232 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 233 |
}, |
| 234 |
{ fileNameAndSuffix: "dummy.js?2", |
| 235 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 236 |
}, |
| 237 |
{ fileNameAndSuffix: "dummy.js?3", |
| 238 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 239 |
}, |
| 240 |
{ fileNameAndSuffix: "dummy.js?4", |
| 241 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 242 |
}, |
| 243 |
{ fileNameAndSuffix: "dummy.js?5", |
| 244 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 245 |
}, |
| 246 |
{ fileNameAndSuffix: "dummy.js?6", |
| 247 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 248 |
}, |
| 249 |
{ fileNameAndSuffix: "dummy.js?7", |
| 250 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 251 |
}, |
| 252 |
{ fileNameAndSuffix: "dummy.js?8", |
| 253 |
internalPriority: SpecialPowers.Ci.nsISupportsPriority.PRIORITY_NORMAL |
| 254 |
}, |
| 255 |
] |
| 256 |
|
| 257 |
export const kTestData = [ |
| 258 |
{ testFileName: "script-initial-load-head.h2.html", |
| 259 |
expectedRequests: kExpectedRequestsForScriptsInHead |
| 260 |
}, |
| 261 |
{ testFileName: "script-initial-load-body.h2.html", |
| 262 |
expectedRequests: kExpectedRequestsForScriptsInBody |
| 263 |
}, |
| 264 |
{ testFileName: "async-script-initial-load.h2.html", |
| 265 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScripts |
| 266 |
}, |
| 267 |
{ testFileName: "deferred-script-initial-load.h2.html", |
| 268 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScripts |
| 269 |
}, |
| 270 |
{ testFileName: "module-script-initial-load.h2.html", |
| 271 |
expectedRequests: kExpectedRequestsForModuleScripts |
| 272 |
}, |
| 273 |
{ testFileName: "async-module-script-initial-load.h2.html", |
| 274 |
expectedRequests: kExpectedRequestsForModuleScripts |
| 275 |
}, |
| 276 |
// Dynamic insertion executes non-speculative-parsing |
| 277 |
// (https://developer.mozilla.org/en-US/docs/Glossary/speculative_parsing) |
| 278 |
// code paths. Moreover such inserted scripts are loaded asynchronously. |
| 279 |
{ testFileName: "script-dynamic-insertion.h2.html", |
| 280 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScripts |
| 281 |
}, |
| 282 |
{ testFileName: "module-script-dynamic-insertion.h2.html", |
| 283 |
expectedRequests: kExpectedRequestsForModuleScripts |
| 284 |
} |
| 285 |
]; |
| 286 |
|
| 287 |
export const kTestDataDisabled = [ |
| 288 |
{ testFileName: "script-initial-load-head.h2.html", |
| 289 |
expectedRequests: kExpectedRequestsForScriptsInHeadDisabled |
| 290 |
}, |
| 291 |
{ testFileName: "script-initial-load-body.h2.html", |
| 292 |
expectedRequests: kExpectedRequestsForScriptsInBodyDisabled |
| 293 |
}, |
| 294 |
{ testFileName: "async-script-initial-load.h2.html", |
| 295 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScriptsDisabled |
| 296 |
}, |
| 297 |
{ testFileName: "deferred-script-initial-load.h2.html", |
| 298 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScriptsDisabled |
| 299 |
}, |
| 300 |
{ testFileName: "module-script-initial-load.h2.html", |
| 301 |
expectedRequests: kExpectedRequestsForModuleScriptsDisabled |
| 302 |
}, |
| 303 |
{ testFileName: "async-module-script-initial-load.h2.html", |
| 304 |
expectedRequests: kExpectedRequestsForModuleScriptsDisabled |
| 305 |
}, |
| 306 |
{ testFileName: "script-dynamic-insertion.h2.html", |
| 307 |
expectedRequests: kExpectedRequestsForNonModuleAsyncAndDeferredScriptsDisabled |
| 308 |
}, |
| 309 |
{ testFileName: "module-script-dynamic-insertion.h2.html", |
| 310 |
expectedRequests: kExpectedRequestsForModuleScriptsDisabled |
| 311 |
} |
| 312 |
]; |