Tests for
Bug 735668 - Assertion failure / debug crash when linking to a YouSendIt or Dropbox account. Ensure the right 'this' is used. r+a=bienvenu
--- a/mail/test/mozmill/cloudfile/test-cloudfile-backend-dropbox.js
+++ b/mail/test/mozmill/cloudfile/test-cloudfile-backend-dropbox.js
@@ -185,8 +185,30 @@ function test_deleting_uploads() {
provider.deleteFile(file, deleteObserver);
mc.waitFor(function() deleteObserver.success);
// Check to make sure the file was deleted on the server
assert_equals(1, obs.numSightings(kDeleteFile));
assert_equals(obs.data[kDeleteFile][0], kFilename);
Services.obs.removeObserver(obs, kDeleteFile);
}
+
+/**
+ * Test that when we call createExistingAccount, onStopRequest is successfully
+ * called, and we pass the correct parameters.
+ */
+function test_create_existing_account() {
+ let provider = gServer.getPreparedBackend("someNewAccount");
+ let done = false;
+ let myObs = {
+ onStartRequest: function(aRequest, aContext) {
+ },
+ onStopRequest: function(aRequest, aContext, aStatusCode) {
+ assert_true(aContext instanceof Ci.nsIMsgCloudFileProvider);
+ assert_equals(aStatusCode, Components.results.NS_OK);
+ done = true;
+ },
+ }
+
+ provider.createExistingAccount(myObs);
+ mc.waitFor(function() done);
+}
+
--- a/mail/test/mozmill/cloudfile/test-cloudfile-backend-yousendit.js
+++ b/mail/test/mozmill/cloudfile/test-cloudfile-backend-yousendit.js
@@ -11,17 +11,18 @@ let Cc = Components.classes;
let Ci = Components.interfaces;
const MODULE_NAME = 'test-cloudfile-backend-yousendit';
const RELATIVE_ROOT = '../shared-modules';
const MODULE_REQUIRES = ['folder-display-helpers',
'compose-helpers',
'cloudfile-yousendit-helpers',
- 'observer-helpers',];
+ 'observer-helpers',
+ 'prompt-helpers',];
Cu.import('resource://gre/modules/Services.jsm');
var gServer, gObsManager;
function setupModule(module) {
let fdh = collector.getModule('folder-display-helpers');
fdh.installInto(module);
@@ -36,16 +37,19 @@ function setupModule(module) {
cbh.installInto(module);
let cyh = collector.getModule('cloudfile-yousendit-helpers');
cyh.installInto(module);
let oh = collector.getModule('observer-helpers');
oh.installInto(module);
+ let ph = collector.getModule('prompt-helpers');
+ ph.installInto(module);
+
gObsManager = new cbh.SimpleRequestObserverManager();
// Enable logging for this group of tests.
Services.prefs.setCharPref("YouSendIt.logging.dump", "All");
};
function teardownModule(module) {
Services.prefs.clearUserPref("YouSendIt.logging.dump");
@@ -178,16 +182,39 @@ function test_deleting_uploads() {
mc.waitFor(function() deleteObserver.success);
// Check to make sure the file was deleted on the server
assert_equals(1, obs.numSightings(kDeleteFile));
assert_equals(obs.data[kDeleteFile][0], kFilename);
Services.obs.removeObserver(obs, kDeleteFile);
}
+/**
+ * Test that when we call createExistingAccount, onStopRequest is successfully
+ * called, and we pass the correct parameters.
+ */
+function test_create_existing_account() {
+ // We have to mock out the auth prompter, or else we'll lock up.
+ gMockAuthPromptReg.register();
+ let provider = gServer.getPreparedBackend("someNewAccount");
+ let done = false;
+ let myObs = {
+ onStartRequest: function(aRequest, aContext) {
+ },
+ onStopRequest: function(aRequest, aContext, aStatusCode) {
+ assert_true(aContext instanceof Ci.nsIMsgCloudFileProvider);
+ assert_equals(aStatusCode, Components.results.NS_OK);
+ done = true;
+ },
+ }
+
+ provider.createExistingAccount(myObs);
+ mc.waitFor(function() done);
+ gMockAuthPromptReg.unregister();
+}
function test_delete_refreshes_stale_token() {
const kFilename = "testFile1";
const kUserEmail = "test@example.com";
// Stop the default YSI mock server, and create our own.
gServer.stop(mc);
gServer = new MockYouSendItServer();
--- a/mail/test/mozmill/shared-modules/test-prompt-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-prompt-helpers.js
@@ -41,31 +41,74 @@ var Cu = Components.utils;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
const MODULE_NAME = 'prompt-helpers';
const RELATIVE_ROOT = '../shared-modules';
// we need this for the main controller
-const MODULE_REQUIRES = [];
+const MODULE_REQUIRES = ['mock-object-helpers'];
const kMockPromptServiceName = "Mock Prompt Service";
const kPromptServiceContractID = "@mozilla.org/embedcomp/prompt-service;1";
const kPromptServiceName = "Prompt Service";
+let gMockAuthPromptReg;
+
function setupModule() {
+ let moh = collector.getModule('mock-object-helpers');
+ gMockAuthPromptReg = new moh.MockObjectReplacer("@mozilla.org/prompter;1",
+ MockAuthPromptFactoryConstructor);
}
function installInto(module) {
setupModule();
// Now copy helper functions
module.gMockPromptService = gMockPromptService;
+ module.gMockAuthPromptReg = gMockAuthPromptReg;
+ module.gMockAuthPrompt = gMockAuthPrompt;
}
+function MockAuthPromptFactoryConstructor() {
+ return gMockAuthPromptFactory;
+}
+
+var gMockAuthPromptFactory = {
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptFactory]),
+ getPrompt: function(aParent, aIID, aResult) {
+ return gMockAuthPrompt.QueryInterface(aIID);
+ }
+}
+
+
+var gMockAuthPrompt = {
+ password: "",
+
+ QueryInterface: XPCOMUtils.generateQI([Ci.nsIAuthPrompt]),
+
+ prompt: function MAP_prompt(aTitle, aText, aRealm, aSave,
+ aDefaultText) {
+ throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+ },
+
+ promptUsernameAndPassword: function
+ MAP_promptUsernameAndPassword(aTitle, aText, aRealm, aSave,
+ aUser, aPwd) {
+ throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+ },
+
+ promptPassword: function MAP_promptPassword(aTitle, aText,
+ aRealm, aSave,
+ aPwd) {
+ aPwd.value = this.password;
+ return true;
+ }
+};
+
var gMockPromptService = {
_registered: false,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPromptService]),
_will_return: null,
_inout_value: null,
_promptState: null,
_origFactory: null,
_promptCb: null,