OLD | NEW |
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 () { |
11 testing.Test.call(this); | 11 testing.Test.call(this); |
12 } | 12 } |
13 | 13 |
14 GoogleNowCardsUnitTest.prototype = { | 14 GoogleNowCardsUnitTest.prototype = { |
15 __proto__: testing.Test.prototype, | 15 __proto__: testing.Test.prototype, |
16 | 16 |
17 /** @override */ | 17 /** @override */ |
18 extraLibraries: [ | 18 extraLibraries: [ |
19 'cards.js' | 19 'cards.js' |
20 ] | 20 ] |
21 }; | 21 }; |
22 | 22 |
| 23 // Test implementation of a function provided by utility.js. |
| 24 function verify(condition, message) { |
| 25 assertTrue(condition, message); |
| 26 } |
| 27 |
23 var testCardId = 'TEST CARD ID'; | 28 var testCardId = 'TEST CARD ID'; |
24 var testNotification = {testNotificationField: 'TEST NOTIFICATION VALUE'}; | 29 var testNotificationIdA = 'TEST CARD ID-A'; |
25 var expectedShowAlarmId = 'card-show-TEST CARD ID'; | 30 var testNotificationIdB = 'TEST CARD ID-B'; |
26 var expectedHideAlarmId = 'card-hide-TEST CARD ID'; | 31 var testNotificationA = { |
27 var testActionUrls = {testField: 'TEST VALUE'}; | 32 testNotificationField: 'TEST NOTIFICATION VALUE A', |
28 var testDismissals = [ | 33 priority: 1 |
29 {testDismissalField: 'TEST DISMISSAL VALUE 1'}, | 34 }; |
30 {testDismissalField: 'TEST DISMISSAL VALUE 2'} | 35 var testNotificationB = { |
31 ]; | 36 testNotificationField: 'TEST NOTIFICATION VALUE B', |
32 var testGroupRank = 271; | 37 priority: 2 |
| 38 }; |
| 39 var groupNameA = 'A'; |
| 40 var groupNameB = 'B'; |
| 41 var expectedAlarmId = 'card-TEST CARD ID'; |
| 42 var testActionUrlsA = {testField: 'TEST VALUE A'}; |
| 43 var testActionUrlsB = {testField: 'TEST VALUE B'}; |
| 44 var testDismissalA = {testDismissalField: 'TEST DISMISSAL VALUE A'}; |
| 45 var testDismissalB = {testDismissalField: 'TEST DISMISSAL VALUE B'}; |
33 var LOCATION_CARDS_LINK_THRESHOLD = 10; | 46 var LOCATION_CARDS_LINK_THRESHOLD = 10; |
34 var localStorage = {locationCardsShown: 0}; | 47 var localStorage = {locationCardsShown: 0}; |
| 48 var notificationUpdateSuccessful = true; |
| 49 var notificationUpdateFailed = false; |
35 | 50 |
36 function setUpCardManagerTest(fixture) { | 51 function setUpCardManagerTest(fixture) { |
37 fixture.makeAndRegisterMockApis([ | 52 fixture.makeAndRegisterMockApis([ |
38 'chrome.alarms.clear', | 53 'chrome.alarms.clear', |
39 'chrome.alarms.create', | 54 'chrome.alarms.create', |
40 'chrome.notifications.clear', | 55 'instrumented.notifications.clear', |
41 'chrome.storage.local.set', | 56 'chrome.storage.local.set', |
42 'countLocationCard', | 57 'countLocationCard', |
43 'instrumented.alarms.onAlarm.addListener', | 58 'instrumented.alarms.onAlarm.addListener', |
44 'instrumented.notifications.create', | 59 'instrumented.notifications.create', |
45 'instrumented.notifications.update', | 60 'instrumented.notifications.update', |
46 'instrumented.storage.local.get', | 61 'instrumented.storage.local.get', |
47 'tasks.add' | 62 'tasks.add' |
48 ]); | 63 ]); |
49 | 64 |
50 chrome.runtime = {}; // No error. | 65 chrome.runtime = {}; // No error. |
(...skipping 18 matching lines...) Expand all Loading... |
69 } | 84 } |
70 | 85 |
71 TEST_F('GoogleNowCardsUnitTest', 'BuildCardManager', function() { | 86 TEST_F('GoogleNowCardsUnitTest', 'BuildCardManager', function() { |
72 // Tests that buildCardSet() call completes with no problems. | 87 // Tests that buildCardSet() call completes with no problems. |
73 var test = setUpCardManagerTest(this); | 88 var test = setUpCardManagerTest(this); |
74 | 89 |
75 assertEquals('object', typeof test.cardSet); | 90 assertEquals('object', typeof test.cardSet); |
76 assertEquals('function', typeof test.alarmCallback); | 91 assertEquals('function', typeof test.alarmCallback); |
77 }); | 92 }); |
78 | 93 |
| 94 TEST_F('GoogleNowCardsUnitTest', 'UpdateSimpleHideFuture', function() { |
| 95 // Update a simple card with the hide event in future. |
| 96 |
| 97 var testUncombinedNotification = { |
| 98 receivedNotification: { |
| 99 notificationId: testNotificationIdA, |
| 100 chromeNotificationId: testCardId, |
| 101 chromeNotificationOptions: testNotificationA, |
| 102 actionUrls: testActionUrlsA, |
| 103 dismissal: testDismissalA, |
| 104 groupName: groupNameA |
| 105 }, |
| 106 hideTime: 300001 |
| 107 }; |
| 108 |
| 109 // Setup and expectations. |
| 110 var test = setUpCardManagerTest(this); |
| 111 this.mockApis.expects(once()). |
| 112 chrome_alarms_clear(expectedAlarmId); |
| 113 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); |
| 114 this.mockApis.expects(once()). |
| 115 instrumented_notifications_update( |
| 116 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), |
| 117 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)), |
| 118 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). |
| 119 will(invokeCallback( |
| 120 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateSuccessful)); |
| 121 this.mockApis.expects(once()). |
| 122 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); |
| 123 |
| 124 // Call tested method. |
| 125 var notificationData = test.cardSet.update( |
| 126 testCardId, [testUncombinedNotification], {}); |
| 127 |
| 128 // Check the return value. |
| 129 assertEquals( |
| 130 JSON.stringify({ |
| 131 actionUrls: testActionUrlsA, |
| 132 timestamp: 300000, |
| 133 combinedCard: [testUncombinedNotification] |
| 134 }), |
| 135 JSON.stringify(notificationData)); |
| 136 }); |
| 137 |
| 138 TEST_F('GoogleNowCardsUnitTest', 'CreateSimpleHideFuture', function() { |
| 139 // Create a simple card with the hide event in future. |
| 140 |
| 141 var testUncombinedNotification = { |
| 142 receivedNotification: { |
| 143 notificationId: testNotificationIdA, |
| 144 chromeNotificationId: testCardId, |
| 145 chromeNotificationOptions: testNotificationA, |
| 146 actionUrls: testActionUrlsA, |
| 147 dismissal: testDismissalA, |
| 148 groupName: groupNameA |
| 149 }, |
| 150 hideTime: 300001 |
| 151 }; |
| 152 |
| 153 // Setup and expectations. |
| 154 var test = setUpCardManagerTest(this); |
| 155 this.makeMockLocalFunctions(['onCardShown']); |
| 156 |
| 157 this.mockApis.expects(once()). |
| 158 chrome_alarms_clear(expectedAlarmId); |
| 159 |
| 160 // notifications.update will return false, which will trigger |
| 161 // notifications.create. |
| 162 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); |
| 163 this.mockApis.expects(once()). |
| 164 instrumented_notifications_update( |
| 165 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), |
| 166 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)), |
| 167 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). |
| 168 will(invokeCallback( |
| 169 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateFailed)); |
| 170 var chromeNotificationsCreateSavedArgs = new SaveMockArguments(); |
| 171 this.mockApis.expects(once()). |
| 172 instrumented_notifications_create( |
| 173 chromeNotificationsCreateSavedArgs.match(eq(testCardId)), |
| 174 chromeNotificationsCreateSavedArgs.match(eqJSON(testNotificationA)), |
| 175 chromeNotificationsCreateSavedArgs.match(ANYTHING)). |
| 176 will(invokeCallback(chromeNotificationsCreateSavedArgs, 2, testCardId)); |
| 177 |
| 178 this.mockLocalFunctions.expects(once()). |
| 179 onCardShown(eqJSON(testUncombinedNotification.receivedNotification)); |
| 180 |
| 181 this.mockApis.expects(once()). |
| 182 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); |
| 183 |
| 184 // Call tested method. |
| 185 var notificationData = test.cardSet.update( |
| 186 testCardId, |
| 187 [testUncombinedNotification], |
| 188 {}, |
| 189 this.mockLocalFunctions.functions().onCardShown); |
| 190 |
| 191 // Check the return value. |
| 192 assertEquals( |
| 193 JSON.stringify({ |
| 194 actionUrls: testActionUrlsA, |
| 195 timestamp: 300000, |
| 196 combinedCard: [testUncombinedNotification] |
| 197 }), |
| 198 JSON.stringify(notificationData)); |
| 199 }); |
| 200 |
| 201 TEST_F('GoogleNowCardsUnitTest', 'CreateSimpleShowFuture', function() { |
| 202 // Create a simple card with the show event in future. Should create an alarm |
| 203 // to fire at the show time. |
| 204 |
| 205 var testUncombinedNotification = { |
| 206 receivedNotification: { |
| 207 notificationId: testNotificationIdA, |
| 208 chromeNotificationId: testCardId, |
| 209 chromeNotificationOptions: testNotificationA, |
| 210 actionUrls: testActionUrlsA, |
| 211 dismissal: testDismissalA, |
| 212 groupName: groupNameA |
| 213 }, |
| 214 showTime: 300001, |
| 215 hideTime: 300002 |
| 216 }; |
| 217 |
| 218 // Setup and expectations. |
| 219 var test = setUpCardManagerTest(this); |
| 220 |
| 221 this.mockApis.expects(once()). |
| 222 chrome_alarms_clear(expectedAlarmId); |
| 223 this.mockApis.expects(once()). |
| 224 instrumented_notifications_clear(testCardId, ANYTHING); |
| 225 this.mockApis.expects(once()). |
| 226 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); |
| 227 |
| 228 // Call tested method. |
| 229 var notificationData = test.cardSet.update( |
| 230 testCardId, [testUncombinedNotification], {}); |
| 231 |
| 232 // Check the return value. |
| 233 assertEquals( |
| 234 JSON.stringify({ |
| 235 timestamp: 300000, |
| 236 combinedCard: [testUncombinedNotification] |
| 237 }), |
| 238 JSON.stringify(notificationData)); |
| 239 }); |
| 240 |
| 241 TEST_F('GoogleNowCardsUnitTest', 'UpdateSimpleHidePast', function() { |
| 242 // Update a simple card with the hide event in the past (actually, present). |
| 243 // Should clear the notification. |
| 244 |
| 245 var testUncombinedNotification = { |
| 246 receivedNotification: { |
| 247 notificationId: testNotificationIdA, |
| 248 chromeNotificationId: testCardId, |
| 249 chromeNotificationOptions: testNotificationA, |
| 250 actionUrls: testActionUrlsA, |
| 251 dismissal: testDismissalA, |
| 252 groupName: groupNameA |
| 253 }, |
| 254 hideTime: 300000 |
| 255 }; |
| 256 |
| 257 // Setup and expectations. |
| 258 var test = setUpCardManagerTest(this); |
| 259 this.mockApis.expects(once()). |
| 260 chrome_alarms_clear(expectedAlarmId); |
| 261 this.mockApis.expects(once()). |
| 262 instrumented_notifications_clear(testCardId, ANYTHING); |
| 263 |
| 264 var groups = { |
| 265 A: { |
| 266 cards: [{chromeNotificationId: 'ID1'}, {chromeNotificationId: testCardId}] |
| 267 }, |
| 268 B: { |
| 269 cards: [{chromeNotificationId: testCardId}, {chromeNotificationId: 'ID2'}] |
| 270 } |
| 271 }; |
| 272 |
| 273 // Call tested method. |
| 274 var notificationData = test.cardSet.update( |
| 275 testCardId, [testUncombinedNotification], groups); |
| 276 |
| 277 // Check the return value. |
| 278 assertEquals(undefined, notificationData); |
| 279 |
| 280 // Check that groups were cleaned up. |
| 281 var expectedCleanedGroups = { |
| 282 A: { |
| 283 cards: [{chromeNotificationId: 'ID1'}] |
| 284 }, |
| 285 B: { |
| 286 cards: [{chromeNotificationId: 'ID2'}] |
| 287 } |
| 288 }; |
| 289 |
| 290 assertEquals(JSON.stringify(expectedCleanedGroups), JSON.stringify(groups)); |
| 291 }); |
| 292 |
| 293 TEST_F('GoogleNowCardsUnitTest', 'UpdateComplex', function() { |
| 294 // Update a combined card that contains 2 uncombined cards. The card from |
| 295 // group B has higher priority and wins. |
| 296 |
| 297 var testUncombinedNotificationA = { |
| 298 receivedNotification: { |
| 299 notificationId: testNotificationIdA, |
| 300 chromeNotificationId: testCardId, |
| 301 chromeNotificationOptions: testNotificationA, |
| 302 actionUrls: testActionUrlsA, |
| 303 dismissal: testDismissalA, |
| 304 groupName: groupNameA |
| 305 }, |
| 306 hideTime: 300001 |
| 307 }; |
| 308 |
| 309 var testUncombinedNotificationB = { |
| 310 receivedNotification: { |
| 311 notificationId: testNotificationIdB, |
| 312 chromeNotificationId: testCardId, |
| 313 chromeNotificationOptions: testNotificationB, |
| 314 actionUrls: testActionUrlsB, |
| 315 dismissal: testDismissalB, |
| 316 groupName: groupNameB |
| 317 }, |
| 318 hideTime: 300002 |
| 319 }; |
| 320 |
| 321 // Setup and expectations. |
| 322 var test = setUpCardManagerTest(this); |
| 323 this.mockApis.expects(once()). |
| 324 chrome_alarms_clear(expectedAlarmId); |
| 325 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); |
| 326 this.mockApis.expects(once()). |
| 327 instrumented_notifications_update( |
| 328 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), |
| 329 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationB)), |
| 330 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). |
| 331 will(invokeCallback( |
| 332 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateSuccessful)); |
| 333 this.mockApis.expects(once()). |
| 334 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); |
| 335 |
| 336 // Call tested method. |
| 337 var notificationData = test.cardSet.update( |
| 338 testCardId, |
| 339 [testUncombinedNotificationA, testUncombinedNotificationB], |
| 340 {}); |
| 341 |
| 342 // Check the return value. |
| 343 assertEquals( |
| 344 JSON.stringify({ |
| 345 actionUrls: testActionUrlsB, |
| 346 timestamp: 300000, |
| 347 combinedCard: [testUncombinedNotificationA, testUncombinedNotificationB] |
| 348 }), |
| 349 JSON.stringify(notificationData)); |
| 350 }); |
| 351 |
| 352 TEST_F('GoogleNowCardsUnitTest', 'DismissSimple', function() { |
| 353 // Dismiss a combined card that contains 1 uncombined currently visible card. |
| 354 // The notification should be deleted, and the card data should be cleared. |
| 355 |
| 356 var testUncombinedNotificationA = { |
| 357 receivedNotification: { |
| 358 notificationId: testNotificationIdA, |
| 359 chromeNotificationId: testCardId, |
| 360 chromeNotificationOptions: testNotificationA, |
| 361 actionUrls: testActionUrlsA, |
| 362 dismissal: testDismissalA, |
| 363 groupName: groupNameA |
| 364 }, |
| 365 showTime: 299995, |
| 366 hideTime: 300005 |
| 367 }; |
| 368 |
| 369 // Setup and expectations. |
| 370 var test = setUpCardManagerTest(this); |
| 371 this.mockApis.expects(once()). |
| 372 chrome_alarms_clear(expectedAlarmId); |
| 373 this.mockApis.expects(once()). |
| 374 instrumented_notifications_clear(testCardId, ANYTHING); |
| 375 |
| 376 var groups = { |
| 377 A: { |
| 378 cards: [{chromeNotificationId: 'ID1'}, {chromeNotificationId: testCardId}] |
| 379 }, |
| 380 B: { |
| 381 cards: [{chromeNotificationId: testCardId}, {chromeNotificationId: 'ID2'}] |
| 382 } |
| 383 }; |
| 384 |
| 385 // Call tested method. |
| 386 var dismissalResult = test.cardSet.onDismissal( |
| 387 testCardId, |
| 388 { |
| 389 actionUrls: testActionUrlsA, |
| 390 timestamp: 299999, |
| 391 combinedCard: [testUncombinedNotificationA] |
| 392 }, |
| 393 groups); |
| 394 |
| 395 // Check the return value. |
| 396 assertEquals( |
| 397 JSON.stringify({ |
| 398 dismissals: [ |
| 399 {notificationId: testNotificationIdA, parameters: testDismissalA} |
| 400 ], |
| 401 notificationData: undefined |
| 402 }), |
| 403 JSON.stringify(dismissalResult)); |
| 404 |
| 405 // Check that groups were cleaned up. |
| 406 var expectedCleanedGroups = { |
| 407 A: { |
| 408 cards: [{chromeNotificationId: 'ID1'}] |
| 409 }, |
| 410 B: { |
| 411 cards: [{chromeNotificationId: 'ID2'}] |
| 412 } |
| 413 }; |
| 414 |
| 415 assertEquals(JSON.stringify(expectedCleanedGroups), JSON.stringify(groups)); |
| 416 }); |
| 417 |
| 418 TEST_F('GoogleNowCardsUnitTest', 'DismissComplex', function() { |
| 419 // Dismiss a combined card that contains 2 uncombined cards. One of them (B), |
| 420 // is currently shown, and it should be dismissed. The other one (A) has |
| 421 // showTime in future, and it should not be dismissed. |
| 422 |
| 423 var testUncombinedNotificationA = { |
| 424 receivedNotification: { |
| 425 notificationId: testNotificationIdA, |
| 426 chromeNotificationId: testCardId, |
| 427 chromeNotificationOptions: testNotificationA, |
| 428 actionUrls: testActionUrlsA, |
| 429 dismissal: testDismissalA, |
| 430 groupName: groupNameA |
| 431 }, |
| 432 showTime: 300010, |
| 433 hideTime: 300011 |
| 434 }; |
| 435 |
| 436 var testUncombinedNotificationB = { |
| 437 receivedNotification: { |
| 438 notificationId: testNotificationIdB, |
| 439 chromeNotificationId: testCardId, |
| 440 chromeNotificationOptions: testNotificationB, |
| 441 actionUrls: testActionUrlsB, |
| 442 dismissal: testDismissalB, |
| 443 groupName: groupNameB |
| 444 }, |
| 445 showTime: 299995, |
| 446 hideTime: 300005 |
| 447 }; |
| 448 |
| 449 // Setup and expectations. |
| 450 var test = setUpCardManagerTest(this); |
| 451 this.mockApis.expects(once()). |
| 452 chrome_alarms_clear(expectedAlarmId); |
| 453 this.mockApis.expects(once()). |
| 454 instrumented_notifications_clear(testCardId, ANYTHING); |
| 455 this.mockApis.expects(once()). |
| 456 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300010})); |
| 457 |
| 458 // Call tested method. |
| 459 var dismissalResult = test.cardSet.onDismissal( |
| 460 testCardId, |
| 461 { |
| 462 actionUrls: testActionUrlsB, |
| 463 timestamp: 299999, |
| 464 combinedCard: [testUncombinedNotificationA, testUncombinedNotificationB] |
| 465 }, |
| 466 {}); |
| 467 |
| 468 // Check the return value. |
| 469 assertEquals( |
| 470 JSON.stringify({ |
| 471 dismissals: [ |
| 472 {notificationId: testNotificationIdB, parameters: testDismissalB} |
| 473 ], |
| 474 notificationData: { |
| 475 timestamp: 300000, |
| 476 combinedCard: [testUncombinedNotificationA] |
| 477 }}), |
| 478 JSON.stringify(dismissalResult)); |
| 479 }); |
| 480 |
79 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { | 481 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUnrecognized', function() { |
80 // Tests onAlarm does nothing on an unrelated alarm. | 482 // Tests onAlarm does nothing on an unrelated alarm. |
81 var test = setUpCardManagerTest(this); | 483 var test = setUpCardManagerTest(this); |
82 | 484 |
83 // Call tested method. | 485 // Call tested method. |
84 test.alarmCallback({name: 'unrelated'}); | 486 test.alarmCallback({name: 'unrelated'}); |
85 }); | 487 }); |
| 488 |
| 489 TEST_F('GoogleNowCardsUnitTest', 'onAlarmClear', function() { |
| 490 // Tests onAlarm fired at a moment past all card's events. The card should be |
| 491 // cleaned. |
| 492 var testUncombinedNotification = { |
| 493 receivedNotification: { |
| 494 notificationId: testNotificationIdA, |
| 495 chromeNotificationId: testCardId, |
| 496 chromeNotificationOptions: testNotificationA, |
| 497 actionUrls: testActionUrlsA, |
| 498 dismissal: testDismissalA, |
| 499 groupName: groupNameA |
| 500 }, |
| 501 hideTime: 299999 |
| 502 }; |
| 503 |
| 504 // Setup and expectations. |
| 505 var test = setUpCardManagerTest(this); |
| 506 var tasksAddSavedArgs = new SaveMockArguments(); |
| 507 this.mockApis.expects(once()). |
| 508 tasks_add( |
| 509 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), |
| 510 tasksAddSavedArgs.match(ANYTHING)). |
| 511 will(invokeCallback(tasksAddSavedArgs,1)); |
| 512 var storageGetSavedArgs = new SaveMockArguments(); |
| 513 this.mockApis.expects(once()). |
| 514 instrumented_storage_local_get( |
| 515 storageGetSavedArgs.match( |
| 516 eqJSON(['notificationsData', 'notificationGroups'])), |
| 517 storageGetSavedArgs.match(ANYTHING)). |
| 518 will(invokeCallback( |
| 519 storageGetSavedArgs, |
| 520 1, |
| 521 { |
| 522 notificationsData: { |
| 523 'TEST CARD ID': { |
| 524 actionUrls: testActionUrlsA, |
| 525 timestamp: 299998, |
| 526 combinedCard: [testUncombinedNotification] |
| 527 }, |
| 528 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} |
| 529 }, |
| 530 notificationGroups: { |
| 531 A: { |
| 532 cards: [ |
| 533 {chromeNotificationId: 'ID1'}, |
| 534 {chromeNotificationId: testCardId} |
| 535 ] |
| 536 }, |
| 537 B: { |
| 538 cards: [ |
| 539 {chromeNotificationId: testCardId}, |
| 540 {chromeNotificationId: 'ID2'} |
| 541 ] |
| 542 }}})); |
| 543 this.mockApis.expects(once()). |
| 544 instrumented_notifications_clear(testCardId, ANYTHING); |
| 545 this.mockApis.expects(once()). |
| 546 chrome_alarms_clear(expectedAlarmId); |
| 547 this.mockApis.expects(once()). |
| 548 chrome_storage_local_set(eqJSON({ |
| 549 notificationsData: { |
| 550 'TEST CARD ID 1': {testField: 'TEST VALUE 1'} |
| 551 }, |
| 552 notificationGroups: { |
| 553 A: { |
| 554 cards: [{chromeNotificationId: 'ID1'}] |
| 555 }, |
| 556 B: { |
| 557 cards: [{chromeNotificationId: 'ID2'}] |
| 558 }}})); |
| 559 |
| 560 // Call tested method. |
| 561 test.alarmCallback({name: expectedAlarmId}); |
| 562 }); |
| 563 |
| 564 TEST_F('GoogleNowCardsUnitTest', 'onAlarmUpdate', function() { |
| 565 // Tests onAlarm fired at a moment when there are future card's events. The |
| 566 // card needs to be updated. |
| 567 var testUncombinedNotification = { |
| 568 receivedNotification: { |
| 569 notificationId: testNotificationIdA, |
| 570 chromeNotificationId: testCardId, |
| 571 chromeNotificationOptions: testNotificationA, |
| 572 actionUrls: testActionUrlsA, |
| 573 dismissal: testDismissalA, |
| 574 groupName: groupNameA |
| 575 }, |
| 576 hideTime: 300001 |
| 577 }; |
| 578 |
| 579 // Setup and expectations. |
| 580 var test = setUpCardManagerTest(this); |
| 581 var tasksAddSavedArgs = new SaveMockArguments(); |
| 582 this.mockApis.expects(once()). |
| 583 tasks_add( |
| 584 tasksAddSavedArgs.match(eq(UPDATE_CARD_TASK_NAME)), |
| 585 tasksAddSavedArgs.match(ANYTHING)). |
| 586 will(invokeCallback(tasksAddSavedArgs,1)); |
| 587 var storageGetSavedArgs = new SaveMockArguments(); |
| 588 this.mockApis.expects(once()). |
| 589 instrumented_storage_local_get( |
| 590 storageGetSavedArgs.match( |
| 591 eqJSON(['notificationsData', 'notificationGroups'])), |
| 592 storageGetSavedArgs.match(ANYTHING)). |
| 593 will(invokeCallback( |
| 594 storageGetSavedArgs, |
| 595 1, |
| 596 { |
| 597 notificationsData: { |
| 598 'TEST CARD ID': { |
| 599 actionUrls: testActionUrlsA, |
| 600 timestamp: 299998, |
| 601 combinedCard: [testUncombinedNotification] |
| 602 }}})); |
| 603 this.mockApis.expects(once()). |
| 604 chrome_alarms_clear(expectedAlarmId); |
| 605 var chromeNotificationsUpdateSavedArgs = new SaveMockArguments(); |
| 606 this.mockApis.expects(once()). |
| 607 instrumented_notifications_update( |
| 608 chromeNotificationsUpdateSavedArgs.match(eq(testCardId)), |
| 609 chromeNotificationsUpdateSavedArgs.match(eqJSON(testNotificationA)), |
| 610 chromeNotificationsUpdateSavedArgs.match(ANYTHING)). |
| 611 will(invokeCallback( |
| 612 chromeNotificationsUpdateSavedArgs, 2, notificationUpdateSuccessful)); |
| 613 this.mockApis.expects(once()). |
| 614 chrome_alarms_create(expectedAlarmId, eqJSON({when: 300001})); |
| 615 this.mockApis.expects(once()). |
| 616 chrome_storage_local_set(eqJSON({ |
| 617 notificationsData: { |
| 618 'TEST CARD ID': { |
| 619 actionUrls: testActionUrlsA, |
| 620 timestamp: 300000, |
| 621 combinedCard: [testUncombinedNotification] |
| 622 } |
| 623 }, |
| 624 notificationGroups: { |
| 625 }})); |
| 626 |
| 627 // Call tested method. |
| 628 test.alarmCallback({name: expectedAlarmId}); |
| 629 }); |
OLD | NEW |