| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 cr.define('md_history.history_metrics_test', function() { |
| 6 /** |
| 7 * @constructor |
| 8 * @extends {md_history.BrowserService} |
| 9 */ |
| 10 var TestMetricsBrowserService = function() { this.histogramMap = {}; }; |
| 11 |
| 12 function registerTests() { |
| 13 suite('Metrics', function() { |
| 14 var service; |
| 15 var app; |
| 16 |
| 17 suiteSetup(function() { |
| 18 TestMetricsBrowserService.prototype = { |
| 19 __proto__: md_history.BrowserService.prototype, |
| 20 |
| 21 /** @override */ |
| 22 recordHistogram: function(histogram, value, max) { |
| 23 assertTrue(value < max); |
| 24 |
| 25 if (!(histogram in this.histogramMap)) |
| 26 this.histogramMap[histogram] = {}; |
| 27 |
| 28 if (!(value in this.histogramMap[histogram])) |
| 29 this.histogramMap[histogram][value] = 0; |
| 30 |
| 31 this.histogramMap[histogram][value]++; |
| 32 } |
| 33 }; |
| 34 }); |
| 35 |
| 36 setup(function() { |
| 37 md_history.BrowserService.instance_ = new TestMetricsBrowserService(); |
| 38 service = md_history.BrowserService.getInstance(); |
| 39 |
| 40 app = replaceApp(); |
| 41 return flush(); |
| 42 }); |
| 43 |
| 44 test('History.HistoryView', function() { |
| 45 app.grouped_ = true; |
| 46 |
| 47 var histogram = service.histogramMap['History.HistoryView']; |
| 48 assertEquals(1, histogram[HistoryViewHistogram.HISTORY]); |
| 49 |
| 50 app.selectedPage_ = 'syncedTabs'; |
| 51 assertEquals(1, histogram[HistoryViewHistogram.SIGNIN_PROMO]); |
| 52 updateSignInState(true); |
| 53 return flush().then(() => { |
| 54 assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); |
| 55 app.selectedPage_ = 'history'; |
| 56 assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); |
| 57 app.set('queryState_.range', HistoryRange.WEEK); |
| 58 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); |
| 59 app.set('queryState_.range', HistoryRange.MONTH); |
| 60 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); |
| 61 }); |
| 62 }); |
| 63 }); |
| 64 } |
| 65 return { |
| 66 registerTests: registerTests |
| 67 }; |
| 68 }); |
| OLD | NEW |