Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / tests.html
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright (c) 2014 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
7 -->
8 <head>
9   <title>TVCM Tests: loading...</title>
10   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11   <script src="/platform.min.js"></script>
12   <script src="/polymer.min.js"></script>
13
14   <link rel="import" href="/tvcm.html">
15   <link rel="shortcut icon" href="data:image/x-icon;base64," type="image/x-icon">
16   <link rel="import" href="/tvcm/unittest.html">
17   <link rel="import" href="/tvcm/unittest/interactive_test_runner.html">
18   <style>
19     html, body {
20       box-sizing: border-box;
21       width: 100%;
22       height: 100%;
23       overflow: hidden;
24       margin: 0px;
25     }
26     body > x-base-interactive-test-runner {
27       height: 100%;
28       width: 100%;
29     }
30
31   </style>
32 </head>
33 <body>
34   <script>
35     'use strict';
36
37     // The test runner no-ops pushState so keep it around.
38     var realWindowHistoryPushState = window.history.pushState.bind(
39         window.history);
40
41     function stateToSearchString(defaultState, state) {
42       var parts = [];
43       for (var k in state) {
44         if (state[k] === defaultState[k])
45           continue;
46         var v = state[k];
47         var kv;
48         if (v === true) {
49           kv = k;
50         } else if (v === false) {
51           kv = k + '=false';
52         } else if (v === '') {
53           continue;
54         } else {
55           kv = k + '=' + v;
56         }
57         parts.push(kv);
58       }
59       return parts.join('&');
60     }
61
62     function stateFromSearchString(string) {
63       var state = {};
64       string.split('&').forEach(function(part) {
65         if (part == '')
66           return;
67         var kv = part.split('=');
68         var k, v;
69         if (kv.length == 1) {
70           k = kv[0];
71           v = true;
72         } else {
73           k = kv[0];
74           if (kv[1] == 'false')
75             v = false;
76           else
77             v = kv[1];
78         }
79         state[k] = v;
80       });
81       return state;
82     }
83
84     function loadAndRunTests() {
85       var state = stateFromSearchString(
86           window.location.search.substring(1));
87       updateTitle(state);
88
89       var suiteNamesToLoad;
90       if (state.testSuiteName) {
91         suiteNamesToLoad = [];
92         suiteNamesToLoad.push(state.testSuiteName);
93       }
94
95       var loader = new tvcm.unittest.SuiteLoader(suiteNamesToLoad);
96       return loader.allSuitesLoadedPromise.then(
97         function() {
98           runTests(loader, state);
99         },
100         function(err) {
101           tvcm.showPanic('Module loading failure', err);
102         });
103     }
104
105     function updateTitle(state) {
106       var testFilterString = state.testFilterString || '';
107       var testSuiteName = state.testSuiteName || '';
108
109       var title;
110       if (testSuiteName && testFilterString.length) {
111         title = testFilterString + ' in ' + testSuiteName;
112       } else if (testSuiteName) {
113         title = testSuiteName;
114       } else if (testFilterString) {
115         title = testFilterString + ' in all tests';
116       } else {
117         title = 'All TVCM Tests';
118       }
119
120       if (state.shortFormat)
121         title += '(s)';
122       document.title = title;
123       var runner = document.querySelector('x-base-interactive-test-runner');
124       if (runner)
125         runner.title = title;
126     }
127
128     function runTests(loader, state) {
129       var runner = new tvcm.unittest.InteractiveTestRunner();
130       runner.testLinks = loader.testLinks;
131       runner.allTests = loader.getAllTests();
132       document.body.appendChild(runner);
133
134       runner.setState(state);
135       updateTitle(state);
136
137       runner.addEventListener('statechange', function() {
138         var state = runner.getState();
139         var stateString = stateToSearchString(runner.getDefaultState(),
140                                               state);
141         if (window.location.search.substring(1) == stateString)
142           return;
143
144         updateTitle(state);
145         var stateURL;
146         if (stateString.length > 0)
147           stateURL = window.location.pathname + '?' + stateString;
148         else
149           stateURL = window.location.pathname;
150         realWindowHistoryPushState(state, document.title, stateURL);
151       });
152
153       window.addEventListener('popstate', function(state) {
154         runner.setState(state, true);
155       });
156
157       runner.getHRefForTestCase = function(testCase) {
158         var state = runner.getState();
159         state.testSuiteName = testCase.suite.name;
160         state.testFilterString = testCase.name;
161         state.shortFormat = false;
162
163         var stateString = stateToSearchString(runner.getDefaultState(),
164                                               state);
165         if (stateString.length > 0)
166           return window.location.pathname + '?' + stateString;
167         else
168           return window.location.pathname;
169       }
170     }
171
172     window.addEventListener('load', loadAndRunTests);
173
174   </script>
175 </body>
176 </html>