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