Tim van der Lippe | 83f02be | 2020-01-23 11:11:40 | [diff] [blame^] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 2 | // 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 | */ |
| 13 | AuditsTestRunner._panel = function() { |
| 14 | return /** @type {!Object} **/ (UI.panels).audits; |
| 15 | }; |
| 16 | |
| 17 | /** |
| 18 | * @return {?Element} |
| 19 | */ |
| 20 | AuditsTestRunner.getContainerElement = function() { |
| 21 | return AuditsTestRunner._panel().contentElement; |
| 22 | }; |
| 23 | |
| 24 | /** |
| 25 | * @return {?Element} |
| 26 | */ |
| 27 | AuditsTestRunner.getResultsElement = function() { |
| 28 | return AuditsTestRunner._panel()._auditResultsElement; |
| 29 | }; |
| 30 | |
| 31 | /** |
| 32 | * @return {?Element} |
| 33 | */ |
| 34 | AuditsTestRunner.getDialogElement = function() { |
| 35 | return AuditsTestRunner._panel()._statusView._dialog.contentElement.shadowRoot.querySelector('.audits-view'); |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * @return {?Element} |
| 40 | */ |
Connor Clark | 37fc8b1 | 2019-12-11 20:35:45 | [diff] [blame] | 41 | AuditsTestRunner.getSettingsElement = function() { |
| 42 | return AuditsTestRunner._panel()._settingsPane.element; |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * @return {?Element} |
| 47 | */ |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 48 | AuditsTestRunner.getRunButton = function() { |
| 49 | const dialog = AuditsTestRunner.getContainerElement(); |
| 50 | return dialog && dialog.querySelectorAll('button')[0]; |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * @return {?Element} |
| 55 | */ |
| 56 | AuditsTestRunner.getCancelButton = function() { |
| 57 | const dialog = AuditsTestRunner.getDialogElement(); |
| 58 | return dialog && dialog.querySelectorAll('button')[0]; |
| 59 | }; |
| 60 | |
| 61 | AuditsTestRunner.openStartAudit = function() { |
| 62 | AuditsTestRunner._panel()._renderStartView(); |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * @param {function(string)} onMessage |
| 67 | */ |
| 68 | AuditsTestRunner.addStatusListener = function(onMessage) { |
| 69 | TestRunner.addSniffer(Audits.StatusView.prototype, 'updateStatus', onMessage, true); |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * @return {!Promise<!Object>} |
| 74 | */ |
| 75 | AuditsTestRunner.waitForResults = function() { |
| 76 | return new Promise(resolve => { |
Connor Clark | b734a43 | 2019-08-20 21:58:01 | [diff] [blame] | 77 | TestRunner.addSniffer(Audits.AuditsPanel.prototype, '_buildReportUI', |
| 78 | (lhr, artifacts) => resolve({lhr, artifacts})); |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 79 | }); |
| 80 | }; |
| 81 | |
| 82 | AuditsTestRunner.forcePageAuditabilityCheck = function() { |
| 83 | AuditsTestRunner._panel()._controller.recomputePageAuditability(); |
| 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * @param {?Element} checkboxContainer |
| 88 | * @return {string} |
| 89 | */ |
| 90 | AuditsTestRunner._checkboxStateLabel = function(checkboxContainer) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 91 | if (!checkboxContainer) { |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 92 | return 'missing'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 93 | } |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 94 | |
| 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 | */ |
| 104 | AuditsTestRunner._buttonStateLabel = function(button) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 105 | if (!button) { |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 106 | return 'missing'; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 107 | } |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 108 | |
| 109 | const enabledLabel = button.disabled ? 'disabled' : 'enabled'; |
| 110 | const hiddenLabel = window.getComputedStyle(button).getPropertyValue('visibility'); |
| 111 | return `${button.textContent}: ${enabledLabel} ${hiddenLabel}`; |
| 112 | }; |
| 113 | |
| 114 | AuditsTestRunner.dumpStartAuditState = function() { |
| 115 | TestRunner.addResult('\n========== Audits Start Audit State =========='); |
| 116 | |
| 117 | const containerElement = AuditsTestRunner.getContainerElement(); |
| 118 | const checkboxes = [...containerElement.querySelectorAll('.checkbox')]; |
Connor Clark | a0ccfd7 | 2019-12-11 03:54:12 | [diff] [blame] | 119 | |
Connor Clark | 37fc8b1 | 2019-12-11 20:35:45 | [diff] [blame] | 120 | 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] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 126 | checkboxes.forEach(element => { |
| 127 | TestRunner.addResult(AuditsTestRunner._checkboxStateLabel(element)); |
| 128 | }); |
| 129 | |
| 130 | const helpText = containerElement.querySelector('.audits-help-text'); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 131 | if (!helpText.classList.contains('hidden')) { |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 132 | TestRunner.addResult(`Help text: ${helpText.textContent}`); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 133 | } |
[email protected] | aa1532c | 2019-05-31 03:01:24 | [diff] [blame] | 134 | |
| 135 | TestRunner.addResult(AuditsTestRunner._buttonStateLabel(AuditsTestRunner.getRunButton())); |
| 136 | }; |