Testing fixes for bug 568691 - change xpcshell do_load_module to do_load_manifest, and switch the relevant tests to use manifests and the new function.

This commit is contained in:
Benjamin Smedberg 2010-06-25 10:43:25 -04:00
parent 2be0746f06
commit 5f7a36ec28
22 changed files with 43 additions and 231 deletions

View File

@ -40,7 +40,7 @@ function run_test() {
const nsIXTFPrivate = C_i.nsIXTFPrivate;
const nsIDOMParser = C_i.nsIDOMParser;
const nsIDOMEventTarget = C_i.nsIDOMEventTarget;
do_load_module("xtfComponent.js");
do_load_manifest("xtfComponent.manifest");
const xtfClass = "@mozilla.org/xtf/element-factory;1?namespace=";
do_check_true(xtfClass + "xtf-tests;foo" in Components.classes);

View File

@ -34,6 +34,8 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
// Utility function.
function NOT_IMPLEMENTED() {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
@ -53,8 +55,6 @@ const nsIFactory = C_i.nsIFactory;
const nsIModule = C_i.nsIModule;
const nsISupports = C_i.nsISupports;
const xtfClass = "@mozilla.org/xtf/element-factory;1?namespace=";
/**
* Wrap a JavaScript object for passing to components code.
*/
@ -143,6 +143,8 @@ FooElement.prototype =
function FooElementFactory() {}
FooElementFactory.prototype =
{
classID: Components.ID("{f367b65d-6b7f-4a7f-9a4b-8bde0ff4ef10}"),
// nsIXTFElementFactory
createElement: function createElement(aLocalName) {
var rv = null;
@ -180,73 +182,6 @@ FooElementFactory.prototype =
}
};
const FooComponentFactory = {
// nsIFactory
createInstance: function createInstance(outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return (new FooElementFactory()).QueryInterface(iid);
},
// nsISupports
QueryInterface: function QueryInterface(aIID) {
if (aIID.equals(nsIFactory) ||
(aIID.equals(nsISupports)))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
return null;
}
};
const fooClassID = Components.ID("{f367b65d-6b7f-4a7f-9a4b-8bde0ff4ef10}");
const fooClassDesc = "XTF unit test: Foo element factory";
const fooContractID = xtfClass + "xtf-tests;foo";
/* </foo:element> */
const Module = {
// nsIModule
registerSelf: function registerSelf(compMgr, fileSpec, location, type) {
var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
compReg.registerFactoryLocation(fooClassID,
fooClassDesc,
fooContractID,
fileSpec,
location,
type);
},
// nsIModule
getClassObject: function getClassObject(compMgr, aCID, aIID) {
if (!aIID.equals(nsIFactory)) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
}
if (aCID.equals(fooClassID)) {
return FooComponentFactory;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
},
// nsIModule
canUnload: function canUnload() {
return true;
},
// nsISupports
QueryInterface: function QueryInterface(aIID) {
if (aIID.equals(nsIModule) ||
(aIID.equals(nsISupports)))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
return null;
}
};
function NSGetModule(compMgr, fileSpec) {
return Module;
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([FooElementFactory]);

View File

@ -0,0 +1,2 @@
component {f367b65d-6b7f-4a7f-9a4b-8bde0ff4ef10} xtfComponent.js
contract @mozilla.org/xtf/element-factory;1?namespace=xtf-tests;foo {f367b65d-6b7f-4a7f-9a4b-8bde0ff4ef10}

View File

@ -10,8 +10,6 @@ function CookiePromptService() {
}
CookiePromptService.prototype = {
classDescription: "Cookie Prompt Test Service",
contractID: "@mozilla.org/embedcomp/cookieprompt-service;1",
classID: Components.ID("{509b5540-c87c-11dd-ad8b-0800200c9a66}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsICookiePromptService]),
@ -22,6 +20,4 @@ CookiePromptService.prototype = {
}
};
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([CookiePromptService]);
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([CookiePromptService]);

View File

@ -0,0 +1,2 @@
component {509b5540-c87c-11dd-ad8b-0800200c9a66} cookieprompt.js
contract @mozilla.org/embedcomp/cookieprompt-service;1 {509b5540-c87c-11dd-ad8b-0800200c9a66}

View File

@ -3,7 +3,7 @@
*/
function run_test() {
do_load_module("cookieprompt.js");
do_load_manifest("cookieprompt.manifest");
var cs = Cc["@mozilla.org/cookieService;1"].getService(Ci.nsICookieService);
var cm = Cc["@mozilla.org/cookiemanager;1"].getService(Ci.nsICookieManager2);

View File

@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* vim: sw=4 ts=4 sts=4 et
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Necko Test Code.
*
* The Initial Developer of the Original Code is the Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Marco Bonardo <mak77@bonardo.net> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// Test components used in test_xpcomutils.js
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
const CATEGORY_NAME = "test-cat";
// This component will register under the "test-cat" category.
function CatRegisteredComponent() {}
CatRegisteredComponent.prototype = {
classDescription: "CatRegisteredComponent",
classID: Components.ID("{163cd427-1f08-4416-a291-83ea71127b0e}"),
contractID: "@unit.test.com/cat-registered-component;1",
QueryInterface: XPCOMUtils.generateQI([]),
_xpcom_categories: [
{ category: CATEGORY_NAME }
]
};
// This component will register under the "test-cat" category.
function CatAppRegisteredComponent() {}
CatAppRegisteredComponent.prototype = {
classDescription: "CatAppRegisteredComponent",
classID: Components.ID("{b686dc84-f42e-4c94-94fe-89d0ac899578}"),
contractID: "@unit.test.com/cat-app-registered-component;1",
QueryInterface: XPCOMUtils.generateQI([]),
_xpcom_categories: [
{ category: CATEGORY_NAME,
apps: [ /* Our app */ "{adb42a9a-0d19-4849-bf4d-627614ca19be}" ]
}
]
};
// This component will not register under the "test-cat" category because
// it does not support our app.
function CatUnregisteredComponent() {}
CatUnregisteredComponent.prototype = {
classDescription: "CatUnregisteredComponent",
classID: Components.ID("{c31a552b-0228-4a1a-8cdf-d8aab7d4eff8}"),
contractID: "@unit.test.com/cat-unregistered-component;1",
QueryInterface: XPCOMUtils.generateQI([]),
_xpcom_categories: [
{ category: CATEGORY_NAME,
apps: [ /* Another app */ "{e84fce36-6ef6-435c-bf63-979a8811dcd4}" ]
}
]
};
let components = [
CatRegisteredComponent,
CatAppRegisteredComponent,
CatUnregisteredComponent,
];
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}

View File

@ -0,0 +1,2 @@
category test-cat CatRegisteredComponent @unit.test.com/cat-registered-component;1
category test-cat CatAppRegisteredComponent @unit.test.com/cat-app-registered-component;1 application={adb42a9a-0d19-4849-bf4d-627614ca19be}

View File

@ -38,7 +38,6 @@ Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function FooComponent() {
this.wrappedJSObject = this;
this.postRegisterCalled = gPostRegisterCalled;
}
FooComponent.prototype =
{
@ -61,7 +60,7 @@ FooComponent.prototype =
thereIsNoSuchIdentifier;
threw = false;
} catch (ex) {
do_check_true(ex.lineNumber == 61);
do_check_true(ex.lineNumber == 60);
}
do_check_true(threw);
@ -117,28 +116,5 @@ function do_check_true(cond, text) {
throw "Failed check: " + text;
}
function postRegister(componentManager, file, componentsArray) {
const Ci = Components.interfaces;
do_check_true(componentManager instanceof Ci.nsIComponentManager,
"postRegister: componentManager param is ok");
do_check_true(file instanceof Ci.nsIFile,
"postRegister: file param is ok");
do_check_true(componentsArray === gComponentsArray,
"postRegister: componentsArray param is ok");
gPostRegisterCalled = true;
}
function preUnregister(componentManager, file, componentsArray) {
const Ci = Components.interfaces;
do_check_true(componentManager instanceof Ci.nsIComponentManager,
"postRegister: componentManager param is ok");
do_check_true(file instanceof Ci.nsIFile,
"postRegister: file param is ok");
do_check_true(componentsArray === gComponentsArray,
"postRegister: componentsArray param is ok");
}
var gPostRegisterCalled = false;
var gComponentsArray = [FooComponent, BarComponent];
var NSGetModule = XPCOMUtils.generateNSGetModule(gComponentsArray,
postRegister, preUnregister);
var NSGetFactory = XPCOMUtils.generateNSGetFactory(gComponentsArray);

View File

@ -0,0 +1,5 @@
component {6b933fe6-6eba-4622-ac86-e4f654f1b474} component_import.js
contract @mozilla.org/tests/module-importer;1 {6b933fe6-6eba-4622-ac86-e4f654f1b474}
component {708a896a-b48d-4bff-906e-fc2fd134b296} component_import.js
contract @mozilla.org/tests/module-importer;2 {708a896a-b48d-4bff-906e-fc2fd134b296}

View File

@ -41,7 +41,7 @@ function run_test() {
var scope = {};
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", scope);
do_check_eq(typeof(scope.XPCOMUtils), "object");
do_check_eq(typeof(scope.XPCOMUtils.generateModule), "function");
do_check_eq(typeof(scope.XPCOMUtils.generateNSGetFactory), "function");
// access module's global object directly without importing any
// symbols
@ -50,20 +50,20 @@ function run_test() {
do_check_eq(typeof(XPCOMUtils), "undefined");
do_check_eq(typeof(module), "object");
do_check_eq(typeof(module.XPCOMUtils), "object");
do_check_eq(typeof(module.XPCOMUtils.generateModule), "function");
do_check_eq(typeof(module.XPCOMUtils.generateNSGetFactory), "function");
do_check_true(scope.XPCOMUtils == module.XPCOMUtils);
// import symbols to our global object
do_check_eq(typeof(Components.utils.import), "function");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
do_check_eq(typeof(XPCOMUtils), "object");
do_check_eq(typeof(XPCOMUtils.generateModule), "function");
do_check_eq(typeof(XPCOMUtils.generateNSGetFactory), "function");
// try on a new object
var scope2 = {};
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", scope2);
do_check_eq(typeof(scope2.XPCOMUtils), "object");
do_check_eq(typeof(scope2.XPCOMUtils.generateModule), "function");
do_check_eq(typeof(scope2.XPCOMUtils.generateNSGetFactory), "function");
do_check_true(scope2.XPCOMUtils == scope.XPCOMUtils);
@ -77,7 +77,7 @@ function run_test() {
var scope3 = {};
Components.utils.import(filePath, scope3);
do_check_eq(typeof(scope3.XPCOMUtils), "object");
do_check_eq(typeof(scope3.XPCOMUtils.generateModule), "function");
do_check_eq(typeof(scope3.XPCOMUtils.generateNSGetFactory), "function");
do_check_true(scope3.XPCOMUtils == scope.XPCOMUtils);
@ -92,7 +92,7 @@ function run_test() {
do_check_true(didThrow);
// try to create a component
do_load_module("component_import.js");
do_load_manifest("component_import.manifest");
const contractID = "@mozilla.org/tests/module-importer;";
do_check_true((contractID + "1") in Components.classes);
var foo = Components.classes[contractID + "1"]

View File

@ -124,7 +124,7 @@ function test_categoryRegistration()
{
const CATEGORY_NAME = "test-cat";
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
const XULAPPINFO_CID = Components.ID("{95d89e3e-a169-41a3-8e56-719978e15b12}");
const XULAPPINFO_CID = Components.ID("{fc937916-656b-4fb3-a395-8c63569e27a8}");
// Create a fake app entry for our category registration apps filter.
let XULAppInfo = {
@ -160,7 +160,7 @@ function test_categoryRegistration()
);
// Load test components.
do_load_module("CatRegistrationComponents.js");
do_load_manifest("CatRegistrationComponents.manifest");
const EXPECTED_ENTRIES = ["CatAppRegisteredComponent",
"CatRegisteredComponent"];

View File

@ -368,7 +368,7 @@ function do_load_httpd_js() {
load(_HTTPD_JS_PATH);
}
function do_load_module(path) {
function do_load_manifest(path) {
var lf = do_get_file(path);
const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
do_check_true(Components.manager instanceof nsIComponentRegistrar);

View File

@ -85,7 +85,7 @@ bs.addObserver(bookmarksObserver, false);
function run_test()
{
// dynamic container sample
do_load_module("../unit/nsDynamicContainerServiceSample.js");
do_load_manifest("../unit/nsDynamicContainerServiceSample.manifest");
// First set the preference for the timer to a large value, so it won't sync
prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL);

View File

@ -76,16 +76,7 @@ DummyObserver.prototype = {
onItemVisited: function() {},
onItemMoved: function() {},
classDescription: "Dummy observer used to test category observers",
classID: Components.ID("62e221d3-68c3-4e1a-8943-a27beb5005fe"),
contractID: "@mozilla.org/places/test/dummy-observer;1",
// Registering in these categories makes us get initialized when either of
// those listeners would be notified.
_xpcom_categories: [
{ category: "bookmark-observers" },
{ category: "history-observers" }
],
QueryInterface: XPCOMUtils.generateQI([
Ci.nsINavBookmarkObserver,
@ -93,6 +84,4 @@ DummyObserver.prototype = {
])
};
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([DummyObserver]);
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([DummyObserver]);

View File

@ -0,0 +1,4 @@
component 62e221d3-68c3-4e1a-8943-a27beb5005fe nsDummyObserver.js
contract @mozilla.org/places/test/dummy-observer;1 62e221d3-68c3-4e1a-8943-a27beb5005fe
category bookmark-observers nsDummyObserver
category history-observers nsDummyObserver

View File

@ -92,12 +92,8 @@ RemoteContainerSampleService.prototype = {
return this.QueryInterface(iid);
},
classDescription: "Remote Container Sample Service",
contractID: "@mozilla.org/browser/remote-container-sample;1",
classID: Components.ID("{0d42adc5-f07a-4da2-b8da-3e2ef114cb67}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDynamicContainer]),
};
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([RemoteContainerSampleService]);
}
const NSGetFactory = XPCOMUtils.generateNSGetFactory([RemoteContainerSampleService]);

View File

@ -0,0 +1,2 @@
component {0d42adc5-f07a-4da2-b8da-3e2ef114cb67} nsDynamicContainerServiceSample.js
contract @mozilla.org/browser/remote-container-sample;1 {0d42adc5-f07a-4da2-b8da-3e2ef114cb67}

View File

@ -72,7 +72,7 @@ bms.addObserver(observer, false);
// main
function run_test() {
// load our dynamic-container sample service
do_load_module("nsDynamicContainerServiceSample.js");
do_load_manifest("nsDynamicContainerServiceSample.manifest");
var testRoot = bms.createFolder(bms.placesRoot, "test root", bms.DEFAULT_INDEX);
var options = hs.getNewQueryOptions();

View File

@ -67,7 +67,7 @@ function verify() {
// main
function run_test() {
do_load_module("nsDummyObserver.js");
do_load_manifest("nsDummyObserver.manifest");
os.addObserver(observer, "dummy-observer-created", true);
os.addObserver(observer, "dummy-observer-item-added", true);

View File

@ -50,7 +50,7 @@
// main
function run_test() {
// load our dynamic-container sample service
do_load_module("nsDynamicContainerServiceSample.js");
do_load_manifest("nsDynamicContainerServiceSample.manifest");
var testRoot = bmsvc.createFolder(bmsvc.placesRoot, "test root", bmsvc.DEFAULT_INDEX);
var exposedFolder = bmsvc.createFolder(testRoot, "exposed folder", bmsvc.DEFAULT_INDEX);
var efId1 = bmsvc.insertBookmark(exposedFolder, uri("http://uri1.tld"), bmsvc.DEFAULT_INDEX, "");

View File

@ -67,7 +67,7 @@ function verify() {
// main
function run_test() {
do_load_module("nsDummyObserver.js");
do_load_manifest("nsDummyObserver.manifest");
os.addObserver(observer, "dummy-observer-created", true);
os.addObserver(observer, "dummy-observer-visited", true);