Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(876)

Unified Diff: chrome/renderer/resources/extensions/apitest.js

Issue 11571014: Lazy load chrome.* APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apitest.js Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/apitest.js
diff --git a/chrome/renderer/resources/extensions/apitest.js b/chrome/renderer/resources/extensions/apitest.js
index 16bc078aa1a991533736a0929b3544b36a97c603..e2c1dcc4b72b990858ba2ce047215ac794e8b3ed 100644
--- a/chrome/renderer/resources/extensions/apitest.js
+++ b/chrome/renderer/resources/extensions/apitest.js
@@ -5,9 +5,17 @@
// extension_apitest.js
// mini-framework for ExtensionApiTest browser tests
- chrome.test = chrome.test || {};
+var binding = require('binding').Binding.create('test');
- chrome.test.tests = chrome.test.tests || [];
+var chrome = requireNative('chrome').GetChrome();
+var GetExtensionAPIDefinition =
+ requireNative('apiDefinitions').GetExtensionAPIDefinition;
+
+binding.registerCustomHook(function(api) {
+ chrome_test = api.compiledApi;
not at google - send to devlin 2013/02/13 01:45:49 should be chromeTest, but I'd just call it test.
cduvall 2013/02/15 00:40:28 Called it chromeTest because test conflicted in so
+ apiFunctions = api.apiFunctions;
+
+ chrome_test.tests = chrome_test.tests || [];
var currentTest = null;
var lastTest = null;
@@ -24,14 +32,14 @@
function testDone() {
// Use setTimeout here to allow previous test contexts to be
// eligible for garbage collection.
- setTimeout(chrome.test.runNextTest, 0);
+ setTimeout(chrome_test.runNextTest, 0);
}
function allTestsDone() {
if (testsFailed == 0) {
- chrome.test.notifyPass();
+ chrome_test.notifyPass();
} else {
- chrome.test.notifyFail('Failed ' + testsFailed + ' of ' +
+ chrome_test.notifyFail('Failed ' + testsFailed + ' of ' +
testCount + ' tests');
}
@@ -42,7 +50,7 @@
var pendingCallbacks = 0;
- chrome.test.callbackAdded = function() {
+ apiFunctions.setHandleRequest('callbackAdded', function() {
pendingCallbacks++;
var called = false;
@@ -52,18 +60,18 @@
pendingCallbacks--;
if (pendingCallbacks == 0) {
- chrome.test.succeed();
+ chrome_test.succeed();
}
};
- };
+ });
- chrome.test.runNextTest = function() {
+ apiFunctions.setHandleRequest('runNextTest', function() {
// There may have been callbacks which were interrupted by failure
// exceptions.
pendingCallbacks = 0;
lastTest = currentTest;
- currentTest = chrome.test.tests.shift();
+ currentTest = chrome_test.tests.shift();
if (!currentTest) {
allTestsDone();
@@ -71,19 +79,19 @@
}
try {
- chrome.test.log("( RUN ) " + testName(currentTest));
+ chrome_test.log("( RUN ) " + testName(currentTest));
currentTest.call();
} catch (e) {
if (e !== failureException)
- chrome.test.fail('uncaught exception: ' + e);
+ chrome_test.fail('uncaught exception: ' + e);
}
- };
+ });
- chrome.test.fail = function(message) {
- chrome.test.log("( FAILED ) " + testName(currentTest));
+ apiFunctions.setHandleRequest('fail', function(message) {
+ chrome_test.log("( FAILED ) " + testName(currentTest));
var stack = {};
- Error.captureStackTrace(stack, chrome.test.fail);
+ Error.captureStackTrace(stack, chrome_test.fail);
if (!message)
message = "FAIL (no message)";
@@ -95,23 +103,24 @@
// Interrupt the rest of the test.
throw failureException;
- };
+ });
- chrome.test.succeed = function() {
+ apiFunctions.setHandleRequest('succeed', function() {
console.log("[SUCCESS] " + testName(currentTest));
- chrome.test.log("( SUCCESS )");
+ chrome_test.log("( SUCCESS )");
testDone();
- };
+ });
- chrome.test.assertTrue = function(test, message) {
- chrome.test.assertBool(test, true, message);
- };
+ apiFunctions.setHandleRequest('assertTrue', function(test, message) {
+ chrome_test.assertBool(test, true, message);
+ });
- chrome.test.assertFalse = function(test, message) {
- chrome.test.assertBool(test, false, message);
- };
+ apiFunctions.setHandleRequest('assertFalse', function(test, message) {
+ chrome_test.assertBool(test, false, message);
+ });
- chrome.test.assertBool = function(test, expected, message) {
+ apiFunctions.setHandleRequest('assertBool',
+ function(test, expected, message) {
if (test !== expected) {
if (typeof(test) == "string") {
if (message)
@@ -119,11 +128,11 @@
else
message = test;
}
- chrome.test.fail(message);
+ chrome_test.fail(message);
}
- };
+ });
- chrome.test.checkDeepEq = function (expected, actual) {
+ apiFunctions.setHandleRequest('checkDeepEq', function(expected, actual) {
if ((expected === null) != (actual === null))
return false;
@@ -146,7 +155,7 @@
var eq = true;
switch (typeof(expected[p])) {
case 'object':
- eq = chrome.test.checkDeepEq(expected[p], actual[p]);
+ eq = chrome_test.checkDeepEq(expected[p], actual[p]);
break;
case 'function':
eq = (typeof(actual[p]) != 'undefined' &&
@@ -161,44 +170,45 @@
return false;
}
return true;
- };
+ });
- chrome.test.assertEq = function(expected, actual, message) {
+ apiFunctions.setHandleRequest('assertEq',
+ function(expected, actual, message) {
var error_msg = "API Test Error in " + testName(currentTest);
if (message)
error_msg += ": " + message;
if (typeof(expected) == 'object') {
- if (!chrome.test.checkDeepEq(expected, actual)) {
- chrome.test.fail(error_msg +
+ if (!chrome_test.checkDeepEq(expected, actual)) {
+ chrome_test.fail(error_msg +
"\nActual: " + JSON.stringify(actual) +
"\nExpected: " + JSON.stringify(expected));
}
return;
}
if (expected != actual) {
- chrome.test.fail(error_msg +
+ chrome_test.fail(error_msg +
"\nActual: " + actual + "\nExpected: " + expected);
}
if (typeof(expected) != typeof(actual)) {
- chrome.test.fail(error_msg +
+ chrome_test.fail(error_msg +
" (type mismatch)\nActual Type: " + typeof(actual) +
"\nExpected Type:" + typeof(expected));
}
- };
+ });
- chrome.test.assertNoLastError = function() {
+ apiFunctions.setHandleRequest('assertNoLastError', function() {
if (chrome.runtime.lastError != undefined) {
- chrome.test.fail("lastError.message == " +
+ chrome_test.fail("lastError.message == " +
chrome.runtime.lastError.message);
}
- };
+ });
- chrome.test.assertLastError = function(expectedError) {
- chrome.test.assertEq(typeof(expectedError), 'string');
- chrome.test.assertTrue(chrome.runtime.lastError != undefined,
+ apiFunctions.setHandleRequest('assertLastError', function(expectedError) {
+ chrome_test.assertEq(typeof(expectedError), 'string');
+ chrome_test.assertTrue(chrome.runtime.lastError != undefined,
"No lastError, but expected " + expectedError);
- chrome.test.assertEq(expectedError, chrome.runtime.lastError.message);
- }
+ chrome_test.assertEq(expectedError, chrome.runtime.lastError.message);
+ });
function safeFunctionApply(func, arguments) {
try {
@@ -206,23 +216,23 @@
func.apply(null, arguments);
} catch (e) {
var msg = "uncaught exception " + e;
- chrome.test.fail(msg);
+ chrome_test.fail(msg);
}
};
// Wrapper for generating test functions, that takes care of calling
// assertNoLastError() and (optionally) succeed() for you.
- chrome.test.callback = function(func, expectedError) {
+ apiFunctions.setHandleRequest('callback', function(func, expectedError) {
if (func) {
- chrome.test.assertEq(typeof(func), 'function');
+ chrome_test.assertEq(typeof(func), 'function');
}
- var callbackCompleted = chrome.test.callbackAdded();
+ var callbackCompleted = chrome_test.callbackAdded();
return function() {
if (expectedError == null) {
- chrome.test.assertNoLastError();
+ chrome_test.assertNoLastError();
} else {
- chrome.test.assertLastError(expectedError);
+ chrome_test.assertLastError(expectedError);
}
if (func) {
@@ -231,20 +241,20 @@
callbackCompleted();
};
- };
+ });
- chrome.test.listenOnce = function(event, func) {
- var callbackCompleted = chrome.test.callbackAdded();
+ apiFunctions.setHandleRequest('listenOnce', function(event, func) {
+ var callbackCompleted = chrome_test.callbackAdded();
var listener = function() {
event.removeListener(listener);
safeFunctionApply(func, arguments);
callbackCompleted();
};
event.addListener(listener);
- };
+ });
- chrome.test.listenForever = function(event, func) {
- var callbackCompleted = chrome.test.callbackAdded();
+ apiFunctions.setHandleRequest('listenForever', function(event, func) {
+ var callbackCompleted = chrome_test.callbackAdded();
var listener = function() {
safeFunctionApply(func, arguments);
@@ -257,18 +267,23 @@
event.addListener(listener);
return done;
- };
+ });
- chrome.test.callbackPass = function(func) {
- return chrome.test.callback(func);
- };
+ apiFunctions.setHandleRequest('callbackPass', function(func) {
+ return chrome_test.callback(func);
+ });
- chrome.test.callbackFail = function(expectedError, func) {
- return chrome.test.callback(func, expectedError);
- };
+ apiFunctions.setHandleRequest('callbackFail', function(expectedError, func) {
+ return chrome_test.callback(func, expectedError);
+ });
- chrome.test.runTests = function(tests) {
- chrome.test.tests = tests;
- testCount = chrome.test.tests.length;
- chrome.test.runNextTest();
- };
+ apiFunctions.setHandleRequest('runTests', function(tests) {
+ chrome_test.tests = tests;
+ testCount = chrome_test.tests.length;
+ chrome_test.runNextTest();
+ });
+
+ apiFunctions.setHandleRequest('getApiDefinitions', GetExtensionAPIDefinition);
+});
+
+exports.binding = binding.generate();

Powered by Google App Engine
This is Rietveld 408576698