diff --git a/toolkit/components/search/tests/xpcshell/data/engineImages.xml b/toolkit/components/search/tests/xpcshell/data/engineImages.xml new file mode 100644 index 00000000000..65b550b31b1 --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/data/engineImages.xml @@ -0,0 +1,22 @@ + + + + IconsTest + IconsTest. Search by Test. + UTF-8 + data:image/x-icon;base64,ico16 + data:image/x-icon;base64,ico32 + data:image/png;base64,ico74 + + + + + + + + + + http://www.bing.com/search + diff --git a/toolkit/components/search/tests/xpcshell/test_multipleIcons.js b/toolkit/components/search/tests/xpcshell/test_multipleIcons.js new file mode 100644 index 00000000000..253ea7f9d02 --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/test_multipleIcons.js @@ -0,0 +1,78 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* + * Tests getIcons() and getIconURLBySize() on engine with multiple icons. + */ + +"use strict"; + +const Ci = Components.interfaces; +const Cu = Components.utils; + +Cu.import("resource://testing-common/httpd.js"); + + function test_multiIcon() { + let engine = Services.search.getEngineByName("IconsTest"); + do_check_neq(engine, null); + + do_print("Running tests on IconsTest engine"); + + do_print("The default should be the 16x16 icon"); + do_check_true(engine.iconURI.spec.contains("ico16")); + + do_check_true(engine.getIconURLBySize(32,32).contains("ico32")); + do_check_true(engine.getIconURLBySize(74,74).contains("ico74")); + + do_print("Invalid dimensions should return null."); + do_check_null(engine.getIconURLBySize(50,50)); + + let allIcons = engine.getIcons(); + + do_print("Check that allIcons contains expected icon sizes"); + do_check_eq(allIcons.length, 3); + let expectedWidths = [16, 32, 74]; + do_check_true(allIcons.every((item) => { + let width = item.width; + do_check_neq(expectedWidths.indexOf(width), -1); + do_check_eq(width, item.height); + + let icon = item.url.split(",").pop(); + do_check_eq(icon, "ico" + width); + + return true; + })); + + do_test_finished(); +} + +function run_test() { + removeMetadata(); + updateAppInfo(); + + let httpServer = new HttpServer(); + httpServer.start(4444); + httpServer.registerDirectory("/", do_get_cwd()); + + do_register_cleanup(function cleanup() { + httpServer.stop(function() {}); + }); + + do_test_pending(); + + let observer = function(aSubject, aTopic, aData) { + if (aData == "engine-loaded") { + test_multiIcon(); + } + }; + + Services.obs.addObserver(observer, "browser-search-engine-modified", false); + + do_print("Adding engine with multiple images"); + Services.search.addEngine("http://localhost:4444/data/engineImages.xml", + Ci.nsISearchEngine.DATA_XML, null, false); + + do_timeout(12000, function() { + do_throw("Timeout"); + }); +} diff --git a/toolkit/components/search/tests/xpcshell/xpcshell.ini b/toolkit/components/search/tests/xpcshell/xpcshell.ini index 38658c08566..8540282ca75 100644 --- a/toolkit/components/search/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini @@ -7,6 +7,7 @@ support-files = data/engine.src data/engine.xml data/engine2.xml + data/engineImages.xml data/ico-size-16x16-png.ico data/search-metadata.json data/search.json @@ -27,6 +28,7 @@ support-files = [test_prefSync.js] [test_notifications.js] [test_addEngine_callback.js] +[test_multipleIcons.js] [test_async.js] [test_sync.js] [test_sync_fallback.js]