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() { this.histogramMap = {}; }; | 10 var TestMetricsBrowserService = function() { |
11 this.histogramMap = {}; | |
12 this.actionMap = {}; | |
13 }; | |
11 | 14 |
12 function registerTests() { | 15 function registerTests() { |
13 suite('Metrics', function() { | 16 suite('Metrics', function() { |
14 var service; | 17 var service; |
15 var app; | 18 var app; |
19 var histogramMap; | |
20 var actionMap; | |
16 | 21 |
17 suiteSetup(function() { | 22 suiteSetup(function() { |
23 disableLinkClicks(); | |
24 | |
18 TestMetricsBrowserService.prototype = { | 25 TestMetricsBrowserService.prototype = { |
19 __proto__: md_history.BrowserService.prototype, | 26 __proto__: md_history.BrowserService.prototype, |
20 | 27 |
21 /** @override */ | 28 /** @override */ |
22 recordHistogram: function(histogram, value, max) { | 29 recordHistogram: function(histogram, value, max) { |
23 assertTrue(value < max); | 30 assertTrue(value < max); |
24 | 31 |
25 if (!(histogram in this.histogramMap)) | 32 if (!(histogram in this.histogramMap)) |
26 this.histogramMap[histogram] = {}; | 33 this.histogramMap[histogram] = {}; |
27 | 34 |
28 if (!(value in this.histogramMap[histogram])) | 35 if (!(value in this.histogramMap[histogram])) |
29 this.histogramMap[histogram][value] = 0; | 36 this.histogramMap[histogram][value] = 0; |
30 | 37 |
31 this.histogramMap[histogram][value]++; | 38 this.histogramMap[histogram][value]++; |
39 }, | |
40 | |
41 /** @override */ | |
42 recordAction: function(action) { | |
43 if (!(action in this.actionMap)) | |
44 this.actionMap[action] = 0 | |
45 | |
46 this.actionMap[action]++; | |
47 }, | |
48 | |
49 /** @override */ | |
50 deleteItems: function() { | |
51 return flush(); | |
32 } | 52 } |
33 }; | 53 }; |
34 }); | 54 }); |
35 | 55 |
36 setup(function() { | 56 setup(function() { |
37 md_history.BrowserService.instance_ = new TestMetricsBrowserService(); | 57 md_history.BrowserService.instance_ = new TestMetricsBrowserService(); |
38 service = md_history.BrowserService.getInstance(); | 58 service = md_history.BrowserService.getInstance(); |
39 | 59 |
60 actionMap = service.actionMap; | |
61 histogramMap = service.histogramMap; | |
62 | |
40 app = replaceApp(); | 63 app = replaceApp(); |
41 return flush(); | 64 return flush(); |
42 }); | 65 }); |
43 | 66 |
44 test('History.HistoryView', function() { | 67 test('History.HistoryView', function() { |
45 app.grouped_ = true; | 68 app.grouped_ = true; |
46 | 69 |
47 var histogram = service.histogramMap['History.HistoryView']; | 70 var histogram = histogramMap['History.HistoryView']; |
48 assertEquals(1, histogram[HistoryViewHistogram.HISTORY]); | 71 assertEquals(1, histogram[HistoryViewHistogram.HISTORY]); |
49 | 72 |
50 app.selectedPage_ = 'syncedTabs'; | 73 app.selectedPage_ = 'syncedTabs'; |
51 assertEquals(1, histogram[HistoryViewHistogram.SIGNIN_PROMO]); | 74 assertEquals(1, histogram[HistoryViewHistogram.SIGNIN_PROMO]); |
52 updateSignInState(true); | 75 updateSignInState(true); |
53 return flush().then(() => { | 76 return flush().then(() => { |
54 assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); | 77 assertEquals(1, histogram[HistoryViewHistogram.SYNCED_TABS]); |
55 app.selectedPage_ = 'history'; | 78 app.selectedPage_ = 'history'; |
56 assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); | 79 assertEquals(2, histogram[HistoryViewHistogram.HISTORY]); |
57 app.set('queryState_.range', HistoryRange.WEEK); | 80 app.set('queryState_.range', HistoryRange.WEEK); |
58 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); | 81 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_WEEK]); |
59 app.set('queryState_.range', HistoryRange.MONTH); | 82 app.set('queryState_.range', HistoryRange.MONTH); |
60 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); | 83 assertEquals(1, histogram[HistoryViewHistogram.GROUPED_MONTH]); |
61 }); | 84 }); |
62 }); | 85 }); |
86 | |
87 test('history-list', function() { | |
tsergeant
2016/08/22 00:23:40
Having these here is okay for now, but we should b
calamity
2016/08/23 04:52:25
My intuition is that there would be a larger maint
| |
88 var historyEntry = | |
89 createHistoryEntry('2015-01-01', 'http://www.google.com'); | |
90 historyEntry.starred = true; | |
91 app.historyResult(createHistoryInfo(), [ | |
92 createHistoryEntry('2015-01-01', 'http://www.example.com'), | |
93 historyEntry | |
94 ]); | |
95 | |
96 return flush().then(() => { | |
97 var items = polymerSelectAll( | |
98 app.$.history.$['infinite-list'], 'history-item'); | |
99 MockInteractions.tap(items[1].$$('#bookmark-star')); | |
100 assertEquals(1, actionMap['BookmarkStarClicked']); | |
101 MockInteractions.tap(items[1].$.title); | |
102 assertEquals(1, actionMap['EntryLinkClick']); | |
103 assertEquals( | |
104 1, histogramMap['HistoryPage.ClickPosition'][1]); | |
105 assertEquals( | |
106 1, histogramMap['HistoryPage.ClickPositionSubset'][1]); | |
107 | |
108 app.set('queryState_.searchTerm', 'goog'); | |
109 assertEquals(1, actionMap['Search']); | |
110 app.set('queryState_.incremental', true); | |
111 app.historyResult(createHistoryInfo('goog'), [ | |
112 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') | |
115 ]); | |
116 return flush(); | |
117 }).then(() => { | |
118 items = polymerSelectAll( | |
119 app.$.history.$['infinite-list'], 'history-item'); | |
120 MockInteractions.tap(items[0].$.title); | |
121 assertEquals(1, actionMap['SearchResultClick']); | |
122 assertEquals(1, histogramMap['HistoryPage.ClickPosition'][0]); | |
123 assertEquals(1, histogramMap['HistoryPage.ClickPositionSubset'][0]); | |
124 MockInteractions.tap(items[0].$.checkbox); | |
125 MockInteractions.tap(items[4].$.checkbox); | |
126 return flush(); | |
127 }).then(() => { | |
128 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
129 assertEquals(1, actionMap['RemoveSelected']); | |
130 return flush(); | |
131 }).then(() => { | |
132 MockInteractions.tap(app.$.history.$$('.cancel-button')); | |
133 assertEquals(1, actionMap['CancelRemoveSelected']); | |
134 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
135 return flush(); | |
136 }).then(() => { | |
137 MockInteractions.tap(app.$.history.$$('.action-button')); | |
138 assertEquals(1, actionMap['ConfirmRemoveSelected']); | |
139 return flush(); | |
140 }).then(() => { | |
141 assertEquals( | |
142 1, histogramMap['HistoryPage.RemoveEntryPosition'][0]); | |
143 assertEquals( | |
144 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][0]); | |
145 assertEquals( | |
146 1, histogramMap['HistoryPage.RemoveEntryPosition'][4]); | |
147 assertEquals( | |
148 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][4]); | |
149 | |
150 items = polymerSelectAll( | |
151 app.$.history.$['infinite-list'], 'history-item'); | |
152 MockInteractions.tap(items[0].$.checkbox); | |
153 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
154 return flush(); | |
155 }).then(() => { | |
156 MockInteractions.tap(app.$.history.$$('.action-button')); | |
157 assertEquals(2, actionMap['ConfirmRemoveSelected']); | |
158 return flush(); | |
159 }).then(() => { | |
160 assertEquals( | |
161 2, histogramMap['HistoryPage.RemoveEntryPosition'][0]); | |
162 assertEquals( | |
163 2, histogramMap['HistoryPage.RemoveEntryPositionSubset'][0]); | |
164 }); | |
165 }); | |
166 | |
167 test('grouped-list', function() { | |
168 app.grouped_ = true; | |
169 var groupedList; | |
170 var dropdowns; | |
171 return flush().then(() => { | |
172 groupedList = app.$.history.$$('#grouped-list'); | |
173 app.set('queryState_.range', HistoryRange.WEEK); | |
174 app.historyResult(createHistoryInfo(), [ | |
175 createHistoryEntry('2015-01-03', 'http://www.google.com'), | |
176 createHistoryEntry('2015-01-03', 'http://www.google.com'), | |
177 createHistoryEntry('2015-01-03', 'http://www.google.com'), | |
178 createHistoryEntry('2015-01-01', 'http://www.google.com'), | |
179 createHistoryEntry('2015-01-01', 'http://www.google.com'), | |
180 createHistoryEntry('2015-01-01', 'http://www.badssl.com'), | |
181 ]); | |
182 | |
183 return waitForEvent(groupedList, 'dom-change', function() { | |
184 return polymerSelectAll( | |
185 groupedList, '.dropdown-indicator').length == 3; | |
186 }); | |
187 }).then(function() { | |
188 dropdowns = polymerSelectAll(groupedList, '.dropdown-indicator'); | |
189 // Open the first and last domains. | |
190 MockInteractions.tap(dropdowns[0]); | |
191 MockInteractions.tap(dropdowns[2]); | |
192 return flush(); | |
193 }).then(function() { | |
194 var items = polymerSelectAll(groupedList, 'history-item'); | |
195 // Select the 2nd item in the first domain and the only item in the | |
196 // last domain. | |
197 MockInteractions.tap(items[1].$.checkbox); | |
198 MockInteractions.tap(items[3].$.checkbox); | |
199 return flush(); | |
200 }).then(() => { | |
201 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
202 return flush(); | |
203 }).then(() => { | |
204 MockInteractions.tap(app.$.history.$$('.action-button')); | |
205 return flush(); | |
206 }).then(() => { | |
207 assertEquals( | |
208 1, histogramMap['HistoryPage.RemoveEntryPosition'][1]); | |
209 assertEquals( | |
210 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][1]); | |
211 assertEquals( | |
212 1, histogramMap['HistoryPage.RemoveEntryPosition'][5]); | |
213 assertEquals( | |
214 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][5]); | |
215 }).then(function() { | |
216 // Open the middle domain. | |
217 MockInteractions.tap(dropdowns[1]); | |
218 return flush(); | |
219 }).then(function() { | |
220 var items = polymerSelectAll(groupedList, 'history-item'); | |
221 // Select the first item in the middle domain. | |
222 MockInteractions.tap(items[2].$.checkbox); | |
223 return flush(); | |
224 }).then(() => { | |
225 MockInteractions.tap(app.$.toolbar.$$('#delete-button')); | |
226 return flush(); | |
227 }).then(() => { | |
228 MockInteractions.tap(app.$.history.$$('.action-button')); | |
229 return flush(); | |
230 }).then(() => { | |
231 assertEquals( | |
232 1, histogramMap['HistoryPage.RemoveEntryPosition'][2]); | |
233 assertEquals( | |
234 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][2]); | |
235 }); | |
236 }); | |
237 | |
238 test('synced-device-manager', function() { | |
239 app.selectedPage_ = 'syncedTabs'; | |
240 var histogram; | |
241 return flush().then(() => { | |
242 histogram = | |
243 histogramMap[SYNCED_TABS_HISTOGRAM_NAME]; | |
244 assertEquals(1, histogram[SyncedTabsHistogram.INITIALIZED]); | |
245 | |
246 var sessionList = [ | |
247 createSession( | |
248 'Nexus 5', | |
249 [createWindow(['http://www.google.com', 'http://example.com'])] | |
250 ), | |
251 createSession( | |
252 'Nexus 6', | |
253 [ | |
254 createWindow(['http://test.com']), | |
255 createWindow(['http://www.gmail.com', 'http://badssl.com']) | |
256 ] | |
257 ), | |
258 ]; | |
259 setForeignSessions(sessionList, true); | |
260 return flush(); | |
261 }).then(() => { | |
262 assertEquals(1, histogram[SyncedTabsHistogram.HAS_FOREIGN_DATA]); | |
263 return flush(); | |
264 }).then(() => { | |
265 cards = polymerSelectAll( | |
266 app.$$('#synced-devices'), 'history-synced-device-card'); | |
267 MockInteractions.tap(cards[0].$['card-heading']); | |
268 assertEquals(1, histogram[SyncedTabsHistogram.COLLAPSE_SESSION]); | |
269 MockInteractions.tap(cards[0].$['card-heading']); | |
270 assertEquals(1, histogram[SyncedTabsHistogram.EXPAND_SESSION]); | |
271 MockInteractions.tap(polymerSelectAll(cards[0], '.website-title')[0]); | |
272 assertEquals(1, histogram[SyncedTabsHistogram.LINK_CLICKED]); | |
273 | |
274 MockInteractions.tap(cards[0].$['menu-button']); | |
275 return flush(); | |
276 }).then(() => { | |
277 MockInteractions.tap(app.$$('#synced-devices').$$('#menuOpenButton')); | |
278 assertEquals(1, histogram[SyncedTabsHistogram.OPEN_ALL]); | |
279 | |
280 MockInteractions.tap( | |
281 app.$$('#synced-devices').$$('#menuDeleteButton')); | |
282 assertEquals(1, histogram[SyncedTabsHistogram.HIDE_FOR_NOW]); | |
283 }); | |
284 }); | |
63 }); | 285 }); |
64 } | 286 } |
65 return { | 287 return { |
66 registerTests: registerTests | 288 registerTests: registerTests |
67 }; | 289 }; |
68 }); | 290 }); |
OLD | NEW |