• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5function getArguments() {
6  // Returns the URL arguments as a dictionary.
7  args = {}
8  var s = location.search;
9  if (s) {
10    var vals = s.substring(1).split('&');
11    for (var i = 0; i < vals.length; i++) {
12      var pair = vals[i].split('=');
13      args[pair[0]] = pair[1];
14    }
15  }
16  return args;
17}
18
19function showSuiteTable(show_the_table) {
20    document.getElementById('suite-table').style.display = (
21        show_the_table ? 'table' : 'none');
22}
23
24function showTestTable(show_the_table) {
25    document.getElementById('test-table').style.display = (
26        show_the_table ? 'table' : 'none');
27}
28
29function showTestsOfOneSuiteOnly(suite_name) {
30  setTitle('Test Results of Suite: ' + suite_name)
31  show_all = (suite_name == 'TOTAL')
32  var testTableBlocks = document.getElementById('test-table')
33      .getElementsByClassName('row_block');
34  Array.prototype.slice.call(testTableBlocks)
35      .forEach(function(testTableBlock) {
36        if (!show_all) {
37          var table_block_in_suite = (testTableBlock.firstElementChild
38            .firstElementChild.firstElementChild.innerHTML)
39            .startsWith(suite_name);
40          if (!table_block_in_suite) {
41            testTableBlock.style.display = 'none';
42            return;
43          }
44        }
45        testTableBlock.style.display = 'table-row-group';
46      });
47  showTestTable(true);
48  showSuiteTable(false);
49  window.scrollTo(0, 0);
50}
51
52function showTestsOfOneSuiteOnlyWithNewState(suite_name) {
53  showTestsOfOneSuiteOnly(suite_name);
54  history.pushState({suite: suite_name}, suite_name, '');
55}
56
57function showSuiteTableOnly() {
58  setTitle('Suites Summary')
59  showTestTable(false);
60  showSuiteTable(true);
61  window.scrollTo(0, 0);
62}
63
64function showSuiteTableOnlyWithReplaceState() {
65  showSuiteTableOnly();
66  history.replaceState({}, 'suite_table', '');
67}
68
69function setBrowserBackButtonLogic() {
70  window.onpopstate = function(event) {
71    if (!event.state || !event.state.suite) {
72      showSuiteTableOnly();
73    } else {
74      showTestsOfOneSuiteOnly(event.state.suite);
75    }
76  };
77}
78
79function setTitle(title) {
80  document.getElementById('summary-header').textContent = title;
81}
82
83function sortByColumn(head) {
84  var table = head.parentNode.parentNode.parentNode;
85  var rowBlocks = Array.prototype.slice.call(
86      table.getElementsByTagName('tbody'));
87
88  // Determine whether to asc or desc and set arrows.
89  var headers = head.parentNode.getElementsByTagName('th');
90  var headIndex = Array.prototype.slice.call(headers).indexOf(head);
91  var asc = -1;
92  for (var i = 0; i < headers.length; i++) {
93    if (headers[i].dataset.ascSorted != 0) {
94      if (headers[i].dataset.ascSorted == 1) {
95          headers[i].getElementsByClassName('up')[0]
96              .style.display = 'none';
97      } else {
98        headers[i].getElementsByClassName('down')[0]
99            .style.display = 'none';
100      }
101      if (headers[i] == head) {
102        asc = headers[i].dataset.ascSorted * -1;
103      } else {
104        headers[i].dataset.ascSorted = 0;
105      }
106      break;
107    }
108  }
109  headers[headIndex].dataset.ascSorted = asc;
110  if (asc == 1) {
111      headers[headIndex].getElementsByClassName('up')[0]
112          .style.display = 'inline';
113  } else {
114      headers[headIndex].getElementsByClassName('down')[0]
115          .style.display = 'inline';
116  }
117
118  // Sort the array by the specified column number (col) and order (asc).
119  rowBlocks.sort(function (a, b) {
120    if (a.style.display == 'none') {
121      return -1;
122    } else if (b.style.display == 'none') {
123      return 1;
124    }
125    var a_rows = Array.prototype.slice.call(a.children);
126    var b_rows = Array.prototype.slice.call(b.children);
127    if (head.className == "text") {
128      // If sorting by text, we only compare the entry on the first row.
129      var aInnerHTML = a_rows[0].children[headIndex].innerHTML;
130      var bInnerHTML = b_rows[0].children[headIndex].innerHTML;
131      return (aInnerHTML == bInnerHTML) ? 0 : (
132          (aInnerHTML > bInnerHTML) ? asc : -1 * asc);
133    } else if (head.className == "number") {
134      // If sorting by number, for example, duration,
135      // we will sum up the durations of different test runs
136      // for one specific test case and sort by the sum.
137      var avalue = 0;
138      var bvalue = 0;
139      a_rows.forEach(function (row, i) {
140        var index = (i > 0) ? headIndex - 1 : headIndex;
141        avalue += Number(row.children[index].innerHTML);
142      });
143      b_rows.forEach(function (row, i) {
144        var index = (i > 0) ? headIndex - 1 : headIndex;
145        bvalue += Number(row.children[index].innerHTML);
146      });
147    } else if (head.className == "flaky") {
148      // Flakiness = (#total - #success - #skipped) / (#total - #skipped)
149      var a_success_or_skipped = 0;
150      var a_skipped = 0;
151      var b_success_or_skipped = 0;
152      var b_skipped = 0;
153      a_rows.forEach(function (row, i) {
154        var index = (i > 0) ? headIndex - 1 : headIndex;
155        var status = row.children[index].innerHTML.trim();
156        if (status == 'SUCCESS') {
157          a_success_or_skipped += 1;
158        }
159        if (status == 'SKIPPED') {
160          a_success_or_skipped += 1;
161          a_skipped += 1;
162        }
163      });
164      b_rows.forEach(function (row, i) {
165        var index = (i > 0) ? headIndex - 1 : headIndex;
166        var status = row.children[index].innerHTML.trim();
167        if (status == 'SUCCESS') {
168          b_success_or_skipped += 1;
169        }
170        if (status == 'SKIPPED') {
171          b_success_or_skipped += 1;
172          b_skipped += 1;
173        }
174      });
175      var atotal_minus_skipped = a_rows.length - a_skipped;
176      var btotal_minus_skipped = b_rows.length - b_skipped;
177
178      var avalue = ((atotal_minus_skipped == 0) ? -1 :
179          (a_rows.length - a_success_or_skipped) / atotal_minus_skipped);
180      var bvalue = ((btotal_minus_skipped == 0) ? -1 :
181          (b_rows.length - b_success_or_skipped) / btotal_minus_skipped);
182    }
183    return asc * (avalue - bvalue);
184  });
185
186  for (var i = 0; i < rowBlocks.length; i++) {
187    table.appendChild(rowBlocks[i]);
188  }
189}
190
191function sortSuiteTableByFailedTestCases() {
192  sortByColumn(document.getElementById('number_fail_tests'));
193}
194