summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/tools/generate.py
blob: 80a655e821b8b07b9f1c85e5b16965ee50da3d2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
template = '''<!DOCTYPE html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Moving script elements between documents</title>
<!-- This is generated by tools/generate.py. Do not manually edit. -->
<link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/moving-between-documents-helper.js"></script>

<body>
<script>
runTest("%s", "%s", "%s", "%s", "%s");
</script>
'''

n = 0
for timing in ["before-prepare", "after-prepare", "move-back"]:
  for destType in ["iframe", "createHTMLDocument"]:
    for inlineOrExternal in ["inline", "external", "empty-src"]:
      for result in ["fetch-error", "parse-error", "success"]:
        for type in ["classic", "module"]:
            # The |inlineOrExternal| keyword creates a certain kind of script,
            # and the |result| keyword can influence the generated script in
            # different ways i.e., giving the script a parse-error, or creating
            # a script that fails to load. When we're creating an inline script,
            # it doesn't make sense to test the fetch-error case, so we ignore
            # this combination, as the server will not react to it in any
            # meaningful way.
          if inlineOrExternal == "inline" and result == "fetch-error":
            continue

          if inlineOrExternal == "empty-src":
            # The "empty-src" tests aim to exercise #prepare-a-script step 26
            # substep 2, where the <script> has a src attribute that is empty:
            #   "If src is the empty string, queue a task to fire an event named
            #    error at the element, and return."
            # Therefore, the server will generate a script that does not have a
            # "parse-error" or "fetch-error", so we can ignore these combinations.
            if result != "success":
              continue

            # The "empty-src" tests check that the parser document <=> node document
            # check is implemented correctly in #prepare-a-script. Therefore we're
            # only interested in tests that move the <script> before #prepare-a-script.
            if timing != "before-prepare":
              continue

          # The current test helper uses
          # #has-a-style-sheet-that-is-blocking-scripts to block script
          # evaluation after #prepare-a-script, but in some cases this
          # doesn't work:
          # - inline scripts to createHTMLDocument
          if timing != "before-prepare" and destType == "createHTMLDocument" and inlineOrExternal == "inline":
            continue
          # - module inline scripts https://github.com/whatwg/html/issues/3890
          if timing != "before-prepare" and inlineOrExternal == "inline" and type == "module":
            continue

          with open('%s-%s-%s-%s-%s.html' % (timing, destType, result, inlineOrExternal, type), 'w') as f:
            f.write(template % (timing, destType, result, inlineOrExternal, type))