Commit 151e70d6 authored by kmarshall's avatar kmarshall Committed by Commit bot

Add mojoPrivate.requireAsync method to chrome IDL.

Add unit tests for requireAsync.

R=mfoltz@chromium.org,sammc@chromium.org
CC=wez@chromium.org,haibinlu@chromium.org
BUG=

Review URL: https://codereview.chromium.org/862793003

Cr-Commit-Position: refs/heads/master@{#313403}
parent b88fe3dc
......@@ -14,6 +14,10 @@ namespace mojoPrivate {
DOMString moduleName,
optional DOMString[] dependencies,
DefineCallback factory);
// Returns a promise that will resolve to an asynchronously
// loaded module.
[nocompile] static any requireAsync(DOMString name);
};
};
......@@ -45,4 +45,14 @@ TEST_F(MojoPrivateApiTest, DefineModuleDoesNotExist) {
"does not exist!"));
}
TEST_F(MojoPrivateApiTest, RequireAsync) {
ASSERT_NO_FATAL_FAILURE(
RunTest("mojo_private_unittest.js", "testRequireAsync"));
}
TEST_F(MojoPrivateApiTest, DefineAndRequire) {
ASSERT_NO_FATAL_FAILURE(
RunTest("mojo_private_unittest.js", "testDefineAndRequire"));
}
} // namespace extensions
......@@ -14,6 +14,10 @@ binding.registerCustomHook(function(bindingsAPI) {
apiFunctions.setHandleRequest('define', function(name, deps, factory) {
define(name, deps || [], factory);
});
apiFunctions.setHandleRequest('requireAsync', function(moduleName) {
return requireAsync(moduleName);
});
});
exports.binding = binding.generate();
......@@ -31,4 +31,24 @@ unittestBindings.exportTests([
mojoPrivate.define('testModule', ['does not exist!'], test.fail);
test.succeed();
},
function testRequireAsync() {
mojoPrivate.requireAsync('mojo/public/js/codec').then(
test.callbackPass(function(codec) {
test.assertEq('function', typeof codec.Message);
}));
},
function testDefineAndRequire() {
mojoPrivate.define('testModule', ['dependency'],
test.callbackPass(function(module) {
test.assertEq(12345, module.result);
}));
mojoPrivate.define('dependency', test.callbackPass(function() {
return {result: 12345};
}));
mojoPrivate.requireAsync('dependency').then(
test.callbackPass(),
test.fail);
}
], test.runTests, exports);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment