8d9203b6ba23bb2e1258cc8290d7146e3a3f6187
[WebKit.git] / Websites / perf.webkit.org / public / v3 / remote.js
1 "use strict";
2
3 class BrowserRemoteAPI extends CommonRemoteAPI {
4
5     sendHttpRequest(path, method, contentType, content)
6     {
7         console.assert(!path.startsWith('http:') && !path.startsWith('https:') && !path.startsWith('file:'));
8
9         return new Promise((resolve, reject) => {
10             Instrumentation.startMeasuringTime('Remote', 'sendHttpRequest');
11
12             function onload() {
13                 Instrumentation.endMeasuringTime('Remote', 'sendHttpRequest');
14                 if (xhr.status != 200)
15                     return reject(xhr.status);
16                 resolve({statusCode: xhr.status, responseText: xhr.responseText});
17             };
18
19             function onerror() {
20                 Instrumentation.endMeasuringTime('Remote', 'sendHttpRequest');
21                 reject(xhr.status);
22             }
23
24             const xhr = new XMLHttpRequest;
25             xhr.onload = onload;
26             xhr.onabort = onerror;
27             xhr.onerror = onerror;
28
29             xhr.open(method, path, true);
30             if (contentType)
31                 xhr.setRequestHeader('Content-Type', contentType);
32             if (content)
33                 xhr.send(content);
34             else
35                 xhr.send();
36         });
37     }
38
39     sendHttpRequestWithFormData(path, formData)
40     {
41         return this.sendHttpRequest(path, 'POST', null, formData); // Content-type is set by the browser.
42     }
43
44 }
45
46 const RemoteAPI = new BrowserRemoteAPI;