1# Types around the generator and generated tests 2 3This document describes types and concepts used across JavaScript and Python parts of this test framework. 4Please refer to the JSDoc in `common.sub.js` or docstrings in Python scripts (if any). 5 6## Scenario 7 8### Properties 9 10- All keys of `test_expansion_schema` in `spec.src.json`, except for `expansion`, `delivery_type`, `delivery_value`, and `source_context_list`. Their values are **string**s specified in `test_expansion_schema`. 11- `source_context_list` 12- `subresource_policy_deliveries` 13 14### Types 15 16- Generator (`spec.src.json`): JSON object 17- Generator (Python): `dict` 18- Runtime (JS): JSON object 19- Runtime (Python): N/A 20 21## `PolicyDelivery` 22 23### Types 24 25- Generator (`spec.src.json`): JSON object 26- Generator (Python): `util.PolicyDelivery` 27- Runtime (JS): JSON object (`@typedef PolicyDelivery` in `common.sub.js`) 28- Runtime (Python): N/A 29 30## `SourceContext` 31 32Subresource requests can be possibly sent from various kinds of fetch client's environment settings objects. For example: 33 34- top-level windows, 35- `<iframe>`s, or 36- `WorkerGlobalScope`s. 37 38A **`SourceContext`** object specifies one environment settings object, and an Array of `SourceContext` specifies a possibly nested context, from the outer-most to inner-most environment settings objects. 39 40Note: The top-level document is processed and trimmed by the generator, and is not included in the `sourceContextList` field of `Scenario` in the generated output. 41 42For example, `[{sourceContextType: "srcdoc"}, {sourceContextType: "worker-classic"}]` means that a subresource request is to be sent from a classic dedicated worker created from `<iframe srcdoc>` inside the top-level HTML Document. 43 44Note: A `SourceContext` (or an array of `SourceContext`) is set based on the fetch client's settings object that is used for the subresource fetch, NOT on the module map settings object nor on the inner-most settings object that appears in the test. 45For example, the `sourceContextList` field of `Scenario` is `[]` (indicating the top-level Window): 46 47- When testing top-level worker script fetch, e.g. `new Worker('worker.js')`. There is `WorkerGlobalScope` created from `worker.js`, but it isn't the fetch client's settings object used for fetching `worker.js` itself. 48- When testing worker script imported from the root worker script, e.g. `new Worker('top.js', {type: 'module'})` where `top.js` has `import 'worker.js'`. Again, the fetch client's settings object used for `worker.js` is the top-level Window, not `WorkerGlobalScope` created by `top.js`. 49 50### Properties 51 52- `sourceContextType`: A string specifying the kind of the source context to be used. 53 Valid values are the keys of `sourceContextMap` in `common.sub.js`, or `"top"` indicating the top-level Document (`"top"` is valid/used only in the generator). 54 55- `policyDeliveries`: A list of `PolicyDelivery` applied to the source context. 56 57### Types 58 59- Generator (`spec.src.json`): JSON object 60- Generator (Python): `util.SourceContext` 61- Runtime (JS): JSON object (`@typedef SourceContext` in `common.sub.js`) 62- Runtime (Python): N/A 63