OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // test_custom_bindings.js | 5 // test_custom_bindings.js |
6 // mini-framework for ExtensionApiTest browser tests | 6 // mini-framework for ExtensionApiTest browser tests |
7 | 7 |
8 var binding = require('binding').Binding.create('test'); | 8 var binding = require('binding').Binding.create('test'); |
9 | 9 |
10 var chrome = requireNative('chrome').GetChrome(); | 10 var chrome = requireNative('chrome').GetChrome(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 apiFunctions.setHandleRequest('callbackAdded', function() { | 55 apiFunctions.setHandleRequest('callbackAdded', function() { |
56 pendingCallbacks++; | 56 pendingCallbacks++; |
57 | 57 |
58 var called = null; | 58 var called = null; |
59 return function() { | 59 return function() { |
60 if (called != null) { | 60 if (called != null) { |
61 var redundantPrefix = 'Error\n'; | 61 var redundantPrefix = 'Error\n'; |
62 chrome.test.fail( | 62 chrome.test.fail( |
63 'Callback has already been run. ' + | 63 'Callback has already been run. ' + |
64 'First call:\n' + called.slice(redundantPrefix.length) + '\n' + | 64 'First call:\n' + |
65 'Second call:\n' + new Error().stack.slice(redundantPrefix.length)); | 65 $String.slice(called, redundantPrefix.length) + '\n' + |
| 66 'Second call:\n' + |
| 67 $String.slice(new Error().stack, redundantPrefix.length)); |
66 } | 68 } |
67 called = new Error().stack; | 69 called = new Error().stack; |
68 | 70 |
69 pendingCallbacks--; | 71 pendingCallbacks--; |
70 if (pendingCallbacks == 0) { | 72 if (pendingCallbacks == 0) { |
71 chromeTest.succeed(); | 73 chromeTest.succeed(); |
72 } | 74 } |
73 }; | 75 }; |
74 }); | 76 }); |
75 | 77 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if ((expected === null) != (actual === null)) | 146 if ((expected === null) != (actual === null)) |
145 return false; | 147 return false; |
146 | 148 |
147 if (expected === actual) | 149 if (expected === actual) |
148 return true; | 150 return true; |
149 | 151 |
150 if (typeof(expected) !== typeof(actual)) | 152 if (typeof(expected) !== typeof(actual)) |
151 return false; | 153 return false; |
152 | 154 |
153 for (var p in actual) { | 155 for (var p in actual) { |
154 if (actual.hasOwnProperty(p) && !expected.hasOwnProperty(p)) | 156 if ($Object.hasOwnProperty(actual, p) && |
| 157 !$Object.hasOwnProperty(expected, p)) { |
155 return false; | 158 return false; |
| 159 } |
156 } | 160 } |
157 for (var p in expected) { | 161 for (var p in expected) { |
158 if (expected.hasOwnProperty(p) && !actual.hasOwnProperty(p)) | 162 if ($Object.hasOwnProperty(expected, p) && |
| 163 !$Object.hasOwnProperty(actual, p)) { |
159 return false; | 164 return false; |
| 165 } |
160 } | 166 } |
161 | 167 |
162 for (var p in expected) { | 168 for (var p in expected) { |
163 var eq = true; | 169 var eq = true; |
164 switch (typeof(expected[p])) { | 170 switch (typeof(expected[p])) { |
165 case 'object': | 171 case 'object': |
166 eq = chromeTest.checkDeepEq(expected[p], actual[p]); | 172 eq = chromeTest.checkDeepEq(expected[p], actual[p]); |
167 break; | 173 break; |
168 case 'function': | 174 case 'function': |
169 eq = (typeof(actual[p]) != 'undefined' && | 175 eq = (typeof(actual[p]) != 'undefined' && |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 apiFunctions.setHandleRequest('assertLastError', function(expectedError) { | 224 apiFunctions.setHandleRequest('assertLastError', function(expectedError) { |
219 chromeTest.assertEq(typeof(expectedError), 'string'); | 225 chromeTest.assertEq(typeof(expectedError), 'string'); |
220 chromeTest.assertTrue(chrome.runtime.lastError != undefined, | 226 chromeTest.assertTrue(chrome.runtime.lastError != undefined, |
221 "No lastError, but expected " + expectedError); | 227 "No lastError, but expected " + expectedError); |
222 chromeTest.assertEq(expectedError, chrome.runtime.lastError.message); | 228 chromeTest.assertEq(expectedError, chrome.runtime.lastError.message); |
223 }); | 229 }); |
224 | 230 |
225 function safeFunctionApply(func, args) { | 231 function safeFunctionApply(func, args) { |
226 try { | 232 try { |
227 if (func) | 233 if (func) |
228 func.apply(null, args); | 234 $Function.apply(func, null, args); |
229 } catch (e) { | 235 } catch (e) { |
230 var msg = "uncaught exception " + e; | 236 var msg = "uncaught exception " + e; |
231 chromeTest.fail(msg); | 237 chromeTest.fail(msg); |
232 } | 238 } |
233 }; | 239 }; |
234 | 240 |
235 // Wrapper for generating test functions, that takes care of calling | 241 // Wrapper for generating test functions, that takes care of calling |
236 // assertNoLastError() and (optionally) succeed() for you. | 242 // assertNoLastError() and (optionally) succeed() for you. |
237 apiFunctions.setHandleRequest('callback', function(func, expectedError) { | 243 apiFunctions.setHandleRequest('callback', function(func, expectedError) { |
238 if (func) { | 244 if (func) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 apiFunctions.setHandleRequest('getApiDefinitions', function() { | 304 apiFunctions.setHandleRequest('getApiDefinitions', function() { |
299 return GetExtensionAPIDefinitionsForTest(); | 305 return GetExtensionAPIDefinitionsForTest(); |
300 }); | 306 }); |
301 | 307 |
302 apiFunctions.setHandleRequest('getApiFeatures', function() { | 308 apiFunctions.setHandleRequest('getApiFeatures', function() { |
303 return GetAPIFeatures(); | 309 return GetAPIFeatures(); |
304 }); | 310 }); |
305 }); | 311 }); |
306 | 312 |
307 exports.binding = binding.generate(); | 313 exports.binding = binding.generate(); |
OLD | NEW |