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