mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 714202 - Fix implementation of AddonsReconciler.pruneChangesBeforeDate(); r=rnewman
This commit is contained in:
parent
e67402658e
commit
b7a5a93bce
@ -547,13 +547,9 @@ AddonsReconciler.prototype = {
|
||||
pruneChangesBeforeDate: function pruneChangesBeforeDate(date) {
|
||||
this._ensureStateLoaded();
|
||||
|
||||
while (this._changes.length > 0) {
|
||||
if (this._changes[0][0] >= date) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete this._changes[0];
|
||||
}
|
||||
this._changes = this._changes.filter(function test_age(change) {
|
||||
return change[0] >= date;
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -150,3 +150,44 @@ add_test(function test_load_state_future_version() {
|
||||
run_next_test();
|
||||
});
|
||||
});
|
||||
|
||||
add_test(function test_prune_changes_before_date() {
|
||||
_("Ensure that old changes are pruned properly.");
|
||||
|
||||
let reconciler = new AddonsReconciler();
|
||||
reconciler._ensureStateLoaded();
|
||||
reconciler._changes = [];
|
||||
|
||||
let now = new Date();
|
||||
const HOUR_MS = 1000 * 60 * 60;
|
||||
|
||||
_("Ensure pruning an empty changes array works.");
|
||||
reconciler.pruneChangesBeforeDate(now);
|
||||
do_check_eq(0, reconciler._changes.length);
|
||||
|
||||
let old = new Date(now.getTime() - HOUR_MS);
|
||||
let young = new Date(now.getTime() - 1000);
|
||||
reconciler._changes.push([old, CHANGE_INSTALLED, "foo"]);
|
||||
reconciler._changes.push([young, CHANGE_INSTALLED, "bar"]);
|
||||
do_check_eq(2, reconciler._changes.length);
|
||||
|
||||
_("Ensure pruning with an old time won't delete anything.");
|
||||
let threshold = new Date(old.getTime() - 1);
|
||||
reconciler.pruneChangesBeforeDate(threshold);
|
||||
do_check_eq(2, reconciler._changes.length);
|
||||
|
||||
_("Ensure pruning a single item works.");
|
||||
let threshold = new Date(young.getTime() - 1000);
|
||||
reconciler.pruneChangesBeforeDate(threshold);
|
||||
do_check_eq(1, reconciler._changes.length);
|
||||
do_check_neq(undefined, reconciler._changes[0]);
|
||||
do_check_eq(young, reconciler._changes[0][0]);
|
||||
do_check_eq("bar", reconciler._changes[0][2]);
|
||||
|
||||
_("Ensure pruning all changes works.");
|
||||
reconciler._changes.push([old, CHANGE_INSTALLED, "foo"]);
|
||||
reconciler.pruneChangesBeforeDate(now);
|
||||
do_check_eq(0, reconciler._changes.length);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user