Bug 917052 - Add dialog box specific tests. r=mbrubeck

This commit is contained in:
Marina Samuel 2013-10-08 16:33:35 -04:00
Родитель e39327f26d
Коммит 7ca6dc1ffa
1 изменённых файлов: 61 добавлений и 0 удалений

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

@ -5,6 +5,31 @@
"use strict";
const Ci = Components.interfaces;
const Cm = Components.manager;
const Cc = Components.classes;
const CONTRACT_ID = "@mozilla.org/xre/runtime;1";
function MockAppInfo() {
}
MockAppInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULRuntime]),
}
let newFactory = {
createInstance: function(aOuter, aIID) {
if (aOuter)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return new MockAppInfo().QueryInterface(aIID);
},
lockFactory: function(aLock) {
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
};
var SanitizeHelper = {
_originalSanitizer: null,
@ -19,10 +44,29 @@ var SanitizeHelper = {
setUp: function setUp() {
SanitizeHelper._originalSanitizer = SanitizeUI._sanitizer;
SanitizeUI._sanitizer = SanitizeHelper.MockSanitizer;
let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
this.gAppInfoClassID = registrar.contractIDToCID(CONTRACT_ID);
this.gIncOldFactory = Cm.getClassObject(Cc[CONTRACT_ID], Ci.nsIFactory);
registrar.unregisterFactory(this.gAppInfoClassID, this.gIncOldFactory);
let components = [MockAppInfo];
registrar.registerFactory(this.gAppInfoClassID, "", CONTRACT_ID, newFactory);
this.gIncOldFactory = Cm.getClassObject(Cc[CONTRACT_ID], Ci.nsIFactory);
this.oldPrompt = Services.prompt;
},
tearDown: function tearDown() {
SanitizeUI._sanitizer = SanitizeHelper._originalSanitizer;
if (this.gIncOldFactory) {
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.unregisterFactory(this.gAppInfoClassID, newFactory);
registrar.registerFactory(this.gAppInfoClassID, "", CONTRACT_ID, this.gIncOldFactory);
}
this.gIncOldFactory = null;
Services.prompt = this.oldPrompt;
},
};
@ -33,9 +77,18 @@ function getAllSelected() {
}
gTests.push({
setUp: SanitizeHelper.setUp,
tearDown: SanitizeHelper.tearDown,
desc: "Test sanitizer UI",
run: function testSanitizeUI() {
// We want to be able to simulate that a specific button
// of the 'clear private data' prompt was pressed.
Services.prompt = {
confirmEx: function() {
return this.retVal;
}
};
// Show options flyout
let promise = waitForEvent(FlyoutPanelsUI.PrefsFlyoutPanel._topmostElement, "PopupChanged", 2000);
FlyoutPanelsUI.show('PrefsFlyoutPanel');
@ -72,8 +125,16 @@ gTests.push({
}
}
// Simulate clicking "button 1", cancel.
Services.prompt.retVal = 1;
let clearButton = document.getElementById("prefs-clear-data");
clearButton.doCommand();
ok(SanitizeHelper.MockSanitizer.clearCalled.length == 0, "Nothing was cleared");
// We will simulate that "button 0" (which should be the clear button)
// was pressed
Services.prompt.retVal = 0;
clearButton.doCommand();
let clearNotificationDeck = document.getElementById("clear-notification");
let clearNotificationDone = document.getElementById("clear-notification-done");