toolkit/components/thumbnails/test/browser_thumbnails_bug818225.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/thumbnails/test/browser_thumbnails_bug818225.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +const URL = "http://mochi.test:8888/browser/toolkit/components/thumbnails/" +
     1.8 +            "test/background_red.html?" + Date.now();
     1.9 +
    1.10 +// Test PageThumbs API function getThumbnailPath
    1.11 +function runTests() {
    1.12 +
    1.13 +  let path = PageThumbs.getThumbnailPath(URL);
    1.14 +  yield testIfExists(path, false, "Thumbnail file does not exist");
    1.15 +
    1.16 +  yield addVisitsAndRepopulateNewTabLinks(URL, next);
    1.17 +  yield createThumbnail(URL);
    1.18 +
    1.19 +  path = PageThumbs.getThumbnailPath(URL);
    1.20 +  let expectedPath = PageThumbsStorage.getFilePathForURL(URL);
    1.21 +  is(path, expectedPath, "Thumbnail file has correct path");
    1.22 +
    1.23 +  yield testIfExists(path, true, "Thumbnail file exists");
    1.24 +
    1.25 +}
    1.26 +
    1.27 +function createThumbnail(aURL) {
    1.28 +  addTab(aURL, function () {
    1.29 +    whenFileExists(aURL, function () {
    1.30 +      gBrowser.removeTab(gBrowser.selectedTab);
    1.31 +      next();
    1.32 +    });
    1.33 +  });
    1.34 +}
    1.35 +
    1.36 +function testIfExists(aPath, aExpected, aMessage) {
    1.37 +  return OS.File.exists(aPath).then(
    1.38 +    function onSuccess(exists) {
    1.39 +      is(exists, aExpected, aMessage);
    1.40 +    },
    1.41 +    function onFailure(error) {
    1.42 +      ok(false, "OS.File.exists() failed " + error);
    1.43 +    }
    1.44 +  );
    1.45 +}

mercurial