diff --git a/data/lib/mailapi/pop3/sync.js b/data/lib/mailapi/pop3/sync.js index 7b47fb38..876706aa 100644 --- a/data/lib/mailapi/pop3/sync.js +++ b/data/lib/mailapi/pop3/sync.js @@ -41,6 +41,13 @@ function lazyWithConnection(getNew, cbIndex, fn) { var args = Array.slice(arguments); require([], function () { var next = function() { + // Only the inbox actually needs a connection. Using the + // connection in a non-inbox folder is an error. + if (!this.isInbox) { + fn.apply(this, [null].concat(args)); + return; + } + this.account.withConnection(function (err, conn, done) { var callback = args[cbIndex]; if (err) { diff --git a/test/test-files.json b/test/test-files.json index 75a97008..88f90d83 100644 --- a/test/test-files.json +++ b/test/test-files.json @@ -99,6 +99,10 @@ "variants": ["pop3:fake"] }, + "test_pop3_connection_use.js": { + "variants": ["pop3:fake"] + }, + "test_activesync_recreate.js": { "variants": ["activesync:fake"] }, diff --git a/test/unit/test_pop3_connection_use.js b/test/unit/test_pop3_connection_use.js new file mode 100644 index 00000000..21daaec6 --- /dev/null +++ b/test/unit/test_pop3_connection_use.js @@ -0,0 +1,56 @@ +/** + * Make sure POP3 only opens a connection for the inbox. + **/ + +define(['rdcommon/testcontext', './resources/th_main', + 'wbxml', 'activesync/codepages', + 'exports'], + function($tc, $th_main, $wbxml, $ascp, exports) { + +var TD = exports.TD = $tc.defineTestsFor( + { id: 'test_pop3_connection_use' }, null, + [$th_main.TESTHELPER], ['app']); + +TD.commonCase('connection use', function(T, RT) { + T.group('setup'); + var testUniverse = T.actor('testUniverse', 'U'); + var testAccount = T.actor('testAccount', 'A', { universe: testUniverse }); + var eSync = T.lazyLogger('sync'); + + var trashFolder = testAccount.do_useExistingFolderWithType('trash', ''); + var inboxFolder = testAccount.do_useExistingFolderWithType('inbox', ''); + + T.action('close existing connection', function() { + testAccount.folderAccount._conn.disconnect(); + }); + + // Trash must not create a connection. + testAccount.do_openFolderView( + 'opens', trashFolder, + { count: 0, full: 0 }, + { top: true, bottom: true, grow: false, newCount: null }, + { + expectFunc: function() { + RT.reportActiveActorThisStep(testAccount.eFolderAccount); + testAccount.eFolderAccount.ignore_saveAccountState(); + } + }); + + // Inbox must create a connection. + testAccount.do_openFolderView( + 'opens', inboxFolder, + { count: 0, full: 0 }, + { top: true, bottom: true, grow: false, newCount: null }, + { syncedToDawnOfTime: true, + expectFunc: function() { + RT.reportActiveActorThisStep(testAccount.eFolderAccount); + testAccount.eFolderAccount.expect_createConnection(); + testAccount.eFolderAccount.ignore_saveAccountState(); + } + }); + + + T.group('cleanup'); +}); + +}); // end define