mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1194893 - Pref for default file upload directory. r=smaug
--HG-- extra : rebase_source : dafc24f3ed145ab406f77a82e2ec8162d695f134
This commit is contained in:
parent
1a97b60af0
commit
f97631d0c3
@ -295,20 +295,25 @@ NS_IMPL_ISUPPORTS(UploadLastDir::ContentPrefCallback, nsIContentPrefCallback2)
|
||||
NS_IMETHODIMP
|
||||
UploadLastDir::ContentPrefCallback::HandleCompletion(uint16_t aReason)
|
||||
{
|
||||
nsCOMPtr<nsIFile> localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
NS_ENSURE_STATE(localFile);
|
||||
nsCOMPtr<nsIFile> localFile;
|
||||
nsAutoString prefStr;
|
||||
|
||||
if (aReason == nsIContentPrefCallback2::COMPLETE_ERROR ||
|
||||
!mResult) {
|
||||
// Default to "desktop" directory for each platform
|
||||
nsCOMPtr<nsIFile> homeDir;
|
||||
NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(homeDir));
|
||||
localFile = do_QueryInterface(homeDir);
|
||||
} else {
|
||||
nsAutoString prefStr;
|
||||
nsCOMPtr<nsIVariant> pref;
|
||||
mResult->GetValue(getter_AddRefs(pref));
|
||||
pref->GetAsAString(prefStr);
|
||||
if (aReason == nsIContentPrefCallback2::COMPLETE_ERROR || !mResult) {
|
||||
prefStr = Preferences::GetString("dom.input.fallbackUploadDir");
|
||||
if (prefStr.IsEmpty()) {
|
||||
// If no custom directory was set through the pref, default to
|
||||
// "desktop" directory for each platform.
|
||||
NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(localFile));
|
||||
}
|
||||
}
|
||||
|
||||
if (!localFile) {
|
||||
if (prefStr.IsEmpty() && mResult) {
|
||||
nsCOMPtr<nsIVariant> pref;
|
||||
mResult->GetValue(getter_AddRefs(pref));
|
||||
pref->GetAsAString(prefStr);
|
||||
}
|
||||
localFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
|
||||
localFile->InitWithPath(prefStr);
|
||||
}
|
||||
|
||||
|
@ -600,3 +600,5 @@ skip-if = buildapp == 'b2g' # bug 1129014
|
||||
[test_image_clone_load.html]
|
||||
[test_bug1203668.html]
|
||||
[test_bug1166138.html]
|
||||
[test_filepicker_default_directory.html]
|
||||
skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android'
|
||||
|
83
dom/html/test/test_filepicker_default_directory.html
Normal file
83
dom/html/test/test_filepicker_default_directory.html
Normal file
@ -0,0 +1,83 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=1194893
|
||||
-->
|
||||
<head>
|
||||
<title>Test for filepicker default directory</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1194893">Mozilla Bug 1194893</a>
|
||||
<div id="content">
|
||||
<input type="file" id="f">
|
||||
</div>
|
||||
<pre id="text">
|
||||
<script class="testbody" type="application/javascript">
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
const { Cc: Cc, Ci: Ci } = SpecialPowers;
|
||||
|
||||
// Platform-independent directory names are #define'd in xpcom/io/nsDirectoryServiceDefs.h
|
||||
var defaultUploadDirectory = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIDirectoryService)
|
||||
.QueryInterface(Ci.nsIProperties)
|
||||
.get("Desk", Ci.nsIFile);
|
||||
|
||||
// When we want to test an upload directory other than the default, we need to
|
||||
// get a valid directory in a platform-independent way. Since NS_OS_DESKTOP_DIR
|
||||
// may fallback to NS_OS_HOME_DIR, let's use NS_OS_TMP_DIR.
|
||||
var customUploadDirectory = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIDirectoryService)
|
||||
.QueryInterface(Ci.nsIProperties)
|
||||
.get("TmpD", Ci.nsIFile);
|
||||
|
||||
// Useful for debugging
|
||||
//info("defaultUploadDirectory" + defaultUploadDirectory.path);
|
||||
//info("customUploadDirectory" + customUploadDirectory.path);
|
||||
|
||||
var MockFilePicker = SpecialPowers.MockFilePicker;
|
||||
MockFilePicker.init(window);
|
||||
|
||||
// need to show the MockFilePicker so .displayDirectory gets set
|
||||
var f = document.getElementById("f");
|
||||
f.focus();
|
||||
|
||||
var testIndex = 0;
|
||||
var tests = [
|
||||
["", defaultUploadDirectory.path],
|
||||
[customUploadDirectory.path, customUploadDirectory.path]
|
||||
]
|
||||
|
||||
MockFilePicker.showCallback = function(filepicker) {
|
||||
info(SpecialPowers.wrap(MockFilePicker).displayDirectory.path);
|
||||
|
||||
is(SpecialPowers.wrap(MockFilePicker).displayDirectory.path,
|
||||
tests[testIndex][1]);
|
||||
|
||||
if (++testIndex == tests.length) {
|
||||
MockFilePicker.cleanup();
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
launchNextTest();
|
||||
}
|
||||
}
|
||||
|
||||
function launchNextTest() {
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{ 'set': [
|
||||
['dom.input.fallbackUploadDir', tests[testIndex][0]],
|
||||
]},
|
||||
function () {
|
||||
f.click();
|
||||
});
|
||||
}
|
||||
|
||||
launchNextTest();
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -5131,3 +5131,6 @@ pref("dom.mozKillSwitch.enabled", false);
|
||||
pref("toolkit.pageThumbs.screenSizeDivisor", 7);
|
||||
pref("toolkit.pageThumbs.minWidth", 0);
|
||||
pref("toolkit.pageThumbs.minHeight", 0);
|
||||
|
||||
// Allow customization of the fallback directory for file uploads
|
||||
pref("dom.input.fallbackUploadDir", "");
|
||||
|
Loading…
Reference in New Issue
Block a user