| 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(); |
| 11 var GetExtensionAPIDefinitions = | 11 var GetExtensionAPIDefinitions = |
| 12 requireNative('apiDefinitions').GetExtensionAPIDefinitions; | 12 requireNative('apiDefinitions').GetExtensionAPIDefinitions; |
| 13 var GetAvailability = requireNative('v8_context').GetAvailability; | 13 var GetAvailability = requireNative('v8_context').GetAvailability; |
| 14 var json = require('json'); |
| 14 | 15 |
| 15 binding.registerCustomHook(function(api) { | 16 binding.registerCustomHook(function(api) { |
| 16 var chromeTest = api.compiledApi; | 17 var chromeTest = api.compiledApi; |
| 17 var apiFunctions = api.apiFunctions; | 18 var apiFunctions = api.apiFunctions; |
| 18 | 19 |
| 19 chromeTest.tests = chromeTest.tests || []; | 20 chromeTest.tests = chromeTest.tests || []; |
| 20 | 21 |
| 21 var currentTest = null; | 22 var currentTest = null; |
| 22 var lastTest = null; | 23 var lastTest = null; |
| 23 var testsFailed = 0; | 24 var testsFailed = 0; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 }); | 175 }); |
| 175 | 176 |
| 176 apiFunctions.setHandleRequest('assertEq', | 177 apiFunctions.setHandleRequest('assertEq', |
| 177 function(expected, actual, message) { | 178 function(expected, actual, message) { |
| 178 var error_msg = "API Test Error in " + testName(currentTest); | 179 var error_msg = "API Test Error in " + testName(currentTest); |
| 179 if (message) | 180 if (message) |
| 180 error_msg += ": " + message; | 181 error_msg += ": " + message; |
| 181 if (typeof(expected) == 'object') { | 182 if (typeof(expected) == 'object') { |
| 182 if (!chromeTest.checkDeepEq(expected, actual)) { | 183 if (!chromeTest.checkDeepEq(expected, actual)) { |
| 183 chromeTest.fail(error_msg + | 184 chromeTest.fail(error_msg + |
| 184 "\nActual: " + JSON.stringify(actual) + | 185 "\nActual: " + json.stringify(actual) + |
| 185 "\nExpected: " + JSON.stringify(expected)); | 186 "\nExpected: " + json.stringify(expected)); |
| 186 } | 187 } |
| 187 return; | 188 return; |
| 188 } | 189 } |
| 189 if (expected != actual) { | 190 if (expected != actual) { |
| 190 chromeTest.fail(error_msg + | 191 chromeTest.fail(error_msg + |
| 191 "\nActual: " + actual + "\nExpected: " + expected); | 192 "\nActual: " + actual + "\nExpected: " + expected); |
| 192 } | 193 } |
| 193 if (typeof(expected) != typeof(actual)) { | 194 if (typeof(expected) != typeof(actual)) { |
| 194 chromeTest.fail(error_msg + | 195 chromeTest.fail(error_msg + |
| 195 " (type mismatch)\nActual Type: " + typeof(actual) + | 196 " (type mismatch)\nActual Type: " + typeof(actual) + |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 }); | 286 }); |
| 286 | 287 |
| 287 apiFunctions.setHandleRequest('getApiDefinitions', function() { | 288 apiFunctions.setHandleRequest('getApiDefinitions', function() { |
| 288 return GetExtensionAPIDefinitions().filter(function(api) { | 289 return GetExtensionAPIDefinitions().filter(function(api) { |
| 289 return GetAvailability(api.namespace).is_available; | 290 return GetAvailability(api.namespace).is_available; |
| 290 }); | 291 }); |
| 291 }); | 292 }); |
| 292 }); | 293 }); |
| 293 | 294 |
| 294 exports.binding = binding.generate(); | 295 exports.binding = binding.generate(); |
| OLD | NEW |