| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 Coverage.CoverageView = class extends UI.VBox { | 5 Coverage.CoverageView = class extends UI.VBox { |
| 6 constructor() { | 6 constructor() { |
| 7 super(true); | 7 super(true); |
| 8 | 8 |
| 9 /** @type {?Coverage.CoverageModel} */ | 9 /** @type {?Coverage.CoverageModel} */ |
| 10 this._model = null; | 10 this._model = null; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 toolbar.appendToolbarItem(this._toggleRecordButton); | 24 toolbar.appendToolbarItem(this._toggleRecordButton); |
| 25 | 25 |
| 26 var startWithReloadAction = | 26 var startWithReloadAction = |
| 27 /** @type {!UI.Action }*/ (UI.actionRegistry.action('coverage.start-with
-reload')); | 27 /** @type {!UI.Action }*/ (UI.actionRegistry.action('coverage.start-with
-reload')); |
| 28 this._startWithReloadButton = UI.Toolbar.createActionButton(startWithReloadA
ction); | 28 this._startWithReloadButton = UI.Toolbar.createActionButton(startWithReloadA
ction); |
| 29 toolbar.appendToolbarItem(this._startWithReloadButton); | 29 toolbar.appendToolbarItem(this._startWithReloadButton); |
| 30 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'larg
eicon-clear'); | 30 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear all'), 'larg
eicon-clear'); |
| 31 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
r.bind(this)); | 31 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, this._clea
r.bind(this)); |
| 32 toolbar.appendToolbarItem(this._clearButton); | 32 toolbar.appendToolbarItem(this._clearButton); |
| 33 | 33 |
| 34 /** @type {?RegExp} */ |
| 35 this._textFilterRegExp = null; |
| 36 |
| 34 toolbar.appendSeparator(); | 37 toolbar.appendSeparator(); |
| 35 this._filterInput = new UI.ToolbarInput(Common.UIString('URL filter'), 0.4,
1, true); | 38 this._filterInput = new UI.ToolbarInput(Common.UIString('URL filter'), 0.4,
1, true); |
| 36 this._filterInput.setEnabled(false); | 39 this._filterInput.setEnabled(false); |
| 37 this._filterInput.addEventListener(UI.ToolbarInput.Event.TextChanged, this._
filterChanged, this); | 40 this._filterInput.addEventListener(UI.ToolbarInput.Event.TextChanged, this._
onFilterChanged, this); |
| 38 toolbar.appendToolbarItem(this._filterInput); | 41 toolbar.appendToolbarItem(this._filterInput); |
| 39 | 42 |
| 43 toolbar.appendSeparator(); |
| 44 this._showContentScriptsSetting = Common.settings.createSetting('showContent
Scripts', false); |
| 45 this._showContentScriptsSetting.addChangeListener(this._onFilterChanged, thi
s); |
| 46 var contentScriptsCheckbox = new UI.ToolbarSettingCheckbox( |
| 47 this._showContentScriptsSetting, Common.UIString('Include extension cont
ent scripts'), |
| 48 Common.UIString('Content scripts')); |
| 49 toolbar.appendToolbarItem(contentScriptsCheckbox); |
| 50 |
| 40 this._coverageResultsElement = this.contentElement.createChild('div', 'cover
age-results'); | 51 this._coverageResultsElement = this.contentElement.createChild('div', 'cover
age-results'); |
| 41 this._landingPage = this._buildLandingPage(); | 52 this._landingPage = this._buildLandingPage(); |
| 42 this._listView = new Coverage.CoverageListView(); | 53 this._listView = new Coverage.CoverageListView(this._isVisible.bind(this, fa
lse)); |
| 43 | 54 |
| 44 this._statusToolbarElement = this.contentElement.createChild('div', 'coverag
e-toolbar-summary'); | 55 this._statusToolbarElement = this.contentElement.createChild('div', 'coverag
e-toolbar-summary'); |
| 45 this._statusMessageElement = this._statusToolbarElement.createChild('div', '
coverage-message'); | 56 this._statusMessageElement = this._statusToolbarElement.createChild('div', '
coverage-message'); |
| 46 this._landingPage.show(this._coverageResultsElement); | 57 this._landingPage.show(this._coverageResultsElement); |
| 47 } | 58 } |
| 48 | 59 |
| 49 /** | 60 /** |
| 50 * @return {!UI.VBox} | 61 * @return {!UI.VBox} |
| 51 */ | 62 */ |
| 52 _buildLandingPage() { | 63 _buildLandingPage() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 this._updateViews(updatedEntries); | 148 this._updateViews(updatedEntries); |
| 138 this._toggleRecordAction.setToggled(false); | 149 this._toggleRecordAction.setToggled(false); |
| 139 this._startWithReloadButton.setEnabled(true); | 150 this._startWithReloadButton.setEnabled(true); |
| 140 this._clearButton.setEnabled(true); | 151 this._clearButton.setEnabled(true); |
| 141 } | 152 } |
| 142 | 153 |
| 143 /** | 154 /** |
| 144 * @param {!Array<!Coverage.CoverageInfo>} updatedEntries | 155 * @param {!Array<!Coverage.CoverageInfo>} updatedEntries |
| 145 */ | 156 */ |
| 146 async _updateViews(updatedEntries) { | 157 async _updateViews(updatedEntries) { |
| 147 var urlEntries = this._model.entries(); | 158 this._updateStats(); |
| 148 this._updateStats(urlEntries); | 159 this._listView.update(this._model.entries()); |
| 149 this._listView.update(urlEntries); | |
| 150 this._decorationManager.update(updatedEntries); | 160 this._decorationManager.update(updatedEntries); |
| 151 } | 161 } |
| 152 | 162 |
| 153 /** | 163 _updateStats() { |
| 154 * @param {!Array<!Coverage.URLCoverageInfo>} coverageInfo | |
| 155 */ | |
| 156 _updateStats(coverageInfo) { | |
| 157 var total = 0; | 164 var total = 0; |
| 158 var unused = 0; | 165 var unused = 0; |
| 159 for (var info of coverageInfo) { | 166 for (var info of this._model.entries()) { |
| 167 if (!this._isVisible(true, info)) |
| 168 continue; |
| 160 total += info.size(); | 169 total += info.size(); |
| 161 unused += info.unusedSize(); | 170 unused += info.unusedSize(); |
| 162 } | 171 } |
| 163 | 172 |
| 164 var percentUnused = total ? Math.round(100 * unused / total) : 0; | 173 var percentUnused = total ? Math.round(100 * unused / total) : 0; |
| 165 this._statusMessageElement.textContent = Common.UIString( | 174 this._statusMessageElement.textContent = Common.UIString( |
| 166 '%s of %s bytes are not used. (%d%%)', Number.bytesToString(unused), Num
ber.bytesToString(total), | 175 '%s of %s bytes are not used. (%d%%)', Number.bytesToString(unused), Num
ber.bytesToString(total), |
| 167 percentUnused); | 176 percentUnused); |
| 168 } | 177 } |
| 169 | 178 |
| 170 _filterChanged() { | 179 _onFilterChanged() { |
| 171 if (!this._listView) | 180 if (!this._listView) |
| 172 return; | 181 return; |
| 173 var text = this._filterInput.value(); | 182 var text = this._filterInput.value(); |
| 174 this._listView.setFilter(text ? createPlainTextSearchRegex(text, 'i') : null
); | 183 this._textFilterRegExp = text ? createPlainTextSearchRegex(text, 'i') : null
; |
| 184 this._listView.updateFilterAndHighlight(this._textFilterRegExp); |
| 185 this._updateStats(); |
| 186 } |
| 187 |
| 188 /** |
| 189 * @param {boolean} ignoreTextFilter |
| 190 * @param {!Coverage.URLCoverageInfo} coverageInfo |
| 191 * @return {boolean} |
| 192 */ |
| 193 _isVisible(ignoreTextFilter, coverageInfo) { |
| 194 var url = coverageInfo.url(); |
| 195 if (url.startsWith(Coverage.CoverageView._extensionBindingsURLPrefix)) |
| 196 return false; |
| 197 if (coverageInfo.isContentScript() && !this._showContentScriptsSetting.get()
) |
| 198 return false; |
| 199 return ignoreTextFilter || !this._textFilterRegExp || this._textFilterRegExp
.test(url); |
| 175 } | 200 } |
| 176 }; | 201 }; |
| 177 | 202 |
| 203 Coverage.CoverageView._extensionBindingsURLPrefix = 'extensions::'; |
| 204 |
| 178 /** | 205 /** |
| 179 * @implements {UI.ActionDelegate} | 206 * @implements {UI.ActionDelegate} |
| 180 */ | 207 */ |
| 181 Coverage.CoverageView.ActionDelegate = class { | 208 Coverage.CoverageView.ActionDelegate = class { |
| 182 /** | 209 /** |
| 183 * @override | 210 * @override |
| 184 * @param {!UI.Context} context | 211 * @param {!UI.Context} context |
| 185 * @param {string} actionId | 212 * @param {string} actionId |
| 186 * @return {boolean} | 213 * @return {boolean} |
| 187 */ | 214 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 204 coverageView._toggleRecording(); | 231 coverageView._toggleRecording(); |
| 205 break; | 232 break; |
| 206 case 'coverage.start-with-reload': | 233 case 'coverage.start-with-reload': |
| 207 coverageView._startWithReload(); | 234 coverageView._startWithReload(); |
| 208 break; | 235 break; |
| 209 default: | 236 default: |
| 210 console.assert(false, `Unknown action: ${actionId}`); | 237 console.assert(false, `Unknown action: ${actionId}`); |
| 211 } | 238 } |
| 212 } | 239 } |
| 213 }; | 240 }; |
| OLD | NEW |