Bug 1033972 - BackgroundPageThumbs.captureIfMissing() and PageThumbs.captureAndStoreIfStale() both incorrectly use PromiseWorker. r=adw

This commit is contained in:
Blair McBride 2014-07-07 14:28:00 +12:00
Родитель e589091417
Коммит b2948dad76
4 изменённых файлов: 21 добавлений и 9 удалений

Просмотреть файл

@ -86,7 +86,7 @@ const BackgroundPageThumbs = {
// incorrect, and no big deal when it is. After the capture is done, we
// atomically test whether the file exists before writing it.
PageThumbsStorage.fileExistsForURL(url).then(exists => {
if (exists.ok) {
if (exists) {
if (options.onDone)
options.onDone(url);
return;

Просмотреть файл

@ -295,7 +295,7 @@ this.PageThumbs = {
captureAndStoreIfStale: function PageThumbs_captureAndStoreIfStale(aBrowser, aCallback) {
let url = aBrowser.currentURI.spec;
PageThumbsStorage.isFileRecentForURL(url).then(recent => {
if (!recent.ok &&
if (!recent &&
// Careful, the call to PageThumbsStorage is async, so the browser may
// have navigated away from the URL or even closed.
aBrowser.currentURI &&

Просмотреть файл

@ -2,11 +2,20 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
function runTests() {
let numNotifications = 0;
function observe(subject, topic, data) {
is(topic, "page-thumbnail:create", "got expected topic");
numNotifications += 1;
}
Services.obs.addObserver(observe, "page-thumbnail:create", false);
let url = "http://example.com/";
let file = thumbnailFile(url);
ok(!file.exists(), "Thumbnail file should not already exist.");
let capturedURL = yield bgCaptureIfMissing(url);
is(numNotifications, 1, "got notification of item being created.");
is(capturedURL, url, "Captured URL should be URL passed to capture");
ok(file.exists(url), "Thumbnail should be cached after capture");
@ -15,10 +24,12 @@ function runTests() {
file.lastModifiedTime = past;
ok(file.lastModifiedTime < pastFudge, "Last modified time should stick!");
capturedURL = yield bgCaptureIfMissing(url);
is(numNotifications, 1, "still only 1 notification of item being created.");
is(capturedURL, url, "Captured URL should be URL passed to second capture");
ok(file.exists(), "Thumbnail should remain cached after second capture");
ok(file.lastModifiedTime < pastFudge,
"File should not have been overwritten");
file.remove(false);
Services.obs.removeObserver(observe, "page-thumbnail:create");
}

Просмотреть файл

@ -67,14 +67,15 @@ function simpleCaptureTest() {
is(numNotifications, 1, "got notification of item being created.");
// The capture is now "fresh" - so requesting the URL should not cause
// a new capture.
PageThumbs.captureAndStoreIfStale(browser);
is(numNotifications, 1, "still only 1 notification of item being created.");
PageThumbs.captureAndStoreIfStale(browser, function() {
is(numNotifications, 1, "still only 1 notification of item being created.");
ensureThumbnailStale(URL);
// Ask for it to be updated.
PageThumbs.captureAndStoreIfStale(browser);
// But it's async, so wait - our observer above will call next() when
// the notification comes.
ensureThumbnailStale(URL);
// Ask for it to be updated.
PageThumbs.captureAndStoreIfStale(browser);
// But it's async, so wait - our observer above will call next() when
// the notification comes.
});
});
yield undefined // wait for callbacks to call 'next'...
}