Chromium Code Reviews| Index: chrome/test/data/webui/md_history/history_metrics_test.js |
| diff --git a/chrome/test/data/webui/md_history/history_metrics_test.js b/chrome/test/data/webui/md_history/history_metrics_test.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cd18ffe78da379ac371a31eb52bd1bfe4bdb1d7b |
| --- /dev/null |
| +++ b/chrome/test/data/webui/md_history/history_metrics_test.js |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('md_history.history_metrics_test', function() { |
| + |
| + function registerTests() { |
| + suite('Metrics', function() { |
| + var browserService; |
| + var app; |
| + |
| + setup(function() { |
| + PolymerTest.clearBody(); |
| + |
| + /** |
| + * @constructor |
| + * @extends {md_history.BrowserService} |
| + */ |
| + var TestMetricsBrowserService = function() { this.histogramMap = {}; }; |
|
tsergeant
2016/08/17 06:03:09
Nit: Maybe move this declaration outside of the se
calamity
2016/08/18 03:11:15
Done.
tsergeant
2016/08/19 00:46:23
Sorry, I was unclear: I meant move the whole TestM
calamity
2016/08/19 06:26:07
Done.
|
| + |
| + TestMetricsBrowserService.prototype = { |
| + __proto__: md_history.BrowserService.prototype, |
| + |
| + /** @override */ |
| + recordHistogram: function(histogram, value, max) { |
| + assertTrue(value < max); |
| + |
| + if (!(histogram in this.histogramMap)) |
| + this.histogramMap[histogram] = {}; |
| + |
| + if (!(value in this.histogramMap[histogram])) |
| + this.histogramMap[histogram][value] = 0; |
| + |
| + this.histogramMap[histogram][value]++; |
| + } |
| + }; |
| + |
| + md_history.BrowserService.instance_ = new TestMetricsBrowserService(); |
| + |
| + browserService = md_history.BrowserService.getInstance(); |
| + app = document.createElement('history-app'); |
| + app.id = 'history-app'; |
| + document.body.appendChild(app); |
| + return flush(); |
| + }); |
| + |
| + test('History.HistoryView', function() { |
| + app.grouped_ = true; |
| + |
| + var histogram = browserService.histogramMap['History.HistoryView']; |
| + assertEquals(1, histogram[HistoryViewHistogram.HISTORY]); |
| + |
| + app.selectedPage_ = 'syncedTabs'; |
| + return waitForAnimationFrame().then(() => { |
| + assertEquals(1, histogram[HistoryViewHistogram.SIGNIN_PROMO]); |
| + updateSignInState(true); |
| + return waitForAnimationFrame(); |
| + }).then(() => { |
| + assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); |
| + app.selectedPage_ = 'history'; |
| + return waitForAnimationFrame(); |
| + }).then(() => { |
| + assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); |
| + app.set('queryState_.range', HistoryRange.WEEK); |
| + return waitForAnimationFrame(); |
| + }).then(() => { |
| + assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); |
| + app.set('queryState_.range', HistoryRange.MONTH); |
| + return waitForAnimationFrame(); |
| + }).then(() => { |
| + assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); |
| + }); |
| + }); |
| + }); |
| + } |
| + return { |
| + registerTests: registerTests |
| + }; |
| +}); |