зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1324622 - merge unit test into mortar. r=ehung
This commit is contained in:
Родитель
97192dfa88
Коммит
43e8390bdd
|
@ -4,6 +4,8 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']
|
||||
|
||||
SOURCES += [
|
||||
'host/rpc.cc',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
"use strict";
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
// For the following 5 lines of codes, we redirect the
|
||||
// path of the "ppapi.js" in addon to the exact file path.
|
||||
Components.utils.import("resource://gre/modules/NetUtil.jsm");
|
||||
let resHandler = Services.io.getProtocolHandler("resource")
|
||||
.QueryInterface(Components.interfaces.nsISubstitutingProtocolHandler);
|
||||
let dataURI = NetUtil.newURI(do_get_file("."));
|
||||
resHandler.setSubstitution("ppapi.js", dataURI);
|
||||
|
||||
// Load the script
|
||||
load("ppapi-runtime.jsm");
|
||||
|
||||
let instanceId = 1;
|
||||
let url = "http://example.com";
|
||||
let info = {
|
||||
documentURL: "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai",
|
||||
url,
|
||||
setupJSInstanceObject: false,
|
||||
isFullFrame: false, //pluginElement.ownerDocument.mozSyntheticDocument,
|
||||
arguments: {
|
||||
keys: ["src", "full-frame", "top-level-url"],
|
||||
values: [url, "", url],
|
||||
},
|
||||
};
|
||||
|
||||
// Head.js is a shared file for all the test_ppb***.js.
|
||||
// Right now, window, process and MessageManager are base classes here.
|
||||
// Fill in the classes when you need the functions of them
|
||||
// and add more mocked classses if you need them in
|
||||
// ppapi-runtime.jsm for your tests.
|
||||
class Mock_Window {}
|
||||
class Mock_Process {}
|
||||
class Mock_MessageManager {
|
||||
addMessageListener () {
|
||||
}
|
||||
}
|
||||
|
||||
// Here the new PPAPIRuntime, Call_PpbFunc and new PPAPIInstance are the
|
||||
// core part to invoke codes in ppapi-runtime.jsm.
|
||||
let rt = new PPAPIRuntime(new Mock_Process());
|
||||
|
||||
function Call_PpbFunc(obj) {
|
||||
if (!obj || !obj.__interface || !obj.__version || !obj.__method) {
|
||||
ok(false, 'invalid JSON');
|
||||
}
|
||||
let fn = obj.__interface + "_" + obj.__method;
|
||||
return rt.table[fn](obj);
|
||||
}
|
||||
|
||||
// PPAPIInstance constructor(id, rt, info, window, eventHandler, containerWindow, mm)
|
||||
let instance = new PPAPIInstance(instanceId, rt, info, new Mock_Window(), null /*docShell.chromeEventHandler*/, null, new Mock_MessageManager());
|
||||
|
||||
do_register_cleanup(function () {
|
||||
resHandler.setSubstitution("ppapi.js", null);
|
||||
})
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
"use strict";
|
||||
|
||||
const PPB_TESTCASES = [
|
||||
{"__interface":"PPB_KeyboardInputEvent","__version":"1.2","__method":"IsKeyboardInputEvent","resource":0},
|
||||
{"__interface":"PPB_KeyboardInputEvent","__version":"1.2","__method":"GetKeyCode","key_event":0},
|
||||
{"__interface":"PPB_KeyboardInputEvent","__version":"1.2","__method":"GetCharacterText","character_event":0}
|
||||
];
|
||||
|
||||
|
||||
class Mock_DomEvent {
|
||||
constructor(eventType) {
|
||||
this.type = eventType;
|
||||
this.timeStamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
class Mock_KeyboardInputEvent extends Mock_DomEvent {
|
||||
constructor(eventType, keyCode, charCode) {
|
||||
super(eventType);
|
||||
this.keyCode = keyCode;
|
||||
this.charCode = charCode;
|
||||
}
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
// We mock a "keydown" event to test "PPB_KeyboardInputEvent".
|
||||
let event = new Mock_KeyboardInputEvent("keydown", 65, 0);
|
||||
// To test PPB_KeyboardInputEvent we need to invoke event resource constructor
|
||||
// in ppapi-runtime.jsm to get a resource id.
|
||||
let eventType = EventTypes.get(event.type);
|
||||
let resource = new eventType.resourceCtor(instance, event);
|
||||
let PP_ResourceID = resource.toJSON();
|
||||
|
||||
PPB_TESTCASES[0].resource = PP_ResourceID;
|
||||
PPB_TESTCASES[1].key_event = PP_ResourceID;
|
||||
Assert.equal(Call_PpbFunc(PPB_TESTCASES[0]), PP_Bool.PP_TRUE);
|
||||
Assert.equal(Call_PpbFunc(PPB_TESTCASES[1]), 65); // 65 is the keyCode when you press 'A'.
|
||||
|
||||
// We mock a "keypress" event to test "PPB_KeyboardInputEvent".
|
||||
event = new Mock_KeyboardInputEvent("keypress", 0, 65);
|
||||
eventType = EventTypes.get(event.type);
|
||||
resource = new eventType.resourceCtor(instance, event);
|
||||
PP_ResourceID = resource.toJSON();
|
||||
|
||||
PPB_TESTCASES[0].resource = PP_ResourceID;
|
||||
PPB_TESTCASES[2].character_event = PP_ResourceID;
|
||||
Assert.equal(Call_PpbFunc(PPB_TESTCASES[0]), PP_Bool.PP_TRUE);
|
||||
Assert.equal(Call_PpbFunc(PPB_TESTCASES[2]).type, PP_VarType.PP_VARTYPE_STRING);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
[DEFAULT]
|
||||
head = head.js
|
||||
tail =
|
||||
support-files =
|
||||
../../host/common/opengles2-utils.jsm
|
||||
../../host/common/ppapi-runtime.jsm
|
||||
|
||||
[test_ppbkeyboard.js]
|
Загрузка…
Ссылка в новой задаче