summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/moving-between-documents/resources/slow-flag-setter.py
blob: 20d7ed4bd0d84b7eaa8238b4204e38129a1093dd (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
import time

def main(request, response):
  headers = [(b"Content-Type", b"text/javascript")]

  result = request.GET.first(b"result", b"success")
  if result == b"css":
    time.sleep(3)
    headers = [(b"Content-Type", b"text/css")]
    body = u""
  else:
    time.sleep(2)

    body = u"""
      fetch('exec');
      console.log('exec');
      if (!window.readyToEvaluate) {
        window.didExecute = "executed too early";
      } else {
        window.didExecute = "executed";
      }
    """
    if result == b"parse-error":
      body = u"1=2 parse error;"
    if result == b"fetch-error":
      return 404, [(b'Content-Type', b'text/plain')], u"""window.didExecute = "fetch error";"""

  return headers, body