author | Saurabh Anand <saurabhanandiit@gmail.com> |
Sat, 21 Jul 2012 11:21:30 +0530 | |
changeset 100015 | e68d8406541e1c18ce4d99362d5846304e3e57f3 |
parent 100014 | 53d053772879141ab879cb3026f8603c591d6518 |
child 100016 | 1a18d1d71ddf3cc99aa31eccd7386f7c8aef972a |
push id | 12300 |
push user | kwierso@gmail.com |
push date | Sat, 21 Jul 2012 06:38:36 +0000 |
treeherder | mozilla-inbound@8b28f53415fe [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 722995 |
milestone | 17.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/browser/components/privatebrowsing/test/browser/Makefile.in +++ b/browser/components/privatebrowsing/test/browser/Makefile.in @@ -16,16 +16,17 @@ MOCHITEST_BROWSER_FILES = \ browser_privatebrowsing_certexceptionsui.js \ browser_privatebrowsing_clearplugindata.js \ browser_privatebrowsing_clearplugindata.html \ browser_privatebrowsing_commandline_toggle.js \ browser_privatebrowsing_concurrent.js \ browser_privatebrowsing_concurrent_page.html \ browser_privatebrowsing_crh.js \ browser_privatebrowsing_downloadLastDir.js \ + browser_privatebrowsing_downloadLastDir_c.js \ browser_privatebrowsing_fastswitch.js \ browser_privatebrowsing_findbar.js \ browser_privatebrowsing_forgetthissite.js \ browser_privatebrowsing_geoprompt.js \ browser_privatebrowsing_geoprompt_page.html \ browser_privatebrowsing_import.js \ browser_privatebrowsing_lastpbcontextexited.js \ browser_privatebrowsing_localStorage.js \
new file mode 100644 --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_downloadLastDir_c.js @@ -0,0 +1,111 @@ +/* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +Cu.import("resource://gre/modules/DownloadLastDir.jsm"); +Cu.import("resource://gre/modules/FileUtils.jsm"); +Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://mochikit/MockFilePicker.jsm"); + +let pb = Cc["@mozilla.org/privatebrowsing;1"]. + getService(Ci.nsIPrivateBrowsingService); + +MockFilePicker.init(); +MockFilePicker.returnValue = Ci.nsIFilePicker.returnOK; + +function test() { + let stringBundleToRestore = ContentAreaUtils.stringBundle; + let validateFileNameToRestore = validateFileName; + + Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); + let prefs = Services.prefs.getBranch("browser.download."); + let tmpDir = FileUtils.getDir("TmpD", [], true); + function newDirectory() { + let dir = tmpDir.clone(); + dir.append("testdir"); + dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700); + return dir; + } + + function newFileInDirectory(dir) { + let file = dir.clone(); + file.append("testfile"); + file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600); + return file; + } + + let dir1 = newDirectory(); + let dir2 = newDirectory(); + let dir3 = newDirectory(); + let file1 = newFileInDirectory(dir1); + let file2 = newFileInDirectory(dir2); + let file3 = newFileInDirectory(dir3); + + // cleanup function registration + registerCleanupFunction(function () { + Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session"); + Services.prefs.clearUserPref("browser.download.lastDir"); + [dir1, dir2, dir3].forEach(function(dir) dir.remove(true)); + MockFilePicker.cleanup(); + ContentAreaUtils.stringBundle = stringBundleToRestore; + validateFileName = validateFileNameToRestore; + gDownloadLastDir.cleanupPrivateFile(); + delete FileUtils; + delete gDownloadLastDir; + }); + + // Overwrite stringBundle to return an object masquerading as a string bundle + delete ContentAreaUtils.stringBundle; + ContentAreaUtils.stringBundle = { + GetStringFromName: function() "" + }; + + // Overwrite validateFileName to validate everything + validateFileName = function(foo) foo; + + let params = { + fpTitleKey: "test", + fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"), + contentType: "text/plain", + saveMode: SAVEMODE_FILEONLY, + saveAsType: kSaveAsType_Complete, + file: null + }; + + prefs.setComplexValue("lastDir", Ci.nsIFile, tmpDir); + MockFilePicker.returnFiles = [file1]; + MockFilePicker.displayDirectory = null; + ok(getTargetFile(params), "Show the file picker dialog with given params"); + // file picker should start with browser.download.lastDir + is(MockFilePicker.displayDirectory.path, tmpDir.path, "file picker should start with browser.download.lastDir"); + // browser.download.lastDir should be modified before entering the private browsing mode + is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be modified before entering PB mode"); + // gDownloadLastDir should be usable outside of the private browsing mode + is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be usable outside of the PB mode"); + + pb.privateBrowsingEnabled = true; + is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should be that set before PB mode"); + MockFilePicker.returnFiles = [file2]; + MockFilePicker.displayDirectory = null; + ok(getTargetFile(params), "Show the file picker dialog with the given params"); + // file picker should start with browser.download.lastDir as set before entering the private browsing mode + is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before entering PB mode"); + // browser.download.lastDir should not be modified inside the private browsing mode + is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir1.path, "LastDir should not be modified inside PB mode"); + // but gDownloadLastDir should be modified + is(gDownloadLastDir.file.path, dir2.path, "gDownloadLastDir should be modified"); + + pb.privateBrowsingEnabled = false; + // gDownloadLastDir should be cleared after leaving the private browsing mode + is(gDownloadLastDir.file.path, dir1.path, "gDownloadLastDir should be cleared after leaving PB mode"); + MockFilePicker.returnFiles = [file3]; + MockFilePicker.displayDirectory = null; + ok(getTargetFile(params), "Show the file picker dialog with the given params"); + // file picker should start with browser.download.lastDir as set before entering the private browsing mode + is(MockFilePicker.displayDirectory.path, dir1.path, "File picker should start with LastDir set before PB mode"); + // browser.download.lastDir should be modified after leaving the private browsing mode + is(prefs.getComplexValue("lastDir", Ci.nsIFile).path, dir3.path, "LastDir should be modified after leaving PB mode"); + // gDownloadLastDir should be usable after leaving the private browsing mode + is(gDownloadLastDir.file.path, dir3.path, "gDownloadLastDir should be usable after leaving PB mode"); +}
deleted file mode 100644 --- a/toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -const Ci = Components.interfaces; -const Cc = Components.classes; - -function loadUtilsScript() { - let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. - getService(Ci.mozIJSSubScriptLoader); - loader.loadSubScript("chrome://global/content/contentAreaUtils.js"); - Components.utils.import("resource://gre/modules/DownloadLastDir.jsm"); -} - -do_get_profile(); - -let window = {}; -function run_test() -{ - let pb; - try { - pb = Cc["@mozilla.org/privatebrowsing;1"]. - getService(Ci.nsIPrivateBrowsingService); - } catch (e) { - print("PB service is not available, bail out"); - return; - } - - loadUtilsScript(); - - let prefsService = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - QueryInterface(Ci.nsIPrefBranch); - prefsService.setBoolPref("browser.privatebrowsing.keep_current_session", true); - let prefs = prefsService.getBranch("browser.download."); - let dirSvc = Cc["@mozilla.org/file/directory_service;1"]. - getService(Ci.nsIProperties); - let tmpDir = dirSvc.get("TmpD", Ci.nsILocalFile); - function newDirectory() { - let dir = tmpDir.clone(); - dir.append("testdir" + Math.floor(Math.random() * 10000)); - dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0700); - return dir; - } - function newFileInDirectory(dir) { - let file = dir.clone(); - file.append("testfile" + Math.floor(Math.random() * 10000)); - file.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0600); - return file; - } - let dir1 = newDirectory(); - let dir2 = newDirectory(); - let dir3 = newDirectory(); - let file1 = newFileInDirectory(dir1); - let file2 = newFileInDirectory(dir2); - let file3 = newFileInDirectory(dir3); - - // overwrite makeFilePicker, as we don't want to create a real filepicker object - let fp = { - appendFilter: function() {}, - appendFilters: function() {}, - init: function() {}, - show: function() Ci.nsIFilePicker.returnOK, - displayDirectory: null, - file: file1 - }; - makeFilePicker = function() fp; - - // Overwrite stringBundle to return an object masquerading as a string bundle - delete ContentAreaUtils.stringBundle; - ContentAreaUtils.stringBundle = { - GetStringFromName: function() "" - }; - - // Overwrite validateFileName to validate everything - validateFileName = function(foo) foo; - - let params = { - fpTitleKey: "test", - fileInfo: new FileInfo("test.txt", "test.txt", "test", "txt", "http://mozilla.org/test.txt"), - contentType: "text/plain", - saveMode: SAVEMODE_FILEONLY, - saveAsType: kSaveAsType_Complete, - file: null - }; - - prefs.setComplexValue("lastDir", Ci.nsILocalFile, tmpDir); - - do_check_true(getTargetFile(params)); - // file picker should start with browser.download.lastDir - do_check_eq(fp.displayDirectory.path, tmpDir.path); - // browser.download.lastDir should be modified before entering the private browsing mode - do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path); - // gDownloadLastDir should be usable outside of the private browsing mode - do_check_eq(gDownloadLastDir.file.path, dir1.path); - - pb.privateBrowsingEnabled = true; - do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path); - fp.file = file2; - fp.displayDirectory = null; - do_check_true(getTargetFile(params)); - // file picker should start with browser.download.lastDir as set before entering the private browsing mode - do_check_eq(fp.displayDirectory.path, dir1.path); - // browser.download.lastDir should not be modified inside the private browsing mode - do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir1.path); - // but gDownloadLastDir should be modified - do_check_eq(gDownloadLastDir.file.path, dir2.path); - - pb.privateBrowsingEnabled = false; - // gDownloadLastDir should be cleared after leaving the private browsing mode - do_check_eq(gDownloadLastDir.file.path, dir1.path); - fp.file = file3; - fp.displayDirectory = null; - do_check_true(getTargetFile(params)); - // file picker should start with browser.download.lastDir as set before entering the private browsing mode - do_check_eq(fp.displayDirectory.path, dir1.path); - // browser.download.lastDir should be modified after leaving the private browsing mode - do_check_eq(prefs.getComplexValue("lastDir", Ci.nsILocalFile).path, dir3.path); - // gDownloadLastDir should be usable after leaving the private browsing mode - do_check_eq(gDownloadLastDir.file.path, dir3.path); - - // cleanup - Cc["@mozilla.org/observer-service;1"] - .getService(Ci.nsIObserverService) - .notifyObservers(null, "quit-application", null); - - prefsService.clearUserPref("browser.privatebrowsing.keep_current_session"); - [dir1, dir2, dir3].forEach(function(dir) dir.remove(true)); -}