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 28 matching lines...) Expand all Loading... |
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 this.makeAndRegisterMockGlobals(['buildServerRequest']); | 44 this.makeAndRegisterMockGlobals(['buildServerRequest']); |
45 this.makeMockLocalFunctions(['sendRequest']); | 45 this.makeMockLocalFunctions(['sendRequest']); |
46 | 46 |
47 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; | 47 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; |
48 | 48 |
49 var expectedRequestParameters = 'error=TEST%20ERROR%20NAME%3A%20' + | 49 var expectedRequestObject = { |
50 'TEST%20ERROR%20MESSAGE&' + | 50 message: 'TEST ERROR NAME: TEST ERROR MESSAGE', |
51 'script=%2F%2Fext_id%2Futility.js&' + | 51 file: '//ext_id/utility.js', |
52 'line=29&' + | 52 line: '29', |
53 'trace=Error%3A%20TEST%20ERROR%20MESSAGE%0A%20%20%20%20' + | 53 trace: 'Error: TEST ERROR MESSAGE\n ' + |
54 'at%20buildErrorWithMessageForServer%20' + | 54 'at buildErrorWithMessageForServer (chrome-extension://ext_id/util' + |
55 '(chrome-extension%3A%2F%2Fext_id%2Futility.js%3A29%3A15)%0A' + | 55 'ity.js:29:15)\n ' + |
56 '%20%20%20%20at%20%3Canonymous%3E%3A2%3A16%0A%20%20%20%20' + | 56 'at <anonymous>:2:16\n ' + |
57 'at%20Object.InjectedScript._evaluateOn%20(%3Canonymous%3E%3A580%3A39)' + | 57 'at Object.InjectedScript._evaluateOn (<anonymous>:580:39)\n ' + |
58 '%0A%20%20%20%20' + | 58 'at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)\n' + |
59 'at%20Object.InjectedScript._evaluateAndWrap%20(%3Canonymous%3E%3A539' + | 59 ' at Object.InjectedScript.evaluate (<anonymous>:458:21)' |
60 '%3A52)%0A%20%20%20%20' + | 60 }; |
61 'at%20Object.InjectedScript.evaluate%20(%3Canonymous%3E%3A458%3A21)'; | |
62 | 61 |
63 this.mockGlobals.expects(once()). | 62 this.mockGlobals.expects(once()). |
64 buildServerRequest('jserror', 'application/x-www-form-urlencoded'). | 63 buildServerRequest('jserrors', 'application/json'). |
65 will(returnValue(mockRequest)); | 64 will(returnValue(mockRequest)); |
66 this.mockLocalFunctions.expects(once()).sendRequest( | 65 this.mockLocalFunctions.expects(once()).sendRequest( |
67 expectedRequestParameters); | 66 JSON.stringify(expectedRequestObject)); |
68 | 67 |
69 // Invoking the tested function. | 68 // Invoking the tested function. |
70 sendErrorReport(testError); | 69 sendErrorReport(testError); |
71 }); | 70 }); |
72 | 71 |
73 TEST_F('GoogleNowUtilityUnitTest', 'SendErrorReport2', function() { | 72 TEST_F('GoogleNowUtilityUnitTest', 'SendErrorReport2', function() { |
74 // Test sending report for an error with a message that should not be sent to | 73 // Test sending report for an error with a message that should not be sent to |
75 // server, with an error generated in an anonymous function. | 74 // server, with an error generated in an anonymous function. |
76 | 75 |
77 // Setup and expectations. | 76 // Setup and expectations. |
78 var testStack = 'TypeError: Property \'processPendingDismissals\' of ' + | 77 var testStack = 'TypeError: Property \'processPendingDismissals\' of ' + |
79 'object [object Object] is not a function\n ' + | 78 'object [object Object] is not a function\n ' + |
80 'at chrome-extension://ext_id/background.js:444:11\n ' + | 79 'at chrome-extension://ext_id/background.js:444:11\n ' + |
81 'at chrome-extension://ext_id/utility.js:509:7'; | 80 'at chrome-extension://ext_id/utility.js:509:7'; |
82 | 81 |
83 var testError = { | 82 var testError = { |
84 stack: testStack, | 83 stack: testStack, |
85 name: 'TypeError' | 84 name: 'TypeError' |
86 }; | 85 }; |
87 | 86 |
88 this.makeAndRegisterMockGlobals(['buildServerRequest']); | 87 this.makeAndRegisterMockGlobals(['buildServerRequest']); |
89 this.makeMockLocalFunctions(['sendRequest']); | 88 this.makeMockLocalFunctions(['sendRequest']); |
90 | 89 |
91 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; | 90 var mockRequest = {send: this.mockLocalFunctions.functions().sendRequest}; |
92 | 91 |
93 var expectedRequestParameters = 'error=TypeError&' + | 92 var expectedRequestObject = { |
94 'script=%2F%2Fext_id%2Fbackground.js&' + | 93 message: 'TypeError', |
95 'line=444&' + | 94 file: '//ext_id/background.js', |
96 'trace=(message%20removed)%0A%20%20%20%20' + | 95 line: '444', |
97 'at%20chrome-extension%3A%2F%2Fext_id%2Fbackground.js%3A444%3A11' + | 96 trace: '(message removed)\n ' + |
98 '%0A%20%20%20%20' + | 97 'at chrome-extension://ext_id/background.js:444:11\n ' + |
99 'at%20chrome-extension%3A%2F%2Fext_id%2Futility.js%3A509%3A7'; | 98 'at chrome-extension://ext_id/utility.js:509:7' |
| 99 }; |
100 | 100 |
101 this.mockGlobals.expects(once()). | 101 this.mockGlobals.expects(once()). |
102 buildServerRequest('jserror', 'application/x-www-form-urlencoded'). | 102 buildServerRequest('jserrors', 'application/json'). |
103 will(returnValue(mockRequest)); | 103 will(returnValue(mockRequest)); |
104 this.mockLocalFunctions.expects(once()).sendRequest( | 104 this.mockLocalFunctions.expects(once()).sendRequest( |
105 expectedRequestParameters); | 105 JSON.stringify(expectedRequestObject)); |
106 | 106 |
107 // Invoking the tested function. | 107 // Invoking the tested function. |
108 sendErrorReport(testError); | 108 sendErrorReport(testError); |
109 }); | 109 }); |
110 | 110 |
111 TEST_F('GoogleNowUtilityUnitTest', 'WrapperCheckInWrappedCallback', function() { | 111 TEST_F('GoogleNowUtilityUnitTest', 'WrapperCheckInWrappedCallback', function() { |
112 // Test generating an error when calling wrapper.checkInWrappedCallback from a | 112 // Test generating an error when calling wrapper.checkInWrappedCallback from a |
113 // non-instrumented code. | 113 // non-instrumented code. |
114 | 114 |
115 // Setup and expectations. | 115 // Setup and expectations. |
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 var alarmsGetSavedArgs = new SaveMockArguments(); | 930 var alarmsGetSavedArgs = new SaveMockArguments(); |
931 this.mockApis.expects(once()). | 931 this.mockApis.expects(once()). |
932 instrumented_alarms_get( | 932 instrumented_alarms_get( |
933 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), | 933 alarmsGetSavedArgs.match(eq(testAttemptAlarmName)), |
934 alarmsGetSavedArgs.match(ANYTHING)). | 934 alarmsGetSavedArgs.match(ANYTHING)). |
935 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); | 935 will(invokeCallback(alarmsGetSavedArgs, 1, {testField: 'TEST VALUE'})); |
936 this.mockLocalFunctions.expects(once()).attempt(); | 936 this.mockLocalFunctions.expects(once()).attempt(); |
937 // Invocation. | 937 // Invocation. |
938 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); | 938 onAlarmHandlerContainer[0]({name: testAttemptAlarmName}); |
939 }); | 939 }); |
OLD | NEW |