summaryrefslogtreecommitdiff
path: root/deps/v8/build/android/pylib/results/presentation/javascript/main_html.js
blob: 76f22f09d5b3bf1d5a6d53a8a6d4119596120c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function getArguments() {
  // Returns the URL arguments as a dictionary.
  args = {}
  var s = location.search;
  if (s) {
    var vals = s.substring(1).split('&');
    for (var i = 0; i < vals.length; i++) {
      var pair = vals[i].split('=');
      args[pair[0]] = pair[1];
    }
  }
  return args;
}

function showSuiteTable(show_the_table) {
    document.getElementById('suite-table').style.display = (
        show_the_table ? 'table' : 'none');
}

function showTestTable(show_the_table) {
    document.getElementById('test-table').style.display = (
        show_the_table ? 'table' : 'none');
}

function showTestsOfOneSuiteOnly(suite_name) {
  setTitle('Test Results of Suite: ' + suite_name)
  show_all = (suite_name == 'TOTAL')
  var testTableBlocks = document.getElementById('test-table')
      .getElementsByClassName('row_block');
  Array.prototype.slice.call(testTableBlocks)
      .forEach(function(testTableBlock) {
        if (!show_all) {
          var table_block_in_suite = (testTableBlock.firstElementChild
            .firstElementChild.firstElementChild.innerHTML)
            .startsWith(suite_name);
          if (!table_block_in_suite) {
            testTableBlock.style.display = 'none';
            return;
          }
        }
        testTableBlock.style.display = 'table-row-group';
      });
  showTestTable(true);
  showSuiteTable(false);
  window.scrollTo(0, 0);
}

function showTestsOfOneSuiteOnlyWithNewState(suite_name) {
  showTestsOfOneSuiteOnly(suite_name);
  history.pushState({suite: suite_name}, suite_name, '');
}

function showSuiteTableOnly() {
  setTitle('Suites Summary')
  showTestTable(false);
  showSuiteTable(true);
  window.scrollTo(0, 0);
}

function showSuiteTableOnlyWithReplaceState() {
  showSuiteTableOnly();
  history.replaceState({}, 'suite_table', '');
}

function setBrowserBackButtonLogic() {
  window.onpopstate = function(event) {
    if (!event.state || !event.state.suite) {
      showSuiteTableOnly();
    } else {
      showTestsOfOneSuiteOnly(event.state.suite);
    }
  };
}

function setTitle(title) {
  document.getElementById('summary-header').textContent = title;
}

function sortByColumn(head) {
  var table = head.parentNode.parentNode.parentNode;
  var rowBlocks = Array.prototype.slice.call(
      table.getElementsByTagName('tbody'));

  // Determine whether to asc or desc and set arrows.
  var headers = head.parentNode.getElementsByTagName('th');
  var headIndex = Array.prototype.slice.call(headers).indexOf(head);
  var asc = -1;
  for (var i = 0; i < headers.length; i++) {
    if (headers[i].dataset.ascSorted != 0) {
      if (headers[i].dataset.ascSorted == 1) {
          headers[i].getElementsByClassName('up')[0]
              .style.display = 'none';
      } else {
        headers[i].getElementsByClassName('down')[0]
            .style.display = 'none';
      }
      if (headers[i] == head) {
        asc = headers[i].dataset.ascSorted * -1;
      } else {
        headers[i].dataset.ascSorted = 0;
      }
      break;
    }
  }
  headers[headIndex].dataset.ascSorted = asc;
  if (asc == 1) {
      headers[headIndex].getElementsByClassName('up')[0]
          .style.display = 'inline';
  } else {
      headers[headIndex].getElementsByClassName('down')[0]
          .style.display = 'inline';
  }

  // Sort the array by the specified column number (col) and order (asc).
  rowBlocks.sort(function (a, b) {
    if (a.style.display == 'none') {
      return -1;
    } else if (b.style.display == 'none') {
      return 1;
    }
    var a_rows = Array.prototype.slice.call(a.children);
    var b_rows = Array.prototype.slice.call(b.children);
    if (head.className == "text") {
      // If sorting by text, we only compare the entry on the first row.
      var aInnerHTML = a_rows[0].children[headIndex].innerHTML;
      var bInnerHTML = b_rows[0].children[headIndex].innerHTML;
      return (aInnerHTML == bInnerHTML) ? 0 : (
          (aInnerHTML > bInnerHTML) ? asc : -1 * asc);
    } else if (head.className == "number") {
      // If sorting by number, for example, duration,
      // we will sum up the durations of different test runs
      // for one specific test case and sort by the sum.
      var avalue = 0;
      var bvalue = 0;
      a_rows.forEach(function (row, i) {
        var index = (i > 0) ? headIndex - 1 : headIndex;
        avalue += Number(row.children[index].innerHTML);
      });
      b_rows.forEach(function (row, i) {
        var index = (i > 0) ? headIndex - 1 : headIndex;
        bvalue += Number(row.children[index].innerHTML);
      });
    } else if (head.className == "flaky") {
      // Flakiness = (#total - #success - #skipped) / (#total - #skipped)
      var a_success_or_skipped = 0;
      var a_skipped = 0;
      var b_success_or_skipped = 0;
      var b_skipped = 0;
      a_rows.forEach(function (row, i) {
        var index = (i > 0) ? headIndex - 1 : headIndex;
        var status = row.children[index].innerHTML.trim();
        if (status == 'SUCCESS') {
          a_success_or_skipped += 1;
        }
        if (status == 'SKIPPED') {
          a_success_or_skipped += 1;
          a_skipped += 1;
        }
      });
      b_rows.forEach(function (row, i) {
        var index = (i > 0) ? headIndex - 1 : headIndex;
        var status = row.children[index].innerHTML.trim();
        if (status == 'SUCCESS') {
          b_success_or_skipped += 1;
        }
        if (status == 'SKIPPED') {
          b_success_or_skipped += 1;
          b_skipped += 1;
        }
      });
      var atotal_minus_skipped = a_rows.length - a_skipped;
      var btotal_minus_skipped = b_rows.length - b_skipped;

      var avalue = ((atotal_minus_skipped == 0) ? -1 :
          (a_rows.length - a_success_or_skipped) / atotal_minus_skipped);
      var bvalue = ((btotal_minus_skipped == 0) ? -1 :
          (b_rows.length - b_success_or_skipped) / btotal_minus_skipped);
    }
    return asc * (avalue - bvalue);
  });

  for (var i = 0; i < rowBlocks.length; i++) {
    table.appendChild(rowBlocks[i]);
  }
}

function sortSuiteTableByFailedTestCases() {
  sortByColumn(document.getElementById('number_fail_tests'));
}

function setTableCellsAsClickable() {
  const tableCells = document.getElementsByTagName('td');
  for(let i = 0; i < tableCells.length; i++) {
    const links = tableCells[i].getElementsByTagName('a');
    // Only make the cell clickable if there is only one link.
    if (links.length == 1) {
      tableCells[i].addEventListener('click', function() {
          links[0].click();
      });
      tableCells[i].addEventListener('mouseover', function() {
          tableCells[i].style.cursor = 'pointer';
          links[0].style.textDecoration = 'underline';
      });
      tableCells[i].addEventListener('mouseout', function() {
          tableCells[i].style.cursor = 'initial';
          links[0].style.textDecoration = 'initial';
      });
    }
  }
}