gecko-dev/toolkit/components/thumbnails/test/test_thumbnails_interfaces.js
Oliver Henshaw 7e5727b51a Bug 1180715 (2/4) - Provide a nsIFileURL interface for thumbnails. review=ttaubert
Use nsISubstitutingProtocolHandler to return a SubstitutingURL and to
resolve the thumbnail URL to the backing nsIFile.

Now the image loader code will realise that moz-page-thumb:// URLs are
backed by a file and will be able to use the file mtime to evaluate
whether the cached imgRequest has expired.

* Implement the nsISubstitutingProtocolHandler methods in the thumbnail
protocol handler. The resolveURI method does all the work, the other
methods are just stubs.

* moz-page-thumb:// is now an URL rather than an URI, so update the
signature accordingly.

* Add xpcshell-test to affirm that SubstitutingURL::EnsureFile()
resolves the backing file correctly.

* Adjust the mochitest to account for the one second granularity of the
mtime tracking.
2015-10-20 10:45:32 +05:30

31 lines
1.3 KiB
JavaScript

// tests to check that moz-page-thumb URLs correctly resolve as file:// URLS
"use strict";
const Cu = Components.utils;
const Cc = Components.classes;
const Cr = Components.results;
const Ci = Components.interfaces;
Cu.import("resource://gre/modules/Services.jsm");
// need profile so that PageThumbsStorage can resolve the path to the underlying file
do_get_profile();
function run_test() {
// first check the protocol handler implements the correct interface
let handler = Services.io.getProtocolHandler("moz-page-thumb");
ok(handler instanceof Ci.nsISubstitutingProtocolHandler,
"moz-page-thumb handler provides substituting interface");
// then check that the file URL resolution works
let uri = Services.io.newURI("moz-page-thumb://thumbnail/?url=http%3A%2F%2Fwww.mozilla.org%2F",
null, null);
ok(uri instanceof Ci.nsIFileURL, "moz-page-thumb:// is a FileURL");
ok(uri.file, "This moz-page-thumb:// object is backed by a file");
// and check that the error case works as specified
let bad = Services.io.newURI("moz-page-thumb://wronghost/?url=http%3A%2F%2Fwww.mozilla.org%2F",
null, null);
Assert.throws(() => handler.resolveURI(bad), /NS_ERROR_NOT_AVAILABLE/i,
"moz-page-thumb object with wrong host must not resolve to a file path");
}