mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 464947 - Clear Recent History dialog should clear form data by timespan. r=mconnor
This commit is contained in:
parent
774dc6063b
commit
edf221eb5a
@ -230,7 +230,10 @@ Sanitizer.prototype = {
|
||||
|
||||
var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
||||
.getService(Components.interfaces.nsIFormHistory2);
|
||||
formHistory.removeAllEntries();
|
||||
if (this.range)
|
||||
formHistory.removeEntriesByTimeframe(this.range[0], this.range[1]);
|
||||
else
|
||||
formHistory.removeAllEntries();
|
||||
},
|
||||
|
||||
get canClear()
|
||||
|
@ -4,6 +4,7 @@ var now_uSec = Date.now() * 1000;
|
||||
const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
|
||||
const bhist = Cc["@mozilla.org/browser/global-history;2"].getService(Ci.nsIBrowserHistory);
|
||||
const iosvc = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||
const formhist = Cc["@mozilla.org/satchel/form-history;1"].getService(Ci.nsIFormHistory2);
|
||||
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader)
|
||||
.loadSubScript("chrome://browser/content/sanitize.js");
|
||||
@ -13,6 +14,7 @@ function test() {
|
||||
var hoursSinceMidnight = new Date().getHours();
|
||||
|
||||
setupHistory();
|
||||
setupFormHistory();
|
||||
setupDownloads();
|
||||
|
||||
// Should test cookies here, but nsICookieManager/nsICookieService
|
||||
@ -28,7 +30,7 @@ function test() {
|
||||
itemPrefs.setBoolPref("downloads", true);
|
||||
itemPrefs.setBoolPref("cache", false);
|
||||
itemPrefs.setBoolPref("cookies", false);
|
||||
itemPrefs.setBoolPref("formdata", false);
|
||||
itemPrefs.setBoolPref("formdata", true);
|
||||
itemPrefs.setBoolPref("offlineApps", false);
|
||||
itemPrefs.setBoolPref("passwords", false);
|
||||
itemPrefs.setBoolPref("sessions", false);
|
||||
@ -46,6 +48,13 @@ function test() {
|
||||
ok(bhist.isVisited(uri("http://today.com")), "Pretend visit to today.com should still exist");
|
||||
ok(bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should still exist");
|
||||
|
||||
ok(!formhist.nameExists("1hour"), "1hour form entry should be deleted");
|
||||
ok(formhist.nameExists("2hour"), "2hour form entry should still exist");
|
||||
ok(formhist.nameExists("4hour"), "4hour form entry should still exist");
|
||||
if(hoursSinceMidnight > 1)
|
||||
ok(formhist.nameExists("today"), "today form entry should still exist");
|
||||
ok(formhist.nameExists("b4today"), "b4today form entry should still exist");
|
||||
|
||||
ok(!downloadExists(5555551), "<1 hour download should now be deleted");
|
||||
ok(downloadExists(5555550), "Year old download should still be present");
|
||||
ok(downloadExists(5555552), "<2 hour old download should still be present");
|
||||
@ -64,6 +73,13 @@ function test() {
|
||||
ok(bhist.isVisited(uri("http://today.com")), "Pretend visit to today.com should still exist");
|
||||
ok(bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should still exist");
|
||||
|
||||
ok(!formhist.nameExists("2hour"), "2hour form entry should be deleted");
|
||||
ok(formhist.nameExists("4hour"), "4hour form entry should still exist");
|
||||
if(hoursSinceMidnight > 2)
|
||||
ok(formhist.nameExists("today"), "today form entry should still exist");
|
||||
ok(formhist.nameExists("b4today"), "b4today form entry should still exist");
|
||||
|
||||
ok(formhist.nameExists("b4today"), "b4today form entry should still exist");
|
||||
ok(!downloadExists(5555552), "<2 hour old download should now be deleted");
|
||||
ok(downloadExists(5555550), "Year old download should still be present");
|
||||
ok(downloadExists(5555553), "<4 hour old download should still be present");
|
||||
@ -79,6 +95,11 @@ function test() {
|
||||
ok(bhist.isVisited(uri("http://today.com")), "Pretend visit to today.com should still exist");
|
||||
ok(bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should still exist");
|
||||
|
||||
ok(!formhist.nameExists("4hour"), "4hour form entry should be deleted");
|
||||
if(hoursSinceMidnight > 4)
|
||||
ok(formhist.nameExists("today"), "today form entry should still exist");
|
||||
ok(formhist.nameExists("b4today"), "b4today form entry should still exist");
|
||||
|
||||
ok(!downloadExists(5555553), "<4 hour old download should now be deleted");
|
||||
ok(downloadExists(5555550), "Year old download should still be present");
|
||||
if(hoursSinceMidnight > 4)
|
||||
@ -91,6 +112,9 @@ function test() {
|
||||
ok(!bhist.isVisited(uri("http://today.com")), "Pretend visit to today.com should now be deleted");
|
||||
ok(bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should still exist");
|
||||
|
||||
ok(!formhist.nameExists("today"), "today form entry should be deleted");
|
||||
ok(formhist.nameExists("b4today"), "b4today form entry should still exist");
|
||||
|
||||
ok(!downloadExists(5555554), "'Today' download should now be deleted");
|
||||
ok(downloadExists(5555550), "Year old download should still be present");
|
||||
|
||||
@ -99,6 +123,8 @@ function test() {
|
||||
s.sanitize();
|
||||
|
||||
ok(!bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should now be deleted");
|
||||
|
||||
ok(!formhist.nameExists("b4today"), "b4today form entry should be deleted");
|
||||
|
||||
ok(!downloadExists(5555550), "Year old download should now be deleted");
|
||||
|
||||
@ -116,7 +142,7 @@ function setupHistory() {
|
||||
bhist.addPageWithDetails(uri("http://today.com/"), "Today", today.valueOf() * 1000);
|
||||
|
||||
let lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.year - 1);
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
bhist.addPageWithDetails(uri("http://before-today.com/"), "Before Today", lastYear.valueOf() * 1000);
|
||||
|
||||
// Confirm everything worked
|
||||
@ -127,6 +153,51 @@ function setupHistory() {
|
||||
ok(bhist.isVisited(uri("http://before-today.com")), "Pretend visit to before-today.com should exist");
|
||||
}
|
||||
|
||||
function setupFormHistory() {
|
||||
// Make sure we've got a clean DB to start with.
|
||||
formhist.removeAllEntries();
|
||||
|
||||
// Add the entries we'll be testing.
|
||||
formhist.addEntry("1hour", "1h");
|
||||
formhist.addEntry("2hour", "2h");
|
||||
formhist.addEntry("4hour", "4h");
|
||||
formhist.addEntry("today", "1d");
|
||||
formhist.addEntry("b4today", "1y");
|
||||
|
||||
// Artifically age the entries to the proper vintage.
|
||||
let db = formhist.DBConnection;
|
||||
let timestamp = now_uSec - 45*60*1000000;
|
||||
db.executeSimpleSQL("UPDATE moz_formhistory SET firstUsed = " +
|
||||
timestamp + " WHERE fieldname = '1hour'");
|
||||
timestamp = now_uSec - 90*60*1000000;
|
||||
db.executeSimpleSQL("UPDATE moz_formhistory SET firstUsed = " +
|
||||
timestamp + " WHERE fieldname = '2hour'");
|
||||
timestamp = now_uSec - 180*60*1000000;
|
||||
db.executeSimpleSQL("UPDATE moz_formhistory SET firstUsed = " +
|
||||
timestamp + " WHERE fieldname = '4hour'");
|
||||
|
||||
let today = new Date();
|
||||
today.setHours(0);
|
||||
today.setMinutes(0);
|
||||
today.setSeconds(1);
|
||||
timestamp = today.valueOf() * 1000;
|
||||
db.executeSimpleSQL("UPDATE moz_formhistory SET firstUsed = " +
|
||||
timestamp + " WHERE fieldname = 'today'");
|
||||
|
||||
let lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
timestamp = lastYear.valueOf() * 1000;
|
||||
db.executeSimpleSQL("UPDATE moz_formhistory SET firstUsed = " +
|
||||
timestamp + " WHERE fieldname = 'b4today'");
|
||||
|
||||
// Sanity check.
|
||||
ok(formhist.nameExists("1hour"), "Checking for 1hour form history entry creation");
|
||||
ok(formhist.nameExists("2hour"), "Checking for 2hour form history entry creation");
|
||||
ok(formhist.nameExists("4hour"), "Checking for 4hour form history entry creation");
|
||||
ok(formhist.nameExists("today"), "Checking for today form history entry creation");
|
||||
ok(formhist.nameExists("b4today"), "Checking for b4today form history entry creation");
|
||||
}
|
||||
|
||||
function setupDownloads() {
|
||||
|
||||
// Add within-1-hour download to DB
|
||||
@ -226,7 +297,7 @@ function setupDownloads() {
|
||||
|
||||
// Add "before today" download
|
||||
let lastYear = new Date();
|
||||
lastYear.setFullYear(lastYear.year - 1);
|
||||
lastYear.setFullYear(lastYear.getFullYear() - 1);
|
||||
data = {
|
||||
id: "5555550",
|
||||
name: "fakefile-old",
|
||||
|
@ -50,7 +50,7 @@ interface mozIStorageConnection;
|
||||
* autocomplete matches.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(d73f5924-3e39-4c67-8f4a-290b85448480)]
|
||||
[scriptable, uuid(5d7d84d1-9798-4016-bf61-a32acf09b29d)]
|
||||
interface nsIFormHistory2 : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -88,6 +88,16 @@ interface nsIFormHistory2 : nsISupports
|
||||
*/
|
||||
boolean entryExists(in AString name, in AString value);
|
||||
|
||||
/**
|
||||
* Removes entries that were created between the specified times.
|
||||
*
|
||||
* @param aBeginTime
|
||||
* The beginning of the timeframe, in microseconds
|
||||
* @param aEndTime
|
||||
* The end of the timeframe, in microseconds
|
||||
*/
|
||||
void removeEntriesByTimeframe(in long long aBeginTime, in long long aEndTime);
|
||||
|
||||
/**
|
||||
* Returns the underlying DB connection the form history module is using.
|
||||
*/
|
||||
|
@ -215,6 +215,12 @@ nsFormHistory::RemoveAllEntries()
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormHistory::RemoveEntriesByTimeframe(PRInt64 aStartTime, PRInt64 aEndTime)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormHistory::GetDBConnection()
|
||||
{
|
||||
|
@ -412,6 +412,27 @@ nsFormHistory::RemoveAllEntries()
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormHistory::RemoveEntriesByTimeframe(PRInt64 aStartTime, PRInt64 aEndTime)
|
||||
{
|
||||
nsCOMPtr<mozIStorageStatement> stmt;
|
||||
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
||||
"DELETE FROM moz_formhistory "
|
||||
"WHERE firstUsed >= ?1 "
|
||||
"AND firstUsed <= ?2"), getter_AddRefs(stmt));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Bind the times and execute statement.
|
||||
rv = stmt->BindInt64Parameter(0, aStartTime);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = stmt->BindInt64Parameter(1, aEndTime);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = stmt->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFormHistory::GetDBConnection(mozIStorageConnection **aResult)
|
||||
{
|
||||
|
BIN
toolkit/components/satchel/test/unit/formhistory_apitest.sqlite
Normal file
BIN
toolkit/components/satchel/test/unit/formhistory_apitest.sqlite
Normal file
Binary file not shown.
158
toolkit/components/satchel/test/unit/test_history_api.js
Normal file
158
toolkit/components/satchel/test/unit/test_history_api.js
Normal file
@ -0,0 +1,158 @@
|
||||
/* ***** 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):
|
||||
* Justin Dolske <dolske@mozilla.com> (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 ***** */
|
||||
|
||||
var testnum = 0;
|
||||
var fh;
|
||||
|
||||
function run_test()
|
||||
{
|
||||
try {
|
||||
|
||||
// ===== test init =====
|
||||
var testfile = do_get_file("toolkit/components/satchel/test/unit/formhistory_apitest.sqlite");
|
||||
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
|
||||
|
||||
// Cleanup from any previous tests or failures.
|
||||
var destFile = profileDir.clone();
|
||||
destFile.append("formhistory.sqlite");
|
||||
if (destFile.exists())
|
||||
destFile.remove(false);
|
||||
|
||||
testfile.copyTo(profileDir, "formhistory.sqlite");
|
||||
|
||||
fh = Cc["@mozilla.org/satchel/form-history;1"].
|
||||
getService(Ci.nsIFormHistory2);
|
||||
|
||||
|
||||
// ===== 1 =====
|
||||
// Check initial state is as expected
|
||||
testnum++;
|
||||
do_check_true(fh.hasEntries);
|
||||
do_check_true(fh.nameExists("name-A"));
|
||||
do_check_true(fh.nameExists("name-B"));
|
||||
do_check_true(fh.nameExists("name-C"));
|
||||
do_check_true(fh.nameExists("name-D"));
|
||||
do_check_true(fh.entryExists("name-A", "value-A"));
|
||||
do_check_true(fh.entryExists("name-B", "value-B1"));
|
||||
do_check_true(fh.entryExists("name-B", "value-B2"));
|
||||
do_check_true(fh.entryExists("name-C", "value-C"));
|
||||
do_check_true(fh.entryExists("name-D", "value-D"));
|
||||
// time-A/B/C/D checked below.
|
||||
|
||||
// ===== 2 =====
|
||||
// Test looking for non-existant / bogus data.
|
||||
testnum++;
|
||||
do_check_false(fh.nameExists("blah"));
|
||||
do_check_false(fh.nameExists(""));
|
||||
do_check_false(fh.nameExists(null));
|
||||
do_check_false(fh.entryExists("name-A", "blah"));
|
||||
do_check_false(fh.entryExists("name-A", ""));
|
||||
do_check_false(fh.entryExists("name-A", null));
|
||||
do_check_false(fh.entryExists("blah", "value-A"));
|
||||
do_check_false(fh.entryExists("", "value-A"));
|
||||
do_check_false(fh.entryExists(null, "value-A"));
|
||||
|
||||
// ===== 3 =====
|
||||
// Test removeEntriesForName with a single matching value
|
||||
testnum++;
|
||||
fh.removeEntriesForName("name-A");
|
||||
do_check_false(fh.entryExists("name-A", "value-A"));
|
||||
do_check_true(fh.entryExists("name-B", "value-B1"));
|
||||
do_check_true(fh.entryExists("name-B", "value-B2"));
|
||||
do_check_true(fh.entryExists("name-C", "value-C"));
|
||||
do_check_true(fh.entryExists("name-D", "value-D"));
|
||||
|
||||
// ===== 4 =====
|
||||
// Test removeEntriesForName with multiple matching values
|
||||
testnum++;
|
||||
fh.removeEntriesForName("name-B");
|
||||
do_check_false(fh.entryExists("name-A", "value-A"));
|
||||
do_check_false(fh.entryExists("name-B", "value-B1"));
|
||||
do_check_false(fh.entryExists("name-B", "value-B2"));
|
||||
do_check_true(fh.entryExists("name-C", "value-C"));
|
||||
do_check_true(fh.entryExists("name-D", "value-D"));
|
||||
|
||||
// ===== 5 =====
|
||||
// Test removing by time range (single entry, not surrounding entries)
|
||||
testnum++;
|
||||
do_check_true(fh.nameExists("time-A")); // firstUsed=1000, lastUsed=1000
|
||||
do_check_true(fh.nameExists("time-B")); // firstUsed=1000, lastUsed=1099
|
||||
do_check_true(fh.nameExists("time-C")); // firstUsed=1099, lastUsed=1099
|
||||
do_check_true(fh.nameExists("time-D")); // firstUsed=2001, lastUsed=2001
|
||||
fh.removeEntriesByTimeframe(1050, 2000);
|
||||
do_check_true(fh.nameExists("time-A"));
|
||||
do_check_true(fh.nameExists("time-B"));
|
||||
do_check_false(fh.nameExists("time-C"));
|
||||
do_check_true(fh.nameExists("time-D"));
|
||||
|
||||
// ===== 6 =====
|
||||
// Test removing by time range (multiple entries)
|
||||
testnum++;
|
||||
fh.removeEntriesByTimeframe(1000, 2000);
|
||||
do_check_false(fh.nameExists("time-A"));
|
||||
do_check_false(fh.nameExists("time-B"));
|
||||
do_check_false(fh.nameExists("time-C"));
|
||||
do_check_true(fh.nameExists("time-D"));
|
||||
|
||||
// ===== 7 =====
|
||||
// test removeAllEntries
|
||||
testnum++;
|
||||
fh.removeAllEntries();
|
||||
do_check_false(fh.hasEntries);
|
||||
do_check_false(fh.nameExists("name-C"));
|
||||
do_check_false(fh.nameExists("name-D"));
|
||||
do_check_false(fh.entryExists("name-C", "value-C"));
|
||||
do_check_false(fh.entryExists("name-D", "value-D"));
|
||||
|
||||
// ===== 8 =====
|
||||
// Add a single entry back
|
||||
testnum++;
|
||||
fh.addEntry("newname-A", "newvalue-A");
|
||||
do_check_true(fh.hasEntries);
|
||||
do_check_true(fh.entryExists("newname-A", "newvalue-A"));
|
||||
|
||||
// ===== 9 =====
|
||||
// Remove the single entry
|
||||
testnum++;
|
||||
fh.removeEntry("newname-A", "newvalue-A");
|
||||
do_check_false(fh.hasEntries);
|
||||
do_check_false(fh.entryExists("newname-A", "newvalue-A"));
|
||||
|
||||
} catch (e) {
|
||||
throw "FAILED in test #" + testnum + " -- " + e;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user