2010-05-13 13:20:30 -07:00
|
|
|
/*
|
|
|
|
* Test icon URI functionality
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cc = Components.classes;
|
|
|
|
|
|
|
|
// There are 3 types of valid icon URIs:
|
|
|
|
// 1. moz-icon:[valid URL]
|
|
|
|
// 2. moz-icon://[file name]
|
|
|
|
// 3. moz-icon://stock/[icon identifier]
|
2010-06-17 04:27:14 -07:00
|
|
|
// Plus we also support moz-icon://[valid URL] for backwards compatibility.
|
2010-05-13 13:20:30 -07:00
|
|
|
|
|
|
|
// Main test entry point.
|
|
|
|
function run_test() {
|
|
|
|
let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
|
|
|
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.
|
|
|
|
currentSpec = "moz-icon://foo.html?contentType=bar&size=button&state=normal";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, false);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
|
|
|
|
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
|
|
|
|
do_check_eq(iconURI.iconSize, "button");
|
|
|
|
do_check_eq(iconURI.iconState, "normal");
|
|
|
|
do_check_eq(iconURI.contentType, "bar");
|
|
|
|
do_check_eq(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
|
|
|
|
currentSpec = "moz-icon://foo.html?size=3";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, false);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
|
|
|
|
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
|
|
|
|
do_check_eq(iconURI.iconSize, "");
|
|
|
|
do_check_eq(iconURI.imageSize, 3);
|
|
|
|
|
|
|
|
// Make sure a valid stock icon URI can be created and that we can obtain
|
|
|
|
// the stock icon's name.
|
|
|
|
currentSpec = "moz-icon://stock/foo";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, false);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
|
|
|
|
iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
|
|
|
|
do_check_eq(iconURI.stockIcon, "foo");
|
|
|
|
|
|
|
|
// Make sure a valid file URL icon URI can be created and that we can obtain
|
|
|
|
// the URL and QI it to an nsIFileURL.
|
|
|
|
currentSpec = "moz-icon:file://foo.txt";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(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;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, false);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
|
2010-06-17 04:27:14 -07:00
|
|
|
do_check_neq(fileURL, null);
|
|
|
|
|
|
|
|
// Now test a file URI which has been created with an extra //
|
|
|
|
currentSpec = "moz-icon://file://foo.txt";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(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;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, false);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
|
|
|
|
do_check_neq(fileURL, null);
|
2010-05-13 13:20:30 -07:00
|
|
|
|
|
|
|
// Now test a simple invalid icon URI. This should fail.
|
|
|
|
currentSpec = "moz-icon:foo";
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(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, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(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 = "moz-icon://data:application/vnd.ms-excel;base64,PHhtbCB2ZXJzaW9uPSIxLjAiIGVuY29kaW5nPSJ1dGYtOCI+PHNzOldvcmtib29rIHhtbG5zOnNzPSJ1cm46c2NoZW1hcy1taWNyb3NvZnQtY29tOm9mZmljZTpzcHJlYWRzaGVldCIgeG1sbnM6eD0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6ZXhjZWwiIHhtbG5zOm89InVybjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSI+PG86RG9jdW1lbnRQcm9wZXJ0aWVzPjxvOlRpdGxlPkFycmF5IEdyaWQ8L286VGl0bGU+PC9vOkRvY3VtZW50UHJvcGVydGllcz48c3M6RXhjZWxXb3JrYm9vaz48c3M6V2luZG93SGVpZ2h0PjkwMDA8L3NzOldpbmRvd0hlaWdodD48c3M6V2luZG93V2lkdGg+MTc0ODA8L3NzOldpbmRvd1dpZHRoPjxzczpQcm90ZWN0U3RydWN0dXJlPkZhbHNlPC9zczpQcm90ZWN0U3RydWN0dXJlPjxzczpQcm90ZWN0V2luZG93cz5GYWxzZTwvc3M6UHJvdGVjdFdpbmRvd3M+PC9zczpFeGNlbFdvcmtib29rPjxzczpTdHlsZXM+PHNzOlN0eWxlIHNzOklEPSJEZWZhdWx0Ij48c3M6QWxpZ25tZW50IHNzOlZlcnRpY2FsPSJUb3AiIHNzOldyYXBUZXh0PSIxIiAvPjxzczpGb250IHNzOkZvbnROYW1lPSJhcmlhbCIgc3M6U2l6ZT0iMTAiIC8+PHNzOkJvcmRlcnM+PHNzOkJvcmRlciBzczpDb2xvcj0iI2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Bzcz
|
|
|
|
try {
|
|
|
|
uri = ioService.newURI(currentSpec, null, null);
|
|
|
|
} catch (e) {
|
|
|
|
exception = true;
|
|
|
|
}
|
|
|
|
do_check_eq(exception, true);
|
|
|
|
exception = false; // reset exception value
|
|
|
|
};
|