| 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 utility.js. | 6 * Test fixture for utility.js. |
| 7 * @constructor | 7 * @constructor |
| 8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
| 9 */ | 9 */ |
| 10 function GoogleNowUtilityUnitTest () { | 10 function GoogleNowUtilityUnitTest () { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 'at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)\n ' + | 34 'at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)\n ' + |
| 35 'at Object.InjectedScript.evaluate (<anonymous>:458:21)'; | 35 'at Object.InjectedScript.evaluate (<anonymous>:458:21)'; |
| 36 | 36 |
| 37 var testError = { | 37 var testError = { |
| 38 canSendMessageToServer: true, | 38 canSendMessageToServer: true, |
| 39 stack: testStack, | 39 stack: testStack, |
| 40 name: 'TEST ERROR NAME', | 40 name: 'TEST ERROR NAME', |
| 41 message: 'TEST ERROR MESSAGE' | 41 message: 'TEST ERROR MESSAGE' |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 var testIdentityToken = 'test identity token'; |
| 45 |
| 44 this.makeAndRegisterMockGlobals(['buildServerRequest']); | 46 this.makeAndRegisterMockGlobals(['buildServerRequest']); |
| 45 this.makeMockLocalFunctions(['sendRequest']); | 47 this.makeMockLocalFunctions(['sendRequest', 'setRequestHeader']); |
| 48 this.makeAndRegisterMockApis(['chrome.identity.getAuthToken']); |
| 46 | 49 |
| 47 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; | 50 var mockRequest = { |
| 51 send: this.mockLocalFunctions.functions().sendRequest, |
| 52 setRequestHeader: this.mockLocalFunctions.functions().setRequestHeader |
| 53 }; |
| 48 | 54 |
| 49 var expectedRequestObject = { | 55 var expectedRequestObject = { |
| 50 message: 'TEST ERROR NAME: TEST ERROR MESSAGE', | 56 message: 'TEST ERROR NAME: TEST ERROR MESSAGE', |
| 51 file: '//ext_id/utility.js', | 57 file: '//ext_id/utility.js', |
| 52 line: '29', | 58 line: '29', |
| 53 trace: 'Error: TEST ERROR MESSAGE\n ' + | 59 trace: 'Error: TEST ERROR MESSAGE\n ' + |
| 54 'at buildErrorWithMessageForServer (chrome-extension://ext_id/util' + | 60 'at buildErrorWithMessageForServer (chrome-extension://ext_id/util' + |
| 55 'ity.js:29:15)\n ' + | 61 'ity.js:29:15)\n ' + |
| 56 'at <anonymous>:2:16\n ' + | 62 'at <anonymous>:2:16\n ' + |
| 57 'at Object.InjectedScript._evaluateOn (<anonymous>:580:39)\n ' + | 63 'at Object.InjectedScript._evaluateOn (<anonymous>:580:39)\n ' + |
| 58 'at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)\n' + | 64 'at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)\n' + |
| 59 ' at Object.InjectedScript.evaluate (<anonymous>:458:21)' | 65 ' at Object.InjectedScript.evaluate (<anonymous>:458:21)' |
| 60 }; | 66 }; |
| 61 | 67 |
| 62 this.mockGlobals.expects(once()). | 68 this.mockGlobals.expects(once()). |
| 63 buildServerRequest('POST', 'jserrors', 'application/json'). | 69 buildServerRequest('POST', 'jserrors', 'application/json'). |
| 64 will(returnValue(mockRequest)); | 70 will(returnValue(mockRequest)); |
| 71 |
| 72 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); |
| 73 this.mockApis.expects(once()). |
| 74 chrome_identity_getAuthToken( |
| 75 chromeIdentityGetAuthTokenSavedArgs.match( |
| 76 eqJSON({interactive: false})), |
| 77 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). |
| 78 will(invokeCallback( |
| 79 chromeIdentityGetAuthTokenSavedArgs, |
| 80 1, |
| 81 testIdentityToken)); |
| 82 |
| 83 this.mockLocalFunctions.expects(once()).setRequestHeader( |
| 84 'Authorization', 'Bearer test identity token'); |
| 65 this.mockLocalFunctions.expects(once()).sendRequest( | 85 this.mockLocalFunctions.expects(once()).sendRequest( |
| 66 JSON.stringify(expectedRequestObject)); | 86 JSON.stringify(expectedRequestObject)); |
| 67 | 87 |
| 68 // Invoking the tested function. | 88 // Invoking the tested function. |
| 69 sendErrorReport(testError); | 89 sendErrorReport(testError); |
| 70 }); | 90 }); |
| 71 | 91 |
| 72 TEST_F('GoogleNowUtilityUnitTest', 'SendErrorReport2', function() { | 92 TEST_F('GoogleNowUtilityUnitTest', 'SendErrorReport2', function() { |
| 73 // Test sending report for an error with a message that should not be sent to | 93 // Test sending report for an error with a message that should not be sent to |
| 74 // server, with an error generated in an anonymous function. | 94 // server, with an error generated in an anonymous function. |
| 75 | 95 |
| 76 // Setup and expectations. | 96 // Setup and expectations. |
| 77 var testStack = 'TypeError: Property \'processPendingDismissals\' of ' + | 97 var testStack = 'TypeError: Property \'processPendingDismissals\' of ' + |
| 78 'object [object Object] is not a function\n ' + | 98 'object [object Object] is not a function\n ' + |
| 79 'at chrome-extension://ext_id/background.js:444:11\n ' + | 99 'at chrome-extension://ext_id/background.js:444:11\n ' + |
| 80 'at chrome-extension://ext_id/utility.js:509:7'; | 100 'at chrome-extension://ext_id/utility.js:509:7'; |
| 81 | 101 |
| 82 var testError = { | 102 var testError = { |
| 83 stack: testStack, | 103 stack: testStack, |
| 84 name: 'TypeError' | 104 name: 'TypeError' |
| 85 }; | 105 }; |
| 86 | 106 |
| 107 var testIdentityToken = 'test identity token'; |
| 108 |
| 87 this.makeAndRegisterMockGlobals(['buildServerRequest']); | 109 this.makeAndRegisterMockGlobals(['buildServerRequest']); |
| 88 this.makeMockLocalFunctions(['sendRequest']); | 110 this.makeMockLocalFunctions(['sendRequest', 'setRequestHeader']); |
| 111 this.makeAndRegisterMockApis(['chrome.identity.getAuthToken']); |
| 89 | 112 |
| 90 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; | 113 var mockRequest = { |
| 114 send: this.mockLocalFunctions.functions().sendRequest, |
| 115 setRequestHeader: this.mockLocalFunctions.functions().setRequestHeader |
| 116 }; |
| 91 | 117 |
| 92 var expectedRequestObject = { | 118 var expectedRequestObject = { |
| 93 message: 'TypeError', | 119 message: 'TypeError', |
| 94 file: '//ext_id/background.js', | 120 file: '//ext_id/background.js', |
| 95 line: '444', | 121 line: '444', |
| 96 trace: '(message removed)\n ' + | 122 trace: '(message removed)\n ' + |
| 97 'at chrome-extension://ext_id/background.js:444:11\n ' + | 123 'at chrome-extension://ext_id/background.js:444:11\n ' + |
| 98 'at chrome-extension://ext_id/utility.js:509:7' | 124 'at chrome-extension://ext_id/utility.js:509:7' |
| 99 }; | 125 }; |
| 100 | 126 |
| 101 this.mockGlobals.expects(once()). | 127 this.mockGlobals.expects(once()). |
| 102 buildServerRequest('POST', 'jserrors', 'application/json'). | 128 buildServerRequest('POST', 'jserrors', 'application/json'). |
| 103 will(returnValue(mockRequest)); | 129 will(returnValue(mockRequest)); |
| 130 |
| 131 var chromeIdentityGetAuthTokenSavedArgs = new SaveMockArguments(); |
| 132 this.mockApis.expects(once()). |
| 133 chrome_identity_getAuthToken( |
| 134 chromeIdentityGetAuthTokenSavedArgs.match( |
| 135 eqJSON({interactive: false})), |
| 136 chromeIdentityGetAuthTokenSavedArgs.match(ANYTHING)). |
| 137 will(invokeCallback( |
| 138 chromeIdentityGetAuthTokenSavedArgs, |
| 139 1, |
| 140 testIdentityToken)); |
| 141 |
| 142 this.mockLocalFunctions.expects(once()).setRequestHeader( |
| 143 'Authorization', 'Bearer test identity token'); |
| 104 this.mockLocalFunctions.expects(once()).sendRequest( | 144 this.mockLocalFunctions.expects(once()).sendRequest( |
| 105 JSON.stringify(expectedRequestObject)); | 145 JSON.stringify(expectedRequestObject)); |
| 106 | 146 |
| 107 // Invoking the tested function. | 147 // Invoking the tested function. |
| 108 sendErrorReport(testError); | 148 sendErrorReport(testError); |
| 109 }); | 149 }); |
| 110 | 150 |
| 111 TEST_F('GoogleNowUtilityUnitTest', 'WrapperCheckInWrappedCallback', function() { | 151 TEST_F('GoogleNowUtilityUnitTest', 'WrapperCheckInWrappedCallback', function() { |
| 112 // Test generating an error when calling wrapper.checkInWrappedCallback from a | 152 // Test generating an error when calling wrapper.checkInWrappedCallback from a |
| 113 // non-instrumented code. | 153 // non-instrumented code. |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 var alarmsGetSavedArgs = new SaveMockArguments(); | 970 var alarmsGetSavedArgs = new SaveMockArguments(); |
| 931 this.mockApis.expects(once()). | 971 this.mockApis.expects(once()). |
| 932 instrumented_alarms_get( | 972 instrumented_alarms_get( |
| 933 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), | 973 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), |
| 934 alarmsGetSavedArgs.match(ANYTHING)). | 974 alarmsGetSavedArgs.match(ANYTHING)). |
| 935 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); | 975 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); |
| 936 this.mockLocalFunctions.expects(once()).attempt(); | 976 this.mockLocalFunctions.expects(once()).attempt(); |
| 937 // Invocation. | 977 // Invocation. |
| 938 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); | 978 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); |
| 939 }); | 979 }); |
| OLD | NEW |