зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1770237: Part 6 - Update XPConnect xpcshell tests to avoid unnecessary legacy component registration. r=mccr8
These tests just test XPConnect wrapping, and don't actually have anything to do with component registration. There are simpler ways to get wrapping that are just as effective. Differential Revision: https://phabricator.services.mozilla.com/D148186
This commit is contained in:
Родитель
de25cced8a
Коммит
6758092966
|
@ -1,29 +0,0 @@
|
|||
component {8ff41d9c-66e9-4453-924a-7d8de0a5e966} xpctest_attributes.js
|
||||
contract @mozilla.org/js/xpc/test/js/ObjectReadWrite;1 {8ff41d9c-66e9-4453-924a-7d8de0a5e966}
|
||||
|
||||
component {916c4247-253d-4ed0-a425-adfedf53ecc8} xpctest_attributes.js
|
||||
contract @mozilla.org/js/xpc/test/js/ObjectReadOnly;1 {916c4247-253d-4ed0-a425-adfedf53ecc8}
|
||||
|
||||
component {2df46559-da21-49bf-b863-0d7b7bbcbc73} xpctest_bug809674.js
|
||||
contract @mozilla.org/js/xpc/test/js/Bug809674;1 {2df46559-da21-49bf-b863-0d7b7bbcbc73}
|
||||
|
||||
component {e3b86f4e-49c0-487c-a2b0-3a986720a044} xpctest_params.js
|
||||
contract @mozilla.org/js/xpc/test/js/Params;1 {e3b86f4e-49c0-487c-a2b0-3a986720a044}
|
||||
|
||||
component {3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8} xpctest_interfaces.js
|
||||
contract @mozilla.org/js/xpc/test/js/InterfaceA;1 {3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8}
|
||||
|
||||
component {ff528c3a-2410-46de-acaa-449aa6403a33} xpctest_interfaces.js
|
||||
contract @mozilla.org/js/xpc/test/js/InterfaceB;1 {ff528c3a-2410-46de-acaa-449aa6403a33}
|
||||
|
||||
component {90ec5c9e-f6da-406b-9a38-14d00f59db76} xpctest_interfaces.js
|
||||
contract @mozilla.org/js/xpc/test/js/TestInterfaceAll;1 {90ec5c9e-f6da-406b-9a38-14d00f59db76}
|
||||
|
||||
component {38dd78aa-467f-4fad-8dcf-4383a743e235} xpctest_returncode_child.js
|
||||
contract @mozilla.org/js/xpc/test/js/ReturnCodeChild;1 {38dd78aa-467f-4fad-8dcf-4383a743e235}
|
||||
|
||||
component {e86573c4-a384-441a-8c92-7b99e8575b28} xpctest_utils.js
|
||||
contract @mozilla.org/js/xpc/test/js/TestUtils;1 {e86573c4-a384-441a-8c92-7b99e8575b28}
|
||||
|
||||
component {43929c74-dc70-11e8-b6f9-8fce71a2796a} xpctest_cenums.js
|
||||
contract @mozilla.org/js/xpc/test/js/CEnums;1 {43929c74-dc70-11e8-b6f9-8fce71a2796a}
|
|
@ -1,48 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestObjectReadWrite() {}
|
||||
TestObjectReadWrite.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestObjectReadWrite"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/ObjectReadWrite;1",
|
||||
classID: Components.ID("{8ff41d9c-66e9-4453-924a-7d8de0a5e966}"),
|
||||
|
||||
/* nsIXPCTestObjectReadWrite */
|
||||
stringProperty: "XPConnect Read-Writable String",
|
||||
booleanProperty: true,
|
||||
shortProperty: 32767,
|
||||
longProperty: 2147483647,
|
||||
floatProperty: 5.5,
|
||||
charProperty: "X",
|
||||
// timeProperty is PRTime and signed type.
|
||||
// So it has to allow negative value.
|
||||
timeProperty: -1
|
||||
};
|
||||
|
||||
|
||||
function TestObjectReadOnly() {}
|
||||
TestObjectReadOnly.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestObjectReadOnly"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/ObjectReadOnly;1",
|
||||
classID: Components.ID("{916c4247-253d-4ed0-a425-adfedf53ecc8}"),
|
||||
|
||||
/* nsIXPCTestObjectReadOnly */
|
||||
strReadOnly: "XPConnect Read-Only String",
|
||||
boolReadOnly: true,
|
||||
shortReadOnly: 32767,
|
||||
longReadOnly: 2147483647,
|
||||
floatReadOnly: 5.5,
|
||||
charReadOnly: "X",
|
||||
// timeProperty is PRTime and signed type.
|
||||
// So it has to allow negative value.
|
||||
timeReadOnly: -1
|
||||
};
|
||||
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestObjectReadWrite, TestObjectReadOnly]);
|
|
@ -1,42 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestBug809674() {}
|
||||
TestBug809674.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestBug809674"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/Bug809674;1",
|
||||
classID: Components.ID("{2df46559-da21-49bf-b863-0d7b7bbcbc73}"),
|
||||
|
||||
/* nsIXPCTestBug809674 */
|
||||
methodWithOptionalArgc() {},
|
||||
|
||||
addArgs(x, y) {
|
||||
return x + y;
|
||||
},
|
||||
addSubMulArgs(x, y, subOut, mulOut) {
|
||||
subOut.value = x - y;
|
||||
mulOut.value = x * y;
|
||||
return x + y;
|
||||
},
|
||||
addVals(x, y) {
|
||||
return x + y;
|
||||
},
|
||||
addMany(x1, x2, x3, x4, x5, x6, x7, x8) {
|
||||
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8;
|
||||
},
|
||||
|
||||
methodNoArgs() {
|
||||
return 7;
|
||||
},
|
||||
methodNoArgsNoRetVal() {},
|
||||
|
||||
valProperty: {value: 42},
|
||||
uintProperty: 123,
|
||||
};
|
||||
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestBug809674]);
|
|
@ -1,27 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestCEnums() {
|
||||
}
|
||||
|
||||
TestCEnums.prototype = {
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestCEnums"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/CEnums;1",
|
||||
classID: Components.ID("{43929c74-dc70-11e8-b6f9-8fce71a2796a}"),
|
||||
|
||||
testCEnumInput: function(input) {
|
||||
if (input != Ci.nsIXPCTestCEnums.shouldBe12Explicit)
|
||||
{
|
||||
throw new Error("Enum values do not match expected value");
|
||||
}
|
||||
},
|
||||
|
||||
testCEnumOutput: function() {
|
||||
return Ci.nsIXPCTestCEnums.shouldBe8Explicit;
|
||||
},
|
||||
};
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestCEnums]);
|
|
@ -1,48 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestInterfaceA() {}
|
||||
TestInterfaceA.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceA;1",
|
||||
classID: Components.ID("{3c8fd2f5-970c-42c6-b5dd-cda1c16dcfd8}"),
|
||||
|
||||
/* nsIXPCTestInterfaceA */
|
||||
name: "TestInterfaceADefaultName"
|
||||
};
|
||||
|
||||
function TestInterfaceB() {}
|
||||
TestInterfaceB.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceB"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceB;1",
|
||||
classID: Components.ID("{ff528c3a-2410-46de-acaa-449aa6403a33}"),
|
||||
|
||||
/* nsIXPCTestInterfaceA */
|
||||
name: "TestInterfaceADefaultName"
|
||||
};
|
||||
|
||||
function TestInterfaceAll() {}
|
||||
TestInterfaceAll.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA",
|
||||
"nsIXPCTestInterfaceB",
|
||||
"nsIXPCTestInterfaceC"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/TestInterfaceAll;1",
|
||||
classID: Components.ID("{90ec5c9e-f6da-406b-9a38-14d00f59db76}"),
|
||||
|
||||
/* nsIXPCTestInterfaceA / nsIXPCTestInterfaceB */
|
||||
name: "TestInterfaceAllDefaultName",
|
||||
|
||||
/* nsIXPCTestInterfaceC */
|
||||
someInteger: 42
|
||||
};
|
||||
|
||||
var NSGetFactory = ComponentUtils.generateNSGetFactory([TestInterfaceA, TestInterfaceB, TestInterfaceAll]);
|
||||
|
|
@ -1,105 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestParams() {
|
||||
}
|
||||
|
||||
/* For once I'm happy that JS is weakly typed. */
|
||||
function f(a, b) {
|
||||
var rv = b.value;
|
||||
b.value = a;
|
||||
return rv;
|
||||
};
|
||||
|
||||
/* Implementation for size_is and iid_is methods. */
|
||||
function f_is(aIs, a, bIs, b, rvIs) {
|
||||
|
||||
// Set up the return value and its 'is' parameter.
|
||||
var rv = b.value;
|
||||
rvIs.value = bIs.value;
|
||||
|
||||
// Set up b and its 'is' parameter.
|
||||
b.value = a;
|
||||
bIs.value = aIs;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
function f_size_and_iid(aSize, aIID, a, bSize, bIID, b, rvSize, rvIID) {
|
||||
|
||||
// Copy the iids.
|
||||
rvIID.value = bIID.value;
|
||||
bIID.value = aIID;
|
||||
|
||||
// Now that we've reduced the problem to one dependent variable, use f_is.
|
||||
return f_is(aSize, a, bSize, b, rvSize);
|
||||
}
|
||||
|
||||
TestParams.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestParams"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/Params;1",
|
||||
classID: Components.ID("{e3b86f4e-49c0-487c-a2b0-3a986720a044}"),
|
||||
|
||||
/* nsIXPCTestParams */
|
||||
testBoolean: f,
|
||||
testOctet: f,
|
||||
testShort: f,
|
||||
testLong: f,
|
||||
testLongLong: f,
|
||||
testUnsignedShort: f,
|
||||
testUnsignedLong: f,
|
||||
testUnsignedLongLong: f,
|
||||
testFloat: f,
|
||||
testDouble: f,
|
||||
testChar: f,
|
||||
testString: f,
|
||||
testWchar: f,
|
||||
testWstring: f,
|
||||
testAString: f,
|
||||
testAUTF8String: f,
|
||||
testACString: f,
|
||||
testJsval: f,
|
||||
testShortSequence: f,
|
||||
testDoubleSequence: f,
|
||||
testAStringSequence: f,
|
||||
testACStringSequence: f,
|
||||
testInterfaceSequence: f,
|
||||
testJsvalSequence: f,
|
||||
testInterfaceIsSequence: f_is,
|
||||
testOptionalSequence: function (arr) { return arr; },
|
||||
testShortArray: f_is,
|
||||
testDoubleArray: f_is,
|
||||
testStringArray: f_is,
|
||||
testByteArrayOptionalLength(arr) { return arr.length; },
|
||||
testWstringArray: f_is,
|
||||
testInterfaceArray: f_is,
|
||||
testJsvalArray: f_is,
|
||||
testSizedString: f_is,
|
||||
testSizedWstring: f_is,
|
||||
testInterfaceIs: f_is,
|
||||
testInterfaceIsArray: f_size_and_iid,
|
||||
testOutAString: function(o) { o.value = "out"; },
|
||||
testStringArrayOptionalSize: function(arr, size) {
|
||||
if (arr.length != size) { throw "bad size passed to test method"; }
|
||||
var rv = "";
|
||||
arr.forEach((x) => rv += x);
|
||||
return rv;
|
||||
},
|
||||
testOmittedOptionalOut(o) {
|
||||
if (typeof o != "object" || o.value !== undefined) {
|
||||
throw new Components.Exception(
|
||||
"unexpected value",
|
||||
Cr.NS_ERROR_ILLEGAL_VALUE
|
||||
);
|
||||
}
|
||||
o.value = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI("http://example.com/");
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestParams]);
|
|
@ -1,17 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestUtils() {}
|
||||
TestUtils.prototype = {
|
||||
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestUtils"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/TestUtils;1",
|
||||
classID: Components.ID("{e86573c4-a384-441a-8c92-7b99e8575b28}"),
|
||||
doubleWrapFunction(fun) { return fun }
|
||||
};
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestUtils]);
|
|
@ -380,20 +380,18 @@ nsXPCTestParams::TestOptionalSequence(const nsTArray<uint8_t>& aInArr,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXPCTestParams::TestOmittedOptionalOut(nsIURI** aOut) {
|
||||
nsXPCTestParams::TestOmittedOptionalOut(nsIXPCTestParams* aJSObj,
|
||||
nsIURI** aOut) {
|
||||
MOZ_ASSERT(!(*aOut), "Unexpected value received");
|
||||
// Call the js component, to check XPConnect won't crash when passing nullptr
|
||||
// as the optional out parameter, and that the out object is built regardless.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIXPCTestParams> jsComponent =
|
||||
do_CreateInstance("@mozilla.org/js/xpc/test/js/Params;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Invoke it directly passing nullptr.
|
||||
rv = jsComponent->TestOmittedOptionalOut(nullptr);
|
||||
rv = aJSObj->TestOmittedOptionalOut(nullptr, nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
// Also invoke it with a ref pointer.
|
||||
nsCOMPtr<nsIURI> someURI;
|
||||
rv = jsComponent->TestOmittedOptionalOut(getter_AddRefs(someURI));
|
||||
rv = aJSObj->TestOmittedOptionalOut(nullptr, getter_AddRefs(someURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsAutoCString spec;
|
||||
rv = someURI->GetSpec(spec);
|
||||
|
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
#include "xpctest_private.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsImportModule.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsXPCTestReturnCodeParent, nsIXPCTestReturnCodeParent)
|
||||
|
||||
NS_IMETHODIMP nsXPCTestReturnCodeParent::CallChild(int32_t childBehavior,
|
||||
nsresult* _retval) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIXPCTestReturnCodeChild> child(
|
||||
do_CreateInstance("@mozilla.org/js/xpc/test/js/ReturnCodeChild;1", &rv));
|
||||
nsCOMPtr<nsIXPCTestReturnCodeChild> child(do_ImportModule(
|
||||
"resource://test/ReturnCodeChild.jsm", "ReturnCodeChild", &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = child->DoIt(childBehavior);
|
||||
*_retval = rv;
|
||||
|
|
|
@ -114,5 +114,5 @@ interface nsIXPCTestParams : nsISupports {
|
|||
ACString testStringArrayOptionalSize([array, size_is(aLength)] in string a, [optional] in unsigned long aLength);
|
||||
|
||||
// Test for omitted optional out parameter.
|
||||
void testOmittedOptionalOut([optional] out nsIURI aOut);
|
||||
void testOmittedOptionalOut(in nsIXPCTestParams aJSObj, [optional] out nsIURI aOut);
|
||||
};
|
||||
|
|
|
@ -19,14 +19,3 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
|
|||
XPCSHELL_TESTS_MANIFESTS += [
|
||||
"unit/xpcshell.ini",
|
||||
]
|
||||
|
||||
TEST_HARNESS_FILES.xpcshell.js.xpconnect.tests.components.js += [
|
||||
"components/js/xpctest.manifest",
|
||||
"components/js/xpctest_attributes.js",
|
||||
"components/js/xpctest_bug809674.js",
|
||||
"components/js/xpctest_cenums.js",
|
||||
"components/js/xpctest_interfaces.js",
|
||||
"components/js/xpctest_params.js",
|
||||
"components/js/xpctest_returncode_child.js",
|
||||
"components/js/xpctest_utils.js",
|
||||
]
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
const {ComponentUtils} = ChromeUtils.import("resource://gre/modules/ComponentUtils.jsm");
|
||||
|
||||
function TestReturnCodeChild() {}
|
||||
TestReturnCodeChild.prototype = {
|
||||
var EXPORTED_SYMBOLS = ["ReturnCodeChild"];
|
||||
|
||||
/* Boilerplate */
|
||||
function xpcWrap(obj, iface) {
|
||||
let ifacePointer = Cc[
|
||||
"@mozilla.org/supports-interface-pointer;1"
|
||||
].createInstance(Ci.nsISupportsInterfacePointer);
|
||||
|
||||
ifacePointer.data = obj;
|
||||
return ifacePointer.data.QueryInterface(iface);
|
||||
}
|
||||
|
||||
var ReturnCodeChild = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestReturnCodeChild"]),
|
||||
contractID: "@mozilla.org/js/xpc/test/js/ReturnCodeChild;1",
|
||||
classID: Components.ID("{38dd78aa-467f-4fad-8dcf-4383a743e235}"),
|
||||
|
||||
doIt(behaviour) {
|
||||
switch (behaviour) {
|
||||
|
@ -29,7 +34,7 @@ TestReturnCodeChild.prototype = {
|
|||
// a different value that we will see (but our caller should not)
|
||||
Components.returnCode = Cr.NS_ERROR_UNEXPECTED;
|
||||
// call the child asking it to do the .returnCode set.
|
||||
let sub = Cc[this.contractID].createInstance(Ci.nsIXPCTestReturnCodeChild);
|
||||
let sub = xpcWrap(ReturnCodeChild, Ci.nsIXPCTestReturnCodeChild);
|
||||
let childResult = Cr.NS_OK;
|
||||
try {
|
||||
sub.doIt(Ci.nsIXPCTestReturnCodeChild.CHILD_SHOULD_RETURN_RESULTCODE);
|
||||
|
@ -44,5 +49,3 @@ TestReturnCodeChild.prototype = {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.NSGetFactory = ComponentUtils.generateNSGetFactory([TestReturnCodeChild]);
|
|
@ -0,0 +1,15 @@
|
|||
"use strict";
|
||||
|
||||
// Wraps the given object in an XPConnect wrapper and, if an interface
|
||||
// is passed, queries the result to that interface.
|
||||
function xpcWrap(obj, iface) {
|
||||
let ifacePointer = Cc[
|
||||
"@mozilla.org/supports-interface-pointer;1"
|
||||
].createInstance(Ci.nsISupportsInterfacePointer);
|
||||
|
||||
ifacePointer.data = obj;
|
||||
if (iface) {
|
||||
return ifacePointer.data.QueryInterface(iface);
|
||||
}
|
||||
return ifacePointer.data;
|
||||
}
|
|
@ -2,23 +2,50 @@
|
|||
* 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/. */
|
||||
|
||||
function run_test() {
|
||||
var ObjectReadWrite = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestObjectReadWrite"]),
|
||||
|
||||
/* nsIXPCTestObjectReadWrite */
|
||||
stringProperty: "XPConnect Read-Writable String",
|
||||
booleanProperty: true,
|
||||
shortProperty: 32767,
|
||||
longProperty: 2147483647,
|
||||
floatProperty: 5.5,
|
||||
charProperty: "X",
|
||||
// timeProperty is PRTime and signed type.
|
||||
// So it has to allow negative value.
|
||||
timeProperty: -1,
|
||||
};
|
||||
|
||||
var ObjectReadOnly = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestObjectReadOnly"]),
|
||||
|
||||
/* nsIXPCTestObjectReadOnly */
|
||||
strReadOnly: "XPConnect Read-Only String",
|
||||
boolReadOnly: true,
|
||||
shortReadOnly: 32767,
|
||||
longReadOnly: 2147483647,
|
||||
floatReadOnly: 5.5,
|
||||
charReadOnly: "X",
|
||||
// timeProperty is PRTime and signed type.
|
||||
// So it has to allow negative value.
|
||||
timeReadOnly: -1,
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
// Load the component manifests.
|
||||
registerXPCTestComponents();
|
||||
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// Test for each component.
|
||||
test_component_readwrite("@mozilla.org/js/xpc/test/native/ObjectReadWrite;1");
|
||||
test_component_readwrite("@mozilla.org/js/xpc/test/js/ObjectReadWrite;1");
|
||||
test_component_readonly("@mozilla.org/js/xpc/test/native/ObjectReadOnly;1");
|
||||
test_component_readonly("@mozilla.org/js/xpc/test/js/ObjectReadOnly;1");
|
||||
test_component_readwrite(Cc["@mozilla.org/js/xpc/test/native/ObjectReadWrite;1"].createInstance());
|
||||
test_component_readwrite(xpcWrap(ObjectReadWrite));
|
||||
test_component_readonly(Cc["@mozilla.org/js/xpc/test/native/ObjectReadOnly;1"].createInstance());
|
||||
test_component_readonly(xpcWrap(ObjectReadOnly));
|
||||
}
|
||||
|
||||
function test_component_readwrite(contractid) {
|
||||
|
||||
function test_component_readwrite(obj) {
|
||||
// Instantiate the object.
|
||||
var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadWrite"]);
|
||||
var o = obj.QueryInterface(Ci.nsIXPCTestObjectReadWrite);
|
||||
|
||||
// Test the initial values.
|
||||
Assert.equal("XPConnect Read-Writable String", o.stringProperty);
|
||||
|
@ -62,10 +89,8 @@ function test_component_readwrite(contractid) {
|
|||
SetAndTestBooleanProperty({}, true);
|
||||
}
|
||||
|
||||
function test_component_readonly(contractid) {
|
||||
|
||||
// Instantiate the object.
|
||||
var o = Cc[contractid].createInstance(Ci["nsIXPCTestObjectReadOnly"]);
|
||||
function test_component_readonly(obj) {
|
||||
var o = obj.QueryInterface(Ci.nsIXPCTestObjectReadOnly);
|
||||
|
||||
// Test the initial values.
|
||||
Assert.equal("XPConnect Read-Only String", o.strReadOnly);
|
||||
|
|
|
@ -9,16 +9,19 @@ registerCleanupFunction(() => {
|
|||
Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
|
||||
});
|
||||
|
||||
function run_test() {
|
||||
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
|
||||
var TestUtils = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestUtils"]),
|
||||
doubleWrapFunction(fun) { return fun }
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
// Generate a CCW to a function.
|
||||
var sb = new Cu.Sandbox(this);
|
||||
sb.eval('function fun(x) { return x; }');
|
||||
Assert.equal(sb.fun("foo"), "foo");
|
||||
|
||||
// Double-wrap the CCW.
|
||||
var utils = Cc["@mozilla.org/js/xpc/test/js/TestUtils;1"].createInstance(Ci.nsIXPCTestUtils);
|
||||
var utils = xpcWrap(TestUtils, Ci.nsIXPCTestUtils);
|
||||
var doubleWrapped = utils.doubleWrapFunction(sb.fun);
|
||||
Assert.equal(doubleWrapped.echo("foo"), "foo");
|
||||
|
||||
|
|
|
@ -2,13 +2,40 @@
|
|||
* 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/. */
|
||||
|
||||
|
||||
var Bug809674 = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestBug809674"]),
|
||||
|
||||
/* nsIXPCTestBug809674 */
|
||||
methodWithOptionalArgc() {},
|
||||
|
||||
addArgs(x, y) {
|
||||
return x + y;
|
||||
},
|
||||
addSubMulArgs(x, y, subOut, mulOut) {
|
||||
subOut.value = x - y;
|
||||
mulOut.value = x * y;
|
||||
return x + y;
|
||||
},
|
||||
addVals(x, y) {
|
||||
return x + y;
|
||||
},
|
||||
addMany(x1, x2, x3, x4, x5, x6, x7, x8) {
|
||||
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8;
|
||||
},
|
||||
|
||||
methodNoArgs() {
|
||||
return 7;
|
||||
},
|
||||
methodNoArgsNoRetVal() {},
|
||||
|
||||
valProperty: {value: 42},
|
||||
uintProperty: 123,
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
|
||||
// Load the component manifest.
|
||||
Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// Instantiate the object.
|
||||
var o = Cc["@mozilla.org/js/xpc/test/js/Bug809674;1"].createInstance(Ci["nsIXPCTestBug809674"]);
|
||||
// XPConnect wrap the object
|
||||
var o = xpcWrap(Bug809674, Ci.nsIXPCTestBug809674);
|
||||
|
||||
// Methods marked [implicit_jscontext].
|
||||
|
||||
|
@ -46,5 +73,4 @@ function run_test() {
|
|||
Assert.ok(true);
|
||||
Assert.ok(/optional_argc/.test(e))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,16 +1,35 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
function run_test() {
|
||||
|
||||
function TestCEnums() {
|
||||
}
|
||||
|
||||
TestCEnums.prototype = {
|
||||
/* Boilerplate */
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestCEnums"]),
|
||||
|
||||
testCEnumInput: function(input) {
|
||||
if (input != Ci.nsIXPCTestCEnums.shouldBe12Explicit)
|
||||
{
|
||||
throw new Error("Enum values do not match expected value");
|
||||
}
|
||||
},
|
||||
|
||||
testCEnumOutput: function() {
|
||||
return Ci.nsIXPCTestCEnums.shouldBe8Explicit;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
function run_test() {
|
||||
// Load the component manifests.
|
||||
registerXPCTestComponents();
|
||||
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// Test for each component.
|
||||
test_interface_consts();
|
||||
test_component("@mozilla.org/js/xpc/test/native/CEnums;1");
|
||||
test_component("@mozilla.org/js/xpc/test/js/CEnums;1");
|
||||
test_component(Cc["@mozilla.org/js/xpc/test/native/CEnums;1"].createInstance());
|
||||
test_component(xpcWrap(new TestCEnums()));
|
||||
}
|
||||
|
||||
function test_interface_consts() {
|
||||
|
@ -29,10 +48,8 @@ function test_interface_consts() {
|
|||
Assert.equal(Ci.nsIXPCTestCEnums.shouldBe3AgainImplicit, 3);
|
||||
}
|
||||
|
||||
function test_component(contractid) {
|
||||
|
||||
// Instantiate the object.
|
||||
var o = Cc[contractid].createInstance(Ci["nsIXPCTestCEnums"]);
|
||||
function test_component(obj) {
|
||||
var o = obj.QueryInterface(Ci.nsIXPCTestCEnums);
|
||||
o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe12Explicit);
|
||||
o.testCEnumInput(Ci.nsIXPCTestCEnums.shouldBe8Explicit | Ci.nsIXPCTestCEnums.shouldBe4Explicit);
|
||||
var a = o.testCEnumOutput();
|
||||
|
|
|
@ -2,22 +2,129 @@
|
|||
* 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/. */
|
||||
|
||||
function TestParams() {
|
||||
}
|
||||
|
||||
/* For once I'm happy that JS is weakly typed. */
|
||||
function f(a, b) {
|
||||
var rv = b.value;
|
||||
b.value = a;
|
||||
return rv;
|
||||
};
|
||||
|
||||
/* Implementation for size_is and iid_is methods. */
|
||||
function f_is(aIs, a, bIs, b, rvIs) {
|
||||
|
||||
// Set up the return value and its 'is' parameter.
|
||||
var rv = b.value;
|
||||
rvIs.value = bIs.value;
|
||||
|
||||
// Set up b and its 'is' parameter.
|
||||
b.value = a;
|
||||
bIs.value = aIs;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
function f_size_and_iid(aSize, aIID, a, bSize, bIID, b, rvSize, rvIID) {
|
||||
|
||||
// Copy the iids.
|
||||
rvIID.value = bIID.value;
|
||||
bIID.value = aIID;
|
||||
|
||||
// Now that we've reduced the problem to one dependent variable, use f_is.
|
||||
return f_is(aSize, a, bSize, b, rvSize);
|
||||
}
|
||||
|
||||
TestParams.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestParams"]),
|
||||
|
||||
/* nsIXPCTestParams */
|
||||
testBoolean: f,
|
||||
testOctet: f,
|
||||
testShort: f,
|
||||
testLong: f,
|
||||
testLongLong: f,
|
||||
testUnsignedShort: f,
|
||||
testUnsignedLong: f,
|
||||
testUnsignedLongLong: f,
|
||||
testFloat: f,
|
||||
testDouble: f,
|
||||
testChar: f,
|
||||
testString: f,
|
||||
testWchar: f,
|
||||
testWstring: f,
|
||||
testAString: f,
|
||||
testAUTF8String: f,
|
||||
testACString: f,
|
||||
testJsval: f,
|
||||
testShortSequence: f,
|
||||
testDoubleSequence: f,
|
||||
testAStringSequence: f,
|
||||
testACStringSequence: f,
|
||||
testInterfaceSequence: f,
|
||||
testJsvalSequence: f,
|
||||
testInterfaceIsSequence: f_is,
|
||||
testOptionalSequence: function (arr) { return arr; },
|
||||
testShortArray: f_is,
|
||||
testDoubleArray: f_is,
|
||||
testStringArray: f_is,
|
||||
testByteArrayOptionalLength(arr) { return arr.length; },
|
||||
testWstringArray: f_is,
|
||||
testInterfaceArray: f_is,
|
||||
testJsvalArray: f_is,
|
||||
testSizedString: f_is,
|
||||
testSizedWstring: f_is,
|
||||
testInterfaceIs: f_is,
|
||||
testInterfaceIsArray: f_size_and_iid,
|
||||
testOutAString: function(o) { o.value = "out"; },
|
||||
testStringArrayOptionalSize: function(arr, size) {
|
||||
if (arr.length != size) { throw "bad size passed to test method"; }
|
||||
var rv = "";
|
||||
arr.forEach((x) => rv += x);
|
||||
return rv;
|
||||
},
|
||||
testOmittedOptionalOut(jsObj, o) {
|
||||
if (typeof o != "object" || o.value !== undefined) {
|
||||
throw new Components.Exception(
|
||||
"unexpected value",
|
||||
Cr.NS_ERROR_ILLEGAL_VALUE
|
||||
);
|
||||
}
|
||||
o.value = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService)
|
||||
.newURI("http://example.com/");
|
||||
}
|
||||
};
|
||||
|
||||
function TestInterfaceA() {}
|
||||
TestInterfaceA.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA"]),
|
||||
|
||||
/* nsIXPCTestInterfaceA */
|
||||
name: "TestInterfaceADefaultName"
|
||||
};
|
||||
|
||||
function TestInterfaceB() {}
|
||||
TestInterfaceB.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceB"]),
|
||||
|
||||
/* nsIXPCTestInterfaceA */
|
||||
name: "TestInterfaceADefaultName"
|
||||
};
|
||||
|
||||
function run_test() {
|
||||
|
||||
// Load the component manifests.
|
||||
registerXPCTestComponents();
|
||||
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// Test for each component.
|
||||
test_component("@mozilla.org/js/xpc/test/native/Params;1");
|
||||
test_component("@mozilla.org/js/xpc/test/js/Params;1");
|
||||
test_component(Cc["@mozilla.org/js/xpc/test/native/Params;1"].createInstance());
|
||||
test_component(xpcWrap(new TestParams()));
|
||||
}
|
||||
|
||||
function test_component(contractid) {
|
||||
|
||||
// Instantiate the object.
|
||||
info("Testing " + contractid);
|
||||
var o = Cc[contractid].createInstance(Ci["nsIXPCTestParams"]);
|
||||
function test_component(obj) {
|
||||
var o = obj.QueryInterface(Ci.nsIXPCTestParams);
|
||||
|
||||
// Possible comparator functions.
|
||||
var standardComparator = function(a,b) {return a == b;};
|
||||
|
@ -142,13 +249,13 @@ function test_component(contractid) {
|
|||
// Helpers to instantiate various test XPCOM objects.
|
||||
var numAsMade = 0;
|
||||
function makeA() {
|
||||
var a = Cc["@mozilla.org/js/xpc/test/js/InterfaceA;1"].createInstance(Ci['nsIXPCTestInterfaceA']);
|
||||
var a = xpcWrap(new TestInterfaceA(), Ci.nsIXPCTestInterfaceA);
|
||||
a.name = 'testA' + numAsMade++;
|
||||
return a;
|
||||
};
|
||||
var numBsMade = 0;
|
||||
function makeB() {
|
||||
var b = Cc["@mozilla.org/js/xpc/test/js/InterfaceB;1"].createInstance(Ci['nsIXPCTestInterfaceB']);
|
||||
var b = xpcWrap(new TestInterfaceB(), Ci.nsIXPCTestInterfaceB);
|
||||
b.name = 'testB' + numBsMade++;
|
||||
return b;
|
||||
};
|
||||
|
@ -230,9 +337,10 @@ function test_component(contractid) {
|
|||
Assert.ok(Array.isArray(ret));
|
||||
Assert.equal(ret.length, 3);
|
||||
|
||||
o.testOmittedOptionalOut();
|
||||
let jsObj = new TestParams();
|
||||
o.testOmittedOptionalOut(jsObj);
|
||||
ret = {};
|
||||
o.testOmittedOptionalOut(ret);
|
||||
o.testOmittedOptionalOut(jsObj, ret);
|
||||
Assert.equal(ret.value.spec, "http://example.com/")
|
||||
|
||||
// Tests for large ArrayBuffers.
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
* 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/. */
|
||||
|
||||
const Cm = Components.manager;
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
function getConsoleMessages() {
|
||||
|
@ -17,7 +15,6 @@ function getConsoleMessages() {
|
|||
function run_test() {
|
||||
// Load the component manifests.
|
||||
registerXPCTestComponents();
|
||||
registerAppManifest(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// and the tests.
|
||||
test_simple();
|
||||
|
|
|
@ -2,11 +2,24 @@
|
|||
* 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/. */
|
||||
|
||||
function TestInterfaceAll() {}
|
||||
TestInterfaceAll.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA",
|
||||
"nsIXPCTestInterfaceB",
|
||||
"nsIXPCTestInterfaceC"]),
|
||||
|
||||
/* nsIXPCTestInterfaceA / nsIXPCTestInterfaceB */
|
||||
name: "TestInterfaceAllDefaultName",
|
||||
|
||||
/* nsIXPCTestInterfaceC */
|
||||
someInteger: 42
|
||||
};
|
||||
|
||||
function newWrappedJS() {
|
||||
return xpcWrap(new TestInterfaceAll());
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
|
||||
// Load the component manifest containing our test interface implementations.
|
||||
Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest'));
|
||||
|
||||
// Shortcut the interfaces we're using.
|
||||
var ifs = {
|
||||
a: Ci['nsIXPCTestInterfaceA'],
|
||||
|
@ -14,20 +27,17 @@ function run_test() {
|
|||
c: Ci['nsIXPCTestInterfaceC']
|
||||
};
|
||||
|
||||
// Shortcut the class we're instantiating. This implements all three interfaces.
|
||||
var cls = Cc["@mozilla.org/js/xpc/test/js/TestInterfaceAll;1"];
|
||||
|
||||
// Run through the logic a few times.
|
||||
for (i = 0; i < 2; ++i)
|
||||
play_with_tearoffs(ifs, cls);
|
||||
for (let i = 0; i < 2; ++i)
|
||||
play_with_tearoffs(ifs);
|
||||
}
|
||||
|
||||
function play_with_tearoffs(ifs, cls) {
|
||||
function play_with_tearoffs(ifs) {
|
||||
|
||||
// Allocate a bunch of objects, QI-ed to B.
|
||||
var instances = [];
|
||||
for (var i = 0; i < 300; ++i)
|
||||
instances.push(cls.createInstance(ifs.b));
|
||||
instances.push(newWrappedJS().QueryInterface(ifs.b));
|
||||
|
||||
// Nothing to collect.
|
||||
gc();
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
// Test that it's not possible to create expando properties on XPCWNs.
|
||||
// See <https://bugzilla.mozilla.org/show_bug.cgi?id=1143810#c5>.
|
||||
|
||||
function TestInterfaceAll() {}
|
||||
TestInterfaceAll.prototype = {
|
||||
QueryInterface: ChromeUtils.generateQI(["nsIXPCTestInterfaceA",
|
||||
"nsIXPCTestInterfaceB",
|
||||
"nsIXPCTestInterfaceC"]),
|
||||
|
||||
/* nsIXPCTestInterfaceA / nsIXPCTestInterfaceB */
|
||||
name: "TestInterfaceAllDefaultName",
|
||||
|
||||
/* nsIXPCTestInterfaceC */
|
||||
someInteger: 42
|
||||
};
|
||||
|
||||
function check_throws(f) {
|
||||
try {
|
||||
f();
|
||||
|
@ -159,8 +172,7 @@ function run_test() {
|
|||
});
|
||||
|
||||
// Test a tearoff object.
|
||||
Components.manager.autoRegister(do_get_file('../components/js/xpctest.manifest'));
|
||||
let b = Cc["@mozilla.org/js/xpc/test/js/TestInterfaceAll;1"].createInstance(Ci.nsIXPCTestInterfaceB);
|
||||
let b = xpcWrap(new TestInterfaceAll(), Ci.nsIXPCTestInterfaceB);
|
||||
let tearoff = b.nsIXPCTestInterfaceA;
|
||||
test_twice(tearoff, {
|
||||
method: "QueryInterface"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[DEFAULT]
|
||||
head =
|
||||
head = head.js
|
||||
support-files =
|
||||
CatRegistrationComponents.manifest
|
||||
CatBackgroundTaskRegistrationComponents.manifest
|
||||
|
@ -15,6 +15,7 @@ support-files =
|
|||
importer.jsm
|
||||
recursive_importA.jsm
|
||||
recursive_importB.jsm
|
||||
ReturnCodeChild.jsm
|
||||
syntax_error.jsm
|
||||
uninitialized_lexical.jsm
|
||||
es6module.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче