Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: image/test/unit/xpcshell.toml
/*
* Test icon URI functionality
*
*/
// There are 3 types of valid icon URIs:
// 1. moz-icon:[valid URL]
// Main test entry point.
function run_test() {
let ioService = Services.io;
let currentSpec = ""; // the uri spec that we're currently testing
let exception = false; // whether or not an exception was thrown
let uri = null; // the current URI
let iconURI = null; // the current icon URI
// Note that if the scheme is not correct the ioservice won't even create an icon URI
// so don't bother testing incorrect schemes here.
// Make sure a valid file name icon URI can be created and that we can obtain
// all arguments, the spec, and the file extension.
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
Assert.equal(iconURI.iconSize, "button");
Assert.equal(iconURI.iconState, "normal");
Assert.equal(iconURI.contentType, "bar");
Assert.equal(iconURI.fileExtension, ".html");
// Make sure a valid file name icon URI can be created with a numeric size,
// and make sure the numeric size is handled properly
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
Assert.equal(iconURI.iconSize, "");
Assert.equal(iconURI.imageSize, 3);
// Make sure a valid stock icon URI can be created and that we can obtain
// the stock icon's name.
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
Assert.equal(iconURI.stockIcon, "foo");
// Make sure an invalid stock icon URI, missing icon identifier, throws.
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.ok(exception);
exception = false; // reset exception value
// Make sure a valid file URL icon URI can be created and that we can obtain
// the URL and QI it to an nsIFileURL.
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
let fileURL = null;
try {
fileURL = iconURI.iconURL.QueryInterface(Ci.nsIFileURL);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
Assert.notEqual(fileURL, null);
// Now test a file URI which has been created with an extra //
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
fileURL = null;
try {
fileURL = iconURI.iconURL.QueryInterface(Ci.nsIFileURL);
} catch (e) {
exception = true;
}
Assert.equal(exception, false);
exception = false; // reset exception value
Assert.notEqual(fileURL, null);
// Now test a simple invalid icon URI. This should fail.
currentSpec = "moz-icon:foo";
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, true);
exception = false; // reset exception value
// Now test an icon URI that has a URI for a path but that is not a URL. This should fail.
// This is png data for a little red dot that I got from wikipedia.
currentSpec =
"moz-icon:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, true);
exception = false; // reset exception value
// Now test a URI that should be a file name but is ridiculously long. This should fail.
currentSpec =
try {
uri = ioService.newURI(currentSpec);
} catch (e) {
exception = true;
}
Assert.equal(exception, true);
exception = false; // reset exception value
}