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