Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / unittest / test_case.js
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 tvcm.require('tvcm.guid');
8 tvcm.require('tvcm.unittest.constants');
9
10 tvcm.exportTo('tvcm.unittest', function() {
11   var TestTypes = tvcm.unittest.TestTypes;
12
13   function TestCase(suite, testType, name, test, options) {
14     this.guid_ = tvcm.GUID.allocate();
15     this.suite_ = suite;
16     this.testType_ = testType;
17     this.name_ = name;
18
19     this.options_ = options;
20
21     this.test_ = test;
22   }
23
24   TestCase.parseFullyQualifiedName = function(fqn) {
25     var i = fqn.lastIndexOf('.');
26     if (i == -1)
27       throw new Error('FullyQualifiedNames must have a period in them');
28     return {
29       suiteName: fqn.substr(0, i),
30       testCaseName: fqn.substr(i + 1)
31     };
32   };
33
34   TestCase.prototype = {
35     __proto__: Object.prototype,
36
37     get guid() {
38       return this.guid;
39     },
40
41     get suite() {
42       return this.suite_;
43     },
44
45     get testType() {
46       return this.testType_;
47     },
48
49     get name() {
50       return this.name_;
51     },
52
53     get fullyQualifiedName() {
54       return this.suite_.name + '.' + this.name_;
55     },
56
57     get options() {
58       return this.options_;
59     },
60
61     run: function(htmlHook) {
62       return this.test_();
63     },
64
65     // TODO(nduca): The routing of this is a bit awkward. Probably better
66     // to install a global function.
67     addHTMLOutput: function(element) {
68       tvcm.unittest.addHTMLOutputForCurrentTest(element);
69     }
70   };
71
72   function PerfTestCase(suite, name, test, options) {
73     TestCase.call(this, suite, TestTypes.PERFTEST, name, test, options);
74   }
75
76   PerfTestCase.prototype = {
77     __proto__: TestCase.prototype
78   };
79
80   return {
81     TestCase: TestCase,
82     PerfTestCase: PerfTestCase
83   };
84 });