Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: chrome/test/data/webui/md_history/history_metrics_test.js

Issue 2255033002: [MD History] Copy stats from the old history page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sidebar_stats
Patch Set: learn_the_alphabet Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 updateSignInState(false); 64 updateSignInState(false);
42 return flush(); 65 return flush();
43 }); 66 });
44 67
45 test('History.HistoryPageView', function() { 68 test('History.HistoryPageView', function() {
46 app.grouped_ = true; 69 app.grouped_ = true;
47 70
48 var histogram = service.histogramMap['History.HistoryPageView']; 71 var histogram = histogramMap['History.HistoryPageView'];
49 assertEquals(1, histogram[HistoryPageViewHistogram.HISTORY]); 72 assertEquals(1, histogram[HistoryPageViewHistogram.HISTORY]);
50 73
51 app.selectedPage_ = 'syncedTabs'; 74 app.selectedPage_ = 'syncedTabs';
52 assertEquals(1, histogram[HistoryPageViewHistogram.SIGNIN_PROMO]); 75 assertEquals(1, histogram[HistoryPageViewHistogram.SIGNIN_PROMO]);
53 updateSignInState(true); 76 updateSignInState(true);
54 return flush().then(() => { 77 return flush().then(() => {
55 assertEquals(1, histogram[HistoryPageViewHistogram.SYNCED_TABS]); 78 assertEquals(1, histogram[HistoryPageViewHistogram.SYNCED_TABS]);
56 app.selectedPage_ = 'history'; 79 app.selectedPage_ = 'history';
57 assertEquals(2, histogram[HistoryPageViewHistogram.HISTORY]); 80 assertEquals(2, histogram[HistoryPageViewHistogram.HISTORY]);
58 app.set('queryState_.range', HistoryRange.WEEK); 81 app.set('queryState_.range', HistoryRange.WEEK);
59 assertEquals(1, histogram[HistoryPageViewHistogram.GROUPED_WEEK]); 82 assertEquals(1, histogram[HistoryPageViewHistogram.GROUPED_WEEK]);
60 app.set('queryState_.range', HistoryRange.MONTH); 83 app.set('queryState_.range', HistoryRange.MONTH);
61 assertEquals(1, histogram[HistoryPageViewHistogram.GROUPED_MONTH]); 84 assertEquals(1, histogram[HistoryPageViewHistogram.GROUPED_MONTH]);
62 }); 85 });
63 }); 86 });
87
88 test('history-list', function() {
89 var historyEntry =
90 createHistoryEntry('2015-01-01', 'http://www.google.com');
91 historyEntry.starred = true;
92 app.historyResult(createHistoryInfo(), [
93 createHistoryEntry('2015-01-01', 'http://www.example.com'),
94 historyEntry
95 ]);
96
97 return flush().then(() => {
98 var items = polymerSelectAll(
99 app.$.history.$['infinite-list'], 'history-item');
100 MockInteractions.tap(items[1].$$('#bookmark-star'));
101 assertEquals(1, actionMap['BookmarkStarClicked']);
102 MockInteractions.tap(items[1].$.title);
103 assertEquals(1, actionMap['EntryLinkClick']);
104 assertEquals(
105 1, histogramMap['HistoryPage.ClickPosition'][1]);
106 assertEquals(
107 1, histogramMap['HistoryPage.ClickPositionSubset'][1]);
108
109 app.set('queryState_.searchTerm', 'goog');
110 assertEquals(1, actionMap['Search']);
111 app.set('queryState_.incremental', true);
112 app.historyResult(createHistoryInfo('goog'), [
113 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')
116 ]);
117 return flush();
118 }).then(() => {
119 items = polymerSelectAll(
120 app.$.history.$['infinite-list'], 'history-item');
121 MockInteractions.tap(items[0].$.title);
122 assertEquals(1, actionMap['SearchResultClick']);
123 assertEquals(1, histogramMap['HistoryPage.ClickPosition'][0]);
124 assertEquals(1, histogramMap['HistoryPage.ClickPositionSubset'][0]);
125 MockInteractions.tap(items[0].$.checkbox);
126 MockInteractions.tap(items[4].$.checkbox);
127 return flush();
128 }).then(() => {
129 MockInteractions.tap(app.$.toolbar.$$('#delete-button'));
130 assertEquals(1, actionMap['RemoveSelected']);
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 items = polymerSelectAll(
143 app.$.history.$['infinite-list'], 'history-item');
144 MockInteractions.tap(items[0].$['menu-button']);
145 return flush();
146 }).then(() => {
147 MockInteractions.tap(app.$.history.$$('#menuRemoveButton'));
148 return flush();
149 }).then(() => {
150 assertEquals(
151 1, histogramMap['HistoryPage.RemoveEntryPosition'][0]);
152 assertEquals(
153 1, histogramMap['HistoryPage.RemoveEntryPositionSubset'][0]);
154 });
155 });
156
157 test('synced-device-manager', function() {
158 app.selectedPage_ = 'syncedTabs';
159 var histogram;
160 return flush().then(() => {
161 histogram =
162 histogramMap[SYNCED_TABS_HISTOGRAM_NAME];
163 assertEquals(1, histogram[SyncedTabsHistogram.INITIALIZED]);
164
165 var sessionList = [
166 createSession(
167 'Nexus 5',
168 [createWindow(['http://www.google.com', 'http://example.com'])]
169 ),
170 createSession(
171 'Nexus 6',
172 [
173 createWindow(['http://test.com']),
174 createWindow(['http://www.gmail.com', 'http://badssl.com'])
175 ]
176 ),
177 ];
178 setForeignSessions(sessionList, true);
179 return flush();
180 }).then(() => {
181 assertEquals(1, histogram[SyncedTabsHistogram.HAS_FOREIGN_DATA]);
182 return flush();
183 }).then(() => {
184 cards = polymerSelectAll(
185 app.$$('#synced-devices'), 'history-synced-device-card');
186 MockInteractions.tap(cards[0].$['card-heading']);
187 assertEquals(1, histogram[SyncedTabsHistogram.COLLAPSE_SESSION]);
188 MockInteractions.tap(cards[0].$['card-heading']);
189 assertEquals(1, histogram[SyncedTabsHistogram.EXPAND_SESSION]);
190 MockInteractions.tap(polymerSelectAll(cards[0], '.website-title')[0]);
191 assertEquals(1, histogram[SyncedTabsHistogram.LINK_CLICKED]);
192
193 MockInteractions.tap(cards[0].$['menu-button']);
194 return flush();
195 }).then(() => {
196 MockInteractions.tap(app.$$('#synced-devices').$$('#menuOpenButton'));
197 assertEquals(1, histogram[SyncedTabsHistogram.OPEN_ALL]);
198
199 MockInteractions.tap(
200 app.$$('#synced-devices').$$('#menuDeleteButton'));
201 assertEquals(1, histogram[SyncedTabsHistogram.HIDE_FOR_NOW]);
202 });
203 });
64 }); 204 });
65 } 205 }
66 return { 206 return {
67 registerTests: registerTests 207 registerTests: registerTests
68 }; 208 };
69 }); 209 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698