summaryrefslogtreecommitdiff
path: root/tooling/talertest/selenium/testhost.html
blob: 01641547d205848314aacee9ccc56787492816f7 (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
62
63
<!doctype html>
<html>
  <head>
    <title>Browser Test Host</title>

    <script src="/testlib/selenium/esprima.js"></script>
    <script src="/testlib/selenium/escodegen.browser.js"></script>
    <script src="/testlib/selenium/instrumenter.js"></script>

    <script src="/src/vendor/URI.js"></script>

    <!-- for instrumentation to work, we have to use the non-csp version -->
    <script src="/testlib/selenium/system.js"></script>

  </head>
  <body>
    <script>
    document.body.appendChild(document.createTextNode(`starting test`));
    document.body.appendChild(document.createElement("br"));

    var requestCoverage = false;

    let parser = document.createElement('a');

    let oldTranslate = System.translate.bind(System);
    System.translate = (load) => {
      let srcP = oldTranslate(load);
      if (!requestCoverage) {
        return srcP;
      }

      parser.href = load.name;
      let modName = parser.pathname.substring(1);

      if (/.*\/?taler-emscripten-lib.js/.test(load.name)) {
        // don't instrument emscripten
        document.body.appendChild(document.createTextNode(`not instrumenting ${modName}`));
        document.body.appendChild(document.createElement("br"));
        return srcP;
      }

      let inst = new Instrumenter();
      document.body.appendChild(document.createTextNode(`instrumenting ${modName}`));
      document.body.appendChild(document.createElement("br"));

      return Promise.resolve(srcP).then((src) => {
        return inst.instrumentSync(src, modName);
      });
    }

    System.config({
        baseURL: "/",
        defaultJSExtensions: true,
        meta: {
          "src/emscripten/taler-emscripten-lib": {
            format: "global",
            exports: "Module",
          },
        },
    });
    </script>
  </body>
</html>