2009-04-15 10:59:07 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-04-15 10:59:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the sanitize dialog (a.k.a. the clear recent history dialog).
|
|
|
|
* See bug 480169.
|
|
|
|
*
|
|
|
|
* The purpose of this test is not to fully flex the sanitize timespan code;
|
2013-09-18 23:06:20 -07:00
|
|
|
* browser/base/content/test/general/browser_sanitize-timespans.js does that. This
|
2009-04-15 10:59:07 -07:00
|
|
|
* test checks the UI of the dialog and makes sure it's correctly connected to
|
|
|
|
* the sanitize timespan code.
|
|
|
|
*
|
|
|
|
* Some of this code, especially the history creation parts, was taken from
|
2013-09-18 23:06:20 -07:00
|
|
|
* browser/base/content/test/general/browser_sanitize-timespans.js.
|
2009-04-15 10:59:07 -07:00
|
|
|
*/
|
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "FormHistory",
|
|
|
|
"resource://gre/modules/FormHistory.jsm");
|
2013-08-21 00:36:07 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
|
|
|
|
"resource://gre/modules/Downloads.jsm");
|
2013-04-19 15:21:30 -07:00
|
|
|
|
2012-01-24 14:08:42 -08:00
|
|
|
let tempScope = {};
|
|
|
|
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
|
|
|
.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
|
|
|
|
let Sanitizer = tempScope.Sanitizer;
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
const kMsecPerMin = 60 * 1000;
|
2012-05-14 11:42:29 -07:00
|
|
|
const kUsecPerMin = 60 * 1000000;
|
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
let formEntries, downloadIDs, olderDownloadIDs;
|
2013-04-19 15:21:30 -07:00
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
// Add tests here. Each is a function that's called by doNextTest().
|
|
|
|
var gAllTests = [
|
|
|
|
|
2009-09-15 03:06:34 -07:00
|
|
|
/**
|
|
|
|
* Initializes the dialog to its default state.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
// Select "Last Hour"
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
|
|
|
|
// Hide details
|
|
|
|
if (!this.getItemList().collapsed)
|
|
|
|
this.toggleDetails();
|
|
|
|
this.acceptDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
/**
|
|
|
|
* Cancels the dialog, makes sure history not cleared.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
// Add history (within the past hour)
|
|
|
|
let uris = [];
|
2013-01-24 20:55:22 -08:00
|
|
|
let places = [];
|
|
|
|
let pURI;
|
2009-04-15 10:59:07 -07:00
|
|
|
for (let i = 0; i < 30; i++) {
|
2013-01-24 20:55:22 -08:00
|
|
|
pURI = makeURI("http://" + i + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
|
|
|
|
uris.push(pURI);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
addVisits(places, function() {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
|
|
|
|
this.checkPrefCheckbox("history", false);
|
|
|
|
this.checkDetails(false);
|
2009-05-15 09:42:08 -07:00
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
// Show details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(true);
|
2009-05-15 09:42:08 -07:00
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
// Hide details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(false);
|
|
|
|
this.cancelDialog();
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
|
|
|
yield promiseHistoryClearedState(uris, false);
|
2013-04-19 15:21:30 -07:00
|
|
|
yield blankSlate();
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
function () {
|
|
|
|
// Add downloads (within the past hour).
|
|
|
|
Task.spawn(function () {
|
|
|
|
downloadIDs = [];
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
yield addDownloadWithMinutesAgo(downloadIDs, i);
|
|
|
|
}
|
|
|
|
// Add downloads (over an hour ago).
|
|
|
|
olderDownloadIDs = [];
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
yield addDownloadWithMinutesAgo(olderDownloadIDs, 61 + i);
|
|
|
|
}
|
|
|
|
|
|
|
|
doNextTest();
|
|
|
|
}).then(null, Components.utils.reportError);
|
|
|
|
},
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
/**
|
|
|
|
* Ensures that the combined history-downloads checkbox clears both history
|
|
|
|
* visits and downloads when checked; the dialog respects simple timespan.
|
|
|
|
*/
|
|
|
|
function () {
|
2013-01-24 20:55:22 -08:00
|
|
|
// Add history (within the past hour).
|
2009-04-15 10:59:07 -07:00
|
|
|
let uris = [];
|
2013-01-24 20:55:22 -08:00
|
|
|
let places = [];
|
|
|
|
let pURI;
|
2009-04-15 10:59:07 -07:00
|
|
|
for (let i = 0; i < 30; i++) {
|
2013-01-24 20:55:22 -08:00
|
|
|
pURI = makeURI("http://" + i + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
|
|
|
|
uris.push(pURI);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
2013-01-24 20:55:22 -08:00
|
|
|
// Add history (over an hour ago).
|
2009-04-15 10:59:07 -07:00
|
|
|
let olderURIs = [];
|
|
|
|
for (let i = 0; i < 5; i++) {
|
2013-01-24 20:55:22 -08:00
|
|
|
pURI = makeURI("http://" + (61 + i) + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(61 + i)});
|
|
|
|
olderURIs.push(pURI);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
addVisits(places, function() {
|
|
|
|
let totalHistoryVisits = uris.length + olderURIs.length;
|
|
|
|
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
|
|
|
|
this.checkPrefCheckbox("history", true);
|
|
|
|
this.acceptDialog();
|
|
|
|
|
|
|
|
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
|
|
|
|
"timeSpan pref should be hour after accepting dialog with " +
|
|
|
|
"hour selected");
|
|
|
|
boolPrefIs("cpd.history", true,
|
|
|
|
"history pref should be true after accepting dialog with " +
|
|
|
|
"history checkbox checked");
|
|
|
|
boolPrefIs("cpd.downloads", true,
|
|
|
|
"downloads pref should be true after accepting dialog with " +
|
|
|
|
"history checkbox checked");
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
2013-01-24 20:55:22 -08:00
|
|
|
// History visits and downloads within one hour should be cleared.
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield ensureDownloadsClearedState(downloadIDs, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
|
|
|
|
// Visits and downloads > 1 hour should still exist.
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(olderURIs, false);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield ensureDownloadsClearedState(olderDownloadIDs, false);
|
2013-01-24 20:55:22 -08:00
|
|
|
|
|
|
|
// OK, done, cleanup after ourselves.
|
2013-04-19 15:21:30 -07:00
|
|
|
yield blankSlate();
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(olderURIs, true);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield ensureDownloadsClearedState(olderDownloadIDs, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
/**
|
|
|
|
* Add form history entries for the next test.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
formEntries = [];
|
|
|
|
|
|
|
|
let iter = function() {
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
formEntries.push(addFormEntryWithMinutesAgo(iter, i));
|
2013-07-10 14:52:04 -07:00
|
|
|
yield undefined;
|
2013-04-19 15:21:30 -07:00
|
|
|
}
|
|
|
|
doNextTest();
|
|
|
|
}();
|
|
|
|
|
|
|
|
iter.next();
|
|
|
|
},
|
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
function () {
|
|
|
|
// Add downloads (within the past hour).
|
|
|
|
Task.spawn(function () {
|
|
|
|
downloadIDs = [];
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
yield addDownloadWithMinutesAgo(downloadIDs, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
doNextTest();
|
|
|
|
}).then(null, Components.utils.reportError);
|
|
|
|
},
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
/**
|
|
|
|
* Ensures that the combined history-downloads checkbox removes neither
|
|
|
|
* history visits nor downloads when not checked.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
// Add history, downloads, form entries (within the past hour).
|
|
|
|
let uris = [];
|
2013-01-24 20:55:22 -08:00
|
|
|
let places = [];
|
|
|
|
let pURI;
|
2009-04-15 10:59:07 -07:00
|
|
|
for (let i = 0; i < 5; i++) {
|
2013-01-24 20:55:22 -08:00
|
|
|
pURI = makeURI("http://" + i + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(i)});
|
|
|
|
uris.push(pURI);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
addVisits(places, function() {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
is(this.isWarningPanelVisible(), false,
|
|
|
|
"Warning panel should be hidden after previously accepting dialog " +
|
|
|
|
"with a predefined timespan");
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
|
|
|
|
|
|
|
|
// Remove only form entries, leave history (including downloads).
|
|
|
|
this.checkPrefCheckbox("history", false);
|
|
|
|
this.checkPrefCheckbox("formdata", true);
|
|
|
|
this.acceptDialog();
|
|
|
|
|
|
|
|
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_HOUR,
|
|
|
|
"timeSpan pref should be hour after accepting dialog with " +
|
|
|
|
"hour selected");
|
|
|
|
boolPrefIs("cpd.history", false,
|
|
|
|
"history pref should be false after accepting dialog with " +
|
|
|
|
"history checkbox unchecked");
|
|
|
|
boolPrefIs("cpd.downloads", false,
|
|
|
|
"downloads pref should be false after accepting dialog with " +
|
|
|
|
"history checkbox unchecked");
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
2013-01-24 20:55:22 -08:00
|
|
|
// Of the three only form entries should be cleared.
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(uris, false);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield ensureDownloadsClearedState(downloadIDs, false);
|
2013-04-19 15:21:30 -07:00
|
|
|
|
|
|
|
formEntries.forEach(function (entry) {
|
|
|
|
let exists = yield formNameExists(entry);
|
|
|
|
is(exists, false, "form entry " + entry + " should no longer exist");
|
|
|
|
});
|
2013-01-24 20:55:22 -08:00
|
|
|
|
|
|
|
// OK, done, cleanup after ourselves.
|
2013-04-19 15:21:30 -07:00
|
|
|
yield blankSlate();
|
2013-02-04 13:08:51 -08:00
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield ensureDownloadsClearedState(downloadIDs, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the "Everything" duration option works.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
// Add history.
|
|
|
|
let uris = [];
|
2013-01-24 20:55:22 -08:00
|
|
|
let places = [];
|
|
|
|
let pURI;
|
|
|
|
// within past hour, within past two hours, within past four hours and
|
|
|
|
// outside past four hours
|
|
|
|
[10, 70, 130, 250].forEach(function(aValue) {
|
|
|
|
pURI = makeURI("http://" + aValue + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
|
|
|
|
uris.push(pURI);
|
|
|
|
});
|
|
|
|
addVisits(places, function() {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
is(this.isWarningPanelVisible(), false,
|
|
|
|
"Warning panel should be hidden after previously accepting dialog " +
|
|
|
|
"with a predefined timespan");
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
|
|
|
|
this.checkPrefCheckbox("history", true);
|
|
|
|
this.checkDetails(true);
|
|
|
|
|
|
|
|
// Hide details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(false);
|
2009-05-15 09:42:08 -07:00
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
// Show details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(true);
|
2009-09-15 03:06:34 -07:00
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
this.acceptDialog();
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
|
|
|
|
"timeSpan pref should be everything after accepting dialog " +
|
|
|
|
"with everything selected");
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the "Everything" warning is visible on dialog open after
|
|
|
|
* the previous test.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
// Add history.
|
|
|
|
let uris = [];
|
2013-01-24 20:55:22 -08:00
|
|
|
let places = [];
|
|
|
|
let pURI;
|
|
|
|
// within past hour, within past two hours, within past four hours and
|
|
|
|
// outside past four hours
|
|
|
|
[10, 70, 130, 250].forEach(function(aValue) {
|
|
|
|
pURI = makeURI("http://" + aValue + "-minutes-ago.com/");
|
|
|
|
places.push({uri: pURI, visitDate: visitTimeForMinutesAgo(aValue)});
|
|
|
|
uris.push(pURI);
|
|
|
|
});
|
|
|
|
addVisits(places, function() {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
is(this.isWarningPanelVisible(), true,
|
|
|
|
"Warning panel should be visible after previously accepting dialog " +
|
|
|
|
"with clearing everything");
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
|
|
|
|
this.checkPrefCheckbox("history", true);
|
|
|
|
this.acceptDialog();
|
|
|
|
|
|
|
|
intPrefIs("sanitize.timeSpan", Sanitizer.TIMESPAN_EVERYTHING,
|
|
|
|
"timeSpan pref should be everything after accepting dialog " +
|
|
|
|
"with everything selected");
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2009-05-15 09:42:08 -07:00
|
|
|
},
|
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
/**
|
|
|
|
* Add form history entry for the next test.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
let iter = function() {
|
|
|
|
formEntries = [ addFormEntryWithMinutesAgo(iter, 10) ];
|
2013-07-10 14:52:04 -07:00
|
|
|
yield undefined;
|
2013-04-19 15:21:30 -07:00
|
|
|
doNextTest();
|
|
|
|
}();
|
|
|
|
|
|
|
|
iter.next();
|
|
|
|
},
|
|
|
|
|
2011-09-21 21:08:58 -07:00
|
|
|
/**
|
|
|
|
* The next three tests checks that when a certain history item cannot be
|
|
|
|
* cleared then the checkbox should be both disabled and unchecked.
|
|
|
|
* In addition, we ensure that this behavior does not modify the preferences.
|
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
// Add history.
|
2013-01-24 20:55:22 -08:00
|
|
|
let pURI = makeURI("http://" + 10 + "-minutes-ago.com/");
|
|
|
|
addVisits({uri: pURI, visitDate: visitTimeForMinutesAgo(10)}, function() {
|
|
|
|
let uris = [ pURI ];
|
|
|
|
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function() {
|
|
|
|
// Check that the relevant checkboxes are enabled
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='privacy.cpd.formdata']");
|
|
|
|
ok(cb.length == 1 && !cb[0].disabled, "There is formdata, checkbox to " +
|
|
|
|
"clear formdata should be enabled.");
|
|
|
|
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='privacy.cpd.history']");
|
|
|
|
ok(cb.length == 1 && !cb[0].disabled, "There is history, checkbox to " +
|
|
|
|
"clear history should be enabled.");
|
|
|
|
|
|
|
|
this.checkAllCheckboxes();
|
|
|
|
this.acceptDialog();
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
|
|
|
yield promiseHistoryClearedState(uris, true);
|
2013-04-19 15:21:30 -07:00
|
|
|
|
|
|
|
let exists = yield formNameExists(formEntries[0]);
|
|
|
|
is(exists, false, "form entry " + formEntries[0] + " should no longer exist");
|
2013-01-24 20:55:22 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
});
|
2011-09-21 21:08:58 -07:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function() {
|
|
|
|
boolPrefIs("cpd.history", true,
|
|
|
|
"history pref should be true after accepting dialog with " +
|
|
|
|
"history checkbox checked");
|
|
|
|
boolPrefIs("cpd.formdata", true,
|
|
|
|
"formdata pref should be true after accepting dialog with " +
|
|
|
|
"formdata checkbox checked");
|
|
|
|
|
|
|
|
|
|
|
|
// Even though the formdata pref is true, because there is no history
|
|
|
|
// left to clear, the checkbox will be disabled.
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='privacy.cpd.formdata']");
|
|
|
|
ok(cb.length == 1 && cb[0].disabled && !cb[0].checked,
|
|
|
|
"There is no formdata history, checkbox should be disabled and be " +
|
|
|
|
"cleared to reduce user confusion (bug 497664).");
|
|
|
|
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='privacy.cpd.history']");
|
|
|
|
ok(cb.length == 1 && !cb[0].disabled && cb[0].checked,
|
|
|
|
"There is no history, but history checkbox should always be enabled " +
|
|
|
|
"and will be checked from previous preference.");
|
|
|
|
|
|
|
|
this.acceptDialog();
|
|
|
|
}
|
|
|
|
wh.open();
|
|
|
|
},
|
2013-04-19 15:21:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add form history entry for the next test.
|
|
|
|
*/
|
2011-09-21 21:08:58 -07:00
|
|
|
function () {
|
2013-04-19 15:21:30 -07:00
|
|
|
let iter = function() {
|
|
|
|
formEntries = [ addFormEntryWithMinutesAgo(iter, 10) ];
|
2013-07-10 14:52:04 -07:00
|
|
|
yield undefined;
|
2013-04-19 15:21:30 -07:00
|
|
|
doNextTest();
|
|
|
|
}();
|
2011-12-17 01:31:50 -08:00
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
iter.next();
|
|
|
|
},
|
|
|
|
|
|
|
|
function () {
|
2011-09-21 21:08:58 -07:00
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function() {
|
|
|
|
boolPrefIs("cpd.formdata", true,
|
|
|
|
"formdata pref should persist previous value after accepting " +
|
|
|
|
"dialog where you could not clear formdata.");
|
|
|
|
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='privacy.cpd.formdata']");
|
|
|
|
ok(cb.length == 1 && !cb[0].disabled && cb[0].checked,
|
|
|
|
"There exists formEntries so the checkbox should be in sync with " +
|
|
|
|
"the pref.");
|
|
|
|
|
|
|
|
this.acceptDialog();
|
2013-02-04 13:08:51 -08:00
|
|
|
};
|
|
|
|
wh.onunload = function () {
|
2013-04-19 15:21:30 -07:00
|
|
|
let exists = yield formNameExists(formEntries[0]);
|
|
|
|
is(exists, false, "form entry " + formEntries[0] + " should no longer exist");
|
2011-09-21 21:08:58 -07:00
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2009-05-15 09:42:08 -07:00
|
|
|
/**
|
2009-09-15 03:06:34 -07:00
|
|
|
* These next six tests together ensure that toggling details persists
|
2009-06-09 07:12:35 -07:00
|
|
|
* across dialog openings.
|
2009-05-15 09:42:08 -07:00
|
|
|
*/
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
2009-11-17 11:49:59 -08:00
|
|
|
// Check all items and select "Everything"
|
|
|
|
this.checkAllCheckboxes();
|
2009-09-15 03:06:34 -07:00
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
|
|
|
|
|
|
|
|
// Hide details
|
2009-05-15 09:42:08 -07:00
|
|
|
this.toggleDetails();
|
2009-09-15 03:06:34 -07:00
|
|
|
this.checkDetails(false);
|
|
|
|
this.acceptDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
2009-11-17 11:49:59 -08:00
|
|
|
// Details should remain closed because all items are checked.
|
2009-09-15 03:06:34 -07:00
|
|
|
this.checkDetails(false);
|
|
|
|
|
2009-11-17 11:49:59 -08:00
|
|
|
// Uncheck history.
|
2009-09-15 03:06:34 -07:00
|
|
|
this.checkPrefCheckbox("history", false);
|
|
|
|
this.acceptDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
2009-11-17 11:49:59 -08:00
|
|
|
// Details should be open because not all items are checked.
|
|
|
|
this.checkDetails(true);
|
|
|
|
|
|
|
|
// Modify the Site Preferences item state (bug 527820)
|
|
|
|
this.checkAllCheckboxes();
|
|
|
|
this.checkPrefCheckbox("siteSettings", false);
|
|
|
|
this.acceptDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
// Details should be open because not all items are checked.
|
2009-05-15 09:42:08 -07:00
|
|
|
this.checkDetails(true);
|
2009-09-15 03:06:34 -07:00
|
|
|
|
|
|
|
// Hide details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(false);
|
2009-05-15 09:42:08 -07:00
|
|
|
this.cancelDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
2009-06-09 07:12:35 -07:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
2009-05-15 09:42:08 -07:00
|
|
|
wh.onload = function () {
|
2009-11-17 11:49:59 -08:00
|
|
|
// Details should be open because not all items are checked.
|
2009-05-15 09:42:08 -07:00
|
|
|
this.checkDetails(true);
|
2009-09-15 03:06:34 -07:00
|
|
|
|
|
|
|
// Select another duration
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_HOUR);
|
2009-05-15 09:42:08 -07:00
|
|
|
// Hide details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(false);
|
2009-09-15 03:06:34 -07:00
|
|
|
this.acceptDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
// Details should not be open because "Last Hour" is selected
|
|
|
|
this.checkDetails(false);
|
|
|
|
|
|
|
|
this.cancelDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
// Details should have remained closed
|
|
|
|
this.checkDetails(false);
|
|
|
|
|
|
|
|
// Show details
|
|
|
|
this.toggleDetails();
|
|
|
|
this.checkDetails(true);
|
2009-05-15 09:42:08 -07:00
|
|
|
this.cancelDialog();
|
|
|
|
};
|
|
|
|
wh.open();
|
2011-12-18 14:17:50 -08:00
|
|
|
},
|
|
|
|
function () {
|
2012-09-13 11:47:04 -07:00
|
|
|
// Test for offline cache deletion
|
2011-12-18 14:17:50 -08:00
|
|
|
|
|
|
|
// Prepare stuff, we will work with www.example.com
|
|
|
|
var URL = "http://www.example.com";
|
|
|
|
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService);
|
|
|
|
var URI = ios.newURI(URL, null, null);
|
|
|
|
|
|
|
|
var sm = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
2012-07-21 00:29:40 -07:00
|
|
|
var principal = sm.getNoAppCodebasePrincipal(URI);
|
2011-12-18 14:17:50 -08:00
|
|
|
|
|
|
|
// Give www.example.com privileges to store offline data
|
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager);
|
2012-07-23 11:08:07 -07:00
|
|
|
pm.addFromPrincipal(principal, "offline-app", Ci.nsIPermissionManager.ALLOW_ACTION);
|
|
|
|
pm.addFromPrincipal(principal, "offline-app", Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN);
|
2011-12-18 14:17:50 -08:00
|
|
|
|
|
|
|
// Store something to the offline cache
|
|
|
|
const nsICache = Components.interfaces.nsICache;
|
|
|
|
var cs = Components.classes["@mozilla.org/network/cache-service;1"]
|
|
|
|
.getService(Components.interfaces.nsICacheService);
|
|
|
|
var session = cs.createSession(URL + "/manifest", nsICache.STORE_OFFLINE, nsICache.STREAM_BASED);
|
|
|
|
|
|
|
|
// Open the dialog
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
|
|
|
|
// Show details
|
|
|
|
this.toggleDetails();
|
|
|
|
// Clear only offlineApps
|
|
|
|
this.uncheckAllCheckboxes();
|
|
|
|
this.checkPrefCheckbox("offlineApps", true);
|
|
|
|
this.acceptDialog();
|
|
|
|
|
2012-09-13 11:47:04 -07:00
|
|
|
// Check if the cache has been deleted
|
2011-12-18 14:17:50 -08:00
|
|
|
var size = -1;
|
|
|
|
var visitor = {
|
|
|
|
visitDevice: function (deviceID, deviceInfo)
|
|
|
|
{
|
|
|
|
if (deviceID == "offline")
|
|
|
|
size = deviceInfo.totalSize;
|
|
|
|
|
|
|
|
// Do not enumerate entries
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
visitEntry: function (deviceID, entryInfo)
|
|
|
|
{
|
|
|
|
// Do not enumerate entries.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
cs.visitEntries(visitor);
|
|
|
|
is(size, 0, "offline application cache entries evicted");
|
|
|
|
};
|
2012-07-11 02:18:13 -07:00
|
|
|
|
|
|
|
var cacheListener = {
|
|
|
|
onCacheEntryAvailable: function (entry, access, status) {
|
|
|
|
is(status, Cr.NS_OK);
|
|
|
|
var stream = entry.openOutputStream(0);
|
|
|
|
var content = "content";
|
|
|
|
stream.write(content, content.length);
|
|
|
|
stream.close();
|
|
|
|
entry.close();
|
|
|
|
wh.open();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
session.asyncOpenCacheEntry(URL, nsICache.ACCESS_READ_WRITE, cacheListener);
|
2011-12-18 14:17:50 -08:00
|
|
|
},
|
|
|
|
function () {
|
|
|
|
// Test for offline apps permission deletion
|
|
|
|
|
|
|
|
// Prepare stuff, we will work with www.example.com
|
|
|
|
var URL = "http://www.example.com";
|
|
|
|
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService);
|
|
|
|
var URI = ios.newURI(URL, null, null);
|
|
|
|
|
2012-07-23 11:08:07 -07:00
|
|
|
var sm = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
|
|
|
.getService(Ci.nsIScriptSecurityManager);
|
|
|
|
var principal = sm.getNoAppCodebasePrincipal(URI);
|
|
|
|
|
2011-12-18 14:17:50 -08:00
|
|
|
// Open the dialog
|
|
|
|
let wh = new WindowHelper();
|
|
|
|
wh.onload = function () {
|
|
|
|
this.selectDuration(Sanitizer.TIMESPAN_EVERYTHING);
|
|
|
|
// Show details
|
|
|
|
this.toggleDetails();
|
|
|
|
// Clear only offlineApps
|
|
|
|
this.uncheckAllCheckboxes();
|
|
|
|
this.checkPrefCheckbox("siteSettings", true);
|
|
|
|
this.acceptDialog();
|
|
|
|
|
|
|
|
// Check all has been deleted (privileges, data, cache)
|
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"]
|
|
|
|
.getService(Ci.nsIPermissionManager);
|
2012-07-23 11:08:07 -07:00
|
|
|
is(pm.testPermissionFromPrincipal(principal, "offline-app"), 0, "offline-app permissions removed");
|
2011-12-18 14:17:50 -08:00
|
|
|
};
|
|
|
|
wh.open();
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
// Index in gAllTests of the test currently being run. Incremented for each
|
|
|
|
// test run. See doNextTest().
|
|
|
|
var gCurrTest = 0;
|
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
let now_mSec = Date.now();
|
|
|
|
let now_uSec = now_mSec * 1000;
|
2009-04-15 10:59:07 -07:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This wraps the dialog and provides some convenience methods for interacting
|
|
|
|
* with it.
|
|
|
|
*
|
|
|
|
* @param aWin
|
|
|
|
* The dialog's nsIDOMWindow
|
|
|
|
*/
|
|
|
|
function WindowHelper(aWin) {
|
|
|
|
this.win = aWin;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowHelper.prototype = {
|
|
|
|
/**
|
|
|
|
* "Presses" the dialog's OK button.
|
|
|
|
*/
|
|
|
|
acceptDialog: function () {
|
|
|
|
is(this.win.document.documentElement.getButton("accept").disabled, false,
|
|
|
|
"Dialog's OK button should not be disabled");
|
|
|
|
this.win.document.documentElement.acceptDialog();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Presses" the dialog's Cancel button.
|
|
|
|
*/
|
|
|
|
cancelDialog: function () {
|
|
|
|
this.win.document.documentElement.cancelDialog();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the details progressive disclosure button and the item list
|
|
|
|
* hidden by it match up. Also makes sure the height of the dialog is
|
|
|
|
* sufficient for the item list and warning panel.
|
2009-05-15 09:42:08 -07:00
|
|
|
*
|
|
|
|
* @param aShouldBeShown
|
|
|
|
* True if you expect the details to be shown and false if hidden
|
2009-04-15 10:59:07 -07:00
|
|
|
*/
|
2009-05-15 09:42:08 -07:00
|
|
|
checkDetails: function (aShouldBeShown) {
|
2009-04-15 10:59:07 -07:00
|
|
|
let button = this.getDetailsButton();
|
|
|
|
let list = this.getItemList();
|
|
|
|
let hidden = list.hidden || list.collapsed;
|
2009-05-15 09:42:08 -07:00
|
|
|
is(hidden, !aShouldBeShown,
|
|
|
|
"Details should be " + (aShouldBeShown ? "shown" : "hidden") +
|
|
|
|
" but were actually " + (hidden ? "hidden" : "shown"));
|
2009-04-15 10:59:07 -07:00
|
|
|
let dir = hidden ? "down" : "up";
|
|
|
|
is(button.className, "expander-" + dir,
|
|
|
|
"Details button should be " + dir + " because item list is " +
|
|
|
|
(hidden ? "" : "not ") + "hidden");
|
|
|
|
let height = 0;
|
2010-05-18 06:37:43 -07:00
|
|
|
if (!hidden) {
|
|
|
|
ok(list.boxObject.height > 30, "listbox has sufficient size")
|
2009-04-15 10:59:07 -07:00
|
|
|
height += list.boxObject.height;
|
2010-05-18 06:37:43 -07:00
|
|
|
}
|
2009-04-15 10:59:07 -07:00
|
|
|
if (this.isWarningPanelVisible())
|
|
|
|
height += this.getWarningPanel().boxObject.height;
|
|
|
|
ok(height < this.win.innerHeight,
|
|
|
|
"Window should be tall enough to fit warning panel and item list");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (Un)checks a history scope checkbox (browser & download history,
|
|
|
|
* form history, etc.).
|
|
|
|
*
|
|
|
|
* @param aPrefName
|
2009-05-13 15:42:07 -07:00
|
|
|
* The final portion of the checkbox's privacy.cpd.* preference name
|
2009-04-15 10:59:07 -07:00
|
|
|
* @param aCheckState
|
|
|
|
* True if the checkbox should be checked, false otherwise
|
|
|
|
*/
|
|
|
|
checkPrefCheckbox: function (aPrefName, aCheckState) {
|
2009-05-13 15:42:07 -07:00
|
|
|
var pref = "privacy.cpd." + aPrefName;
|
|
|
|
var cb = this.win.document.querySelectorAll(
|
|
|
|
"#itemList > [preference='" + pref + "']");
|
|
|
|
is(cb.length, 1, "found checkbox for " + pref + " preference");
|
|
|
|
if (cb[0].checked != aCheckState)
|
|
|
|
cb[0].click();
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
2009-09-15 03:06:34 -07:00
|
|
|
/**
|
2009-11-17 11:49:59 -08:00
|
|
|
* Makes sure all the checkboxes are checked.
|
2009-09-15 03:06:34 -07:00
|
|
|
*/
|
2011-12-18 14:17:50 -08:00
|
|
|
_checkAllCheckboxesCustom: function (check) {
|
2009-09-15 03:06:34 -07:00
|
|
|
var cb = this.win.document.querySelectorAll("#itemList > [preference]");
|
|
|
|
ok(cb.length > 1, "found checkboxes for preferences");
|
|
|
|
for (var i = 0; i < cb.length; ++i) {
|
|
|
|
var pref = this.win.document.getElementById(cb[i].getAttribute("preference"));
|
2011-12-18 14:17:50 -08:00
|
|
|
if (!!pref.value ^ check)
|
2009-09-15 03:06:34 -07:00
|
|
|
cb[i].click();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-18 14:17:50 -08:00
|
|
|
checkAllCheckboxes: function () {
|
|
|
|
this._checkAllCheckboxesCustom(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
uncheckAllCheckboxes: function () {
|
|
|
|
this._checkAllCheckboxesCustom(false);
|
|
|
|
},
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
/**
|
|
|
|
* @return The details progressive disclosure button
|
|
|
|
*/
|
|
|
|
getDetailsButton: function () {
|
|
|
|
return this.win.document.getElementById("detailsExpander");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The dialog's duration dropdown
|
|
|
|
*/
|
|
|
|
getDurationDropdown: function () {
|
|
|
|
return this.win.document.getElementById("sanitizeDurationChoice");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The item list hidden by the details progressive disclosure button
|
|
|
|
*/
|
|
|
|
getItemList: function () {
|
|
|
|
return this.win.document.getElementById("itemList");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return The clear-everything warning box
|
|
|
|
*/
|
|
|
|
getWarningPanel: function () {
|
|
|
|
return this.win.document.getElementById("sanitizeEverythingWarningBox");
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return True if the "Everything" warning panel is visible (as opposed to
|
|
|
|
* the tree)
|
|
|
|
*/
|
|
|
|
isWarningPanelVisible: function () {
|
|
|
|
return !this.getWarningPanel().hidden;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opens the clear recent history dialog. Before calling this, set
|
|
|
|
* this.onload to a function to execute onload. It should close the dialog
|
|
|
|
* when done so that the tests may continue. Set this.onunload to a function
|
2013-04-19 15:21:30 -07:00
|
|
|
* to execute onunload. this.onunload is optional. If it returns true, the
|
|
|
|
* caller is expected to call waitForAsyncUpdates at some point; if false is
|
|
|
|
* returned, waitForAsyncUpdates is called automatically.
|
2009-04-15 10:59:07 -07:00
|
|
|
*/
|
|
|
|
open: function () {
|
|
|
|
let wh = this;
|
|
|
|
|
2010-02-06 00:47:42 -08:00
|
|
|
function windowObserver(aSubject, aTopic, aData) {
|
|
|
|
if (aTopic != "domwindowopened")
|
|
|
|
return;
|
|
|
|
|
2010-04-02 00:20:42 -07:00
|
|
|
Services.ww.unregisterNotification(windowObserver);
|
2010-02-06 00:47:42 -08:00
|
|
|
|
|
|
|
var loaded = false;
|
|
|
|
let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
|
|
|
|
win.addEventListener("load", function onload(event) {
|
|
|
|
win.removeEventListener("load", onload, false);
|
|
|
|
|
|
|
|
if (win.name !== "SanitizeDialog")
|
2009-04-15 10:59:07 -07:00
|
|
|
return;
|
|
|
|
|
2010-02-06 00:47:42 -08:00
|
|
|
wh.win = win;
|
|
|
|
loaded = true;
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2010-02-06 00:47:42 -08:00
|
|
|
executeSoon(function () {
|
|
|
|
// Some exceptions that reach here don't reach the test harness, but
|
|
|
|
// ok()/is() do...
|
|
|
|
try {
|
|
|
|
wh.onload();
|
|
|
|
}
|
|
|
|
catch (exc) {
|
|
|
|
win.close();
|
|
|
|
ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, false);
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2010-02-06 00:47:42 -08:00
|
|
|
win.addEventListener("unload", function onunload(event) {
|
|
|
|
if (win.name !== "SanitizeDialog") {
|
2009-04-15 10:59:07 -07:00
|
|
|
win.removeEventListener("unload", onunload, false);
|
2010-02-06 00:47:42 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Why is unload fired before load?
|
|
|
|
if (!loaded)
|
|
|
|
return;
|
|
|
|
|
|
|
|
win.removeEventListener("unload", onunload, false);
|
|
|
|
wh.win = win;
|
|
|
|
|
|
|
|
executeSoon(function () {
|
|
|
|
// Some exceptions that reach here don't reach the test harness, but
|
|
|
|
// ok()/is() do...
|
|
|
|
try {
|
2013-02-04 13:08:51 -08:00
|
|
|
if (wh.onunload) {
|
|
|
|
Task.spawn(wh.onunload).then(function() {
|
|
|
|
waitForAsyncUpdates(doNextTest);
|
2013-08-21 00:36:07 -07:00
|
|
|
}).then(null, Components.utils.reportError);
|
2013-02-04 13:08:51 -08:00
|
|
|
} else {
|
|
|
|
waitForAsyncUpdates(doNextTest);
|
|
|
|
}
|
2010-02-06 00:47:42 -08:00
|
|
|
}
|
|
|
|
catch (exc) {
|
|
|
|
win.close();
|
|
|
|
ok(false, "Unexpected exception: " + exc + "\n" + exc.stack);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, false);
|
|
|
|
}
|
2010-04-02 00:20:42 -07:00
|
|
|
Services.ww.registerNotification(windowObserver);
|
|
|
|
Services.ww.openWindow(null,
|
|
|
|
"chrome://browser/content/sanitize.xul",
|
|
|
|
"SanitizeDialog",
|
|
|
|
"chrome,titlebar,dialog,centerscreen,modal",
|
|
|
|
null);
|
2009-04-15 10:59:07 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selects a duration in the duration dropdown.
|
|
|
|
*
|
|
|
|
* @param aDurVal
|
|
|
|
* One of the Sanitizer.TIMESPAN_* values
|
|
|
|
*/
|
|
|
|
selectDuration: function (aDurVal) {
|
|
|
|
this.getDurationDropdown().value = aDurVal;
|
|
|
|
if (aDurVal === Sanitizer.TIMESPAN_EVERYTHING) {
|
|
|
|
is(this.isWarningPanelVisible(), true,
|
|
|
|
"Warning panel should be visible for TIMESPAN_EVERYTHING");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is(this.isWarningPanelVisible(), false,
|
|
|
|
"Warning panel should not be visible for non-TIMESPAN_EVERYTHING");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles the details progressive disclosure button.
|
|
|
|
*/
|
|
|
|
toggleDetails: function () {
|
|
|
|
this.getDetailsButton().click();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a download to history.
|
|
|
|
*
|
|
|
|
* @param aMinutesAgo
|
|
|
|
* The download will be downloaded this many minutes ago
|
|
|
|
*/
|
2013-08-21 00:36:07 -07:00
|
|
|
function addDownloadWithMinutesAgo(aExpectedPathList, aMinutesAgo) {
|
2013-09-12 12:20:30 -07:00
|
|
|
let publicList = yield Downloads.getList(Downloads.PUBLIC);
|
2013-08-21 00:36:07 -07:00
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
let name = "fakefile-" + aMinutesAgo + "-minutes-ago";
|
2013-08-21 00:36:07 -07:00
|
|
|
let download = yield Downloads.createDownload({
|
|
|
|
source: "https://bugzilla.mozilla.org/show_bug.cgi?id=480169",
|
|
|
|
target: name
|
|
|
|
});
|
|
|
|
download.startTime = new Date(now_mSec - (aMinutesAgo * kMsecPerMin));
|
|
|
|
download.canceled = true;
|
|
|
|
publicList.add(download);
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
ok((yield downloadExists(name)),
|
|
|
|
"Sanity check: download " + name +
|
2009-04-15 10:59:07 -07:00
|
|
|
" should exist after creating it");
|
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
aExpectedPathList.push(name);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a form entry to history.
|
|
|
|
*
|
|
|
|
* @param aMinutesAgo
|
|
|
|
* The entry will be added this many minutes ago
|
|
|
|
*/
|
2013-04-19 15:21:30 -07:00
|
|
|
function addFormEntryWithMinutesAgo(then, aMinutesAgo) {
|
2009-04-15 10:59:07 -07:00
|
|
|
let name = aMinutesAgo + "-minutes-ago";
|
|
|
|
|
|
|
|
// Artifically age the entry to the proper vintage.
|
2012-05-14 11:42:29 -07:00
|
|
|
let timestamp = now_uSec - (aMinutesAgo * kUsecPerMin);
|
2009-04-15 10:59:07 -07:00
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
FormHistory.update({ op: "add", fieldname: name, value: "dummy", firstUsed: timestamp },
|
|
|
|
{ handleError: function (error) {
|
|
|
|
do_throw("Error occurred updating form history: " + error);
|
|
|
|
},
|
|
|
|
handleCompletion: function (reason) { then.next(); }
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
/**
|
|
|
|
* Checks if a form entry exists.
|
|
|
|
*/
|
|
|
|
function formNameExists(name)
|
|
|
|
{
|
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
|
|
|
let count = 0;
|
|
|
|
FormHistory.count({ fieldname: name },
|
|
|
|
{ handleResult: function (result) count = result,
|
|
|
|
handleError: function (error) {
|
|
|
|
do_throw("Error occurred searching form history: " + error);
|
|
|
|
deferred.reject(error);
|
|
|
|
},
|
|
|
|
handleCompletion: function (reason) {
|
|
|
|
if (!reason) deferred.resolve(count);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
}
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
/**
|
|
|
|
* Removes all history visits, downloads, and form entries.
|
|
|
|
*/
|
|
|
|
function blankSlate() {
|
2011-08-23 05:34:15 -07:00
|
|
|
PlacesUtils.bhistory.removeAllPages();
|
2013-04-19 15:21:30 -07:00
|
|
|
|
2013-08-21 00:36:07 -07:00
|
|
|
// The promise is resolved only when removing both downloads and form history are done.
|
2013-04-19 15:21:30 -07:00
|
|
|
let deferred = Promise.defer();
|
2013-08-21 00:36:07 -07:00
|
|
|
let formHistoryDone = false, downloadsDone = false;
|
|
|
|
|
|
|
|
Task.spawn(function deleteAllDownloads() {
|
2013-09-12 12:20:30 -07:00
|
|
|
let publicList = yield Downloads.getList(Downloads.PUBLIC);
|
2013-08-21 00:36:07 -07:00
|
|
|
let downloads = yield publicList.getAll();
|
|
|
|
for (let download of downloads) {
|
2013-09-17 09:02:21 -07:00
|
|
|
yield publicList.remove(download);
|
2013-08-21 00:36:07 -07:00
|
|
|
yield download.finalize(true);
|
|
|
|
}
|
|
|
|
downloadsDone = true;
|
|
|
|
if (formHistoryDone) {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
}).then(null, Components.utils.reportError);
|
|
|
|
|
2013-04-19 15:21:30 -07:00
|
|
|
FormHistory.update({ op: "remove" },
|
|
|
|
{ handleError: function (error) {
|
|
|
|
do_throw("Error occurred updating form history: " + error);
|
|
|
|
deferred.reject(error);
|
|
|
|
},
|
2013-08-21 00:36:07 -07:00
|
|
|
handleCompletion: function (reason) {
|
|
|
|
if (!reason) {
|
|
|
|
formHistoryDone = true;
|
|
|
|
if (downloadsDone) {
|
|
|
|
deferred.resolve();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-19 15:21:30 -07:00
|
|
|
});
|
|
|
|
return deferred.promise;
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the given pref is the expected value.
|
|
|
|
*
|
|
|
|
* @param aPrefName
|
|
|
|
* The pref's sub-branch under the privacy branch
|
|
|
|
* @param aExpectedVal
|
|
|
|
* The pref's expected value
|
|
|
|
* @param aMsg
|
|
|
|
* Passed to is()
|
|
|
|
*/
|
|
|
|
function boolPrefIs(aPrefName, aExpectedVal, aMsg) {
|
2009-07-27 23:18:29 -07:00
|
|
|
is(gPrefService.getBoolPref("privacy." + aPrefName), aExpectedVal, aMsg);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-08-21 00:36:07 -07:00
|
|
|
* Checks to see if the download with the specified path exists.
|
2009-04-15 10:59:07 -07:00
|
|
|
*
|
2013-08-21 00:36:07 -07:00
|
|
|
* @param aPath
|
|
|
|
* The path of the download to check
|
2009-04-15 10:59:07 -07:00
|
|
|
* @return True if the download exists, false otherwise
|
|
|
|
*/
|
2013-08-21 00:36:07 -07:00
|
|
|
function downloadExists(aPath)
|
2009-04-15 10:59:07 -07:00
|
|
|
{
|
2013-08-21 00:36:07 -07:00
|
|
|
return Task.spawn(function() {
|
2013-09-12 12:20:30 -07:00
|
|
|
let publicList = yield Downloads.getList(Downloads.PUBLIC);
|
2013-08-21 00:36:07 -07:00
|
|
|
let listArray = yield publicList.getAll();
|
|
|
|
throw new Task.Result(listArray.some(i => i.target.path == aPath));
|
|
|
|
});
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs the next test in the gAllTests array. If all tests have been run,
|
|
|
|
* finishes the entire suite.
|
|
|
|
*/
|
|
|
|
function doNextTest() {
|
|
|
|
if (gAllTests.length <= gCurrTest) {
|
|
|
|
blankSlate();
|
2011-08-23 05:34:15 -07:00
|
|
|
waitForAsyncUpdates(finish);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
let ct = gCurrTest;
|
|
|
|
gCurrTest++;
|
|
|
|
gAllTests[ct]();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the specified downloads are either cleared or not.
|
|
|
|
*
|
|
|
|
* @param aDownloadIDs
|
|
|
|
* Array of download database IDs
|
|
|
|
* @param aShouldBeCleared
|
|
|
|
* True if each download should be cleared, false otherwise
|
|
|
|
*/
|
|
|
|
function ensureDownloadsClearedState(aDownloadIDs, aShouldBeCleared) {
|
|
|
|
let niceStr = aShouldBeCleared ? "no longer" : "still";
|
|
|
|
aDownloadIDs.forEach(function (id) {
|
2013-08-21 00:36:07 -07:00
|
|
|
is((yield downloadExists(id)), !aShouldBeCleared,
|
2009-04-15 10:59:07 -07:00
|
|
|
"download " + id + " should " + niceStr + " exist");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that the given pref is the expected value.
|
|
|
|
*
|
|
|
|
* @param aPrefName
|
|
|
|
* The pref's sub-branch under the privacy branch
|
|
|
|
* @param aExpectedVal
|
|
|
|
* The pref's expected value
|
|
|
|
* @param aMsg
|
|
|
|
* Passed to is()
|
|
|
|
*/
|
|
|
|
function intPrefIs(aPrefName, aExpectedVal, aMsg) {
|
2009-07-27 23:18:29 -07:00
|
|
|
is(gPrefService.getIntPref("privacy." + aPrefName), aExpectedVal, aMsg);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 20:55:22 -08:00
|
|
|
/**
|
|
|
|
* Creates a visit time.
|
|
|
|
*
|
|
|
|
* @param aMinutesAgo
|
|
|
|
* The visit will be visited this many minutes ago
|
|
|
|
*/
|
|
|
|
function visitTimeForMinutesAgo(aMinutesAgo) {
|
|
|
|
return now_uSec - aMinutesAgo * kUsecPerMin;
|
|
|
|
}
|
|
|
|
|
2009-04-15 10:59:07 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function test() {
|
2010-11-24 01:44:35 -08:00
|
|
|
requestLongerTimeout(2);
|
2013-05-02 18:20:08 -07:00
|
|
|
waitForExplicitFinish();
|
2013-04-19 15:21:30 -07:00
|
|
|
blankSlate();
|
2009-04-15 10:59:07 -07:00
|
|
|
// Kick off all the tests in the gAllTests array.
|
2011-08-23 05:34:15 -07:00
|
|
|
waitForAsyncUpdates(doNextTest);
|
2009-04-15 10:59:07 -07:00
|
|
|
}
|