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 // TODO(robliao,vadimt): Determine the granularity of testing to perform. | 5 // TODO(robliao,vadimt): Determine the granularity of testing to perform. |
6 | 6 |
7 /** | 7 /** |
8 * Test fixture for background.js. | 8 * Test fixture for background.js. |
9 * @constructor | 9 * @constructor |
10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 ]); | 63 ]); |
64 fixture.makeAndRegisterMockApis([ | 64 fixture.makeAndRegisterMockApis([ |
65 'authenticationManager.isSignedIn', | 65 'authenticationManager.isSignedIn', |
66 'chrome.location.clearWatch', | 66 'chrome.location.clearWatch', |
67 'chrome.storage.local.remove', | 67 'chrome.storage.local.remove', |
68 'instrumented.metricsPrivate.getVariationParams', | 68 'instrumented.metricsPrivate.getVariationParams', |
69 'instrumented.notifications.getAll', | 69 'instrumented.notifications.getAll', |
70 'instrumented.notifications.getPermissionLevel', | 70 'instrumented.notifications.getPermissionLevel', |
71 'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get', | 71 'instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get', |
72 'instrumented.storage.local.get', | 72 'instrumented.storage.local.get', |
73 'instrumented.webstorePrivate.getBrowserLogin', | |
74 'tasks.add', | 73 'tasks.add', |
75 'updateCardsAttempts.isRunning', | 74 'updateCardsAttempts.isRunning', |
76 'updateCardsAttempts.stop' | 75 'updateCardsAttempts.stop' |
77 ]); | 76 ]); |
78 } | 77 } |
79 | 78 |
80 /** | 79 /** |
81 * Sets up the test to expect the state machine calls and send | 80 * Sets up the test to expect the state machine calls and send |
82 * the specified state machine state. Currently used to test initialize(). | 81 * the specified state machine state. Currently used to test initialize(). |
83 * Note that this CAN NOT be used if any of the methods below are called | 82 * Note that this CAN NOT be used if any of the methods below are called |
84 * outside of this context with the same argument matchers. | 83 * outside of this context with the same argument matchers. |
85 * expects() calls cannot be chained with the same argument matchers. | 84 * expects() calls cannot be chained with the same argument matchers. |
86 * @param {object} fixture Test fixture. | 85 * @param {object} fixture Test fixture. |
87 * @param {string} testIdentityToken getAuthToken callback token. | 86 * @param {string} testIdentityToken getAuthToken callback token. |
88 * @param {boolean} testGeolocationPref Geolocation Preference callback value. | 87 * @param {boolean} testGeolocationPref Geolocation Preference callback value. |
89 * @param {object} testExperimentVariationParams Response of | 88 * @param {object} testExperimentVariationParams Response of |
90 * metricsPrivate.getVariationParams. | 89 * metricsPrivate.getVariationParams. |
91 * @param {string} testExperimentVariationParams Response of | 90 * @param {string} testExperimentVariationParams Response of |
92 * notifications.getPermissionLevel. | 91 * notifications.getPermissionLevel. |
93 * @param {boolean} testGoogleNowEnabled True if the user is opted in to Google | 92 * @param {boolean} testGoogleNowEnabled True if the user is opted in to Google |
94 * Now. | 93 * Now. |
95 */ | 94 */ |
96 function expectStateMachineCalls( | 95 function expectStateMachineCalls( |
97 fixture, | 96 fixture, |
98 testIdentityToken, | 97 testIdentityToken, |
99 testGeolocationPref, | 98 testGeolocationPref, |
100 testExperimentVariationParams, | 99 testExperimentVariationParams, |
101 testNotificationPermissionLevel, | 100 testNotificationPermissionLevel, |
102 testGoogleNowEnabled) { | 101 testGoogleNowEnabled) { |
| 102 var authenticationManagerIsSignedInSavedArgs = new SaveMockArguments(); |
103 fixture.mockApis.expects(once()). | 103 fixture.mockApis.expects(once()). |
104 authenticationManager_isSignedIn(). | 104 authenticationManager_isSignedIn( |
105 will(returnValue(new Promise(function(resolve) { | 105 authenticationManagerIsSignedInSavedArgs.match(ANYTHING)). |
106 resolve(!!testIdentityToken); | 106 will(invokeCallback( |
107 }))); | 107 authenticationManagerIsSignedInSavedArgs, |
| 108 0, |
| 109 testIdentityToken)); |
108 | 110 |
109 var getVariationParamsSavedArgs = new SaveMockArguments(); | 111 var getVariationParamsSavedArgs = new SaveMockArguments(); |
110 fixture.mockApis.expects(once()). | 112 fixture.mockApis.expects(once()). |
111 instrumented_metricsPrivate_getVariationParams( | 113 instrumented_metricsPrivate_getVariationParams( |
112 getVariationParamsSavedArgs.match(ANYTHING), | 114 getVariationParamsSavedArgs.match(ANYTHING), |
113 getVariationParamsSavedArgs.match(ANYTHING)). | 115 getVariationParamsSavedArgs.match(ANYTHING)). |
114 will(invokeCallback( | 116 will(invokeCallback( |
115 getVariationParamsSavedArgs, 1, testExperimentVariationParams)); | 117 getVariationParamsSavedArgs, 1, testExperimentVariationParams)); |
116 | 118 |
117 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); | 119 var googleGeolocationPrefGetSavedArgs = new SaveMockArguments(); |
118 fixture.mockApis.expects(once()). | 120 fixture.mockApis.expects(once()). |
119 instrumented_preferencesPrivate_googleGeolocationAccessEnabled_get( | 121 instrumented_preferencesPrivate_googleGeolocationAccessEnabled_get( |
120 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), | 122 googleGeolocationPrefGetSavedArgs.match(eqJSON({})), |
121 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). | 123 googleGeolocationPrefGetSavedArgs.match(ANYTHING)). |
122 will(invokeCallback( | 124 will(invokeCallback( |
123 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); | 125 googleGeolocationPrefGetSavedArgs, 1, {value: testGeolocationPref})); |
124 | 126 |
125 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); | 127 var notificationGetPermissionLevelSavedArgs = new SaveMockArguments(); |
126 fixture.mockApis.expects(once()). | 128 fixture.mockApis.expects(once()). |
127 instrumented_notifications_getPermissionLevel( | 129 instrumented_notifications_getPermissionLevel( |
128 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). | 130 notificationGetPermissionLevelSavedArgs.match(ANYTHING)). |
129 will(invokeCallback( | 131 will(invokeCallback( |
130 notificationGetPermissionLevelSavedArgs, | 132 notificationGetPermissionLevelSavedArgs, |
131 0, | 133 0, |
132 testNotificationPermissionLevel)) | 134 testNotificationPermissionLevel)) |
133 | 135 |
134 var storageGetSavedArgs = new SaveMockArguments(); | 136 var storageGetSavedArgs = new SaveMockArguments();» |
135 fixture.mockApis.expects(once()). | 137 fixture.mockApis.expects(once()).» |
136 instrumented_storage_local_get( | 138 instrumented_storage_local_get(» |
137 storageGetSavedArgs.match(eq('googleNowEnabled')), | 139 storageGetSavedArgs.match(eq('googleNowEnabled')),» |
138 storageGetSavedArgs.match(ANYTHING)). | 140 storageGetSavedArgs.match(ANYTHING)).» |
139 will(invokeCallback( | 141 will(invokeCallback( |
140 storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled})); | 142 storageGetSavedArgs, 1, {googleNowEnabled: testGoogleNowEnabled}));»
|
141 | 143 |
142 fixture.mockGlobals.expects(once()). | 144 fixture.mockGlobals.expects(once()). |
143 setBackgroundEnable(ANYTHING); | 145 setBackgroundEnable(ANYTHING); |
144 } | 146 } |
145 | 147 |
146 /** | 148 /** |
147 * Sets up the test to expect the initialization calls that | 149 * Sets up the test to expect the initialization calls that |
148 * initialize() invokes. | 150 * initialize() invokes. |
149 * Note that this CAN NOT be used if any of the methods below are called | 151 * Note that this CAN NOT be used if any of the methods below are called |
150 * outside of this context with the same argument matchers. | 152 * outside of this context with the same argument matchers. |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 receivedNotificationWithShowTime | 590 receivedNotificationWithShowTime |
589 ] | 591 ] |
590 }; | 592 }; |
591 | 593 |
592 // Invoking the tested function. | 594 // Invoking the tested function. |
593 combineGroup(combinedCards, storedGroup); | 595 combineGroup(combinedCards, storedGroup); |
594 | 596 |
595 // Check the output value. | 597 // Check the output value. |
596 var expectedCombinedCards = { | 598 var expectedCombinedCards = { |
597 'EXISTING CARD': [ | 599 'EXISTING CARD': [ |
598 1, | 600 1, |
599 { | 601 { |
600 receivedNotification: receivedNotificationNoShowTime, | 602 receivedNotification: receivedNotificationNoShowTime, |
601 hideTime: 11000 | 603 hideTime: 11000 |
602 } | 604 } |
603 ], | 605 ], |
604 'NEW CARD': [ | 606 'NEW CARD': [ |
605 { | 607 { |
606 receivedNotification: receivedNotificationWithShowTime, | 608 receivedNotification: receivedNotificationWithShowTime, |
607 showTime: 12000, | 609 showTime: 12000, |
608 hideTime: 13000 | 610 hideTime: 13000 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 eqJSON({ | 889 eqJSON({ |
888 notificationGroups: expectedUpdatedGroups, | 890 notificationGroups: expectedUpdatedGroups, |
889 recentDismissals: {}})); | 891 recentDismissals: {}})); |
890 | 892 |
891 this.mockGlobals.expects(once()). | 893 this.mockGlobals.expects(once()). |
892 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); | 894 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); |
893 | 895 |
894 // Invoking the tested function. | 896 // Invoking the tested function. |
895 processServerResponse(serverResponse, fakeOnCardShownFunction); | 897 processServerResponse(serverResponse, fakeOnCardShownFunction); |
896 }); | 898 }); |
OLD | NEW |