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

Side by Side Diff: tracing/tracing/ui/analysis/memory_dump_sub_view_util_test.html

Issue 2776653002: [ESLint] Fix violations when enabling curly rule in eslint. (Closed)
Patch Set: Fix test Created 3 years, 9 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2015 The Chromium Authors. All rights reserved. 3 Copyright (c) 2015 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/tracing/base/iteration_helpers.html"> 8 <link rel="import" href="/tracing/base/iteration_helpers.html">
9 <link rel="import" href="/tracing/base/scalar.html"> 9 <link rel="import" href="/tracing/base/scalar.html">
10 <link rel="import" href="/tracing/base/unit.html"> 10 <link rel="import" href="/tracing/base/unit.html">
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 assert.isUndefined(opt_expectedColor); // Test sanity check. 49 assert.isUndefined(opt_expectedColor); // Test sanity check.
50 return; 50 return;
51 } 51 }
52 52
53 var node = tr.ui.b.asHTMLOrTextNode(value); 53 var node = tr.ui.b.asHTMLOrTextNode(value);
54 var spanEl = document.createElement('span'); 54 var spanEl = document.createElement('span');
55 Polymer.dom(spanEl).appendChild(node); 55 Polymer.dom(spanEl).appendChild(node);
56 test.addHTMLOutput(spanEl); 56 test.addHTMLOutput(spanEl);
57 57
58 assert.strictEqual(Polymer.dom(node).textContent, expectedTextContent); 58 assert.strictEqual(Polymer.dom(node).textContent, expectedTextContent);
59 if (opt_expectedColor === undefined) 59 if (opt_expectedColor === undefined) {
60 assert.notInstanceOf(node, HTMLElement); 60 assert.notInstanceOf(node, HTMLElement);
61 else 61 } else {
62 assert.strictEqual(node.style.color, opt_expectedColor); 62 assert.strictEqual(node.style.color, opt_expectedColor);
63 }
63 } 64 }
64 65
65 function checkCompareFieldsEqual(column, fieldValuesA, fieldValuesB) { 66 function checkCompareFieldsEqual(column, fieldValuesA, fieldValuesB) {
66 assert.strictEqual(column.compareFields(fieldValuesA, fieldValuesB), 0); 67 assert.strictEqual(column.compareFields(fieldValuesA, fieldValuesB), 0);
67 } 68 }
68 69
69 function checkCompareFieldsLess(column, fieldValuesA, fieldValuesB) { 70 function checkCompareFieldsLess(column, fieldValuesA, fieldValuesB) {
70 assert.isBelow(column.compareFields(fieldValuesA, fieldValuesB), 0); 71 assert.isBelow(column.compareFields(fieldValuesA, fieldValuesB), 0);
71 assert.isAbove(column.compareFields(fieldValuesB, fieldValuesA), 0); 72 assert.isAbove(column.compareFields(fieldValuesB, fieldValuesA), 0);
72 } 73 }
73 74
74 function checkNumericMemoryColumnFieldFormat(test, column, fieldValues, unit, 75 function checkNumericMemoryColumnFieldFormat(test, column, fieldValues, unit,
75 expectedValue) { 76 expectedValue) {
76 var value = column.formatMultipleFields( 77 var value = column.formatMultipleFields(
77 buildScalarCell(unit, fieldValues).fields); 78 buildScalarCell(unit, fieldValues).fields);
78 if (expectedValue === undefined) { 79 if (expectedValue === undefined) {
79 assert.equal(value, ''); 80 assert.equal(value, '');
80 assert.isUndefined(expectedUnits); // Test sanity check. 81 assert.isUndefined(expectedUnits); // Test sanity check.
81 return; 82 return;
82 } 83 }
83 84
84 test.addHTMLOutput(value); 85 test.addHTMLOutput(value);
85 assert.equal(value.tagName, 'TR-V-UI-SCALAR-SPAN'); 86 assert.equal(value.tagName, 'TR-V-UI-SCALAR-SPAN');
86 assert.equal(value.value, expectedValue); 87 assert.equal(value.value, expectedValue);
87 assert.equal(value.unit, unit); 88 assert.equal(value.unit, unit);
88 } 89 }
89 90
90 function buildScalarCell(unit, values) { 91 function buildScalarCell(unit, values) {
91 return new MemoryCell(values.map(function(value) { 92 return new MemoryCell(values.map(function(value) {
92 if (value === undefined) 93 if (value === undefined) return undefined;
93 return undefined;
94 return new Scalar(unit, value); 94 return new Scalar(unit, value);
95 })); 95 }));
96 } 96 }
97 97
98 function buildTestRows() { 98 function buildTestRows() {
99 return [ 99 return [
100 { 100 {
101 title: 'Row 1', 101 title: 'Row 1',
102 fields: { 102 fields: {
103 'cpu_temperature': new MemoryCell(['below zero', 'absolute zero']) 103 'cpu_temperature': new MemoryCell(['below zero', 'absolute zero'])
(...skipping 29 matching lines...) Expand all
133 } 133 }
134 } 134 }
135 ]; 135 ];
136 } 136 }
137 137
138 function checkCellValue( 138 function checkCellValue(
139 test, value, expectedText, expectedColor, opt_expectedInfos) { 139 test, value, expectedText, expectedColor, opt_expectedInfos) {
140 var expectedInfos = opt_expectedInfos || []; 140 var expectedInfos = opt_expectedInfos || [];
141 assert.lengthOf(Polymer.dom(value).childNodes, 1 + expectedInfos.length); 141 assert.lengthOf(Polymer.dom(value).childNodes, 1 + expectedInfos.length);
142 assert.strictEqual(value.style.color, expectedColor); 142 assert.strictEqual(value.style.color, expectedColor);
143 if (typeof expectedText === 'string') 143 if (typeof expectedText === 'string') {
144 assert.strictEqual( 144 assert.strictEqual(
145 Polymer.dom(Polymer.dom(value).childNodes[0]).textContent, 145 Polymer.dom(Polymer.dom(value).childNodes[0]).textContent,
146 expectedText); 146 expectedText);
147 else 147 } else {
148 expectedText(Polymer.dom(value).childNodes[0]); 148 expectedText(Polymer.dom(value).childNodes[0]);
149 }
149 for (var i = 0; i < expectedInfos.length; i++) { 150 for (var i = 0; i < expectedInfos.length; i++) {
150 var expectedInfo = expectedInfos[i]; 151 var expectedInfo = expectedInfos[i];
151 var infoEl = Polymer.dom(value).childNodes[i + 1]; 152 var infoEl = Polymer.dom(value).childNodes[i + 1];
152 assert.strictEqual(Polymer.dom(infoEl).textContent, expectedInfo.icon); 153 assert.strictEqual(Polymer.dom(infoEl).textContent, expectedInfo.icon);
153 assert.strictEqual(infoEl.title, expectedInfo.message); 154 assert.strictEqual(infoEl.title, expectedInfo.message);
154 assert.strictEqual(infoEl.style.color, expectedInfo.color || ''); 155 assert.strictEqual(infoEl.style.color, expectedInfo.color || '');
155 } 156 }
156 test.addHTMLOutput(value); 157 test.addHTMLOutput(value);
157 } 158 }
158 159
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 516
516 assert.isTrue(MemoryColumn.nameMatchesCondition('test_column', /test/)); 517 assert.isTrue(MemoryColumn.nameMatchesCondition('test_column', /test/));
517 assert.isTrue( 518 assert.isTrue(
518 MemoryColumn.nameMatchesCondition('test_column', /^[^_]*_[^_]*$/)); 519 MemoryColumn.nameMatchesCondition('test_column', /^[^_]*_[^_]*$/));
519 assert.isFalse(MemoryColumn.nameMatchesCondition('test_column', /test$/)); 520 assert.isFalse(MemoryColumn.nameMatchesCondition('test_column', /test$/));
520 }); 521 });
521 522
522 test('checkStringMemoryColumn_value_singleField', function() { 523 test('checkStringMemoryColumn_value_singleField', function() {
523 var c = new StringMemoryColumn('', ['x'], AggregationMode.MAX); 524 var c = new StringMemoryColumn('', ['x'], AggregationMode.MAX);
524 c.color = function(fields, contexts) { 525 c.color = function(fields, contexts) {
525 if (fields[0] < '0') 526 if (fields[0] < '0') return 'green';
526 return 'green'; 527 if (contexts && contexts[0] % 2 === 0) return 'red';
527 if (contexts && contexts[0] % 2 === 0)
528 return 'red';
529 return undefined; 528 return undefined;
530 }; 529 };
531 530
532 var infos1 = [{ icon: '\u{1F648}', message: 'Some info', color: 'blue' }]; 531 var infos1 = [{ icon: '\u{1F648}', message: 'Some info', color: 'blue' }];
533 var infos2 = [ 532 var infos2 = [
534 { icon: '\u{1F649}', message: 'Start', color: 'cyan' }, 533 { icon: '\u{1F649}', message: 'Start', color: 'cyan' },
535 { icon: '\u{1F64A}', message: 'Stop' } 534 { icon: '\u{1F64A}', message: 'Stop' }
536 ]; 535 ];
537 c.addInfos = function(fields, contexts, infos) { 536 c.addInfos = function(fields, contexts, infos) {
538 if (fields[0] < '0') 537 if (fields[0] < '0') {
539 infos.push.apply(infos, infos1); 538 infos.push.apply(infos, infos1);
540 else if (contexts && contexts[0] % 2 === 0) 539 } else if (contexts && contexts[0] % 2 === 0) {
541 infos.push.apply(infos, infos2); 540 infos.push.apply(infos, infos2);
541 }
542 }; 542 };
543 543
544 var row = {x: new MemoryCell(['123'])}; 544 var row = {x: new MemoryCell(['123'])};
545 assert.strictEqual(c.value(row), '123'); 545 assert.strictEqual(c.value(row), '123');
546 546
547 var row = {x: new MemoryCell(['-123']), contexts: [undefined]}; 547 var row = {x: new MemoryCell(['-123']), contexts: [undefined]};
548 checkCellValue(this, c.value(row), '-123', 'green', infos1); 548 checkCellValue(this, c.value(row), '-123', 'green', infos1);
549 549
550 var row = {x: new MemoryCell(['123']), contexts: [42]}; 550 var row = {x: new MemoryCell(['123']), contexts: [42]};
551 checkCellValue(this, c.value(row), '123', 'red', infos2); 551 checkCellValue(this, c.value(row), '123', 'red', infos2);
552 }); 552 });
553 553
554 test('checkStringMemoryColumn_value_multipleFields', function() { 554 test('checkStringMemoryColumn_value_multipleFields', function() {
555 var c1 = new StringMemoryColumn('test_column1', ['x'], 555 var c1 = new StringMemoryColumn('test_column1', ['x'],
556 undefined /* aggregation mode */); 556 undefined /* aggregation mode */);
557 var c2 = new StringMemoryColumn('test_column2', ['x'], 557 var c2 = new StringMemoryColumn('test_column2', ['x'],
558 AggregationMode.DIFF); 558 AggregationMode.DIFF);
559 c2.color = function(fields, contexts) { 559 c2.color = function(fields, contexts) {
560 return '#009999'; 560 return '#009999';
561 }; 561 };
562 var c3 = new StringMemoryColumn('test_column3', ['x'], 562 var c3 = new StringMemoryColumn('test_column3', ['x'],
563 AggregationMode.MAX); 563 AggregationMode.MAX);
564 c3.color = function(fields, contexts) { 564 c3.color = function(fields, contexts) {
565 if (fields[0] < '0') 565 if (fields[0] < '0') {
566 return 'green'; 566 return 'green';
567 else if (contexts && contexts[contexts.length - 1] % 2 === 0) 567 } else if (contexts && contexts[contexts.length - 1] % 2 === 0) {
568 return 'red'; 568 return 'red';
569 }
569 return undefined; 570 return undefined;
570 }; 571 };
571 572
572 var infos1 = [{ icon: '\u{1F648}', message: 'Some info', color: 'blue' }]; 573 var infos1 = [{ icon: '\u{1F648}', message: 'Some info', color: 'blue' }];
573 var infos2 = [ 574 var infos2 = [
574 { icon: '\u{1F649}', message: 'Start', color: 'cyan' }, 575 { icon: '\u{1F649}', message: 'Start', color: 'cyan' },
575 { icon: '\u{1F64A}', message: 'Stop' } 576 { icon: '\u{1F64A}', message: 'Stop' }
576 ]; 577 ];
577 c1.addInfos = c2.addInfos = c3.addInfos = 578 c1.addInfos = c2.addInfos = c3.addInfos =
578 function(fields, contexts, infos) { 579 function(fields, contexts, infos) {
579 if (fields[0] < '0') 580 if (fields[0] < '0') {
580 infos.push.apply(infos, infos1); 581 infos.push.apply(infos, infos1);
581 else if (contexts && contexts[contexts.length - 1] % 2 === 0) 582 } else if (contexts && contexts[contexts.length - 1] % 2 === 0) {
582 infos.push.apply(infos, infos2); 583 infos.push.apply(infos, infos2);
584 }
583 }; 585 };
584 586
585 var row = {x: new MemoryCell(['123', '456'])}; 587 var row = {x: new MemoryCell(['123', '456'])};
586 checkCellValue(this, c1.value(row), '(unsupported aggregation mode)', ''); 588 checkCellValue(this, c1.value(row), '(unsupported aggregation mode)', '');
587 checkCellValue(this, c2.value(row), '123 \u2192 456', 'rgb(0, 153, 153)'); 589 checkCellValue(this, c2.value(row), '123 \u2192 456', 'rgb(0, 153, 153)');
588 assert.strictEqual(c3.value(row), '456'); 590 assert.strictEqual(c3.value(row), '456');
589 591
590 var row = { 592 var row = {
591 x: new MemoryCell(['-123', undefined, '+123']), 593 x: new MemoryCell(['-123', undefined, '+123']),
592 contexts: [12, 14, undefined] 594 contexts: [12, 14, undefined]
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 }); 1229 });
1228 assert.deepEqual(Object.keys(cells), ['a', 'b', 'd']); 1230 assert.deepEqual(Object.keys(cells), ['a', 'b', 'd']);
1229 checkSizeNumericFields( 1231 checkSizeNumericFields(
1230 cells.a, mockColumn, [9, undefined, undefined, undefined]); 1232 cells.a, mockColumn, [9, undefined, undefined, undefined]);
1231 checkSizeNumericFields(cells.b, mockColumn, [314, 159, undefined, 265]); 1233 checkSizeNumericFields(cells.b, mockColumn, [314, 159, undefined, 265]);
1232 checkSizeNumericFields( 1234 checkSizeNumericFields(
1233 cells.d, mockColumn, [undefined, undefined, undefined, 0]); 1235 cells.d, mockColumn, [undefined, undefined, undefined, 0]);
1234 }); 1236 });
1235 }); 1237 });
1236 </script> 1238 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698