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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 chromeTest.assertEq(expectedError, chrome.runtime.lastError.message); | 228 chromeTest.assertEq(expectedError, chrome.runtime.lastError.message); |
229 }); | 229 }); |
230 | 230 |
231 apiFunctions.setHandleRequest('assertThrows', | 231 apiFunctions.setHandleRequest('assertThrows', |
232 function(fn, self, args, message) { | 232 function(fn, self, args, message) { |
233 chromeTest.assertTrue(typeof fn == 'function'); | 233 chromeTest.assertTrue(typeof fn == 'function'); |
234 try { | 234 try { |
235 fn.apply(self, args); | 235 fn.apply(self, args); |
236 chromeTest.fail('Did not throw error: ' + fn); | 236 chromeTest.fail('Did not throw error: ' + fn); |
237 } catch (e) { | 237 } catch (e) { |
238 if (message !== undefined) | 238 if (e !== failureException && message !== undefined) { |
239 chromeTest.assertEq(message, e.message); | 239 if (typeof(message) == 'object' && |
240 message.constructor.name == 'RegExp') { | |
not at google - send to devlin
2013/08/29 15:20:25
any reason why you're not using "message instanceo
Jeffrey Yasskin
2013/08/29 21:46:43
Because I don't know JavaScript. Done.
| |
241 chromeTest.assertTrue(message.test(e.message), | |
242 e.message + ' should match ' + message) | |
243 } else { | |
244 chromeTest.assertEq(message, e.message); | |
245 } | |
246 } | |
240 } | 247 } |
241 }); | 248 }); |
242 | 249 |
243 function safeFunctionApply(func, args) { | 250 function safeFunctionApply(func, args) { |
244 try { | 251 try { |
245 if (func) | 252 if (func) |
246 $Function.apply(func, null, args); | 253 $Function.apply(func, null, args); |
247 } catch (e) { | 254 } catch (e) { |
248 var msg = "uncaught exception " + e; | 255 var msg = "uncaught exception " + e; |
249 chromeTest.fail(msg); | 256 chromeTest.fail(msg); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 apiFunctions.setHandleRequest('getApiDefinitions', function() { | 323 apiFunctions.setHandleRequest('getApiDefinitions', function() { |
317 return GetExtensionAPIDefinitionsForTest(); | 324 return GetExtensionAPIDefinitionsForTest(); |
318 }); | 325 }); |
319 | 326 |
320 apiFunctions.setHandleRequest('getApiFeatures', function() { | 327 apiFunctions.setHandleRequest('getApiFeatures', function() { |
321 return GetAPIFeatures(); | 328 return GetAPIFeatures(); |
322 }); | 329 }); |
323 }); | 330 }); |
324 | 331 |
325 exports.binding = binding.generate(); | 332 exports.binding = binding.generate(); |
OLD | NEW |