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

Side by Side Diff: chrome/browser/resources/google_now/cards_unittest.gtestjs

Issue 27030012: Restoring notifications on startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More rgustafson's comments Created 7 years, 2 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
« no previous file with comments | « chrome/browser/resources/google_now/cards.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * Test fixture for cards.js. 6 * Test fixture for cards.js.
7 * @constructor 7 * @constructor
8 * @extends {testing.Test} 8 * @extends {testing.Test}
9 */ 9 */
10 function GoogleNowCardsUnitTest () { 10 function GoogleNowCardsUnitTest () {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 cardCreateInfo: { 148 cardCreateInfo: {
149 notification: testNotification, 149 notification: testNotification,
150 hideTime: 1313000, 150 hideTime: 1313000,
151 version: 0 151 version: 0
152 }, 152 },
153 dismissals: testDismissals 153 dismissals: testDismissals
154 }), 154 }),
155 JSON.stringify(notificationData)); 155 JSON.stringify(notificationData));
156 }); 156 });
157 157
158 TEST_F('GoogleNowCardsUnitTest', 'CreateCardHideTimeExpired', function() {
159 // Creates a new card with trigger specifying hide time which is in the past.
160
161 // Setup and expectations.
162 var test = setUpCardManagerTest(this);
163 this.mockApis.expects(once()).
164 chrome_alarms_clear(expectedHideAlarmId);
165 this.mockApis.expects(once()).
166 chrome_alarms_clear(expectedShowAlarmId);
167 this.mockApis.expects(once()).
168 chrome_alarms_create(expectedHideAlarmId, eqJSON({when: 299999}));
169
170 // Call tested method.
171 var notificationData = test.cardSet.update(testCardId, {
172 notification: testNotification,
173 actionUrls: testActionUrls,
174 dismissals: testDismissals,
175 groupRank: testGroupRank,
176 version: 0,
177 trigger: {hideTime: 299999}});
178
179 // Check the return value.
180 assertEquals(
181 JSON.stringify({
182 actionUrls: testActionUrls,
183 cardCreateInfo: {
184 notification: testNotification,
185 hideTime: 299999,
186 version: 0
187 },
188 dismissals: testDismissals
189 }),
190 JSON.stringify(notificationData));
191 });
192
158 TEST_F('GoogleNowCardsUnitTest', 'UpdateCardSameVersion', function() { 193 TEST_F('GoogleNowCardsUnitTest', 'UpdateCardSameVersion', function() {
159 // Updates a card with another card with same version. 194 // Updates a card with another card with same version.
160 195
161 // Setup and expectations. 196 // Setup and expectations.
162 var test = setUpCardManagerTest(this); 197 var test = setUpCardManagerTest(this);
163 this.mockApis.expects(once()). 198 this.mockApis.expects(once()).
164 chrome_alarms_clear(expectedHideAlarmId); 199 chrome_alarms_clear(expectedHideAlarmId);
165 this.mockApis.expects(once()). 200 this.mockApis.expects(once()).
166 chrome_alarms_clear(expectedShowAlarmId); 201 chrome_alarms_clear(expectedShowAlarmId);
167 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); 202 var chromeNotificationsCreateSavedArgs = new SaveMockArguments();
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Tests onAlarm does nothing on an unrelated alarm. 350 // Tests onAlarm does nothing on an unrelated alarm.
316 var test = setUpCardManagerTest(this); 351 var test = setUpCardManagerTest(this);
317 352
318 // Call tested method. 353 // Call tested method.
319 test.alarmCallback({name: 'unrelated'}); 354 test.alarmCallback({name: 'unrelated'});
320 }); 355 });
321 356
322 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowNoData', function() { 357 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowNoData', function() {
323 // Tests onAlarm for the 'show' alarm when there is no data for the card. 358 // Tests onAlarm for the 'show' alarm when there is no data for the card.
324 var test = setUpCardManagerTest(this); 359 var test = setUpCardManagerTest(this);
360
361 var tasksAddSavedArgs = new SaveMockArguments();
362 this.mockApis.expects(once()).
363 tasks_add(
364 tasksAddSavedArgs.match(eq(SHOW_CARD_TASK_NAME)),
365 tasksAddSavedArgs.match(ANYTHING)).
366 will(invokeCallback(tasksAddSavedArgs,1));
367
325 var storageGetSavedArgs = new SaveMockArguments(); 368 var storageGetSavedArgs = new SaveMockArguments();
326 this.mockApis.expects(once()). 369 this.mockApis.expects(once()).
327 instrumented_storage_local_get( 370 instrumented_storage_local_get(
328 storageGetSavedArgs.match(eq('notificationsData')), 371 storageGetSavedArgs.match(eq('notificationsData')),
329 storageGetSavedArgs.match(ANYTHING)). 372 storageGetSavedArgs.match(ANYTHING)).
330 will(invokeCallback(storageGetSavedArgs, 1, {})); 373 will(invokeCallback(storageGetSavedArgs, 1, {}));
331 374
332 // Call tested method. 375 // Call tested method.
333 test.alarmCallback({name: expectedShowAlarmId}); 376 test.alarmCallback({name: expectedShowAlarmId});
334 }); 377 });
335 378
336 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowHasDataCreate', function() { 379 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowHasDataCreate', function() {
337 // Tests onAlarm for the 'show' alarm when there is data for the card. The 380 // Tests onAlarm for the 'show' alarm when there is data for the card. The
338 // notification will be created because there is no previous version. 381 // notification will be created because there is no previous version.
339 var test = setUpCardManagerTest(this); 382 var test = setUpCardManagerTest(this);
383
384 var tasksAddSavedArgs = new SaveMockArguments();
385 this.mockApis.expects(once()).
386 tasks_add(
387 tasksAddSavedArgs.match(eq(SHOW_CARD_TASK_NAME)),
388 tasksAddSavedArgs.match(ANYTHING)).
389 will(invokeCallback(tasksAddSavedArgs,1));
390
340 var storageGetSavedArgs = new SaveMockArguments(); 391 var storageGetSavedArgs = new SaveMockArguments();
341 this.mockApis.expects(once()). 392 this.mockApis.expects(once()).
342 instrumented_storage_local_get( 393 instrumented_storage_local_get(
343 storageGetSavedArgs.match(eq('notificationsData')), 394 storageGetSavedArgs.match(eq('notificationsData')),
344 storageGetSavedArgs.match(ANYTHING)). 395 storageGetSavedArgs.match(ANYTHING)).
345 will(invokeCallback( 396 will(invokeCallback(
346 storageGetSavedArgs, 397 storageGetSavedArgs,
347 1, 398 1,
348 { 399 {
349 notificationsData: { 400 notificationsData: {
(...skipping 14 matching lines...) Expand all
364 chrome_alarms_create(expectedHideAlarmId, eqJSON({when: 1313000})); 415 chrome_alarms_create(expectedHideAlarmId, eqJSON({when: 1313000}));
365 416
366 // Call tested method. 417 // Call tested method.
367 test.alarmCallback({name: expectedShowAlarmId}); 418 test.alarmCallback({name: expectedShowAlarmId});
368 }); 419 });
369 420
370 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowHasDataUpdate', function() { 421 TEST_F('GoogleNowCardsUnitTest', 'onAlarmShowHasDataUpdate', function() {
371 // Tests onAlarm for the 'show' alarm when there is data for the card. The 422 // Tests onAlarm for the 'show' alarm when there is data for the card. The
372 // notification will be updated because previous version is same as current. 423 // notification will be updated because previous version is same as current.
373 var test = setUpCardManagerTest(this); 424 var test = setUpCardManagerTest(this);
425
426 var tasksAddSavedArgs = new SaveMockArguments();
427 this.mockApis.expects(once()).
428 tasks_add(
429 tasksAddSavedArgs.match(eq(SHOW_CARD_TASK_NAME)),
430 tasksAddSavedArgs.match(ANYTHING)).
431 will(invokeCallback(tasksAddSavedArgs,1));
432
374 var storageGetSavedArgs = new SaveMockArguments(); 433 var storageGetSavedArgs = new SaveMockArguments();
375 this.mockApis.expects(once()). 434 this.mockApis.expects(once()).
376 instrumented_storage_local_get( 435 instrumented_storage_local_get(
377 storageGetSavedArgs.match(eq('notificationsData')), 436 storageGetSavedArgs.match(eq('notificationsData')),
378 storageGetSavedArgs.match(ANYTHING)). 437 storageGetSavedArgs.match(ANYTHING)).
379 will(invokeCallback( 438 will(invokeCallback(
380 storageGetSavedArgs, 439 storageGetSavedArgs,
381 1, 440 1,
382 { 441 {
383 notificationsData: { 442 notificationsData: {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 testField: 'TEST VALUE 0', 532 testField: 'TEST VALUE 0',
474 } 533 }
475 ] 534 ]
476 } 535 }
477 } 536 }
478 })); 537 }));
479 538
480 // Call tested method. 539 // Call tested method.
481 test.alarmCallback({name: expectedHideAlarmId}); 540 test.alarmCallback({name: expectedHideAlarmId});
482 }); 541 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/google_now/cards.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698