Bug 605949: Fix intermittent failure in test_bug384052.js. r=robstrong, a=tests

This commit is contained in:
Dave Townsend 2010-10-26 10:47:31 -07:00
Родитель ef8b1b1848
Коммит ffc57e8af9
1 изменённых файлов: 19 добавлений и 38 удалений

Просмотреть файл

@ -1,67 +1,54 @@
const Cc = Components.classes;
const Ci = Components.interfaces;
const CLASS_ID = Components.ID("{12345678-1234-1234-1234-123456789abc}");
const CONTRACT_ID = "@mozilla.org/test-parameter-source;1";
var gTestURL = "http://127.0.0.1:4444/?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
var gExpectedURL = null;
var gTestURL = "http://127.0.0.1:4444/update.rdf?itemID=%ITEM_ID%&custom1=%CUSTOM1%&custom2=%CUSTOM2%";
var gExpectedQuery = "itemID=test@mozilla.org&custom1=custom_parameter_1&custom2=custom_parameter_2";
var gSeenExpectedURL = false;
var gComponentRegistrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
var gObserverService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
var gCategoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
var gComponentRegistrar = Components.manager.QueryInterface(AM_Ci.nsIComponentRegistrar);
var gCategoryManager = AM_Cc["@mozilla.org/categorymanager;1"].getService(AM_Ci.nsICategoryManager);
// Get the HTTP server.
do_load_httpd_js();
var testserver;
// Factory for our parameter handler
var paramHandlerFactory = {
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIFactory) || iid.equals(Ci.nsISupports))
if (iid.equals(AM_Ci.nsIFactory) || iid.equals(AM_Ci.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
createInstance: function(outer, iid) {
var bag = Cc["@mozilla.org/hash-property-bag;1"]
.createInstance(Ci.nsIWritablePropertyBag);
var bag = AM_Cc["@mozilla.org/hash-property-bag;1"].
createInstance(AM_Ci.nsIWritablePropertyBag);
bag.setProperty("CUSTOM1", "custom_parameter_1");
bag.setProperty("CUSTOM2", "custom_parameter_2");
return bag.QueryInterface(iid);
}
};
// Observer that should recognize when extension manager requests our URL
var observer = {
QueryInterface: function(iid) {
if (iid.equals(Ci.nsIObserver) || iid.equals(Ci.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
observe: function(subject, topic, data) {
if (topic == "http-on-modify-request") {
var channel = subject.QueryInterface(Ci.nsIChannel);
if (channel.originalURI.spec == gExpectedURL)
gSeenExpectedURL = true;
}
}
}
function initTest()
{
do_test_pending();
// Setup extension manager
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
// Create and configure the HTTP server.
testserver = new nsHttpServer();
testserver.registerPathHandler("/update.rdf", function(aRequest, aResponse) {
gSeenExpectedURL = aRequest.queryString == gExpectedQuery;
aResponse.setStatusLine(null, 404, "Not Found");
});
testserver.start(4444);
// Register our parameter handlers
gComponentRegistrar.registerFactory(CLASS_ID, "Test component", CONTRACT_ID, paramHandlerFactory);
gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM1", CONTRACT_ID, false, false);
gCategoryManager.addCategoryEntry("extension-update-params", "CUSTOM2", CONTRACT_ID, false, false);
// Register observer to get notified when URLs are requested
gObserverService.addObserver(observer, "http-on-modify-request", false);
// Install a test extension into the profile
let dir = gProfD.clone();
dir.append("extensions");
@ -88,8 +75,6 @@ function shutdownTest()
gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM1", false);
gCategoryManager.deleteCategoryEntry("extension-update-params", "CUSTOM2", false);
gObserverService.removeObserver(observer, "http-on-modify-request");
do_test_finished();
}
@ -97,10 +82,6 @@ function run_test()
{
initTest();
gExpectedURL = gTestURL.replace(/%ITEM_ID%/, "test@mozilla.org")
.replace(/%CUSTOM1%/, "custom_parameter_1")
.replace(/%CUSTOM2%/, "custom_parameter_2");
AddonManager.getAddonByID("test@mozilla.org", function(item) {
// Initiate update
item.findUpdates({