2fe6d290a31481ee37817c97f7905f66eca06278
[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>All TVCM Tests</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     function loadAndRunTests() {
36       var loader = new tvcm.unittest.SuiteLoader();
37       return loader.allSuitesLoadedPromise.then(function() {
38         var results = new tvcm.unittest.InteractiveTestRunner();
39         results.testLinks = loader.testLinks;
40         results.allTests = loader.getAllTests();
41         document.body.appendChild(results);
42
43         results.setState(stateFromSearchString(
44             window.location.search.substring(1)));
45
46         function stateToSearchString(defaultState, state) {
47           var parts = [];
48           for (var k in state) {
49             if (state[k] === defaultState[k])
50               continue;
51             var v = state[k];
52             var kv;
53             if (v === true) {
54               kv = k;
55             } else if (v === false) {
56               kv = k + '=false';
57             } else if (v === '') {
58               debugger;
59               continue;
60             } else {
61               kv = k + '=' + v;
62             }
63             parts.push(kv);
64           }
65           return parts.join('&');
66         }
67
68         function stateFromSearchString(string) {
69           var state = {};
70           string.split('&').forEach(function(part) {
71             if (part == '')
72               return;
73             var kv = part.split('=');
74             var k, v;
75             if (kv.length == 1) {
76               k = kv[0];
77               v = true;
78             } else {
79               k = kv[0];
80               if (kv[1] == 'false')
81                 v = false;
82               else
83                 v = kv[1];
84             }
85             state[k] = v;
86           });
87           return state;
88         }
89
90         results.addEventListener('statechange', function() {
91           debugger;
92           var state = results.getState();
93           var stateString = stateToSearchString(results.getDefaultState(),
94                                                 state);
95           if (window.location.search == stateString)
96             return;
97           var stateURL;
98           if (stateString.length > 0)
99             stateURL = window.location.pathname + '?' + stateString;
100           else
101             stateURL = window.location.pathname;
102           window.history.pushState(state, document.title, stateURL);
103         });
104
105         window.addEventListener('popstate', function(state) {
106           results.setState(state);
107         });
108
109         results.getHRefForTestCase = function(testCase) {
110           var state = results.getState();
111           state.testFilterString = testCase.fullyQualifiedName;
112           state.shortFormat = false;
113
114           var stateString = stateToSearchString(results.getDefaultState(),
115                                                 state);
116           if (stateString.length > 0)
117             return window.location.pathname + '?' + stateString;
118           else
119             return window.location.pathname;
120         }
121       });
122     }
123
124     window.addEventListener('load', loadAndRunTests);
125
126   </script>
127 </body>
128 </html>