summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/tools/wave/www/newsession.html
blob: 0ff308c8b4b23802b530674b6a8214d45c4ae975 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>New Session - Web Platform Test Runner</title>
    <link rel="stylesheet" href="css/bulma-0.7.5/bulma.min.css" />
    <link rel="stylesheet" href="css/style.css" />
    <link rel="stylesheet" href="css/main.css" />
    <script src="lib/davidshimjs/qrcode.js"></script>
    <script src="lib/keycodes.js"></script>
    <script src="lib/wave-service.js"></script>
  </head>
  <body>
    <section class="section">
      <div class="container site-header">
        <img src="res/wavelogo_2016.jpg" alt="WAVE Logo" class="site-logo" />
        <h1 class="title is-spaced">New Session</h1>
      </div>

      <div class="container">
        <div id="content">
          <div id="qr-code"></div>
          <br />
          <p>
            Scan QR Code OR visit
            <a
              id="results-page-url"
              style="font-weight: bold; color: #23d160;"
              target="_blank"
            ></a>
            and follow instructions
          </p>
          <div id="button-wrapper">
            <button
              id="start-button"
              class="button is-large is-success tabbable"
            >
              Start
            </button>
            <button
              id="results-button"
              class="button is-large is-light tabbable"
            >
              View Result Page
            </button>
          </div>

          <div>(Alternatively to start the test you can just press Return)</div>

          <div id="details-wrapper">
            <h3 class="title is-5 is-spaced">Details</h3>
            <div class="detail">
              <div>Token:</div>
              <div id="token"></div>
            </div>
            <div class="detail">
              <div>User Agent:</div>
              <div id="user-agent"></div>
            </div>
            <div class="detail">
              <div>Test Types:</div>
              <div id="test-types"></div>
            </div>
            <div class="detail">
              <div>Total Test Files:</div>
              <div id="total-tests"></div>
            </div>
            <div class="detail">
              <div>Reference Tokens:</div>
              <div id="reference-tokens"></div>
            </div>
            <div class="detail">
              <div>Test Timeouts:</div>
              <div id="test-timeout"></div>
            </div>
            <div class="detail">
              <div>Test Paths:</div>
              <div id="test-path"></div>
            </div>
          </div>
        </div>
      </div>
    </section>

    <script>
      var HOSTNAME = location.hostname;
      var PORT = location.port;
      var PROTOCOL = location.protocol.replace(/:/, "");
      var QUERY = location.search.replace(/\?/, "");
      var match = QUERY.match(/token=([^&]+)/);
      var TOKEN = match ? match[1] : null;
      var RESUME = /[\?&]resume=/.test(location.search);
      if (TOKEN)
        document.cookie = "resume_token=" + TOKEN + "; expires=Fri, 31 Dec 9999 23:59:59 GMT";
      var selectedTabbable = -1;

      document.onload = function() {
        if (RESUME) {
          document.getElementById("start-button").innerHTML = "Resume";
          document.getElementById("new-button").style.display = "block";
        }
        document.getElementById("results-page-url").innerHTML =
          "http://" + location.host + WEB_ROOT + "overview.html";
        document.getElementById("results-page-url").href =
          "http://" + location.host + WEB_ROOT + "overview.html";
      };

      function displaySessionConfiguration(configuration) {
        var userAgent = document.getElementById("user-agent");
        userAgent.innerText = configuration.userAgent;
        var testPath = document.getElementById("test-path");
        for (var i = 0; i < configuration.tests.include.length; i++) {
          var path = configuration.tests.include[i];
          testPath.innerText += path + "\n";
        }
        var testTypes = document.getElementById("test-types");
        testTypes.innerText = configuration.types.join(", ");
        var testTimeout = document.getElementById("test-timeout");
        for (var timeout in configuration.timeouts) {
          testTimeout.innerText +=
            timeout + ": " + configuration.timeouts[timeout] / 1000 + "s\n";
        }
        var referenceTokens = document.getElementById("reference-tokens");
        if (configuration.referenceTokens.length === 0) {
          referenceTokens.innerText = "none";
        } else {
          for (var i = 0; i < configuration.referenceTokens.length; i++) {
            var token = configuration.referenceTokens[i];
            referenceTokens.innerText += token + "\n";
          }
        }
      }

      function displaySessionStatus(status) {
        var testTypes = document.getElementById("total-tests");
        var count = 0;
        for (var api in status.testFilesCount) {
          count += status.testFilesCount[api];
        }
        testTypes.innerText = count;
      }

      function startTests() {
        WaveService.startSession(token, function() {
          WaveService.readNextTest(token, function(url) {
            location.href = url;
          });
        });
      }

      var resultsUrl =
        "http://" + location.host + WEB_ROOT + "results.html" + location.search;
      new QRCode(document.getElementById("qr-code"), resultsUrl);

      var resultsButton = document.getElementById("results-button");
      resultsButton.onclick = function() {
        window.open(resultsUrl, "_blank");
      };

      var startButton = document.getElementById("start-button");
      startButton.onclick = startTests;

      function removeClass(element, className) {
        var elementClass = element.className;
        var index = elementClass.indexOf(className);
        if (index !== -1) {
          element.className = elementClass.replace(className, "");
        }
      }

      function addClass(element, className) {
        element.className += " " + className;
      }

      function skipFocus(steps) {
        var tabbables = document.getElementsByClassName("tabbable");
        if (selectedTabbable === -1) {
          selectedTabbable = 0;
        } else {
          removeClass(tabbables[selectedTabbable], "focused");
          selectedTabbable += steps;
        }

        if (selectedTabbable >= tabbables.length) {
          selectedTabbable = 0;
        }

        if (selectedTabbable < 0) {
          selectedTabbable = tabbables.length - 1;
        }

        tabbables[selectedTabbable].focus();
        addClass(tabbables[selectedTabbable], "focused");
      }

      function focusNext() {
        skipFocus(1);
      }

      function focusPrevious() {
        skipFocus(-1);
      }

      document.onkeydown = function(event) {
        event = event || window.event;
        var charCode =
          typeof event.which === "number" ? event.which : event.keyCode;

        if (ACTION_KEYS.indexOf(charCode) !== -1) {
          event.preventDefault();
          if (selectedTabbable === -1) {
            startTests();
            return;
          }
          var tabbables = document.getElementsByClassName("tabbable");
          var element = tabbables[selectedTabbable];
          if (element.type === "checkbox") {
            element.checked = !element.checked;
          } else {
            element.click();
          }
        }

        if (PREV_KEYS.indexOf(charCode) !== -1) {
          focusPrevious();
        }

        if (NEXT_KEYS.indexOf(charCode) !== -1) {
          focusNext();
        }
      };

      var match = location.search.match(/token=([^&]+)/);
      var token = match[1];
      var tokenView = document.getElementById("token");
      tokenView.innerText = token;

      WaveService.readSession(token, displaySessionConfiguration);
      WaveService.readSessionStatus(token, displaySessionStatus);

      if (window.localStorage) {
        var storage = window.localStorage;
        var state = JSON.parse(storage.getItem("wave"));
        if (!state) {
          state = {};
        }
        if (!state.recent_sessions) {
          state.recent_sessions = [];
        }
        if (state.recent_sessions.indexOf(token) === -1) {
          state.recent_sessions.unshift(token);
        }
        storage.setItem("wave", JSON.stringify(state));
      }
    </script>
  </body>
</html>