blob: 4e67de73efd83b2e461807eb95ea1bcb67d9cce7 [file] [log] [blame]
Tim van der Lippe83f02be2020-01-23 11:11:401// Copyright 2017 The Chromium Authors. All rights reserved.
[email protected]aa1532c2019-05-31 03:01:242// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * @fileoverview using private properties isn't a Closure violation in tests.
7 * @suppress {accessControls}
8 */
9
10/**
11 * @return {!Audits.AuditsPanel}
12 */
13AuditsTestRunner._panel = function() {
14 return /** @type {!Object} **/ (UI.panels).audits;
15};
16
17/**
18 * @return {?Element}
19 */
20AuditsTestRunner.getContainerElement = function() {
21 return AuditsTestRunner._panel().contentElement;
22};
23
24/**
25 * @return {?Element}
26 */
27AuditsTestRunner.getResultsElement = function() {
28 return AuditsTestRunner._panel()._auditResultsElement;
29};
30
31/**
32 * @return {?Element}
33 */
34AuditsTestRunner.getDialogElement = function() {
35 return AuditsTestRunner._panel()._statusView._dialog.contentElement.shadowRoot.querySelector('.audits-view');
36};
37
38/**
39 * @return {?Element}
40 */
Connor Clark37fc8b12019-12-11 20:35:4541AuditsTestRunner.getSettingsElement = function() {
42 return AuditsTestRunner._panel()._settingsPane.element;
43};
44
45/**
46 * @return {?Element}
47 */
[email protected]aa1532c2019-05-31 03:01:2448AuditsTestRunner.getRunButton = function() {
49 const dialog = AuditsTestRunner.getContainerElement();
50 return dialog && dialog.querySelectorAll('button')[0];
51};
52
53/**
54 * @return {?Element}
55 */
56AuditsTestRunner.getCancelButton = function() {
57 const dialog = AuditsTestRunner.getDialogElement();
58 return dialog && dialog.querySelectorAll('button')[0];
59};
60
61AuditsTestRunner.openStartAudit = function() {
62 AuditsTestRunner._panel()._renderStartView();
63};
64
65/**
66 * @param {function(string)} onMessage
67 */
68AuditsTestRunner.addStatusListener = function(onMessage) {
69 TestRunner.addSniffer(Audits.StatusView.prototype, 'updateStatus', onMessage, true);
70};
71
72/**
73 * @return {!Promise<!Object>}
74 */
75AuditsTestRunner.waitForResults = function() {
76 return new Promise(resolve => {
Connor Clarkb734a432019-08-20 21:58:0177 TestRunner.addSniffer(Audits.AuditsPanel.prototype, '_buildReportUI',
78 (lhr, artifacts) => resolve({lhr, artifacts}));
[email protected]aa1532c2019-05-31 03:01:2479 });
80};
81
82AuditsTestRunner.forcePageAuditabilityCheck = function() {
83 AuditsTestRunner._panel()._controller.recomputePageAuditability();
84};
85
86/**
87 * @param {?Element} checkboxContainer
88 * @return {string}
89 */
90AuditsTestRunner._checkboxStateLabel = function(checkboxContainer) {
Tim van der Lippe1d6e57a2019-09-30 11:55:3491 if (!checkboxContainer) {
[email protected]aa1532c2019-05-31 03:01:2492 return 'missing';
Tim van der Lippe1d6e57a2019-09-30 11:55:3493 }
[email protected]aa1532c2019-05-31 03:01:2494
95 const label = checkboxContainer.textElement.textContent;
96 const checkedLabel = checkboxContainer.checkboxElement.checked ? 'x' : ' ';
97 return `[${checkedLabel}] ${label}`;
98};
99
100/**
101 * @param {?Element} button
102 * @return {string}
103 */
104AuditsTestRunner._buttonStateLabel = function(button) {
Tim van der Lippe1d6e57a2019-09-30 11:55:34105 if (!button) {
[email protected]aa1532c2019-05-31 03:01:24106 return 'missing';
Tim van der Lippe1d6e57a2019-09-30 11:55:34107 }
[email protected]aa1532c2019-05-31 03:01:24108
109 const enabledLabel = button.disabled ? 'disabled' : 'enabled';
110 const hiddenLabel = window.getComputedStyle(button).getPropertyValue('visibility');
111 return `${button.textContent}: ${enabledLabel} ${hiddenLabel}`;
112};
113
114AuditsTestRunner.dumpStartAuditState = function() {
115 TestRunner.addResult('\n========== Audits Start Audit State ==========');
116
117 const containerElement = AuditsTestRunner.getContainerElement();
118 const checkboxes = [...containerElement.querySelectorAll('.checkbox')];
Connor Clarka0ccfd72019-12-11 03:54:12119
Connor Clark37fc8b12019-12-11 20:35:45120 const toolbarShadowRoot =
121 AuditsTestRunner.getSettingsElement().querySelector('.audits-settings-pane > div').shadowRoot;
122 for (const checkbox of toolbarShadowRoot.querySelectorAll('.checkbox')) {
123 checkboxes.push(checkbox);
124 }
125
[email protected]aa1532c2019-05-31 03:01:24126 checkboxes.forEach(element => {
127 TestRunner.addResult(AuditsTestRunner._checkboxStateLabel(element));
128 });
129
130 const helpText = containerElement.querySelector('.audits-help-text');
Tim van der Lippe1d6e57a2019-09-30 11:55:34131 if (!helpText.classList.contains('hidden')) {
[email protected]aa1532c2019-05-31 03:01:24132 TestRunner.addResult(`Help text: ${helpText.textContent}`);
Tim van der Lippe1d6e57a2019-09-30 11:55:34133 }
[email protected]aa1532c2019-05-31 03:01:24134
135 TestRunner.addResult(AuditsTestRunner._buttonStateLabel(AuditsTestRunner.getRunButton()));
136};