Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('md_history.history_metrics_test', function() { | 5 cr.define('md_history.history_metrics_test', function() { |
| 6 | 6 |
| 7 function registerTests() { | 7 function registerTests() { |
| 8 suite('Metrics', function() { | 8 suite('Metrics', function() { |
| 9 var browserService; | |
| 10 var app; | 9 var app; |
| 11 var histogramMap; | 10 var histogramMap; |
| 11 var actionMap; | |
| 12 | |
| 13 suiteSetup(function() { | |
| 14 disableLinkClicks(); | |
| 15 }); | |
| 12 | 16 |
| 13 setup(function() { | 17 setup(function() { |
| 14 PolymerTest.clearBody(); | 18 PolymerTest.clearBody(); |
| 15 histogramMap = {}; | 19 histogramMap = {}; |
| 20 actionMap = {}; | |
| 16 | 21 |
| 17 /** | 22 /** |
| 18 * @constructor | 23 * @constructor |
| 19 * @extends {md_history.BrowserService} | 24 * @extends {md_history.BrowserService} |
| 20 */ | 25 */ |
| 21 var TestMetricsBrowserService = function() {}; | 26 var TestMetricsBrowserService = function() {}; |
| 22 | 27 |
| 23 TestMetricsBrowserService.prototype = { | 28 TestMetricsBrowserService.prototype = { |
| 24 __proto__: md_history.BrowserService.prototype, | 29 __proto__: md_history.BrowserService.prototype, |
| 25 | 30 |
| 26 /** @override */ | 31 /** @override */ |
| 27 recordHistogram: function(histogram, value, max) { | 32 recordHistogram: function(histogram, value, max) { |
| 28 assertTrue(value < max); | 33 assertTrue(value < max); |
| 29 | 34 |
| 30 if (!(histogram in histogramMap)) | 35 if (!(histogram in histogramMap)) |
| 31 histogramMap[histogram] = {}; | 36 histogramMap[histogram] = {}; |
| 32 | 37 |
| 33 if (!(value in histogramMap[histogram])) | 38 if (!(value in histogramMap[histogram])) |
| 34 histogramMap[histogram][value] = 0; | 39 histogramMap[histogram][value] = 0; |
| 35 | 40 |
| 36 histogramMap[histogram][value]++; | 41 histogramMap[histogram][value]++; |
| 42 }, | |
| 43 | |
| 44 /** @override */ | |
| 45 recordAction: function(action) { | |
| 46 if (!(action in actionMap)) | |
| 47 actionMap[action] = 0 | |
| 48 | |
| 49 actionMap[action]++; | |
| 50 }, | |
| 51 | |
| 52 /** @override */ | |
| 53 deleteItems: function() { | |
| 54 return flush(); | |
| 37 } | 55 } |
| 38 }; | 56 }; |
| 39 | 57 |
| 40 md_history.BrowserService.instance_ = new TestMetricsBrowserService(); | 58 md_history.BrowserService.instance_ = new TestMetricsBrowserService(); |
| 41 | 59 |
| 42 app = document.createElement('history-app'); | 60 app = document.createElement('history-app'); |
| 43 app.id = 'history-app'; | 61 app.id = 'history-app'; |
| 44 document.body.appendChild(app); | 62 document.body.appendChild(app); |
| 45 return flush(); | 63 return flush(); |
| 46 }); | 64 }); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 57 return flush().then(() => { | 75 return flush().then(() => { |
| 58 assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); | 76 assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); |
| 59 app.selectedPage_ = 'history'; | 77 app.selectedPage_ = 'history'; |
| 60 assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); | 78 assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); |
| 61 app.set('queryState_.range', HistoryRange.WEEK); | 79 app.set('queryState_.range', HistoryRange.WEEK); |
| 62 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); | 80 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); |
| 63 app.set('queryState_.range', HistoryRange.MONTH); | 81 app.set('queryState_.range', HistoryRange.MONTH); |
| 64 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); | 82 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); |
| 65 }); | 83 }); |
| 66 }); | 84 }); |
| 85 | |
| 86 test('history-list', function() { | |
| 87 var historyEntry = | |
| 88 createHistoryEntry('2015-01-01', 'http://www.google.com'); | |
| 89 historyEntry.starred = true; | |
| 90 app.historyResult(createHistoryInfo(), [ | |
| 91 createHistoryEntry('2015-01-01', 'http://www.example.com'), | |
| 92 historyEntry | |
| 93 ]); | |
| 94 | |
| 95 return flush().then(() => { | |
| 96 var items = polymerSelectAll( | |
| 97 app.$.history.$['infinite-list'], 'history-item'); | |
| 98 MockInteractions.tap(items[1].$$('#bookmark-star')); | |
| 99 assertEquals(1, actionMap['BookmarkStarClicked']); | |
| 100 MockInteractions.tap(items[1].$.title); | |
| 101 assertEquals(1, actionMap['EntryLinkClick']); | |
| 102 assertEquals( | |
| 103 1, histogramMap['HistoryPage.ClickPosition'][1]); | |
| 104 assertEquals( | |
| 105 1, histogramMap['HistoryPage.ClickPositionSubset'] | |
| 106 [1]); | |
| 107 | |
| 108 app.set('queryState_.searchTerm', 'goog'); | |
| 109 assertEquals(1, actionMap['Search']); | |
| 110 app.historyResult(createHistoryInfo('goog'), [ | |
| 111 createHistoryEntry('2015-01-01', 'http://www.google.com'), | |
| 112 createHistoryEntry('2015-01-01', 'http://www.google.com'), | |
| 113 createHistoryEntry('2015-01-01', 'http://www.google.com') | |
| 114 ]); | |
| 115 return flush(); | |
| 116 }).then(() => { | |
| 117 items = polymerSelectAll( | |
| 118 app.$.history.$['infinite-list'], 'history-item'); | |
| 119 MockInteractions.tap(items[0].$.title); | |
| 120 assertEquals(1, actionMap['SearchResultClick']); | |
| 121 assertEquals( | |
| 122 1, histogramMap['HistoryPage.ClickPosition'][0]); | |
| 123 assertEquals( | |
| 124 1, histogramMap['HistoryPage.ClickPositionSubset'] | |
| 125 [0]); | |
| 126 MockInteractions.tap(items[0].$.checkbox); | |
| 127 MockInteractions.tap(items[2].$.checkbox); | |
| 128 return flush(); | |
| 129 }).then(() => { | |
| 130 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
|
tsergeant
2016/08/18 04:14:34
You can check that RemoveSelected is recorded here
calamity
2016/08/19 13:59:44
Done.
| |
| 131 return flush(); | |
| 132 }).then(() => { | |
| 133 MockInteractions.tap(app.$.history.$$('.cancel-button')); | |
| 134 assertEquals(1, actionMap['CancelRemoveSelected']); | |
| 135 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
| 136 return flush(); | |
| 137 }).then(() => { | |
| 138 MockInteractions.tap(app.$.history.$$('.action-button')); | |
| 139 assertEquals(1, actionMap['ConfirmRemoveSelected']); | |
| 140 return flush(); | |
| 141 }).then(() => { | |
| 142 assertEquals( | |
| 143 1, histogramMap['HistoryPage.RemoveEntryPosition'] | |
| 144 [0]); | |
| 145 assertEquals( | |
| 146 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][0]); | |
| 147 assertEquals( | |
| 148 1, histogramMap['HistoryPage.RemoveEntryPosition'] | |
| 149 [2]); | |
| 150 assertEquals( | |
| 151 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][2]); | |
| 152 }); | |
| 153 }); | |
| 154 | |
| 155 test('synced-device-manager', function() { | |
| 156 app.selectedPage_ = 'syncedTabs'; | |
| 157 var histogram; | |
| 158 return flush().then(() => { | |
| 159 histogram = | |
| 160 histogramMap[SYNCED_TABS_HISTOGRAM_NAME]; | |
| 161 assertEquals(1, histogram[SyncedTabsHistogram.INITIALIZED]); | |
| 162 | |
| 163 var sessionList = [ | |
| 164 createSession( | |
| 165 'Nexus 5', | |
| 166 [createWindow(['http://www.google.com', 'http://example.com'])] | |
| 167 ), | |
| 168 createSession( | |
| 169 'Nexus 6', | |
| 170 [ | |
| 171 createWindow(['http://test.com']), | |
| 172 createWindow(['http://www.gmail.com', 'http://badssl.com']) | |
| 173 ] | |
| 174 ), | |
| 175 ]; | |
| 176 setForeignSessions(sessionList, true); | |
| 177 return flush(); | |
| 178 }).then(() => { | |
| 179 assertEquals(1, histogram[SyncedTabsHistogram.HAS_FOREIGN_DATA]); | |
| 180 return flush(); | |
| 181 }).then(() => { | |
| 182 cards = polymerSelectAll( | |
| 183 app.$$('#synced-devices'), 'history-synced-device-card'); | |
| 184 MockInteractions.tap(cards[0].$['card-heading']); | |
| 185 assertEquals(1, histogram[SyncedTabsHistogram.COLLAPSE_SESSION]); | |
| 186 MockInteractions.tap(cards[0].$['card-heading']); | |
| 187 assertEquals(1, histogram[SyncedTabsHistogram.EXPAND_SESSION]); | |
| 188 MockInteractions.tap(polymerSelectAll(cards[0], '.website-title')[0]); | |
| 189 assertEquals(1, histogram[SyncedTabsHistogram.LINK_CLICKED]); | |
| 190 | |
| 191 MockInteractions.tap(cards[0].$['menu-button']); | |
| 192 return flush(); | |
| 193 }).then(() => { | |
| 194 MockInteractions.tap(app.$$('#synced-devices').$$('#open-all')); | |
| 195 assertEquals(1, histogram[SyncedTabsHistogram.OPEN_ALL]); | |
| 196 | |
| 197 MockInteractions.tap(app.$$('#synced-devices').$$('#delete-session')); | |
| 198 assertEquals(1, histogram[SyncedTabsHistogram.HIDE_FOR_NOW]); | |
| 199 }); | |
| 200 }); | |
| 67 }); | 201 }); |
| 68 } | 202 } |
| 69 return { | 203 return { |
| 70 registerTests: registerTests | 204 registerTests: registerTests |
| 71 }; | 205 }; |
| 72 }); | 206 }); |
| OLD | NEW |