Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/counters/WarningErrorCounter.js

Issue 2975523002: DevTools: add console test helpers to new test runner & migrate a console test (Closed)
Patch Set: fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
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 * @implements {UI.ToolbarItem.Provider}
7 * @unrestricted
8 */
9 Counters.WarningErrorCounter = class {
10 constructor() {
11 Counters.WarningErrorCounter._instanceForTest = this;
12
13 this._counter = createElement('div');
14 this._counter.addEventListener('click', Common.console.show.bind(Common.cons ole), false);
15 this._toolbarItem = new UI.ToolbarItem(this._counter);
16 var shadowRoot = UI.createShadowRootWithCoreStyles(this._counter, 'counters/ errorWarningCounter.css');
17
18 this._errors = this._createItem(shadowRoot, 'smallicon-error');
19 this._warnings = this._createItem(shadowRoot, 'smallicon-warning');
20 this._titles = [];
21
22 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events. ConsoleCleared, this._update, this);
23 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events. MessageAdded, this._update, this);
24 ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events. MessageUpdated, this._update, this);
25 this._update();
26 }
27
28 /**
29 * @param {!Node} shadowRoot
30 * @param {string} iconType
31 * @return {!{item: !Element, text: !Element}}
32 */
33 _createItem(shadowRoot, iconType) {
34 var item = createElementWithClass('span', 'counter-item');
35 var icon = item.createChild('label', '', 'dt-icon-label');
36 icon.type = iconType;
37 var text = icon.createChild('span');
38 shadowRoot.appendChild(item);
39 return {item: item, text: text};
40 }
41
42 /**
43 * @param {!{item: !Element, text: !Element}} item
44 * @param {number} count
45 * @param {boolean} first
46 * @param {string} title
47 */
48 _updateItem(item, count, first, title) {
49 item.item.classList.toggle('hidden', !count);
50 item.item.classList.toggle('counter-item-first', first);
51 item.text.textContent = count;
52 if (count)
53 this._titles.push(title);
54 }
55
56 _update() {
57 var errors = ConsoleModel.consoleModel.errors();
58 var warnings = ConsoleModel.consoleModel.warnings();
59
60 this._titles = [];
61 this._toolbarItem.setVisible(!!(errors || warnings));
62 this._updateItem(this._errors, errors, false, Common.UIString(errors === 1 ? '%d error' : '%d errors', errors));
63 this._updateItem(
64 this._warnings, warnings, !errors, Common.UIString(warnings === 1 ? '%d warning' : '%d warnings', warnings));
65 this._counter.title = this._titles.join(', ');
66 UI.inspectorView.toolbarItemResized();
67 }
68
69 /**
70 * @override
71 * @return {?UI.ToolbarItem}
72 */
73 item() {
74 return this._toolbarItem;
75 }
76 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698