Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / unittest / module_test_case_runner.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/module_test_case_backend.html</title>
10   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11   <script src="/polymer.js"></script>
12   <link rel="import" href="/tvcm/unittest.html">
13   <link rel="import" href="/tvcm/unittest/text_test_results.html">
14   <link rel="import" href="/tvcm/unittest/suite_loader.html">
15   <link rel="import" href="/tvcm/unittest/test_runner.html">
16 </head>
17 <body>
18   <h1 id="status">
19   </h1>
20   <script>
21     'use strict';
22     /**
23      * Polled by tvcm.module_test_case
24      */
25     window.__readyToRun = false;
26
27     var statusEl = document.querySelector('#status');
28     function discoverTestsInModules(testModuleNames) {
29       statusEl.textContent = 'Discovering tests...';
30       var loader = new tvcm.unittest.SuiteLoader(testModuleNames);
31       return loader.allSuitesLoadedPromise.then(function() {
32         return loader.getAllTests().filter(function(test) {
33           return test.testType == tvcm.unittest.TestTypes.UNITTEST;
34         }).map(function(test) {
35           statusEl.textContent = 'Idle';
36           return test.fullyQualifiedName;
37         });
38       });
39     }
40
41     function runTestNamed(fullyQualifiedTestName) {
42       statusEl.textContent = 'Running ' + fullyQualifiedTestName;
43       function cleanup() {
44         statusEl.textContent = '';
45       }
46       return _runTestNamedImpl(fullyQualifiedTestName).then(
47         cleanup, cleanup);
48     }
49
50     function _runTestNamedImpl(fullyQualifiedTestName) {
51       var p = tvcm.unittest.TestCase.parseFullyQualifiedName(
52           fullyQualifiedTestName);
53       var suiteNameToLoad = p.suiteName;
54       var testCaseNameToRun = p.testCaseName;
55
56       var runTestResolver;
57       var runTestPromise = new Promise(function(resolve, reject) {
58         runTestResolver = {
59           resolve: resolve,
60           reject: reject
61         };
62       });
63
64       var loader = new tvcm.unittest.SuiteLoader([suiteNameToLoad]);
65       loader.allSuitesLoadedPromise.then(
66         beginRunningTestCase,
67         loadSuiteFailed);
68
69       var results = new tvcm.unittest.TextTestResults();
70       function loadSuiteFailed(e) {
71         var normalizedException = tvcm.normalizeException(e);
72         runTestResolver.reject(e);
73       }
74
75       function beginRunningTestCase() {
76         var testCase = loader.findTestWithFullyQualifiedName(
77             fullyQualifiedTestName);
78         var runner = new tvcm.unittest.TestRunner(results, [testCase]);
79         runner.beginRunning();
80         return runner.runCompletedPromise.then(
81           runTestCaseComplete,
82           runTestCaseComplete);
83       }
84
85       function runTestCaseComplete() {
86         if (results.numTestsThatFailed === 0) {
87           runTestResolver.resolve();
88           return;
89         }
90
91         runTestResolver.reject(results.buffer);
92       }
93       return runTestPromise;
94     }
95
96     window.addEventListener('load', function() {
97       window.__readyToRun = true;
98     });
99   </script>
100 </body>
101 </html>