зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1591495 - Update thumbnail tests to use more modern primitives, like add_task. r=Gijs
Depends on D50851 Differential Revision: https://phabricator.services.mozilla.com/D50852 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d3d93be943
Коммит
fac08e5f9c
|
@ -1,25 +1,24 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_bad_url() {
|
||||
let url = "invalid-protocol://ffggfsdfsdf/";
|
||||
ok(!thumbnailExists(url), "Thumbnail should not be cached already.");
|
||||
let numCalls = 0;
|
||||
BackgroundPageThumbs.capture(url, {
|
||||
onDone: function onDone(capturedURL) {
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture");
|
||||
is(numCalls++, 0, "onDone should be called only once");
|
||||
ok(
|
||||
!thumbnailExists(url),
|
||||
"Capture failed so thumbnail should not be cached"
|
||||
);
|
||||
next();
|
||||
},
|
||||
});
|
||||
yield new Promise(resolve => {
|
||||
bgAddPageThumbObserver(url).catch(function(err) {
|
||||
ok(true, "page-thumbnail error produced");
|
||||
resolve();
|
||||
let observer = bgAddPageThumbObserver(url);
|
||||
await new Promise(resolve => {
|
||||
BackgroundPageThumbs.capture(url, {
|
||||
onDone: function onDone(capturedURL) {
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture");
|
||||
is(numCalls++, 0, "onDone should be called only once");
|
||||
ok(
|
||||
!thumbnailExists(url),
|
||||
"Capture failed so thumbnail should not be cached"
|
||||
);
|
||||
resolve();
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await Assert.rejects(observer, /page-thumbnail:error/);
|
||||
});
|
||||
|
|
|
@ -1,20 +1,15 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_basic() {
|
||||
let url = "http://www.example.com/";
|
||||
ok(!thumbnailExists(url), "Thumbnail should not be cached yet.");
|
||||
|
||||
let capturePromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(url).then(() => {
|
||||
ok(true, `page-thumbnail created for ${url}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
let capturedURL = yield bgCapture(url);
|
||||
let capturePromise = bgAddPageThumbObserver(url);
|
||||
let [capturedURL] = await bgCapture(url);
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture");
|
||||
yield capturePromise;
|
||||
await capturePromise;
|
||||
|
||||
ok(thumbnailExists(url), "Thumbnail should be cached after capture");
|
||||
removeThumbnail(url);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_captureIfMissing() {
|
||||
let numNotifications = 0;
|
||||
function observe(subject, topic, data) {
|
||||
is(topic, "page-thumbnail:create", "got expected topic");
|
||||
|
@ -14,7 +14,7 @@ function* runTests() {
|
|||
let file = thumbnailFile(url);
|
||||
ok(!file.exists(), "Thumbnail file should not already exist.");
|
||||
|
||||
let capturedURL = yield bgCaptureIfMissing(url);
|
||||
let [capturedURL] = await 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");
|
||||
|
@ -23,7 +23,7 @@ function* runTests() {
|
|||
let pastFudge = past + 30000;
|
||||
file.lastModifiedTime = past;
|
||||
ok(file.lastModifiedTime < pastFudge, "Last modified time should stick!");
|
||||
capturedURL = yield bgCaptureIfMissing(url);
|
||||
[capturedURL] = await 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");
|
||||
|
@ -34,4 +34,4 @@ function* runTests() {
|
|||
|
||||
file.remove(false);
|
||||
Services.obs.removeObserver(observe, "page-thumbnail:create");
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_crash_during_capture() {
|
||||
// make a good capture first - this ensures we have the <browser>
|
||||
let goodUrl = bgTestPageURL();
|
||||
yield bgCapture(goodUrl);
|
||||
await bgCapture(goodUrl);
|
||||
ok(thumbnailExists(goodUrl), "Thumbnail should be cached after capture");
|
||||
removeThumbnail(goodUrl);
|
||||
|
||||
|
@ -12,7 +12,7 @@ function* runTests() {
|
|||
// will die. The second one should immediately capture after the crash.
|
||||
let waitUrl = bgTestPageURL({ wait: 30000 });
|
||||
let sawWaitUrlCapture = false;
|
||||
bgCapture(waitUrl, {
|
||||
let failCapture = bgCapture(waitUrl, {
|
||||
onDone: () => {
|
||||
sawWaitUrlCapture = true;
|
||||
ok(
|
||||
|
@ -21,7 +21,7 @@ function* runTests() {
|
|||
);
|
||||
},
|
||||
});
|
||||
bgCapture(goodUrl, {
|
||||
let goodCapture = bgCapture(goodUrl, {
|
||||
onDone: () => {
|
||||
ok(sawWaitUrlCapture, "waitUrl capture should have finished first");
|
||||
ok(
|
||||
|
@ -29,30 +29,20 @@ function* runTests() {
|
|||
"We should have recovered and completed the 2nd capture after the crash"
|
||||
);
|
||||
removeThumbnail(goodUrl);
|
||||
// Test done.
|
||||
next();
|
||||
},
|
||||
});
|
||||
let crashPromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(waitUrl).catch(function(err) {
|
||||
ok(true, `page-thumbnail error thrown for ${waitUrl}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
let capturePromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(goodUrl).then(() => {
|
||||
ok(true, `page-thumbnail created for ${goodUrl}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
let crashPromise = bgAddPageThumbObserver(waitUrl);
|
||||
let capturePromise = bgAddPageThumbObserver(goodUrl);
|
||||
|
||||
info("Crashing the thumbnail content process.");
|
||||
let crash = yield BrowserTestUtils.crashFrame(
|
||||
let crash = await BrowserTestUtils.crashFrame(
|
||||
BackgroundPageThumbs._thumbBrowser,
|
||||
false
|
||||
);
|
||||
ok(crash.CrashTime, "Saw a crash from this test");
|
||||
|
||||
yield crashPromise;
|
||||
yield capturePromise;
|
||||
}
|
||||
await Assert.rejects(crashPromise, /page-thumbnail:error/);
|
||||
|
||||
await Promise.all([failCapture, goodCapture, capturePromise]);
|
||||
});
|
||||
|
|
|
@ -1,33 +1,29 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_crash_while_idle() {
|
||||
// make a good capture first - this ensures we have the <browser>
|
||||
let goodUrl = bgTestPageURL();
|
||||
yield bgCapture(goodUrl);
|
||||
await bgCapture(goodUrl);
|
||||
ok(thumbnailExists(goodUrl), "Thumbnail should be cached after capture");
|
||||
removeThumbnail(goodUrl);
|
||||
|
||||
// Nothing is pending - crash the process.
|
||||
info("Crashing the thumbnail content process.");
|
||||
let crash = yield BrowserTestUtils.crashFrame(
|
||||
let crash = await BrowserTestUtils.crashFrame(
|
||||
BackgroundPageThumbs._thumbBrowser,
|
||||
false
|
||||
);
|
||||
ok(crash.CrashTime, "Saw a crash from this test");
|
||||
|
||||
// Now queue another capture and ensure it recovers.
|
||||
bgCapture(goodUrl, {
|
||||
await bgCapture(goodUrl, {
|
||||
onDone: () => {
|
||||
ok(
|
||||
thumbnailExists(goodUrl),
|
||||
"We should have recovered and handled new capture requests"
|
||||
);
|
||||
removeThumbnail(goodUrl);
|
||||
// Test done.
|
||||
next();
|
||||
},
|
||||
});
|
||||
|
||||
yield true;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
yield SpecialPowers.pushPrefEnv({
|
||||
add_task(async function thumbnails_bg_destroy_browser() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["dom.ipc.processCount", 1]],
|
||||
});
|
||||
|
||||
|
@ -15,17 +15,20 @@ function* runTests() {
|
|||
let defaultTimeout = BackgroundPageThumbs._destroyBrowserTimeout;
|
||||
BackgroundPageThumbs._destroyBrowserTimeout = 1000;
|
||||
|
||||
yield bgCapture(url1);
|
||||
await bgCapture(url1);
|
||||
ok(thumbnailExists(url1), "First file should exist after capture.");
|
||||
removeThumbnail(url1);
|
||||
|
||||
// arbitrary wait - intermittent failures noted after 2 seconds
|
||||
for (let i = 0; i < 5; i++) {
|
||||
yield wait(1000);
|
||||
if (BackgroundPageThumbs._thumbBrowser === undefined) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
await TestUtils.waitForCondition(
|
||||
() => {
|
||||
return BackgroundPageThumbs._thumbBrowser === undefined;
|
||||
},
|
||||
"BackgroundPageThumbs._thumbBrowser should eventually be discarded.",
|
||||
1000,
|
||||
5
|
||||
);
|
||||
|
||||
is(
|
||||
BackgroundPageThumbs._thumbBrowser,
|
||||
undefined,
|
||||
|
@ -33,7 +36,7 @@ function* runTests() {
|
|||
);
|
||||
BackgroundPageThumbs._destroyBrowserTimeout = defaultTimeout;
|
||||
|
||||
yield bgCapture(url2);
|
||||
await bgCapture(url2);
|
||||
ok(thumbnailExists(url2), "Second file should exist after capture.");
|
||||
removeThumbnail(url2);
|
||||
|
||||
|
@ -42,4 +45,4 @@ function* runTests() {
|
|||
undefined,
|
||||
"Thumb browser should exist immediately after capture."
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -9,16 +9,15 @@ const BASE_URL =
|
|||
* the image itself is captured instead of the the browser window displaying the
|
||||
* image, and that the thumbnail maintains the image aspect ratio.
|
||||
*/
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_image_capture() {
|
||||
// Test that malformed input causes _finishCurrentCapture to be called with
|
||||
// the correct reason.
|
||||
const emptyUrl = "data:text/plain,";
|
||||
yield bgCapture(emptyUrl, {
|
||||
await bgCapture(emptyUrl, {
|
||||
isImage: true,
|
||||
onDone: (url, reason) => {
|
||||
// BackgroundPageThumbs.TEL_CAPTURE_DONE_LOAD_FAILED === 6
|
||||
is(reason, 6, "Should have the right failure reason");
|
||||
next();
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -43,23 +42,16 @@ function* runTests() {
|
|||
},
|
||||
]) {
|
||||
dontExpireThumbnailURLs([url]);
|
||||
const capturedPromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(url).then(() => {
|
||||
ok(true, `page-thumbnail created for ${url}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
yield bgCapture(url);
|
||||
yield capturedPromise;
|
||||
const capturedPromise = bgAddPageThumbObserver(url);
|
||||
await bgCapture(url);
|
||||
await capturedPromise;
|
||||
ok(thumbnailExists(url), "The image thumbnail should exist after capture");
|
||||
|
||||
const thumb = PageThumbs.getThumbnailURL(url);
|
||||
const htmlns = "http://www.w3.org/1999/xhtml";
|
||||
const img = document.createElementNS(htmlns, "img");
|
||||
yield new Promise(resolve => {
|
||||
img.onload = () => resolve();
|
||||
img.src = thumb;
|
||||
});
|
||||
img.src = thumb;
|
||||
await BrowserTestUtils.waitForEvent(img, "load");
|
||||
|
||||
// 448px is the default max-width of an image thumbnail
|
||||
const expectedWidth = Math.min(448, width);
|
||||
|
@ -100,4 +92,4 @@ function* runTests() {
|
|||
|
||||
removeThumbnail(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_no_alert() {
|
||||
let url =
|
||||
"data:text/html,<script>try { alert('yo!'); } catch (e) {}</script>";
|
||||
ok(!thumbnailExists(url), "Thumbnail file should not already exist.");
|
||||
|
||||
let capturedURL = yield bgCapture(url);
|
||||
let [capturedURL] = await bgCapture(url);
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture.");
|
||||
ok(
|
||||
thumbnailExists(url),
|
||||
"Thumbnail file should exist even though it alerted."
|
||||
);
|
||||
removeThumbnail(url);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// the following tests attempt to display modal dialogs. The test just
|
||||
// relies on the fact that if the dialog was displayed the test will hang
|
||||
// and timeout. IOW - the tests would pass if the dialogs appear and are
|
||||
// manually closed by the user - so don't do that :) (obviously there is
|
||||
// noone available to do that when run via tbpl etc, so this should be safe,
|
||||
// and it's tricky to use the window-watcher to check a window *does not*
|
||||
// appear - how long should the watcher be active before assuming it's not
|
||||
// going to appear?)
|
||||
function* runTests() {
|
||||
/**
|
||||
* The following tests attempt to display modal dialogs. The test just
|
||||
* relies on the fact that if the dialog was displayed the test will hang
|
||||
* and timeout. IOW - the tests would pass if the dialogs appear and are
|
||||
* manually closed by the user - so don't do that :) (obviously there is
|
||||
* noone available to do that when run via tbpl etc, so this should be safe,
|
||||
* and it's tricky to use the window-watcher to check a window *does not*
|
||||
* appear - how long should the watcher be active before assuming it's not
|
||||
* going to appear?)
|
||||
*/
|
||||
add_task(async function thumbnails_bg_no_auth_prompt() {
|
||||
let url =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/authenticate.sjs?user=anyone";
|
||||
ok(!thumbnailExists(url), "Thumbnail file should not already exist.");
|
||||
|
||||
let capturedURL = yield bgCapture(url);
|
||||
let [capturedURL] = await bgCapture(url);
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture.");
|
||||
ok(
|
||||
thumbnailExists(url),
|
||||
"Thumbnail file should exist even though it requires auth."
|
||||
);
|
||||
removeThumbnail(url);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,47 +1,49 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_no_cookies_sent() {
|
||||
// Visit the test page in the browser and tell it to set a cookie.
|
||||
let url = bgTestPageURL({ setGreenCookie: true });
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
|
||||
let browser = tab.linkedBrowser;
|
||||
|
||||
// The root element of the page shouldn't be green yet.
|
||||
yield ContentTask.spawn(browser, null, function() {
|
||||
Assert.notEqual(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(0, 255, 0)",
|
||||
"The page shouldn't be green yet."
|
||||
);
|
||||
});
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url,
|
||||
},
|
||||
async browser => {
|
||||
// The root element of the page shouldn't be green yet.
|
||||
await ContentTask.spawn(browser, null, function() {
|
||||
Assert.notEqual(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(0, 255, 0)",
|
||||
"The page shouldn't be green yet."
|
||||
);
|
||||
});
|
||||
|
||||
// Cookie should be set now. Reload the page to verify. Its root element
|
||||
// will be green if the cookie's set.
|
||||
browser.reload();
|
||||
yield BrowserTestUtils.browserLoaded(browser);
|
||||
yield ContentTask.spawn(browser, null, function() {
|
||||
Assert.equal(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(0, 255, 0)",
|
||||
"The page should be green now."
|
||||
);
|
||||
});
|
||||
// Cookie should be set now. Reload the page to verify. Its root element
|
||||
// will be green if the cookie's set.
|
||||
browser.reload();
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
await ContentTask.spawn(browser, null, function() {
|
||||
Assert.equal(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(0, 255, 0)",
|
||||
"The page should be green now."
|
||||
);
|
||||
});
|
||||
|
||||
// Capture the page. Get the image data of the capture and verify it's not
|
||||
// green. (Checking only the first pixel suffices.)
|
||||
yield bgCapture(url);
|
||||
ok(thumbnailExists(url), "Thumbnail file should exist after capture.");
|
||||
// Capture the page. Get the image data of the capture and verify it's not
|
||||
// green. (Checking only the first pixel suffices.)
|
||||
await bgCapture(url);
|
||||
ok(thumbnailExists(url), "Thumbnail file should exist after capture.");
|
||||
|
||||
retrieveImageDataForURL(url, function([r, g, b]) {
|
||||
isnot(
|
||||
[r, g, b].toString(),
|
||||
[0, 255, 0].toString(),
|
||||
"The captured page should not be green."
|
||||
);
|
||||
gBrowser.removeTab(tab);
|
||||
removeThumbnail(url);
|
||||
next();
|
||||
});
|
||||
yield true;
|
||||
}
|
||||
let [r, g, b] = await retrieveImageDataForURL(url);
|
||||
isnot(
|
||||
[r, g, b].toString(),
|
||||
[0, 255, 0].toString(),
|
||||
"The captured page should not be green."
|
||||
);
|
||||
removeThumbnail(url);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
// check that if a page captured in the background attempts to set a cookie,
|
||||
// that cookie is not saved for subsequent requests.
|
||||
function* runTests() {
|
||||
yield SpecialPowers.pushPrefEnv({
|
||||
/**
|
||||
* Check that if a page captured in the background attempts to set a cookie,
|
||||
* that cookie is not saved for subsequent requests.
|
||||
*/
|
||||
add_task(async function thumbnails_bg_no_cookies_stored() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["privacy.usercontext.about_newtab_segregation.enabled", true]],
|
||||
});
|
||||
let url = bgTestPageURL({
|
||||
|
@ -13,22 +15,25 @@ function* runTests() {
|
|||
xhr: bgTestPageURL({ setRedCookie: true }),
|
||||
});
|
||||
ok(!thumbnailExists(url), "Thumbnail file should not exist before capture.");
|
||||
yield bgCapture(url);
|
||||
await bgCapture(url);
|
||||
ok(thumbnailExists(url), "Thumbnail file should exist after capture.");
|
||||
removeThumbnail(url);
|
||||
// now load it up in a browser - it should *not* be red, otherwise the
|
||||
// cookie above was saved.
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, url);
|
||||
let browser = tab.linkedBrowser;
|
||||
|
||||
// The root element of the page shouldn't be red.
|
||||
yield ContentTask.spawn(browser, null, function() {
|
||||
Assert.notEqual(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(255, 0, 0)",
|
||||
"The page shouldn't be red."
|
||||
);
|
||||
});
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url,
|
||||
},
|
||||
async browser => {
|
||||
// The root element of the page shouldn't be red.
|
||||
await ContentTask.spawn(browser, null, function() {
|
||||
Assert.notEqual(
|
||||
content.document.documentElement.style.backgroundColor,
|
||||
"rgb(255, 0, 0)",
|
||||
"The page shouldn't be red."
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -1,31 +1,24 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_no_duplicates() {
|
||||
let url = "http://example.com/1";
|
||||
ok(!thumbnailExists(url), "Thumbnail file should not already exist.");
|
||||
let numCallbacks = 0;
|
||||
let doneCallback = function(doneUrl) {
|
||||
is(doneUrl, url, "called back with correct url");
|
||||
numCallbacks += 1;
|
||||
// We will delete the file after the first callback, then check it
|
||||
// still doesn't exist on the second callback, which should give us
|
||||
// confidence that we didn't end up with 2 different captures happening
|
||||
// for the same url...
|
||||
if (numCallbacks == 1) {
|
||||
|
||||
let firstCapture = bgCapture(url, {
|
||||
onDone: doneUrl => {
|
||||
is(doneUrl, url, "called back with correct url");
|
||||
ok(thumbnailExists(url), "Thumbnail file should now exist.");
|
||||
removeThumbnail(url);
|
||||
return;
|
||||
}
|
||||
if (numCallbacks == 2) {
|
||||
},
|
||||
});
|
||||
|
||||
let secondCapture = bgCapture(url, {
|
||||
onDone: doneUrl => {
|
||||
is(doneUrl, url, "called back with correct url");
|
||||
ok(!thumbnailExists(url), "Thumbnail file should still be deleted.");
|
||||
// and that's all we expect, so we are done...
|
||||
next();
|
||||
return;
|
||||
}
|
||||
ok(false, "only expecting 2 callbacks");
|
||||
};
|
||||
BackgroundPageThumbs.capture(url, { onDone: doneCallback });
|
||||
BackgroundPageThumbs.capture(url, { onDone: doneCallback });
|
||||
yield true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all([firstCapture, secondCapture]);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_queueing() {
|
||||
let urls = [
|
||||
"http://www.example.com/0",
|
||||
"http://www.example.com/1",
|
||||
|
@ -10,12 +10,16 @@ function* runTests() {
|
|||
"http://www.example.com/2",
|
||||
];
|
||||
dontExpireThumbnailURLs(urls);
|
||||
urls.forEach(url => {
|
||||
|
||||
let promises = [];
|
||||
|
||||
for (let url of urls) {
|
||||
ok(!thumbnailExists(url), "Thumbnail should not exist yet: " + url);
|
||||
let isTimeoutTest = url.includes("wait");
|
||||
BackgroundPageThumbs.capture(url, {
|
||||
|
||||
let promise = bgCapture(url, {
|
||||
timeout: isTimeoutTest ? 100 : 30000,
|
||||
onDone: function onDone(capturedURL) {
|
||||
onDone: capturedURL => {
|
||||
ok(!!urls.length, "onDone called, so URLs should still remain");
|
||||
is(
|
||||
capturedURL,
|
||||
|
@ -35,12 +39,11 @@ function* runTests() {
|
|||
);
|
||||
removeThumbnail(url);
|
||||
}
|
||||
if (!urls.length) {
|
||||
// Test done.
|
||||
next();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
yield true;
|
||||
}
|
||||
|
||||
promises.push(promise);
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_redirect() {
|
||||
let finalURL = "http://example.com/redirected";
|
||||
let originalURL = bgTestPageURL({ redirect: finalURL });
|
||||
|
||||
|
@ -14,24 +14,13 @@ function* runTests() {
|
|||
"Thumbnail file for final URL should not exist yet."
|
||||
);
|
||||
|
||||
let captureOriginalPromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(originalURL).then(() => {
|
||||
ok(true, `page-thumbnail created for ${originalURL}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
let captureOriginalPromise = bgAddPageThumbObserver(originalURL);
|
||||
let captureFinalPromise = bgAddPageThumbObserver(finalURL);
|
||||
|
||||
let captureFinalPromise = new Promise(resolve => {
|
||||
bgAddPageThumbObserver(finalURL).then(() => {
|
||||
ok(true, `page-thumbnail created for ${finalURL}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
let capturedURL = yield bgCapture(originalURL);
|
||||
let [capturedURL] = await bgCapture(originalURL);
|
||||
is(capturedURL, originalURL, "Captured URL should be URL passed to capture");
|
||||
yield captureOriginalPromise;
|
||||
yield captureFinalPromise;
|
||||
await captureOriginalPromise;
|
||||
await captureFinalPromise;
|
||||
ok(
|
||||
thumbnailExists(originalURL),
|
||||
"Thumbnail for original URL should be cached"
|
||||
|
@ -40,4 +29,4 @@ function* runTests() {
|
|||
|
||||
removeThumbnail(originalURL);
|
||||
removeThumbnail(finalURL);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,26 +1,23 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_timeout() {
|
||||
let url = bgTestPageURL({ wait: 30000 });
|
||||
ok(!thumbnailExists(url), "Thumbnail should not be cached already.");
|
||||
let numCalls = 0;
|
||||
BackgroundPageThumbs.capture(url, {
|
||||
let thumbnailErrorPromise = bgAddPageThumbObserver(url);
|
||||
|
||||
await bgCapture(url, {
|
||||
timeout: 0,
|
||||
onDone: function onDone(capturedURL) {
|
||||
onDone: capturedURL => {
|
||||
is(capturedURL, url, "Captured URL should be URL passed to capture");
|
||||
is(numCalls++, 0, "onDone should be called only once");
|
||||
ok(
|
||||
!thumbnailExists(url),
|
||||
"Capture timed out so thumbnail should not be cached"
|
||||
);
|
||||
next();
|
||||
},
|
||||
});
|
||||
yield new Promise(resolve => {
|
||||
bgAddPageThumbObserver(url).catch(function(err) {
|
||||
ok(true, `page-thumbnail error thrown for ${url}`);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
await Assert.rejects(thumbnailErrorPromise, /page-thumbnail:error/);
|
||||
});
|
||||
|
|
|
@ -7,8 +7,8 @@ const image96x96 =
|
|||
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAAAJCAYAAADNYymqAAAAKklEQVR42u3RMQEAAAjDMFCO9CGDg1RC00lN6awGAACADQAACAAAAXjXApPGFm+IdJG9AAAAAElFTkSuQmCC";
|
||||
const baseURL = "http://mozilla${i}.com/";
|
||||
|
||||
function* runTests() {
|
||||
yield SpecialPowers.pushPrefEnv({
|
||||
add_task(async function thumbnails_bg_topsites() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
[
|
||||
"browser.newtabpage.activity-stream.improvesearch.topSiteSearchShortcuts",
|
||||
|
@ -18,18 +18,18 @@ function* runTests() {
|
|||
});
|
||||
// Add 3 top sites - 2 visits each so it can pass frecency threshold of the top sites query
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
yield PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
yield PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
await PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
await PlacesTestUtils.addVisits(baseURL.replace("${i}", i));
|
||||
}
|
||||
|
||||
// Add favicon data for 2 of the top sites
|
||||
let faviconData = new Map();
|
||||
faviconData.set("http://mozilla1.com/", image1x1);
|
||||
faviconData.set("http://mozilla2.com/", image96x96);
|
||||
yield PlacesTestUtils.addFavicons(faviconData);
|
||||
await PlacesTestUtils.addFavicons(faviconData);
|
||||
|
||||
// Sanity check that we've successfully added all 3 urls to top sites
|
||||
let links = yield NewTabUtils.activityStreamLinks.getTopSites();
|
||||
let links = await NewTabUtils.activityStreamLinks.getTopSites();
|
||||
is(
|
||||
links[0].url,
|
||||
baseURL.replace("${i}", 3),
|
||||
|
@ -52,7 +52,7 @@ function* runTests() {
|
|||
|
||||
// Check that the correct sites will capture screenshots
|
||||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
let topSites = yield gBrowserThumbnails._topSiteURLs;
|
||||
let topSites = await gBrowserThumbnails._topSiteURLs;
|
||||
ok(
|
||||
topSites.includes("http://mozilla1.com/"),
|
||||
"Top site did not have a rich icon - get a screenshot"
|
||||
|
@ -72,5 +72,5 @@ function* runTests() {
|
|||
|
||||
// Clean up
|
||||
NewTabUtils.pinnedLinks.unpin(pinnedSite);
|
||||
yield PlacesUtils.history.clear();
|
||||
}
|
||||
await PlacesUtils.history.clear();
|
||||
});
|
||||
|
|
|
@ -5,16 +5,23 @@
|
|||
* These tests ensure that capturing a sites's thumbnail, saving it and
|
||||
* retrieving it from the cache works.
|
||||
*/
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_bug726727() {
|
||||
// Create a tab that shows an error page.
|
||||
let tab = BrowserTestUtils.addTab(gBrowser, "http://127.0.0.1:1/");
|
||||
let browser = tab.linkedBrowser;
|
||||
yield BrowserTestUtils.waitForContentEvent(browser, "DOMContentLoaded");
|
||||
|
||||
yield new Promise(resolve => {
|
||||
PageThumbs.shouldStoreThumbnail(browser).then(aResult => {
|
||||
ok(!aResult, "we're not going to capture an error page");
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
},
|
||||
async browser => {
|
||||
let errorPageLoaded = BrowserTestUtils.browserLoaded(
|
||||
browser,
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
BrowserTestUtils.loadURI(browser, "http://127.0.0.1:1");
|
||||
await errorPageLoaded;
|
||||
let result = await PageThumbs.shouldStoreThumbnail(browser);
|
||||
ok(!result, "we're not going to capture an error page");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -14,19 +14,25 @@ function isRedThumbnailFuzz(r, g, b, expectedR, expectedB, expectedG, aFuzz) {
|
|||
}
|
||||
|
||||
// Test for black borders caused by scrollbars.
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_bug727765() {
|
||||
// Create a tab with a page with a red background and scrollbars.
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
|
||||
// Check the thumbnail color of the bottom right pixel.
|
||||
yield whenFileExists(URL);
|
||||
yield retrieveImageDataForURL(URL, function(aData) {
|
||||
let [r, g, b] = [].slice.call(aData, -4);
|
||||
let fuzz = 2; // Windows 8 x64 blends with the scrollbar a bit.
|
||||
var message =
|
||||
"Expected red thumbnail rgb(255, 0, 0), got " + r + "," + g + "," + b;
|
||||
ok(isRedThumbnailFuzz(r, g, b, 255, 0, 0, fuzz), message);
|
||||
next();
|
||||
});
|
||||
}
|
||||
// Check the thumbnail color of the bottom right pixel.
|
||||
await whenFileExists(URL);
|
||||
|
||||
let data = await retrieveImageDataForURL(URL);
|
||||
let [r, g, b] = [].slice.call(data, -4);
|
||||
let fuzz = 2; // Windows 8 x64 blends with the scrollbar a bit.
|
||||
var message =
|
||||
"Expected red thumbnail rgb(255, 0, 0), got " + r + "," + g + "," + b;
|
||||
ok(isRedThumbnailFuzz(r, g, b, 255, 0, 0, fuzz), message);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -7,29 +7,28 @@ const URL =
|
|||
Date.now();
|
||||
|
||||
// Test PageThumbs API function getThumbnailPath
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_bg_bug818225() {
|
||||
let path = PageThumbs.getThumbnailPath(URL);
|
||||
yield testIfExists(path, false, "Thumbnail file does not exist");
|
||||
await testIfExists(path, false, "Thumbnail file does not exist");
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
|
||||
yield addVisitsAndRepopulateNewTabLinks(URL, next);
|
||||
yield createThumbnail(URL);
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
await whenFileExists(URL);
|
||||
}
|
||||
);
|
||||
|
||||
path = PageThumbs.getThumbnailPath(URL);
|
||||
let expectedPath = PageThumbsStorageService.getFilePathForURL(URL);
|
||||
is(path, expectedPath, "Thumbnail file has correct path");
|
||||
|
||||
yield testIfExists(path, true, "Thumbnail file exists");
|
||||
}
|
||||
|
||||
function createThumbnail(aURL) {
|
||||
addTab(aURL, function() {
|
||||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
whenFileExists(aURL, function() {
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
next();
|
||||
});
|
||||
});
|
||||
}
|
||||
await testIfExists(path, true, "Thumbnail file exists");
|
||||
});
|
||||
|
||||
function testIfExists(aPath, aExpected, aMessage) {
|
||||
return OS.File.exists(aPath).then(
|
||||
|
|
|
@ -5,16 +5,33 @@
|
|||
* These tests ensure that capturing a sites's thumbnail, saving it and
|
||||
* retrieving it from the cache works.
|
||||
*/
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_capture() {
|
||||
// Create a tab with a red background.
|
||||
yield addTab("data:text/html,<body bgcolor=ff0000></body>");
|
||||
yield captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: "data:text/html,<body bgcolor=ff0000></body>",
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
|
||||
// Load a page with a green background.
|
||||
yield navigateTo("data:text/html,<body bgcolor=00ff00></body>");
|
||||
yield captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
// Load a page with a green background.
|
||||
let loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
BrowserTestUtils.loadURI(
|
||||
browser,
|
||||
"data:text/html,<body bgcolor=00ff00></body>"
|
||||
);
|
||||
await loaded;
|
||||
await captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
|
||||
// Load a page with a blue background.
|
||||
yield navigateTo("data:text/html,<body bgcolor=0000ff></body>");
|
||||
yield captureAndCheckColor(0, 0, 255, "we have a blue thumbnail");
|
||||
}
|
||||
// Load a page with a blue background.
|
||||
loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
BrowserTestUtils.loadURI(
|
||||
browser,
|
||||
"data:text/html,<body bgcolor=0000ff></body>"
|
||||
);
|
||||
await loaded;
|
||||
await captureAndCheckColor(0, 0, 255, "we have a blue thumbnail");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@ Services.scriptloader.loadSubScript(
|
|||
const EXPIRATION_MIN_CHUNK_SIZE = 50;
|
||||
const { PageThumbsExpiration } = tmp;
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_expiration() {
|
||||
// Create dummy URLs.
|
||||
let dummyURLs = [];
|
||||
for (let i = 0; i < EXPIRATION_MIN_CHUNK_SIZE + 10; i++) {
|
||||
|
@ -26,47 +26,47 @@ function* runTests() {
|
|||
dontExpireThumbnailURLs([URL1, URL2, URL3].concat(dummyURLs));
|
||||
|
||||
// Create three thumbnails.
|
||||
yield createDummyThumbnail(URL1);
|
||||
await createDummyThumbnail(URL1);
|
||||
ok(thumbnailExists(URL1), "first thumbnail created");
|
||||
|
||||
yield createDummyThumbnail(URL2);
|
||||
await createDummyThumbnail(URL2);
|
||||
ok(thumbnailExists(URL2), "second thumbnail created");
|
||||
|
||||
yield createDummyThumbnail(URL3);
|
||||
await createDummyThumbnail(URL3);
|
||||
ok(thumbnailExists(URL3), "third thumbnail created");
|
||||
|
||||
// Remove the third thumbnail.
|
||||
yield expireThumbnails([URL1, URL2]);
|
||||
await expireThumbnails([URL1, URL2]);
|
||||
ok(thumbnailExists(URL1), "first thumbnail still exists");
|
||||
ok(thumbnailExists(URL2), "second thumbnail still exists");
|
||||
ok(!thumbnailExists(URL3), "third thumbnail has been removed");
|
||||
|
||||
// Remove the second thumbnail.
|
||||
yield expireThumbnails([URL1]);
|
||||
await expireThumbnails([URL1]);
|
||||
ok(thumbnailExists(URL1), "first thumbnail still exists");
|
||||
ok(!thumbnailExists(URL2), "second thumbnail has been removed");
|
||||
|
||||
// Remove all thumbnails.
|
||||
yield expireThumbnails([]);
|
||||
await expireThumbnails([]);
|
||||
ok(!thumbnailExists(URL1), "all thumbnails have been removed");
|
||||
|
||||
// Create some more files than the min chunk size.
|
||||
for (let url of dummyURLs) {
|
||||
yield createDummyThumbnail(url);
|
||||
await createDummyThumbnail(url);
|
||||
}
|
||||
|
||||
ok(dummyURLs.every(thumbnailExists), "all dummy thumbnails created");
|
||||
|
||||
// Expire thumbnails and expect 10 remaining.
|
||||
yield expireThumbnails([]);
|
||||
await expireThumbnails([]);
|
||||
let remainingURLs = dummyURLs.filter(thumbnailExists);
|
||||
is(remainingURLs.length, 10, "10 dummy thumbnails remaining");
|
||||
|
||||
// Expire thumbnails again. All should be gone by now.
|
||||
yield expireThumbnails([]);
|
||||
await expireThumbnails([]);
|
||||
remainingURLs = remainingURLs.filter(thumbnailExists);
|
||||
is(remainingURLs.length, 0, "no dummy thumbnails remaining");
|
||||
}
|
||||
});
|
||||
|
||||
function createDummyThumbnail(aURL) {
|
||||
info("Creating dummy thumbnail for " + aURL);
|
||||
|
@ -74,25 +74,9 @@ function createDummyThumbnail(aURL) {
|
|||
for (let i = 0; i < 10; ++i) {
|
||||
dummy[i] = i;
|
||||
}
|
||||
PageThumbsStorage.writeData(aURL, dummy).then(
|
||||
function onSuccess() {
|
||||
info("createDummyThumbnail succeeded");
|
||||
executeSoon(next);
|
||||
},
|
||||
function onFailure(error) {
|
||||
ok(false, "createDummyThumbnail failed " + error);
|
||||
}
|
||||
);
|
||||
return PageThumbsStorage.writeData(aURL, dummy);
|
||||
}
|
||||
|
||||
function expireThumbnails(aKeep) {
|
||||
PageThumbsExpiration.expireThumbnails(aKeep).then(
|
||||
function onSuccess() {
|
||||
info("expireThumbnails succeeded");
|
||||
executeSoon(next);
|
||||
},
|
||||
function onFailure(error) {
|
||||
ok(false, "expireThumbnails failed " + error);
|
||||
}
|
||||
);
|
||||
return PageThumbsExpiration.expireThumbnails(aKeep);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ const URL =
|
|||
"://example.com/browser/toolkit/components/thumbnails/" +
|
||||
"test/privacy_cache_control.sjs";
|
||||
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_privacy() {
|
||||
registerCleanupFunction(function() {
|
||||
Services.prefs.clearUserPref(PREF_DISK_CACHE_SSL);
|
||||
});
|
||||
|
@ -37,39 +37,36 @@ function* runTests() {
|
|||
{ scheme: "https", cacheControl: "private", diskCacheSSL: false },
|
||||
];
|
||||
|
||||
yield checkCombinations(positive, true);
|
||||
yield checkCombinations(negative, false);
|
||||
}
|
||||
await checkCombinations(positive, true);
|
||||
await checkCombinations(negative, false);
|
||||
});
|
||||
|
||||
function checkCombinations(aCombinations, aResult) {
|
||||
let combi = aCombinations.shift();
|
||||
if (!combi) {
|
||||
next();
|
||||
return;
|
||||
async function checkCombinations(aCombinations, aResult) {
|
||||
for (let combination of aCombinations) {
|
||||
let url = combination.scheme + URL;
|
||||
if (combination.cacheControl) {
|
||||
url += "?" + combination.cacheControl;
|
||||
}
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [[PREF_DISK_CACHE_SSL, combination.diskCacheSSL]],
|
||||
});
|
||||
|
||||
// Add the test page as a top link so it has a chance to be thumbnailed
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(url);
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url,
|
||||
},
|
||||
async browser => {
|
||||
let msg = JSON.stringify(combination) + " == " + aResult;
|
||||
let aIsSafeSite = await PageThumbs.shouldStoreThumbnail(browser);
|
||||
Assert.equal(aIsSafeSite, aResult, msg);
|
||||
}
|
||||
);
|
||||
|
||||
await SpecialPowers.popPrefEnv();
|
||||
}
|
||||
|
||||
let url = combi.scheme + URL;
|
||||
if (combi.cacheControl) {
|
||||
url += "?" + combi.cacheControl;
|
||||
}
|
||||
Services.prefs.setBoolPref(PREF_DISK_CACHE_SSL, combi.diskCacheSSL);
|
||||
|
||||
// Add the test page as a top link so it has a chance to be thumbnailed
|
||||
addVisitsAndRepopulateNewTabLinks(url, _ => {
|
||||
testCombination(combi, url, aCombinations, aResult);
|
||||
});
|
||||
}
|
||||
|
||||
function testCombination(combi, url, aCombinations, aResult) {
|
||||
let tab = (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, url));
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
BrowserTestUtils.browserLoaded(browser).then(async () => {
|
||||
let msg = JSON.stringify(combi) + " == " + aResult;
|
||||
let aIsSafeSite = await PageThumbs.shouldStoreThumbnail(browser);
|
||||
is(aIsSafeSite, aResult, msg);
|
||||
gBrowser.removeTab(tab);
|
||||
// Continue with the next combination.
|
||||
checkCombinations(aCombinations, aResult);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,21 +12,31 @@ const FINAL_URL =
|
|||
/**
|
||||
* These tests ensure that we save and provide thumbnails for redirecting sites.
|
||||
*/
|
||||
function* runTests() {
|
||||
add_task(async function thumbnails_redirect() {
|
||||
dontExpireThumbnailURLs([URL, FINAL_URL]);
|
||||
|
||||
// Kick off history by loading a tab first or the test fails in single mode.
|
||||
yield addTab(URL);
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
browser => {}
|
||||
);
|
||||
|
||||
// Create a tab, redirecting to a page with a red background.
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(255, 0, 0, "we have a red thumbnail");
|
||||
|
||||
// Wait until the referrer's thumbnail's file has been written.
|
||||
yield whenFileExists(URL);
|
||||
yield retrieveImageDataForURL(URL, function([r, g, b]) {
|
||||
is("" + [r, g, b], "255,0,0", "referrer has a red thumbnail");
|
||||
next();
|
||||
});
|
||||
}
|
||||
// Wait until the referrer's thumbnail's file has been written.
|
||||
await whenFileExists(URL);
|
||||
let [r, g, b] = await retrieveImageDataForURL(URL);
|
||||
is("" + [r, g, b], "255,0,0", "referrer has a red thumbnail");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -11,59 +11,57 @@ const { Sanitizer } = ChromeUtils.import("resource:///modules/Sanitizer.jsm");
|
|||
* Newly captured thumbnails should be saved as files and they should as well
|
||||
* be removed when the user sanitizes their history.
|
||||
*/
|
||||
function* runTests() {
|
||||
yield (async function() {
|
||||
dontExpireThumbnailURLs([URL, URL_COPY]);
|
||||
add_task(async function thumbnails_storage() {
|
||||
dontExpireThumbnailURLs([URL, URL_COPY]);
|
||||
|
||||
await promiseClearHistory();
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
|
||||
// Make sure Storage.copy() updates an existing file.
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
let copy = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL_COPY)
|
||||
);
|
||||
let mtime = (copy.lastModifiedTime -= 60);
|
||||
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
isnot(
|
||||
new FileUtils.File(PageThumbsStorageService.getFilePathForURL(URL_COPY))
|
||||
.lastModifiedTime,
|
||||
mtime,
|
||||
"thumbnail file was updated"
|
||||
);
|
||||
|
||||
let file = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL)
|
||||
);
|
||||
let fileCopy = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL_COPY)
|
||||
);
|
||||
|
||||
// Clear the browser history. Retry until the files are gone because Windows
|
||||
// locks them sometimes.
|
||||
info("Clearing history");
|
||||
while (file.exists() || fileCopy.exists()) {
|
||||
await promiseClearHistory();
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
}
|
||||
info("History is clear");
|
||||
|
||||
// Make sure Storage.copy() updates an existing file.
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
let copy = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL_COPY)
|
||||
);
|
||||
let mtime = (copy.lastModifiedTime -= 60);
|
||||
info("Repopulating");
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
|
||||
await PageThumbsStorage.copy(URL, URL_COPY);
|
||||
isnot(
|
||||
new FileUtils.File(PageThumbsStorageService.getFilePathForURL(URL_COPY))
|
||||
.lastModifiedTime,
|
||||
mtime,
|
||||
"thumbnail file was updated"
|
||||
);
|
||||
info("Clearing the last 10 minutes of browsing history");
|
||||
// Clear the last 10 minutes of browsing history.
|
||||
await promiseClearHistory(true);
|
||||
|
||||
let file = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL)
|
||||
);
|
||||
let fileCopy = new FileUtils.File(
|
||||
PageThumbsStorageService.getFilePathForURL(URL_COPY)
|
||||
);
|
||||
info("Attempt to clear file");
|
||||
// Retry until the file is gone because Windows locks it sometimes.
|
||||
await promiseClearFile(file, URL);
|
||||
|
||||
// Clear the browser history. Retry until the files are gone because Windows
|
||||
// locks them sometimes.
|
||||
info("Clearing history");
|
||||
while (file.exists() || fileCopy.exists()) {
|
||||
await promiseClearHistory();
|
||||
}
|
||||
info("History is clear");
|
||||
|
||||
info("Repopulating");
|
||||
await promiseAddVisitsAndRepopulateNewTabLinks(URL);
|
||||
await promiseCreateThumbnail();
|
||||
|
||||
info("Clearing the last 10 minutes of browsing history");
|
||||
// Clear the last 10 minutes of browsing history.
|
||||
await promiseClearHistory(true);
|
||||
|
||||
info("Attempt to clear file");
|
||||
// Retry until the file is gone because Windows locks it sometimes.
|
||||
await promiseClearFile(file, URL);
|
||||
|
||||
info("Done");
|
||||
})();
|
||||
}
|
||||
info("Done");
|
||||
});
|
||||
|
||||
async function promiseClearFile(aFile, aURL) {
|
||||
if (!aFile.exists()) {
|
||||
|
@ -87,14 +85,15 @@ function promiseClearHistory(aUseRange) {
|
|||
return Sanitizer.sanitize(["history"], options);
|
||||
}
|
||||
|
||||
function promiseCreateThumbnail() {
|
||||
return new Promise(resolve => {
|
||||
addTab(URL, function() {
|
||||
async function promiseCreateThumbnail() {
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
gBrowserThumbnails.clearTopSiteURLCache();
|
||||
whenFileExists(URL, function() {
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
await whenFileExists(URL);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -5,23 +5,6 @@
|
|||
* These tests check the auto-update facility of the thumbnail service.
|
||||
*/
|
||||
|
||||
function* runTests() {
|
||||
// A "trampoline" - a generator that iterates over sub-iterators
|
||||
let tests = [
|
||||
simpleCaptureTest,
|
||||
capIfStaleErrorResponseUpdateTest,
|
||||
capIfStaleGoodResponseUpdateTest,
|
||||
regularCapErrorResponseUpdateTest,
|
||||
regularCapGoodResponseUpdateTest,
|
||||
];
|
||||
for (let test of tests) {
|
||||
info("Running subtest " + test.name);
|
||||
for (let iterator of test()) {
|
||||
yield iterator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ensureThumbnailStale(url) {
|
||||
// We go behind the back of the thumbnail service and change the
|
||||
// mtime of the file to be in the past.
|
||||
|
@ -40,36 +23,40 @@ function getThumbnailModifiedTime(url) {
|
|||
return file.lastModifiedTime;
|
||||
}
|
||||
|
||||
// The tests!
|
||||
/* Check functionality of a normal captureAndStoreIfStale request */
|
||||
function* simpleCaptureTest() {
|
||||
let numNotifications = 0;
|
||||
/**
|
||||
* Check functionality of a normal captureAndStoreIfStale request
|
||||
*/
|
||||
add_task(async function thumbnails_captureAndStoreIfStale_normal() {
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?simple";
|
||||
|
||||
function observe(subject, topic, data) {
|
||||
is(topic, "page-thumbnail:create", "got expected topic");
|
||||
is(data, URL, "data is our test URL");
|
||||
if (++numNotifications == 2) {
|
||||
// This is the final notification and signals test success...
|
||||
Services.obs.removeObserver(observe, "page-thumbnail:create");
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
next();
|
||||
}
|
||||
}
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
let numNotifications = 0;
|
||||
|
||||
Services.obs.addObserver(observe, "page-thumbnail:create");
|
||||
// Create a tab - we don't care what the content is.
|
||||
yield addTab(URL);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
let observed = TestUtils.topicObserved(
|
||||
"page-thumbnail:create",
|
||||
(subject, data) => {
|
||||
is(data, URL, "data is our test URL");
|
||||
|
||||
// Capture the screenshot.
|
||||
PageThumbs.captureAndStore(browser).then(function() {
|
||||
// We've got a capture so should have seen the observer.
|
||||
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).then(function() {
|
||||
// Once we get the second notification, we saw the last captureAndStoreIsStale,
|
||||
// and we can tear down.
|
||||
if (++numNotifications == 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
await PageThumbs.captureAndStore(browser);
|
||||
// We've got a capture so should have seen the observer.
|
||||
is(numNotifications, 1, "got notification of item being created.");
|
||||
|
||||
await PageThumbs.captureAndStoreIfStale(browser);
|
||||
is(
|
||||
numNotifications,
|
||||
1,
|
||||
|
@ -77,105 +64,148 @@ function* simpleCaptureTest() {
|
|||
);
|
||||
|
||||
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'...
|
||||
}
|
||||
await PageThumbs.captureAndStoreIfStale(browser);
|
||||
await observed;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/* Check functionality of captureAndStoreIfStale when there is an error response
|
||||
from the server.
|
||||
/**
|
||||
* Check functionality of captureAndStoreIfStale when there is an error response
|
||||
* from the server.
|
||||
*/
|
||||
function* capIfStaleErrorResponseUpdateTest() {
|
||||
add_task(async function thumbnails_captureAndStoreIfStale_error_response() {
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?fail";
|
||||
yield addTab(URL);
|
||||
|
||||
yield captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
// update the thumbnail to be stale, then re-request it. The server will
|
||||
// return a 400 response and a red thumbnail.
|
||||
// The service should not save the thumbnail - so we (a) check the thumbnail
|
||||
// remains green and (b) check the mtime of the file is < now.
|
||||
ensureThumbnailStale(URL);
|
||||
yield navigateTo(URL);
|
||||
// now() returns a higher-precision value than the modified time of a file.
|
||||
// As we set the thumbnail very stale, allowing 1 second of "slop" here
|
||||
// works around this while still keeping the test valid.
|
||||
let now = Date.now() - 1000;
|
||||
PageThumbs.captureAndStoreIfStale(gBrowser.selectedBrowser).then(() => {
|
||||
PageThumbsStorageService.getFilePathForURL(URL);
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
|
||||
ok(getThumbnailModifiedTime(URL) < now, "modified time should be < now");
|
||||
retrieveImageDataForURL(URL, function([r, g, b]) {
|
||||
// update the thumbnail to be stale, then re-request it. The server will
|
||||
// return a 400 response and a red thumbnail.
|
||||
// The service should not save the thumbnail - so we (a) check the thumbnail
|
||||
// remains green and (b) check the mtime of the file is < now.
|
||||
ensureThumbnailStale(URL);
|
||||
BrowserTestUtils.loadURI(browser, URL);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// now() returns a higher-precision value than the modified time of a file.
|
||||
// As we set the thumbnail very stale, allowing 1 second of "slop" here
|
||||
// works around this while still keeping the test valid.
|
||||
let now = Date.now() - 1000;
|
||||
await PageThumbs.captureAndStoreIfStale(gBrowser.selectedBrowser);
|
||||
|
||||
ok(getThumbnailModifiedTime(URL) < now, "modified time should be < now");
|
||||
let [r, g, b] = await retrieveImageDataForURL(URL);
|
||||
is("" + [r, g, b], "" + [0, 255, 0], "thumbnail is still green");
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
next();
|
||||
});
|
||||
});
|
||||
yield undefined; // wait for callback to call 'next'...
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/* Check functionality of captureAndStoreIfStale when there is a non-error
|
||||
response from the server. This test is somewhat redundant - although it is
|
||||
using a http:// URL instead of a data: url like most others.
|
||||
/**
|
||||
* Check functionality of captureAndStoreIfStale when there is a non-error
|
||||
* response from the server. This test is somewhat redundant - although it is
|
||||
* using a http:// URL instead of a data: url like most others.
|
||||
*/
|
||||
function* capIfStaleGoodResponseUpdateTest() {
|
||||
add_task(async function thumbnails_captureAndStoreIfStale_non_error_response() {
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?ok";
|
||||
yield addTab(URL);
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
yield captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
// update the thumbnail to be stale, then re-request it. The server will
|
||||
// return a 200 response and a red thumbnail - so that new thumbnail should
|
||||
// end up captured.
|
||||
ensureThumbnailStale(URL);
|
||||
yield navigateTo(URL);
|
||||
// now() returns a higher-precision value than the modified time of a file.
|
||||
// As we set the thumbnail very stale, allowing 1 second of "slop" here
|
||||
// works around this while still keeping the test valid.
|
||||
let now = Date.now() - 1000;
|
||||
PageThumbs.captureAndStoreIfStale(browser).then(() => {
|
||||
ok(getThumbnailModifiedTime(URL) >= now, "modified time should be >= now");
|
||||
// the captureAndStoreIfStale request saw a 200 response with the red body,
|
||||
// so we expect to see the red version here.
|
||||
retrieveImageDataForURL(URL, function([r, g, b]) {
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
// update the thumbnail to be stale, then re-request it. The server will
|
||||
// return a 200 response and a red thumbnail - so that new thumbnail should
|
||||
// end up captured.
|
||||
ensureThumbnailStale(URL);
|
||||
BrowserTestUtils.loadURI(browser, URL);
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
// now() returns a higher-precision value than the modified time of a file.
|
||||
// As we set the thumbnail very stale, allowing 1 second of "slop" here
|
||||
// works around this while still keeping the test valid.
|
||||
let now = Date.now() - 1000;
|
||||
await PageThumbs.captureAndStoreIfStale(browser);
|
||||
Assert.greater(
|
||||
getThumbnailModifiedTime(URL),
|
||||
now,
|
||||
"modified time should be >= now"
|
||||
);
|
||||
let [r, g, b] = await retrieveImageDataForURL(URL);
|
||||
is("" + [r, g, b], "" + [255, 0, 0], "thumbnail is now red");
|
||||
next();
|
||||
});
|
||||
});
|
||||
yield undefined; // wait for callback to call 'next'...
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/* Check functionality of captureAndStore when there is an error response
|
||||
from the server.
|
||||
/**
|
||||
* Check functionality of captureAndStore when there is an error response
|
||||
* from the server.
|
||||
*/
|
||||
function* regularCapErrorResponseUpdateTest() {
|
||||
add_task(async function thumbnails_captureAndStore_error_response() {
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?fail";
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
}
|
||||
);
|
||||
|
||||
// do it again - the server will return a 400, so the foreground service
|
||||
// should not update it.
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(0, 255, 0, "we still have a green thumbnail");
|
||||
}
|
||||
|
||||
/* Check functionality of captureAndStore when there is an OK response
|
||||
from the server.
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(0, 255, 0, "we still have a green thumbnail");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Check functionality of captureAndStore when there is an OK response
|
||||
* from the server.
|
||||
*/
|
||||
function* regularCapGoodResponseUpdateTest() {
|
||||
add_task(async function thumbnails_captureAndStore_ok_response() {
|
||||
const URL =
|
||||
"http://mochi.test:8888/browser/toolkit/components/thumbnails/test/thumbnails_update.sjs?ok";
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
gBrowser.removeTab(gBrowser.selectedTab);
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(0, 255, 0, "we have a green thumbnail");
|
||||
}
|
||||
);
|
||||
|
||||
// do it again - the server will return a 200, so the foreground service
|
||||
// should update it.
|
||||
yield addTab(URL);
|
||||
yield captureAndCheckColor(255, 0, 0, "we now have a red thumbnail");
|
||||
}
|
||||
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url: URL,
|
||||
},
|
||||
async browser => {
|
||||
await captureAndCheckColor(255, 0, 0, "we now have a red thumbnail");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче