Adopt custom elements API in perf dashboard
[WebKit-https.git] / Websites / perf.webkit.org / browser-tests / index.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <link rel="stylesheet" href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css">
5 <script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.js"></script>
6 <script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.min.js"></script>
7 <script>
8
9 mocha.setup('bdd');
10
11 </script>
12 </head>
13 <body>
14 <div id="mocha"></div>
15 <script src="component-base-tests.js"></script>
16 <script>
17
18 afterEach(() => {
19     BrowsingContext.cleanup();
20 });
21
22 class BrowsingContext {
23
24     constructor()
25     {
26         let iframe = document.createElement('iframe');
27         document.body.appendChild(iframe);
28         iframe.style.position = 'absolute';
29         iframe.style.left = '0px';
30         iframe.style.top = '0px';
31         BrowsingContext._iframes.push(iframe);
32
33         this._iframe = iframe;
34         this.symbols = {};
35         this.global = this._iframe.contentWindow;
36         this.document = this._iframe.contentDocument;
37     }
38
39     importScript(path, ...symbolList)
40     {
41         const doc = this._iframe.contentDocument;
42         const global = this._iframe.contentWindow;
43         return new Promise((resolve, reject) => {
44             let script = doc.createElement('script');
45             script.addEventListener('load', resolve);
46             script.addEventListener('error', reject);
47             script.src = path;
48             doc.body.appendChild(script);
49         }).then(() => {
50             const script = doc.createElement('script');
51             script.textContent = `window.importedSymbols = [${symbolList.join(', ')}];`;
52             doc.body.appendChild(script);
53
54             const importedSymbols = global.importedSymbols;
55             for (let i = 0; i < symbolList.length; i++)
56                 this.symbols[symbolList[i]] = importedSymbols[i];
57
58             return symbolList.length == 1 ? importedSymbols[0] : importedSymbols;
59         });
60     }
61
62     static cleanup()
63     {
64         BrowsingContext._iframes.forEach((iframe) => { iframe.remove(); });
65         BrowsingContext._iframes = [];
66     }
67
68     static createWithScripts(scriptList)
69     {
70         let iframe = document.createElement('iframe');
71         document.body.appendChild(iframe);
72         const doc = iframe.contentDocument;
73
74         let symbolList = [];
75         return Promise.all(scriptList.map((entry) => {
76             let [path, ...symbols] = entry;
77             symbolList = symbolList.concat(symbols);
78             return new Promise((resolve, reject) => {
79                 let script = doc.createElement('script');
80                 script.addEventListener('load', resolve);
81                 script.addEventListener('error', reject);
82                 script.src = path;
83                 doc.body.appendChild(script);
84             });
85         })).then(() => {
86             const script = doc.createElement('script');
87             script.textContent = `var symbols = { ${symbolList.join(', ')} };`;
88             doc.body.appendChild(script);
89             return iframe.contentWindow;
90         });
91     }
92 }
93 BrowsingContext._iframes = [];
94
95 mocha.checkLeaks();
96 mocha.globals(['expect', 'BrowsingContext']);
97 mocha.run();
98
99 </script>
100 </body>
101 </html>