diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index 7df366fb744..3fa3d61d569 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -1551,6 +1551,19 @@ nsDownloadManager::CleanUp() rv = stmt->Execute(); NS_ENSURE_SUCCESS(rv, rv); + // privacy cleanup, if there's an old downloads.rdf around, just delete it + nsCOMPtr oldDownloadsFile; + rv = NS_GetSpecialDirectory(NS_APP_DOWNLOADS_50_FILE, + getter_AddRefs(oldDownloadsFile)); + + if (NS_FAILED(rv)) return rv; + + PRBool fileExists; + if (NS_SUCCEEDED(oldDownloadsFile->Exists(&fileExists)) && fileExists) { + rv = oldDownloadsFile->Remove(PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + } + // Notify the UI with the topic and null subject to indicate "remove all" return mObserverService->NotifyObservers(nsnull, "download-manager-remove-download", diff --git a/toolkit/components/downloads/test/unit/test_bug_329741.js b/toolkit/components/downloads/test/unit/test_bug_329741.js new file mode 100644 index 00000000000..64455aa1c2e --- /dev/null +++ b/toolkit/components/downloads/test/unit/test_bug_329741.js @@ -0,0 +1,72 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Download Manager Test Code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mike Connor (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// This tests the cleanup code to make sure we properly remove old downloads.rdf files +// when clearing data. + +function cleanup() +{ + // removing rdf + var rdfFile = dirSvc.get("DLoads", Ci.nsIFile); + if (rdfFile.exists()) rdfFile.remove(true); + + // removing database + var dbFile = dirSvc.get("ProfD", Ci.nsIFile); + dbFile.append("downloads.sqlite"); + if (dbFile.exists()) + try { dbFile.remove(true); } catch(e) { /* stupid windows box */ } +} + +cleanup(); + +importDownloadsFile("bug_381535_downloads.rdf"); +importDownloadsFile("bug_409179_downloads.sqlite"); + +function run_test() +{ + var rdfFile = dirSvc.get("DLoads", Ci.nsIFile); + do_check_true(rdfFile.exists()); + + var dm = Cc["@mozilla.org/download-manager;1"]. + getService(Ci.nsIDownloadManager); + + dm.cleanUp(); + + do_check_false(rdfFile.exists()); + + cleanup(); +} diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index 67dfab0bded..4149f4e765b 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -3799,6 +3799,19 @@ nsNavHistory::RemoveAllPages() nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING("VACUUM")); NS_ENSURE_SUCCESS(rv, rv); #endif + + // privacy cleanup, if there's an old history.dat around, just delete it + nsCOMPtr oldHistoryFile; + nsresult rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE, + getter_AddRefs(oldHistoryFile)); + if (NS_FAILED(rv)) return rv; + + PRBool fileExists; + if (NS_SUCCEEDED(oldHistoryFile->Exists(&fileExists)) && fileExists) { + rv = oldHistoryFile->Remove(PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + } + return NS_OK; } diff --git a/toolkit/components/places/tests/unit/history.dat b/toolkit/components/places/tests/unit/history.dat new file mode 100644 index 00000000000..c10e7ee0710 --- /dev/null +++ b/toolkit/components/places/tests/unit/history.dat @@ -0,0 +1 @@ +// < <(a=c)> // (f=iso-8859-1) (8A=Typed)(8B=LastPageVisited)(8C=ByteOrder) (80=ns:history:db:row:scope:history:all) (81=ns:history:db:table:kind:history)(82=URL)(83=Referrer) (84=LastVisitDate)(85=FirstVisitDate)(86=VisitCount)(87=Name) (88=Hostname)(89=Hidden)> <(80=LE)(81=http://en-us.www.mozilla.com/en-US/firefox/2.0.0.12/whatsnew/) (82=1205364946314923)(83=en-us.www.mozilla.com)(84 =F$00i$00r$00e$00f$00o$00x$00 $00U$00p$00d$00a$00t$00e$00d$00)> {1:^80 {(k^81:c)(s=9)[1(^8C=LE)]} [2(^82^81)(^84^82)(^85^82)(^88^83)(^87^84)]} @$${2{@ @$$}2}@ \ No newline at end of file diff --git a/toolkit/components/places/tests/unit/test_history.js b/toolkit/components/places/tests/unit/test_history.js index fd25d6b8706..8b1424f53b6 100644 --- a/toolkit/components/places/tests/unit/test_history.js +++ b/toolkit/components/places/tests/unit/test_history.js @@ -223,4 +223,16 @@ function run_test() { do_check_false(uri_in_db(referrerURI)); add_visit(uri("http://mozilla.com"), referrerURI); do_check_true(uri_in_db(referrerURI)); + + // test to ensure history.dat gets deleted if all history is being cleared + var file = do_get_file("toolkit/components/places/tests/unit/history.dat"); + var histFile = dirSvc.get("ProfD", Ci.nsIFile); + file.copyTo(histFile, "history.dat"); + histFile.append("history.dat"); + do_check_true(histFile.exists()); + + var globalHistory = Components.classes["@mozilla.org/browser/global-history;2"] + .getService(Components.interfaces.nsIBrowserHistory); + globalHistory.removeAllPages(); + do_check_false(histFile.exists()); } diff --git a/toolkit/components/satchel/Makefile.in b/toolkit/components/satchel/Makefile.in index 3da53990bac..2844f4a7412 100644 --- a/toolkit/components/satchel/Makefile.in +++ b/toolkit/components/satchel/Makefile.in @@ -42,6 +42,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = public src +DIRS = public src test include $(topsrcdir)/config/rules.mk diff --git a/toolkit/components/satchel/src/nsStorageFormHistory.cpp b/toolkit/components/satchel/src/nsStorageFormHistory.cpp index 77ee0676fa9..0f22c92b066 100644 --- a/toolkit/components/satchel/src/nsStorageFormHistory.cpp +++ b/toolkit/components/satchel/src/nsStorageFormHistory.cpp @@ -315,6 +315,21 @@ nsFormHistory::RemoveAllEntries() getter_AddRefs(dbDeleteAll)); NS_ENSURE_SUCCESS(rv,rv); + // privacy cleanup, if there's an old mork formhistory around, just delete it + nsCOMPtr oldFormHistoryFile; + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, + getter_AddRefs(oldFormHistoryFile)); + if (NS_FAILED(rv)) return rv; + + rv = oldFormHistoryFile->Append(NS_LITERAL_STRING("formhistory.dat")); + NS_ENSURE_SUCCESS(rv, rv); + + PRBool fileExists; + if (NS_SUCCEEDED(oldFormHistoryFile->Exists(&fileExists)) && fileExists) { + rv = oldFormHistoryFile->Remove(PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + } + return dbDeleteAll->Execute(); } diff --git a/toolkit/components/satchel/test/Makefile.in b/toolkit/components/satchel/test/Makefile.in new file mode 100644 index 00000000000..75d5ac48758 --- /dev/null +++ b/toolkit/components/satchel/test/Makefile.in @@ -0,0 +1,53 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is Mozilla code. +# +# The Initial Developer of the Original Code is +# Mozilla Corporation. +# Portions created by the Initial Developer are Copyright (C) 2008 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Shawn Wilsher (Original Author) +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = test_satchel + +XPCSHELL_TESTS = \ + unit \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + diff --git a/toolkit/components/satchel/test/unit/formhistory.dat b/toolkit/components/satchel/test/unit/formhistory.dat new file mode 100644 index 00000000000..2cdfce75664 --- /dev/null +++ b/toolkit/components/satchel/test/unit/formhistory.dat @@ -0,0 +1 @@ +// < <(a=c)> // (f=iso-8859-1) (80=ns:formhistory:db:row:scope:formhistory:all) (81=ns:formhistory:db:table:kind:formhistory)(82=Value)(83=Name) (84=ByteOrder)> <(80=llll)(81=q$00)(82=f$00o$00o$00)> {1:^80 {(k^81:c)(s=9)[1(^84^80)]} [2(^83^81)(^82^82)]} \ No newline at end of file diff --git a/toolkit/components/satchel/test/unit/head_satchel.js b/toolkit/components/satchel/test/unit/head_satchel.js new file mode 100644 index 00000000000..90eb4c986b3 --- /dev/null +++ b/toolkit/components/satchel/test/unit/head_satchel.js @@ -0,0 +1,78 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Form Autocomplete Test Code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mike Connor (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const Ci = Components.interfaces; +const Cc = Components.classes; +var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. + getService(Ci.nsIProperties); + +var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. + getService(Ci.nsIProperties); +var profileDir = null; +try { + profileDir = dirSvc.get("ProfD", Ci.nsIFile); +} catch (e) { } +if (!profileDir) { + // Register our own provider for the profile directory. + // It will simply return the current directory. + var provider = { + getFile: function(prop, persistent) { + persistent.value = true; + if (prop == "ProfD") { + return dirSvc.get("CurProcD", Ci.nsILocalFile); + } + print("*** Throwing trying to get " + prop); + throw Cr.NS_ERROR_FAILURE; + }, + QueryInterface: function(iid) { + if (iid.equals(Ci.nsIDirectoryProvider) || + iid.equals(Ci.nsISupports)) { + return this; + } + throw Cr.NS_ERROR_NO_INTERFACE; + } + }; + dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider); +} + +function cleanUpFormHist() { + var formhistFile = dirSvc.get("ProfD", Ci.nsIFile); + formhistFile.append("formhistory.dat"); + if (formhistFile.exists()) + formhistFile.remove(); +} +cleanUpFormHist(); diff --git a/toolkit/components/satchel/test/unit/test_bug_329741.js b/toolkit/components/satchel/test/unit/test_bug_329741.js new file mode 100644 index 00000000000..1eca12c3d4d --- /dev/null +++ b/toolkit/components/satchel/test/unit/test_bug_329741.js @@ -0,0 +1,54 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Satchel Test Code. + * + * The Initial Developer of the Original Code is + * Mozilla Corporation. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Mike Connor (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// Test to make sure we drop formhistory.dat when clearing form logins + + + +function run_test() +{ + var file = do_get_file("toolkit/components/satchel/test/unit/formhistory.dat"); + var formhistFile = dirSvc.get("ProfD", Ci.nsIFile); + file.copyTo(formhistFile, "formhistory.dat"); + formhistFile.append("formhistory.dat"); + do_check_true(formhistFile.exists()); + + var formHistory = Cc["@mozilla.org/satchel/form-history;1"]. + getService(Ci.nsIFormHistory2); + formHistory.removeAllEntries(); + do_check_false(formhistFile.exists()); +}