mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 784558. [Page Thumbnails] Re-add removeFile function to allow single thumbnail removal, used when removing entries from the history. r=felipe
This commit is contained in:
parent
52c4b843a1
commit
b43b2b7eb8
@ -19,6 +19,9 @@ let PageThumbsWorker = {
|
||||
let data = {result: null, data: null};
|
||||
|
||||
switch (msg.type) {
|
||||
case "removeFile":
|
||||
data.result = this.removeFile(msg);
|
||||
break;
|
||||
case "removeFiles":
|
||||
data.result = this.removeFiles(msg);
|
||||
break;
|
||||
@ -48,6 +51,15 @@ let PageThumbsWorker = {
|
||||
return entries;
|
||||
},
|
||||
|
||||
removeFile: function Worker_removeFile(msg) {
|
||||
try {
|
||||
OS.File.remove(msg.path);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
removeFiles: function Worker_removeFiles(msg) {
|
||||
for (let file of msg.paths) {
|
||||
try {
|
||||
|
@ -19,21 +19,9 @@ XPCOMUtils.defineLazyGetter(this, "Sanitizer", function () {
|
||||
*/
|
||||
function runTests() {
|
||||
yield clearHistory();
|
||||
yield createThumbnail();
|
||||
|
||||
// create a thumbnail
|
||||
yield addTab(URL);
|
||||
yield whenFileExists();
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
|
||||
// clear all browser history
|
||||
yield clearHistory();
|
||||
|
||||
// create a thumbnail
|
||||
yield addTab(URL);
|
||||
yield whenFileExists();
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
|
||||
// make sure copy() updates an existing file
|
||||
// Make sure Storage.copy() updates an existing file.
|
||||
PageThumbsStorage.copy(URL, URL_COPY);
|
||||
let copy = PageThumbsStorage.getFileForURL(URL_COPY);
|
||||
let mtime = copy.lastModifiedTime -= 60;
|
||||
@ -42,9 +30,31 @@ function runTests() {
|
||||
isnot(PageThumbsStorage.getFileForURL(URL_COPY).lastModifiedTime, mtime,
|
||||
"thumbnail file was updated");
|
||||
|
||||
// clear last 10 mins of history
|
||||
let file = PageThumbsStorage.getFileForURL(URL);
|
||||
let fileCopy = PageThumbsStorage.getFileForURL(URL_COPY);
|
||||
|
||||
// Clear the browser history. Retry until the files are gone because Windows
|
||||
// locks them sometimes.
|
||||
while (file.exists() || fileCopy.exists()) {
|
||||
yield clearHistory();
|
||||
}
|
||||
|
||||
yield createThumbnail();
|
||||
|
||||
// Clear the last 10 minutes of browsing history.
|
||||
yield clearHistory(true);
|
||||
ok(!copy.exists(), "copy of thumbnail has been removed");
|
||||
|
||||
// Retry until the file is gone because Windows locks it sometimes.
|
||||
while (file.exists()) {
|
||||
// Re-add our URL to the history so that history observer's onDeleteURI()
|
||||
// is called again.
|
||||
let time = Date.now() * 1000;
|
||||
let trans = Ci.nsINavHistoryService.TRANSITION_LINK;
|
||||
PlacesUtils.history.addVisit(makeURI(URL), time, null, trans, false, 0);
|
||||
|
||||
// Try again...
|
||||
yield clearHistory(true);
|
||||
}
|
||||
}
|
||||
|
||||
function clearHistory(aUseRange) {
|
||||
@ -65,25 +75,33 @@ function clearHistory(aUseRange) {
|
||||
if (aUseRange) {
|
||||
let usec = Date.now() * 1000;
|
||||
s.range = [usec - 10 * 60 * 1000 * 1000, usec];
|
||||
s.ignoreTimespan = false;
|
||||
}
|
||||
|
||||
s.sanitize();
|
||||
s.range = null;
|
||||
s.ignoreTimespan = true;
|
||||
|
||||
executeSoon(function () {
|
||||
if (PageThumbsStorage.getFileForURL(URL).exists())
|
||||
clearHistory(aUseRange);
|
||||
else
|
||||
executeSoon(next);
|
||||
}
|
||||
|
||||
function createThumbnail() {
|
||||
addTab(URL, function () {
|
||||
whenFileExists(function () {
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function whenFileExists() {
|
||||
let callback = whenFileExists;
|
||||
|
||||
function whenFileExists(aCallback) {
|
||||
let callback;
|
||||
let file = PageThumbsStorage.getFileForURL(URL);
|
||||
if (file.exists() && file.fileSize)
|
||||
callback = next;
|
||||
if (file.exists() && file.fileSize) {
|
||||
callback = aCallback;
|
||||
} else {
|
||||
callback = function () whenFileExists(aCallback);
|
||||
}
|
||||
|
||||
executeSoon(callback);
|
||||
}
|
||||
|
@ -57,10 +57,11 @@ function next() {
|
||||
/**
|
||||
* Creates a new tab with the given URI.
|
||||
* @param aURI The URI that's loaded in the tab.
|
||||
* @param aCallback The function to call when the tab has loaded.
|
||||
*/
|
||||
function addTab(aURI) {
|
||||
function addTab(aURI, aCallback) {
|
||||
let tab = gBrowser.selectedTab = gBrowser.addTab(aURI);
|
||||
whenLoaded(tab.linkedBrowser);
|
||||
whenLoaded(tab.linkedBrowser, aCallback);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user