| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright 2015 The Chromium Authors. All rights reserved. | 3 Copyright 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/value/numeric.html"> | 8 <link rel="import" href="/tracing/value/numeric.html"> |
| 9 <link rel="import" href="/tracing/value/time_display_mode.html"> | 9 <link rel="import" href="/tracing/value/time_display_mode.html"> |
| 10 <link rel="import" href="/tracing/value/ui/scalar_span.html"> | 10 <link rel="import" href="/tracing/value/ui/scalar_span.html"> |
| 11 <link rel="import" href="/tracing/value/unit.html"> | 11 <link rel="import" href="/tracing/value/unit.html"> |
| 12 <link rel="import" href="/tracing/value/unit_scale.html"> | 12 <link rel="import" href="/tracing/value/unit_scale.html"> |
| 13 | 13 |
| 14 <script> | 14 <script> |
| 15 'use strict'; | 15 'use strict'; |
| 16 | 16 |
| 17 tr.b.unittest.testSuite(function() { | 17 tr.b.unittest.testSuite(function() { |
| 18 var ScalarNumeric = tr.v.ScalarNumeric; | 18 var ScalarNumeric = tr.v.ScalarNumeric; |
| 19 var Unit = tr.v.Unit; | 19 var Unit = tr.v.Unit; |
| 20 var THIS_DOC = document._currentScript.ownerDocument; | 20 var THIS_DOC = document._currentScript.ownerDocument; |
| 21 | 21 |
| 22 function checkScalarSpan( | 22 function checkScalarSpan(test, value, unit, expectedContent, opt_options) { |
| 23 test, value, unit, expectedTextContent, opt_expectedColor) { | 23 var options = opt_options || {}; |
| 24 var span = tr.v.ui.createScalarSpan(new tr.v.ScalarNumeric(unit, value)); | 24 var span = tr.v.ui.createScalarSpan(new tr.v.ScalarNumeric(unit, value), |
| 25 {significance: options.significance}); |
| 26 |
| 27 test.addHTMLOutput(span); |
| 25 assert.strictEqual( | 28 assert.strictEqual( |
| 26 Polymer.dom(span.$.content).textContent, expectedTextContent); | 29 Polymer.dom(span.$.content).textContent, expectedContent); |
| 27 assert.strictEqual(span.$.content.style.color, opt_expectedColor || ''); | 30 assert.strictEqual(window.getComputedStyle(span.$.content).color, |
| 28 test.addHTMLOutput(span); | 31 options.expectedColor || 'rgb(0, 0, 0)'); |
| 32 |
| 33 if (options.expectedTitle) |
| 34 assert.strictEqual(span.$.content.title, options.expectedTitle); |
| 35 |
| 36 if (options.significance !== undefined) { |
| 37 assert.strictEqual(Polymer.dom(span.$.significance).textContent, |
| 38 options.expectedEmoji); |
| 39 assert.strictEqual(window.getComputedStyle(span.$.significance).color, |
| 40 options.expectedEmojiColor || 'rgb(0, 0, 0)'); |
| 41 if (options.expectedTitle) |
| 42 assert.strictEqual(span.$.significance.title, options.expectedTitle); |
| 43 } |
| 29 } | 44 } |
| 30 | 45 |
| 46 test('instantiate_significance', function() { |
| 47 var countD = Unit.byName.count.correspondingDeltaUnit; |
| 48 var countSIBD = Unit.byName.count_smallerIsBetter.correspondingDeltaUnit; |
| 49 var countBIBD = Unit.byName.count_biggerIsBetter.correspondingDeltaUnit; |
| 50 |
| 51 var zero = String.fromCharCode(177) + '0'; |
| 52 |
| 53 checkScalarSpan(this, 0, countSIBD, zero, { |
| 54 significance: tr.v.Significance.DONT_CARE, |
| 55 expectedTitle: 'no change', |
| 56 expectedEmoji: '' |
| 57 }); |
| 58 |
| 59 checkScalarSpan(this, 0, countSIBD, zero, { |
| 60 significance: tr.v.Significance.INSIGNIFICANT, |
| 61 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 62 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 63 expectedTitle: 'no change' |
| 64 }); |
| 65 |
| 66 assert.throws(() => checkScalarSpan(this, 0, countSIBD, zero, |
| 67 {significance: tr.v.Significance.SIGNIFICANT})); |
| 68 |
| 69 checkScalarSpan(this, 0, countBIBD, zero, { |
| 70 significance: tr.v.Significance.DONT_CARE, |
| 71 expectedTitle: 'no change', |
| 72 expectedEmoji: '' |
| 73 }); |
| 74 |
| 75 checkScalarSpan(this, 0, countBIBD, zero, { |
| 76 significance: tr.v.Significance.INSIGNIFICANT, |
| 77 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 78 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 79 expectedTitle: 'no change' |
| 80 }); |
| 81 |
| 82 assert.throws(() => checkScalarSpan(this, 0, countSIBD, zero, |
| 83 {significance: tr.v.Significance.SIGNIFICANT})); |
| 84 |
| 85 checkScalarSpan(this, 1, countSIBD, '+1', { |
| 86 significance: tr.v.Significance.DONT_CARE, |
| 87 expectedColor: 'rgb(255, 0, 0)', |
| 88 expectedTitle: 'regression', |
| 89 expectedEmoji: '' |
| 90 }); |
| 91 |
| 92 checkScalarSpan(this, 1, countSIBD, '+1', { |
| 93 significance: tr.v.Significance.INSIGNIFICANT, |
| 94 expectedColor: 'rgb(255, 0, 0)', |
| 95 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 96 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 97 expectedTitle: 'insignificant regression' |
| 98 }); |
| 99 |
| 100 checkScalarSpan(this, 1, countSIBD, '+1', { |
| 101 significance: tr.v.Significance.SIGNIFICANT, |
| 102 expectedColor: 'rgb(255, 0, 0)', |
| 103 expectedEmoji: tr.v.ui.Emoji.CONFOUNDED_FACE, |
| 104 expectedEmojiColor: 'rgb(255, 0, 0)', |
| 105 expectedTitle: 'significant regression' |
| 106 }); |
| 107 |
| 108 checkScalarSpan(this, 1, countBIBD, '+1', { |
| 109 significance: tr.v.Significance.DONT_CARE, |
| 110 expectedColor: 'rgb(0, 128, 0)', |
| 111 expectedTitle: 'improvement', |
| 112 expectedEmoji: '' |
| 113 }); |
| 114 |
| 115 checkScalarSpan(this, 1, countBIBD, '+1', { |
| 116 significance: tr.v.Significance.INSIGNIFICANT, |
| 117 expectedColor: 'rgb(0, 128, 0)', |
| 118 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 119 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 120 expectedTitle: 'insignificant improvement' |
| 121 }); |
| 122 |
| 123 checkScalarSpan(this, 1, countBIBD, '+1', { |
| 124 significance: tr.v.Significance.SIGNIFICANT, |
| 125 expectedColor: 'rgb(0, 128, 0)', |
| 126 expectedEmoji: tr.v.ui.Emoji.GRINNING_FACE, |
| 127 expectedEmojiColor: 'rgb(0, 128, 0)', |
| 128 expectedTitle: 'significant improvement' |
| 129 }); |
| 130 |
| 131 checkScalarSpan(this, -1, countSIBD, '-1', { |
| 132 significance: tr.v.Significance.DONT_CARE, |
| 133 expectedColor: 'rgb(0, 128, 0)', |
| 134 expectedEmoji: '', |
| 135 expectedEmojiColor: '', |
| 136 expectedTitle: 'improvement' |
| 137 }); |
| 138 |
| 139 checkScalarSpan(this, -1, countSIBD, '-1', { |
| 140 expectedColor: 'rgb(0, 128, 0)', |
| 141 significance: tr.v.Significance.INSIGNIFICANT, |
| 142 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 143 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 144 expectedTitle: 'insignificant improvement' |
| 145 }); |
| 146 |
| 147 checkScalarSpan(this, -1, countSIBD, '-1', { |
| 148 expectedColor: 'rgb(0, 128, 0)', |
| 149 significance: tr.v.Significance.SIGNIFICANT, |
| 150 expectedEmoji: tr.v.ui.Emoji.GRINNING_FACE, |
| 151 expectedEmojiColor: 'rgb(0, 128, 0)', |
| 152 expectedTitle: 'significant improvement' |
| 153 }); |
| 154 |
| 155 checkScalarSpan(this, -1, countBIBD, '-1', { |
| 156 expectedColor: 'rgb(255, 0, 0)', |
| 157 significance: tr.v.Significance.DONT_CARE, |
| 158 expectedEmoji: '' |
| 159 }); |
| 160 |
| 161 checkScalarSpan(this, -1, countBIBD, '-1', { |
| 162 expectedColor: 'rgb(255, 0, 0)', |
| 163 significance: tr.v.Significance.INSIGNIFICANT, |
| 164 expectedEmoji: tr.v.ui.Emoji.NEUTRAL_FACE, |
| 165 expectedEmojiColor: 'rgb(0, 0, 0)', |
| 166 expectedTitle: 'insignificant regression' |
| 167 }); |
| 168 |
| 169 checkScalarSpan(this, -1, countBIBD, '-1', { |
| 170 expectedColor: 'rgb(255, 0, 0)', |
| 171 significance: tr.v.Significance.SIGNIFICANT, |
| 172 expectedEmoji: tr.v.ui.Emoji.CONFOUNDED_FACE, |
| 173 expectedEmojiColor: 'rgb(255, 0, 0)', |
| 174 expectedTitle: 'significant regression' |
| 175 }); |
| 176 |
| 177 checkScalarSpan(this, 1, countD, '+1', { |
| 178 expectedColor: 'rgb(0, 0, 0)', |
| 179 significance: tr.v.Significance.DONT_CARE, |
| 180 expectedEmoji: '' |
| 181 }); |
| 182 |
| 183 checkScalarSpan(this, 1, countD, '+1', { |
| 184 expectedColor: 'rgb(0, 0, 0)', |
| 185 significance: tr.v.Significance.INSIGNIFICANT, |
| 186 expectedEmoji: '' |
| 187 }); |
| 188 |
| 189 checkScalarSpan(this, 1, countD, '+1', { |
| 190 expectedColor: 'rgb(0, 0, 0)', |
| 191 significance: tr.v.Significance.SIGNIFICANT, |
| 192 expectedEmoji: '' |
| 193 }); |
| 194 |
| 195 checkScalarSpan(this, -1, countD, '-1', { |
| 196 expectedColor: 'rgb(0, 0, 0)', |
| 197 significance: tr.v.Significance.DONT_CARE, |
| 198 expectedEmoji: '' |
| 199 }); |
| 200 |
| 201 checkScalarSpan(this, -1, countD, '-1', { |
| 202 expectedColor: 'rgb(0, 0, 0)', |
| 203 significance: tr.v.Significance.INSIGNIFICANT, |
| 204 expectedEmoji: '' |
| 205 }); |
| 206 |
| 207 checkScalarSpan(this, -1, countD, '-1', { |
| 208 expectedColor: 'rgb(0, 0, 0)', |
| 209 significance: tr.v.Significance.SIGNIFICANT, |
| 210 expectedEmoji: '' |
| 211 }); |
| 212 }); |
| 213 |
| 31 test('instantiate', function() { | 214 test('instantiate', function() { |
| 32 checkScalarSpan(this, 123.456789, Unit.byName.timeDurationInMs, | 215 checkScalarSpan(this, 123.456789, Unit.byName.timeDurationInMs, |
| 33 '123.457 ms'); | 216 '123.457 ms'); |
| 34 checkScalarSpan(this, 0, Unit.byName.normalizedPercentage, '0.000%'); | 217 checkScalarSpan(this, 0, Unit.byName.normalizedPercentage, '0.000%'); |
| 35 checkScalarSpan(this, -2560, Unit.byName.sizeInBytes, '-2.5 KiB'); | 218 checkScalarSpan(this, -2560, Unit.byName.sizeInBytes, '-2.5 KiB'); |
| 36 }); | 219 }); |
| 37 | 220 |
| 38 test('instantiate_smallerIsBetter', function() { | 221 test('instantiate_smallerIsBetter', function() { |
| 39 checkScalarSpan(this, 45097156608, Unit.byName.sizeInBytes_smallerIsBetter, | 222 checkScalarSpan(this, 45097156608, Unit.byName.sizeInBytes_smallerIsBetter, |
| 40 '42.0 GiB'); | 223 '42.0 GiB'); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 checkScalarSpan(this, 123.456789, Unit.byName.timeDurationInMsDelta, | 240 checkScalarSpan(this, 123.456789, Unit.byName.timeDurationInMsDelta, |
| 58 '+123.457 ms'); | 241 '+123.457 ms'); |
| 59 checkScalarSpan(this, 0, Unit.byName.normalizedPercentageDelta, | 242 checkScalarSpan(this, 0, Unit.byName.normalizedPercentageDelta, |
| 60 '\u00B10.000%'); | 243 '\u00B10.000%'); |
| 61 checkScalarSpan(this, -2560, Unit.byName.sizeInBytesDelta, | 244 checkScalarSpan(this, -2560, Unit.byName.sizeInBytesDelta, |
| 62 '-2.5 KiB'); | 245 '-2.5 KiB'); |
| 63 }); | 246 }); |
| 64 | 247 |
| 65 test('instantiate_delta_smallerIsBetter', function() { | 248 test('instantiate_delta_smallerIsBetter', function() { |
| 66 checkScalarSpan(this, 45097156608, | 249 checkScalarSpan(this, 45097156608, |
| 67 Unit.byName.sizeInBytesDelta_smallerIsBetter, '+42.0 GiB', 'red'); | 250 Unit.byName.sizeInBytesDelta_smallerIsBetter, '+42.0 GiB', |
| 251 {expectedColor: 'rgb(255, 0, 0)'}); |
| 68 checkScalarSpan(this, 0, Unit.byName.energyInJoulesDelta_smallerIsBetter, | 252 checkScalarSpan(this, 0, Unit.byName.energyInJoulesDelta_smallerIsBetter, |
| 69 '\u00B10.000 J'); | 253 '\u00B10.000 J'); |
| 70 checkScalarSpan(this, -0.25, | 254 checkScalarSpan(this, -0.25, |
| 71 Unit.byName.unitlessNumberDelta_smallerIsBetter, '-0.250', 'green'); | 255 Unit.byName.unitlessNumberDelta_smallerIsBetter, '-0.250', |
| 256 {expectedColor: 'rgb(0, 128, 0)'}); |
| 72 }); | 257 }); |
| 73 | 258 |
| 74 test('instantiate_delta_biggerIsBetter', function() { | 259 test('instantiate_delta_biggerIsBetter', function() { |
| 75 checkScalarSpan(this, 0.07, Unit.byName.powerInWattsDelta_biggerIsBetter, | 260 checkScalarSpan(this, 0.07, Unit.byName.powerInWattsDelta_biggerIsBetter, |
| 76 '+0.070 W', 'green'); | 261 '+0.070 W', {expectedColor: 'rgb(0, 128, 0)'}); |
| 77 checkScalarSpan(this, 0, Unit.byName.timeStampInMsDelta_biggerIsBetter, | 262 checkScalarSpan(this, 0, Unit.byName.timeStampInMsDelta_biggerIsBetter, |
| 78 '\u00B10.000 ms'); | 263 '\u00B10.000 ms'); |
| 79 checkScalarSpan(this, -0.00003, | 264 checkScalarSpan(this, -0.00003, |
| 80 Unit.byName.normalizedPercentageDelta_biggerIsBetter, '-0.003%', 'red'); | 265 Unit.byName.normalizedPercentageDelta_biggerIsBetter, '-0.003%', |
| 266 {expectedColor: 'rgb(255, 0, 0)'}); |
| 81 }); | 267 }); |
| 82 | 268 |
| 83 test('createScalarSpan', function() { | 269 test('createScalarSpan', function() { |
| 84 // No config. | 270 // No config. |
| 85 var span = tr.v.ui.createScalarSpan( | 271 var span = tr.v.ui.createScalarSpan( |
| 86 new ScalarNumeric(Unit.byName.powerInWatts, 3.14)); | 272 new ScalarNumeric(Unit.byName.powerInWatts, 3.14)); |
| 87 assert.strictEqual(span.$.content.textContent, '3.140 W'); | 273 assert.strictEqual(Polymer.dom(span.$.content).textContent, '3.140 W'); |
| 88 assert.strictEqual(span.ownerDocument, document); | 274 assert.strictEqual(span.ownerDocument, document); |
| 89 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); | 275 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); |
| 90 assert.strictEqual(span.value, 3.14); | 276 assert.strictEqual(span.value, 3.14); |
| 91 assert.strictEqual(span.unit, Unit.byName.powerInWatts); | 277 assert.strictEqual(span.unit, Unit.byName.powerInWatts); |
| 92 assert.isUndefined(span.context); | 278 assert.isUndefined(span.context); |
| 93 assert.isUndefined(span.percentage); | 279 assert.isUndefined(span.percentage); |
| 94 assert.isUndefined(span.warning); | 280 assert.isUndefined(span.warning); |
| 95 assert.isFalse(span.rightAlign); | 281 assert.isFalse(span.rightAlign); |
| 96 this.addHTMLOutput(span); | 282 this.addHTMLOutput(span); |
| 97 | 283 |
| 98 // Custom owner document and right align. | 284 // Custom owner document and right align. |
| 99 var span = tr.v.ui.createScalarSpan( | 285 var span = tr.v.ui.createScalarSpan( |
| 100 new ScalarNumeric(Unit.byName.energyInJoules, 2.72), | 286 new ScalarNumeric(Unit.byName.energyInJoules, 2.72), |
| 101 { ownerDocument: THIS_DOC, rightAlign: true }); | 287 { ownerDocument: THIS_DOC, rightAlign: true }); |
| 102 assert.strictEqual(span.$.content.textContent, '2.720 J'); | 288 assert.strictEqual(Polymer.dom(span.$.content).textContent, '2.720 J'); |
| 103 assert.strictEqual(span.ownerDocument, THIS_DOC); | 289 assert.strictEqual(span.ownerDocument, THIS_DOC); |
| 104 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); | 290 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); |
| 105 assert.strictEqual(span.value, 2.72); | 291 assert.strictEqual(span.value, 2.72); |
| 106 assert.strictEqual(span.unit, Unit.byName.energyInJoules); | 292 assert.strictEqual(span.unit, Unit.byName.energyInJoules); |
| 107 assert.isUndefined(span.context); | 293 assert.isUndefined(span.context); |
| 108 assert.isUndefined(span.percentage); | 294 assert.isUndefined(span.percentage); |
| 109 assert.isUndefined(span.warning); | 295 assert.isUndefined(span.warning); |
| 110 assert.isTrue(span.rightAlign); | 296 assert.isTrue(span.rightAlign); |
| 111 this.addHTMLOutput(span); | 297 this.addHTMLOutput(span); |
| 112 | 298 |
| 113 // Unit and sparkline set via config. | 299 // Unit and sparkline set via config. |
| 114 var span = tr.v.ui.createScalarSpan(1.62, | 300 var span = tr.v.ui.createScalarSpan(1.62, |
| 115 { unit: Unit.byName.timeStampInMs, total: 3.24 }); | 301 { unit: Unit.byName.timeStampInMs, total: 3.24 }); |
| 116 assert.strictEqual(span.$.content.textContent, '1.620 ms'); | 302 assert.strictEqual(Polymer.dom(span.$.content).textContent, '1.620 ms'); |
| 117 assert.strictEqual(span.ownerDocument, document); | 303 assert.strictEqual(span.ownerDocument, document); |
| 118 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); | 304 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); |
| 119 assert.strictEqual(span.value, 1.62); | 305 assert.strictEqual(span.value, 1.62); |
| 120 assert.strictEqual(span.unit, Unit.byName.timeStampInMs); | 306 assert.strictEqual(span.unit, Unit.byName.timeStampInMs); |
| 121 assert.isUndefined(span.context); | 307 assert.isUndefined(span.context); |
| 122 assert.strictEqual(span.percentage, 0.5); | 308 assert.strictEqual(span.percentage, 0.5); |
| 123 assert.isUndefined(span.warning); | 309 assert.isUndefined(span.warning); |
| 124 assert.isFalse(span.rightAlign); | 310 assert.isFalse(span.rightAlign); |
| 125 this.addHTMLOutput(span); | 311 this.addHTMLOutput(span); |
| 126 | 312 |
| 127 // Custom context. | 313 // Custom context. |
| 128 var span = tr.v.ui.createScalarSpan( | 314 var span = tr.v.ui.createScalarSpan( |
| 129 new ScalarNumeric(Unit.byName.sizeInBytesDelta_smallerIsBetter, | 315 new ScalarNumeric(Unit.byName.sizeInBytesDelta_smallerIsBetter, |
| 130 256 * 1024 * 1024), { context: { | 316 256 * 1024 * 1024), { context: { |
| 131 unitPrefix: tr.v.UnitScale.Binary.KIBI, | 317 unitPrefix: tr.v.UnitScale.Binary.KIBI, |
| 132 minimumFractionDigits: 2 | 318 minimumFractionDigits: 2 |
| 133 } }); | 319 } }); |
| 134 assert.strictEqual(span.$.content.textContent, '+262,144.00 KiB'); | 320 assert.strictEqual( |
| 321 Polymer.dom(span.$.content).textContent, '+262,144.00 KiB'); |
| 135 assert.strictEqual(span.ownerDocument, document); | 322 assert.strictEqual(span.ownerDocument, document); |
| 136 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); | 323 assert.strictEqual(span.tagName, 'TR-V-UI-SCALAR-SPAN'); |
| 137 assert.strictEqual(span.value, 256 * 1024 * 1024); | 324 assert.strictEqual(span.value, 256 * 1024 * 1024); |
| 138 assert.strictEqual(span.unit, Unit.byName.sizeInBytesDelta_smallerIsBetter); | 325 assert.strictEqual(span.unit, Unit.byName.sizeInBytesDelta_smallerIsBetter); |
| 139 assert.deepEqual(span.context, | 326 assert.deepEqual(span.context, |
| 140 { unitPrefix: tr.v.UnitScale.Binary.KIBI, minimumFractionDigits: 2 }); | 327 { unitPrefix: tr.v.UnitScale.Binary.KIBI, minimumFractionDigits: 2 }); |
| 141 assert.isUndefined(span.percentage); | 328 assert.isUndefined(span.percentage); |
| 142 assert.isUndefined(span.warning); | 329 assert.isUndefined(span.warning); |
| 143 assert.isFalse(span.rightAlign); | 330 assert.isFalse(span.rightAlign); |
| 144 this.addHTMLOutput(span); | 331 this.addHTMLOutput(span); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 164 span.value = new ScalarNumeric(Unit.byName.timeStampInMs, 5.777); | 351 span.value = new ScalarNumeric(Unit.byName.timeStampInMs, 5.777); |
| 165 span.rightAlign = true; | 352 span.rightAlign = true; |
| 166 this.addHTMLOutput(span); | 353 this.addHTMLOutput(span); |
| 167 }); | 354 }); |
| 168 | 355 |
| 169 test('instantiate_withContext', function() { | 356 test('instantiate_withContext', function() { |
| 170 var span = document.createElement('tr-v-ui-scalar-span'); | 357 var span = document.createElement('tr-v-ui-scalar-span'); |
| 171 span.value = new ScalarNumeric( | 358 span.value = new ScalarNumeric( |
| 172 Unit.byName.unitlessNumberDelta_smallerIsBetter, 42); | 359 Unit.byName.unitlessNumberDelta_smallerIsBetter, 42); |
| 173 span.context = { maximumFractionDigits: 2 }; | 360 span.context = { maximumFractionDigits: 2 }; |
| 174 assert.strictEqual(span.$.content.textContent, '+42.00'); | 361 assert.strictEqual(Polymer.dom(span.$.content).textContent, '+42.00'); |
| 175 this.addHTMLOutput(span); | 362 this.addHTMLOutput(span); |
| 176 }); | 363 }); |
| 177 | 364 |
| 178 test('warningAndNonWarningHaveSimilarHeights', function() { | 365 test('warningAndNonWarningHaveSimilarHeights', function() { |
| 179 var spanA = document.createElement('tr-v-ui-scalar-span'); | 366 var spanA = document.createElement('tr-v-ui-scalar-span'); |
| 180 spanA.setValueAndUnit(400, Unit.byName.timeDurationInMs); | 367 spanA.setValueAndUnit(400, Unit.byName.timeDurationInMs); |
| 181 | 368 |
| 182 var spanB = document.createElement('tr-v-ui-scalar-span'); | 369 var spanB = document.createElement('tr-v-ui-scalar-span'); |
| 183 spanB.setValueAndUnit(400, Unit.byName.timeDurationInMs); | 370 spanB.setValueAndUnit(400, Unit.byName.timeDurationInMs); |
| 184 spanB.warning = 'There is a problem with this time'; | 371 spanB.warning = 'There is a problem with this time'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 413 } |
| 227 | 414 |
| 228 addAndCheckScalarSpan(null /* no percentage set */, 'none', 0); | 415 addAndCheckScalarSpan(null /* no percentage set */, 'none', 0); |
| 229 addAndCheckScalarSpan(undefined, 'none', 0); | 416 addAndCheckScalarSpan(undefined, 'none', 0); |
| 230 addAndCheckScalarSpan(0, 'block', 1); | 417 addAndCheckScalarSpan(0, 'block', 1); |
| 231 addAndCheckScalarSpan(0.05, 'block', 5); | 418 addAndCheckScalarSpan(0.05, 'block', 5); |
| 232 addAndCheckScalarSpan(0.5, 'block', 50); | 419 addAndCheckScalarSpan(0.5, 'block', 50); |
| 233 addAndCheckScalarSpan(0.95, 'block', 95); | 420 addAndCheckScalarSpan(0.95, 'block', 95); |
| 234 addAndCheckScalarSpan(1, 'block', 100); | 421 addAndCheckScalarSpan(1, 'block', 100); |
| 235 }); | 422 }); |
| 423 |
| 424 test('emptyNumeric', function() { |
| 425 assert.strictEqual(tr.v.ui.createScalarSpan(), ''); |
| 426 |
| 427 var numeric = tr.v.NumericBuilder.createLinear( |
| 428 tr.v.Unit.byName.timeDurationInMs, tr.b.Range.fromExplicitRange(0, 1000), |
| 429 10).build(); |
| 430 var value = new tr.v.NumericValue('foo', numeric); |
| 431 assert.strictEqual(tr.v.ui.createScalarSpan(value), ''); |
| 432 }); |
| 236 }); | 433 }); |
| 237 </script> | 434 </script> |
| OLD | NEW |