| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 async _stopRecording() { | 67 async _stopRecording() { |
| 68 this._toggleRecordAction.setToggled(false); | 68 this._toggleRecordAction.setToggled(false); |
| 69 this._progressElement.textContent = Common.UIString('Fetching results...'); | 69 this._progressElement.textContent = Common.UIString('Fetching results...'); |
| 70 | 70 |
| 71 var coverageInfo = await this._model.stop(); | 71 var coverageInfo = await this._model.stop(); |
| 72 this._model = null; | 72 this._model = null; |
| 73 this._updateViews(coverageInfo); | 73 this._updateViews(coverageInfo); |
| 74 } | 74 } |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * @param {!Array<!Coverage.CoverageInfo>} coverageInfo | 77 * @param {!Array<!Coverage.URLCoverageInfo>} coverageInfo |
| 78 */ | 78 */ |
| 79 async _updateViews(coverageInfo) { | 79 async _updateViews(coverageInfo) { |
| 80 this._updateStats(coverageInfo); | 80 this._updateStats(coverageInfo); |
| 81 this._coverageResultsElement.removeChildren(); | 81 this._coverageResultsElement.removeChildren(); |
| 82 this._listView.update(coverageInfo); | 82 this._listView.update(coverageInfo); |
| 83 this._listView.show(this._coverageResultsElement); | 83 this._listView.show(this._coverageResultsElement); |
| 84 await Promise.all(coverageInfo.map(entry => Coverage.CoverageView._updateGut
ter(entry))); | 84 await Promise.all(coverageInfo.map(entry => Coverage.CoverageView._updateGut
ter(entry))); |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * @param {!Array<!Coverage.CoverageInfo>} coverageInfo | 88 * @param {!Array<!Coverage.URLCoverageInfo>} coverageInfo |
| 89 */ | 89 */ |
| 90 _updateStats(coverageInfo) { | 90 _updateStats(coverageInfo) { |
| 91 var total = 0; | 91 var total = 0; |
| 92 var unused = 0; | 92 var unused = 0; |
| 93 for (var info of coverageInfo) { | 93 for (var info of coverageInfo) { |
| 94 total += info.size || 0; | 94 total += info.size(); |
| 95 unused += info.unusedSize || 0; | 95 unused += info.unusedSize(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 var percentUnused = total ? Math.round(100 * unused / total) : 0; | 98 var percentUnused = total ? Math.round(100 * unused / total) : 0; |
| 99 this._statusMessageElement.textContent = Common.UIString( | 99 this._statusMessageElement.textContent = Common.UIString( |
| 100 '%s of %s bytes are not used. (%d%%)', Number.bytesToString(unused), Num
ber.bytesToString(total), | 100 '%s of %s bytes are not used. (%d%%)', Number.bytesToString(unused), Num
ber.bytesToString(total), |
| 101 percentUnused); | 101 percentUnused); |
| 102 } | 102 } |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * @param {!Coverage.CoverageInfo} coverageInfo | 105 * @param {!Coverage.URLCoverageInfo} coverageInfo |
| 106 */ | 106 */ |
| 107 static async _updateGutter(coverageInfo) { | 107 static async _updateGutter(coverageInfo) { |
| 108 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(coverageInfo.conte
ntProvider.contentURL()); | 108 var uiSourceCode = Workspace.workspace.uiSourceCodeForURL(coverageInfo.url()
); |
| 109 if (!uiSourceCode) | 109 if (!uiSourceCode) |
| 110 return; | 110 return; |
| 111 // FIXME: gutter should be set in terms of offsets and therefore should not
require contents. | 111 // FIXME: gutter should be set in terms of offsets and therefore should not
require contents. |
| 112 var contents = await coverageInfo.contentProvider.requestContent(); | 112 var ranges = await coverageInfo.buildTextRanges(); |
| 113 if (!contents) | 113 for (var r of ranges) |
| 114 return; | 114 uiSourceCode.addDecoration(r.range, Coverage.CoverageView.LineDecorator.ty
pe, r.count); |
| 115 var text = new Common.Text(contents); | |
| 116 var lastOffset = 0; | |
| 117 var rangesByDepth = []; | |
| 118 for (var segment of coverageInfo.segments) { | |
| 119 if (typeof segment.count !== 'number') { | |
| 120 lastOffset = segment.end; | |
| 121 continue; | |
| 122 } | |
| 123 var startPosition = text.positionFromOffset(lastOffset); | |
| 124 var endPosition = text.positionFromOffset(segment.end); | |
| 125 if (!startPosition.lineNumber) | |
| 126 startPosition.columnNumber += coverageInfo.columnOffset; | |
| 127 startPosition.lineNumber += coverageInfo.lineOffset; | |
| 128 if (!endPosition.lineNumber) | |
| 129 endPosition.columnNumber += coverageInfo.columnOffset; | |
| 130 endPosition.lineNumber += coverageInfo.lineOffset; | |
| 131 | |
| 132 var ranges = rangesByDepth[segment.depth - 1]; // depth === 0 => count ==
= undefined | |
| 133 if (!ranges) { | |
| 134 ranges = []; | |
| 135 rangesByDepth[segment.depth - 1] = ranges; | |
| 136 } | |
| 137 ranges.push({ | |
| 138 count: segment.count, | |
| 139 range: new Common.TextRange( | |
| 140 startPosition.lineNumber, startPosition.columnNumber, endPosition.li
neNumber, endPosition.columnNumber) | |
| 141 }); | |
| 142 lastOffset = segment.end; | |
| 143 } | |
| 144 for (var ranges of rangesByDepth) { | |
| 145 for (var r of ranges) | |
| 146 uiSourceCode.addDecoration(r.range, Coverage.CoverageView.LineDecorator.
type, r.count); | |
| 147 } | |
| 148 } | 115 } |
| 149 }; | 116 }; |
| 150 | 117 |
| 151 /** | 118 /** |
| 152 * @implements {SourceFrame.UISourceCodeFrame.LineDecorator} | 119 * @implements {SourceFrame.UISourceCodeFrame.LineDecorator} |
| 153 */ | 120 */ |
| 154 Coverage.CoverageView.LineDecorator = class { | 121 Coverage.CoverageView.LineDecorator = class { |
| 155 /** | 122 /** |
| 156 * @override | 123 * @override |
| 157 * @param {!Workspace.UISourceCode} uiSourceCode | 124 * @param {!Workspace.UISourceCode} uiSourceCode |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 */ | 162 */ |
| 196 handleAction(context, actionId) { | 163 handleAction(context, actionId) { |
| 197 var coverageViewId = 'coverage'; | 164 var coverageViewId = 'coverage'; |
| 198 UI.viewManager.showView(coverageViewId) | 165 UI.viewManager.showView(coverageViewId) |
| 199 .then(() => UI.viewManager.view(coverageViewId).widget()) | 166 .then(() => UI.viewManager.view(coverageViewId).widget()) |
| 200 .then(widget => /** @type !Coverage.CoverageView} */ (widget)._toggleRec
ording()); | 167 .then(widget => /** @type !Coverage.CoverageView} */ (widget)._toggleRec
ording()); |
| 201 | 168 |
| 202 return true; | 169 return true; |
| 203 } | 170 } |
| 204 }; | 171 }; |
| OLD | NEW |