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

Side by Side Diff: chrome/browser/resources/google_now/cards.js

Issue 121983002: Restoring recently deleted unit tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rgustafson's notes Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Show/hide trigger in a card. 8 * Show/hide trigger in a card.
9 * 9 *
10 * @typedef {{ 10 * @typedef {{
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 /** 106 /**
107 * Builds an object to manage notification card set. 107 * Builds an object to manage notification card set.
108 * @return {Object} Card set interface. 108 * @return {Object} Card set interface.
109 */ 109 */
110 function buildCardSet() { 110 function buildCardSet() {
111 var alarmPrefix = 'card-'; 111 var alarmPrefix = 'card-';
112 112
113 /** 113 /**
114 * Creates/updates/deletes a Chrome notification. 114 * Creates/updates/deletes a Chrome notification.
115 * @param {ChromeNotificationId} cardId Card ID. 115 * @param {ChromeNotificationId} cardId Card ID.
116 * @param {?ReceivedNotification} receivedNotification Google Now card 116 * @param {(ReceivedNotification|undefined)} receivedNotification Google Now
117 * represented as a set of parameters for showing a Chrome notification, 117 * card represented as a set of parameters for showing a Chrome
118 * or null if the notification needs to be deleted. 118 * notification, or null if the notification needs to be deleted.
119 * @param {function(ReceivedNotification)=} onCardShown Optional parameter 119 * @param {function(ReceivedNotification)=} onCardShown Optional parameter
120 * called when each card is shown. 120 * called when each card is shown.
121 */ 121 */
122 function updateNotification(cardId, receivedNotification, onCardShown) { 122 function updateNotification(cardId, receivedNotification, onCardShown) {
123 console.log('cardManager.updateNotification ' + cardId + ' ' + 123 console.log('cardManager.updateNotification ' + cardId + ' ' +
124 JSON.stringify(receivedNotification)); 124 JSON.stringify(receivedNotification));
125 125
126 if (!receivedNotification) { 126 if (!receivedNotification) {
127 instrumented.notifications.clear(cardId, function() {}); 127 instrumented.notifications.clear(cardId, function() {});
128 return; 128 return;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 * @param {function(ReceivedNotification)=} onCardShown Optional parameter 188 * @param {function(ReceivedNotification)=} onCardShown Optional parameter
189 * called when each card is shown. 189 * called when each card is shown.
190 * @return {(NotificationDataEntry|undefined)} Notification data entry for 190 * @return {(NotificationDataEntry|undefined)} Notification data entry for
191 * this card. It's 'undefined' if the card's life is over. 191 * this card. It's 'undefined' if the card's life is over.
192 */ 192 */
193 function update(cardId, combinedCard, notificationGroups, onCardShown) { 193 function update(cardId, combinedCard, notificationGroups, onCardShown) {
194 console.log('cardManager.update ' + JSON.stringify(combinedCard)); 194 console.log('cardManager.update ' + JSON.stringify(combinedCard));
195 195
196 chrome.alarms.clear(alarmPrefix + cardId); 196 chrome.alarms.clear(alarmPrefix + cardId);
197 var now = Date.now(); 197 var now = Date.now();
198 /** @type {?UncombinedNotification} */ 198 /** @type {(UncombinedNotification|undefined)} */
199 var winningCard = null; 199 var winningCard = undefined;
200 // Next moment of time when winning notification selection algotithm can 200 // Next moment of time when winning notification selection algotithm can
201 // potentially return a different notification. 201 // potentially return a different notification.
202 /** @type {?number} */ 202 /** @type {?number} */
203 var nextEventTime = null; 203 var nextEventTime = null;
204 204
205 // Find a winning uncombined notification: a highest-priority notification 205 // Find a winning uncombined notification: a highest-priority notification
206 // that needs to be shown now. 206 // that needs to be shown now.
207 iterateUncombinedNotifications( 207 iterateUncombinedNotifications(
208 combinedCard, 208 combinedCard,
209 now, 209 now,
(...skipping 26 matching lines...) Expand all
236 cardId, winningCard && winningCard.receivedNotification, onCardShown); 236 cardId, winningCard && winningCard.receivedNotification, onCardShown);
237 237
238 if (nextEventTime) { 238 if (nextEventTime) {
239 // If we expect more events, create an alarm for the next one. 239 // If we expect more events, create an alarm for the next one.
240 chrome.alarms.create(alarmPrefix + cardId, {when: nextEventTime}); 240 chrome.alarms.create(alarmPrefix + cardId, {when: nextEventTime});
241 241
242 // The trick with stringify/parse is to create a copy of action URLs, 242 // The trick with stringify/parse is to create a copy of action URLs,
243 // otherwise notifications data with 2 pointers to the same object won't 243 // otherwise notifications data with 2 pointers to the same object won't
244 // be stored correctly to chrome.storage. 244 // be stored correctly to chrome.storage.
245 var winningActionUrls = winningCard && 245 var winningActionUrls = winningCard &&
246 (winningCard.receivedNotification.actionUrls || null) && 246 winningCard.receivedNotification.actionUrls &&
247 JSON.parse(JSON.stringify( 247 JSON.parse(JSON.stringify(
248 winningCard.receivedNotification.actionUrls)); 248 winningCard.receivedNotification.actionUrls));
249 249
250 return { 250 return {
251 actionUrls: winningActionUrls, 251 actionUrls: winningActionUrls,
252 timestamp: now, 252 timestamp: now,
253 combinedCard: combinedCard 253 combinedCard: combinedCard
254 }; 254 };
255 } else { 255 } else {
256 // If there are no more events, we are done with this card. Note that all 256 // If there are no more events, we are done with this card. Note that all
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 }); 358 });
359 }); 359 });
360 } 360 }
361 }); 361 });
362 362
363 return { 363 return {
364 update: update, 364 update: update,
365 onDismissal: onDismissal 365 onDismissal: onDismissal
366 }; 366 };
367 } 367 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698