Skip to content

Commit

Permalink
Bug 1139254 - Use MockRegistrar in chrome. r=gps
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroyuki Ikezoe committed Mar 4, 2015
1 parent 4f975fb commit f5170b0
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions chrome/test/unit/test_bug519468.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,22 @@ var MANIFESTS = [
do_get_file("data/test_bug519468.manifest")
];

Components.utils.import("resource://testing-common/MockRegistrar.jsm");
// Stub in the locale service so we can control what gets returned as the OS locale setting
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

let stubOSLocale = null;

stubID = Components.ID("9d09d686-d913-414c-a1e6-4be8652d7d93");
localeContractID = "@mozilla.org/intl/nslocaleservice;1";

StubLocaleService = {
classDescription: "Stub version of Locale service for testing",
classID: stubID,
contractID: localeContractID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsILocaleService, Ci.nsISupports, Ci.nsIFactory]),

createInstance: function (outer, iid) {
if (outer)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return this.QueryInterface(iid);
},
lockFactory: function (lock) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsILocaleService, Ci.nsISupports]),

getLocaleComponentForUserAgent: function SLS_getLocaleComponentForUserAgent()
{
return stubOSLocale;
}
}

let registrar = Components.manager.nsIComponentRegistrar;
// Save original factory.
let localeCID = registrar.contractIDToCID(localeContractID)
let originalFactory =
Components.manager.getClassObject(Components.classes[localeContractID],
Components.interfaces.nsIFactory);

registrar.registerFactory(stubID, "Unit test Locale Service", localeContractID, StubLocaleService);
MockRegistrar.register("@mozilla.org/intl/nslocaleservice;1", StubLocaleService);

// Now fire up the test
do_test_pending()
Expand Down

0 comments on commit f5170b0

Please sign in to comment.