Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | function test() { |
michael@0 | 7 | waitForExplicitFinish(); |
michael@0 | 8 | |
michael@0 | 9 | let FileUtils = |
michael@0 | 10 | Cu.import("resource://gre/modules/FileUtils.jsm", {}).FileUtils; |
michael@0 | 11 | let DownloadLastDir = |
michael@0 | 12 | Cu.import("resource://gre/modules/DownloadLastDir.jsm", {}).DownloadLastDir; |
michael@0 | 13 | |
michael@0 | 14 | let tmpDir = FileUtils.getDir("TmpD", [], true); |
michael@0 | 15 | let dir1 = newDirectory(); |
michael@0 | 16 | |
michael@0 | 17 | registerCleanupFunction(function () { |
michael@0 | 18 | Services.prefs.clearUserPref("browser.download.lastDir"); |
michael@0 | 19 | dir1.remove(true); |
michael@0 | 20 | }); |
michael@0 | 21 | |
michael@0 | 22 | function testOnWindow(aPrivate, aCallback) { |
michael@0 | 23 | whenNewWindowLoaded({private: aPrivate}, function(win) { |
michael@0 | 24 | let gDownloadLastDir = new DownloadLastDir(win); |
michael@0 | 25 | aCallback(win, gDownloadLastDir); |
michael@0 | 26 | gDownloadLastDir.cleanupPrivateFile(); |
michael@0 | 27 | win.close(); |
michael@0 | 28 | }); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function checkDownloadLastDirInit(aWin, gDownloadLastDir, aCallback) { |
michael@0 | 32 | is(typeof gDownloadLastDir, "object", |
michael@0 | 33 | "gDownloadLastDir should be a valid object"); |
michael@0 | 34 | is(gDownloadLastDir.file, null, |
michael@0 | 35 | "gDownloadLastDir.file should be null to start with"); |
michael@0 | 36 | |
michael@0 | 37 | gDownloadLastDir.file = tmpDir; |
michael@0 | 38 | is(gDownloadLastDir.file.path, tmpDir.path, |
michael@0 | 39 | "LastDir should point to the temporary directory"); |
michael@0 | 40 | isnot(gDownloadLastDir.file, tmpDir, |
michael@0 | 41 | "gDownloadLastDir.file should not be pointing to the tmpDir"); |
michael@0 | 42 | |
michael@0 | 43 | gDownloadLastDir.file = 1; // not an nsIFile |
michael@0 | 44 | is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null"); |
michael@0 | 45 | |
michael@0 | 46 | gDownloadLastDir.file = tmpDir; |
michael@0 | 47 | clearHistory(); |
michael@0 | 48 | is(gDownloadLastDir.file, null, "gDownloadLastDir.file should be null"); |
michael@0 | 49 | |
michael@0 | 50 | gDownloadLastDir.file = tmpDir; |
michael@0 | 51 | aCallback(); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function checkDownloadLastDir(aWin, gDownloadLastDir, aLastDir, aUpdate, aCallback) { |
michael@0 | 55 | if (aUpdate) |
michael@0 | 56 | gDownloadLastDir.file = aLastDir; |
michael@0 | 57 | is(gDownloadLastDir.file.path, aLastDir.path, |
michael@0 | 58 | "gDownloadLastDir should point to the expected last directory"); |
michael@0 | 59 | isnot(gDownloadLastDir.file, aLastDir, |
michael@0 | 60 | "gDownloadLastDir.file should not be pointing to the last directory"); |
michael@0 | 61 | aCallback(); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | function checkDownloadLastDirNull(aWin, gDownloadLastDir, aCallback) { |
michael@0 | 65 | is(gDownloadLastDir.file, null, "gDownloadLastDir should be null"); |
michael@0 | 66 | aCallback(); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | testOnWindow(false, function(win, downloadDir) { |
michael@0 | 70 | checkDownloadLastDirInit(win, downloadDir, function() { |
michael@0 | 71 | testOnWindow(true, function(win, downloadDir) { |
michael@0 | 72 | checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { |
michael@0 | 73 | testOnWindow(false, function(win, downloadDir) { |
michael@0 | 74 | checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { |
michael@0 | 75 | testOnWindow(true, function(win, downloadDir) { |
michael@0 | 76 | checkDownloadLastDir(win, downloadDir, dir1, true, function() { |
michael@0 | 77 | testOnWindow(false, function(win, downloadDir) { |
michael@0 | 78 | checkDownloadLastDir(win, downloadDir, tmpDir, false, function() { |
michael@0 | 79 | testOnWindow(true, function(win, downloadDir) { |
michael@0 | 80 | clearHistory(); |
michael@0 | 81 | checkDownloadLastDirNull(win, downloadDir, function() { |
michael@0 | 82 | testOnWindow(false, function(win, downloadDir) { |
michael@0 | 83 | checkDownloadLastDirNull(win, downloadDir, finish); |
michael@0 | 84 | }); |
michael@0 | 85 | }); |
michael@0 | 86 | }); |
michael@0 | 87 | }); |
michael@0 | 88 | }); |
michael@0 | 89 | }); |
michael@0 | 90 | }); |
michael@0 | 91 | }); |
michael@0 | 92 | }); |
michael@0 | 93 | }); |
michael@0 | 94 | }); |
michael@0 | 95 | }); |
michael@0 | 96 | }); |
michael@0 | 97 | } |