michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /* michael@0: * Tests getIcons() and getIconURLBySize() on engine with multiple icons. michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: function test_multiIcon() { michael@0: let engine = Services.search.getEngineByName("IconsTest"); michael@0: do_check_neq(engine, null); michael@0: michael@0: do_print("Running tests on IconsTest engine"); michael@0: michael@0: do_print("The default should be the 16x16 icon"); michael@0: do_check_true(engine.iconURI.spec.contains("ico16")); michael@0: michael@0: do_check_true(engine.getIconURLBySize(32,32).contains("ico32")); michael@0: do_check_true(engine.getIconURLBySize(74,74).contains("ico74")); michael@0: michael@0: do_print("Invalid dimensions should return null."); michael@0: do_check_null(engine.getIconURLBySize(50,50)); michael@0: michael@0: let allIcons = engine.getIcons(); michael@0: michael@0: do_print("Check that allIcons contains expected icon sizes"); michael@0: do_check_eq(allIcons.length, 3); michael@0: let expectedWidths = [16, 32, 74]; michael@0: do_check_true(allIcons.every((item) => { michael@0: let width = item.width; michael@0: do_check_neq(expectedWidths.indexOf(width), -1); michael@0: do_check_eq(width, item.height); michael@0: michael@0: let icon = item.url.split(",").pop(); michael@0: do_check_eq(icon, "ico" + width); michael@0: michael@0: return true; michael@0: })); michael@0: michael@0: do_test_finished(); michael@0: } michael@0: michael@0: function run_test() { michael@0: removeMetadata(); michael@0: updateAppInfo(); michael@0: michael@0: let httpServer = new HttpServer(); michael@0: httpServer.start(4444); michael@0: httpServer.registerDirectory("/", do_get_cwd()); michael@0: michael@0: do_register_cleanup(function cleanup() { michael@0: httpServer.stop(function() {}); michael@0: }); michael@0: michael@0: do_test_pending(); michael@0: michael@0: let observer = function(aSubject, aTopic, aData) { michael@0: if (aData == "engine-loaded") { michael@0: test_multiIcon(); michael@0: } michael@0: }; michael@0: michael@0: Services.obs.addObserver(observer, "browser-search-engine-modified", false); michael@0: michael@0: do_print("Adding engine with multiple images"); michael@0: Services.search.addEngine("http://localhost:4444/data/engineImages.xml", michael@0: Ci.nsISearchEngine.DATA_XML, null, false); michael@0: michael@0: do_timeout(12000, function() { michael@0: do_throw("Timeout"); michael@0: }); michael@0: }