generate.py (3100B)
1 template = '''<!DOCTYPE html> 2 <meta charset="utf-8"> 3 <meta name="timeout" content="long"> 4 <title>Moving script elements between documents</title> 5 <!-- This is generated by tools/generate.py. Do not manually edit. --> 6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#execute-the-script-block"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="resources/moving-between-documents-helper.js"></script> 10 11 <body> 12 <script> 13 runTest("%s", "%s", "%s", "%s", "%s"); 14 </script> 15 ''' 16 17 n = 0 18 for timing in ["before-prepare", "after-prepare", "move-back"]: 19 for destType in ["iframe", "createHTMLDocument"]: 20 for inlineOrExternal in ["inline", "external", "empty-src"]: 21 for result in ["fetch-error", "parse-error", "success"]: 22 for type in ["classic", "module"]: 23 # The |inlineOrExternal| keyword creates a certain kind of script, 24 # and the |result| keyword can influence the generated script in 25 # different ways i.e., giving the script a parse-error, or creating 26 # a script that fails to load. When we're creating an inline script, 27 # it doesn't make sense to test the fetch-error case, so we ignore 28 # this combination, as the server will not react to it in any 29 # meaningful way. 30 if inlineOrExternal == "inline" and result == "fetch-error": 31 continue 32 33 if inlineOrExternal == "empty-src": 34 # The "empty-src" tests aim to exercise #prepare-a-script step 26 35 # substep 2, where the <script> has a src attribute that is empty: 36 # "If src is the empty string, queue a task to fire an event named 37 # error at the element, and return." 38 # Therefore, the server will generate a script that does not have a 39 # "parse-error" or "fetch-error", so we can ignore these combinations. 40 if result != "success": 41 continue 42 43 # The "empty-src" tests check that the parser document <=> node document 44 # check is implemented correctly in #prepare-a-script. Therefore we're 45 # only interested in tests that move the <script> before #prepare-a-script. 46 if timing != "before-prepare": 47 continue 48 49 # The current test helper uses 50 # #has-a-style-sheet-that-is-blocking-scripts to block script 51 # evaluation after #prepare-a-script, but in some cases this 52 # doesn't work: 53 # - inline scripts to createHTMLDocument 54 if timing != "before-prepare" and destType == "createHTMLDocument" and inlineOrExternal == "inline": 55 continue 56 # - module inline scripts https://github.com/whatwg/html/issues/3890 57 if timing != "before-prepare" and inlineOrExternal == "inline" and type == "module": 58 continue 59 60 with open('%s-%s-%s-%s-%s.html' % (timing, destType, result, inlineOrExternal, type), 'w') as f: 61 f.write(template % (timing, destType, result, inlineOrExternal, type))