Upstream version 10.38.222.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Tools / TestResultServer / static-dashboards / overview_unittests.js
1 // Copyright (C) 2013 Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //         * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //         * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //         * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 module('overview');
30
31 test('getFlakyData', 2, function() {
32     var testTypes = ['MockTestType'];
33
34     var failureMap = {
35         'T': 'TIMEOUT',
36         'C': 'CRASH',
37         'P': 'PASS'
38     }
39
40     var resultsByTestType = {
41         'MockTestType': {
42             'MockBuilder1': {
43                 'tests': {
44                     'TestSuite.NotFlaky': {
45                         'results': [[1, 'T'], [1, 'C']]
46                     },
47                     'TestSuite.Flaky': {
48                         'results': [[1, 'T'], [1, 'C'], [1, 'T']]
49                     },
50                     'TestSuite.VeryFlaky': {
51                         'results': [[1, 'T'], [1, 'C'], [1, 'T'], [1, 'C'], [1, 'T'], [1, 'C'], [1, 'T']]
52                     }
53                 },
54                 'num_failures_by_type': {
55                     'PASS': [10, 12],
56                     'CRASH': [1, 0]
57                 },
58                 'failure_map': failureMap
59             }
60         }
61     };
62
63     var flipCountThreshold = 1;
64     deepEqual(overview._getFlakyData(testTypes, resultsByTestType, flipCountThreshold), {
65         'MockTestType': {
66             "flakyBelowThreshold": {
67                 "TestSuite.Flaky": true,
68                 "TestSuite.VeryFlaky": true
69             },
70             'flaky': {
71                 'TestSuite.Flaky': true,
72                 'TestSuite.VeryFlaky': true
73             },
74             'testCount': 11
75         }
76     })
77
78
79     flipCountThreshold = 5;
80     deepEqual(overview._getFlakyData(testTypes, resultsByTestType, flipCountThreshold), {
81         'MockTestType': {
82             "flakyBelowThreshold": {
83                 "TestSuite.VeryFlaky": true
84             },
85             'flaky': {
86                 "TestSuite.Flaky": true,
87                 'TestSuite.VeryFlaky': true
88             },
89             'testCount': 11
90         }
91     })
92 });
93
94 test('htmlForFlakyTests', 6, function() {
95     var flakyData = {
96         'browser_tests': {
97             'testCount': 0,
98             "flakyBelowThreshold": {},
99             'flaky': {}
100         },
101         'layout-tests': {
102             'testCount': 4,
103             "flakyBelowThreshold": {
104                 'css3/foo.html': true,
105                 'css3/bar.html': true
106             },
107             'flaky': {
108                 'css3/foo.html': true,
109                 'css3/bar.html': true
110             }
111         }
112     }
113
114     var container = document.createElement('div');
115     container.innerHTML = overview._htmlForFlakyTests(flakyData, 'MockGroup');
116
117     // There should only be one row other than the header since browser_tests
118     // have testCount of 0.
119     ok(!container.querySelectorAll('tr')[2]);
120
121     var firstRow = container.querySelectorAll('tr')[1];
122     equal(firstRow.querySelector('td:nth-child(1)').textContent, 'layout-tests');
123     equal(firstRow.querySelector('td:nth-child(1) a').hash, '#group=MockGroup&testType=layout-tests&tests=css3/foo.html,css3/bar.html');
124     equal(firstRow.querySelector('td:nth-child(2)').textContent, '2 / 4');
125     equal(firstRow.querySelector('td:nth-child(3)').textContent, '50%');
126     equal(firstRow.querySelector('td:nth-child(4)').innerHTML, '<div class="flaky-bar" style="width:250px"></div>');
127 });
128
129 test('handleValidHashParameter', 5, function() {
130     var historyInstance = new history.History();
131
132     ok(overview.handleValidHashParameter(historyInstance, 'flipCount', "5"))
133     ok(overview.handleValidHashParameter(historyInstance, 'flipCount', 5))
134     ok(!overview.handleValidHashParameter(historyInstance, 'flipCount', "notanumber"))
135     ok(!overview.handleValidHashParameter(historyInstance, 'flipCount', "5notanumber"))
136     ok(!overview.handleValidHashParameter(historyInstance, 'randomKey', "5"))
137 });
138
139 test('navbar', 3, function() {
140     var flipCount = 5;
141     var container = document.createElement('div');
142     container.innerHTML = overview._htmlForNavBar(flipCount);
143
144     ok(container.querySelector('select'));
145
146     var sliderContainer = container.querySelector('#flip-slider-container');
147     ok(sliderContainer);
148
149     var range = sliderContainer.querySelector('input');
150     equal(range.value, "5");
151 });