1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/search/tests/xpcshell/test_multipleIcons.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/* 1.8 + * Tests getIcons() and getIconURLBySize() on engine with multiple icons. 1.9 + */ 1.10 + 1.11 +"use strict"; 1.12 + 1.13 +const Ci = Components.interfaces; 1.14 +const Cu = Components.utils; 1.15 + 1.16 +Cu.import("resource://testing-common/httpd.js"); 1.17 + 1.18 + function test_multiIcon() { 1.19 + let engine = Services.search.getEngineByName("IconsTest"); 1.20 + do_check_neq(engine, null); 1.21 + 1.22 + do_print("Running tests on IconsTest engine"); 1.23 + 1.24 + do_print("The default should be the 16x16 icon"); 1.25 + do_check_true(engine.iconURI.spec.contains("ico16")); 1.26 + 1.27 + do_check_true(engine.getIconURLBySize(32,32).contains("ico32")); 1.28 + do_check_true(engine.getIconURLBySize(74,74).contains("ico74")); 1.29 + 1.30 + do_print("Invalid dimensions should return null."); 1.31 + do_check_null(engine.getIconURLBySize(50,50)); 1.32 + 1.33 + let allIcons = engine.getIcons(); 1.34 + 1.35 + do_print("Check that allIcons contains expected icon sizes"); 1.36 + do_check_eq(allIcons.length, 3); 1.37 + let expectedWidths = [16, 32, 74]; 1.38 + do_check_true(allIcons.every((item) => { 1.39 + let width = item.width; 1.40 + do_check_neq(expectedWidths.indexOf(width), -1); 1.41 + do_check_eq(width, item.height); 1.42 + 1.43 + let icon = item.url.split(",").pop(); 1.44 + do_check_eq(icon, "ico" + width); 1.45 + 1.46 + return true; 1.47 + })); 1.48 + 1.49 + do_test_finished(); 1.50 +} 1.51 + 1.52 +function run_test() { 1.53 + removeMetadata(); 1.54 + updateAppInfo(); 1.55 + 1.56 + let httpServer = new HttpServer(); 1.57 + httpServer.start(4444); 1.58 + httpServer.registerDirectory("/", do_get_cwd()); 1.59 + 1.60 + do_register_cleanup(function cleanup() { 1.61 + httpServer.stop(function() {}); 1.62 + }); 1.63 + 1.64 + do_test_pending(); 1.65 + 1.66 + let observer = function(aSubject, aTopic, aData) { 1.67 + if (aData == "engine-loaded") { 1.68 + test_multiIcon(); 1.69 + } 1.70 + }; 1.71 + 1.72 + Services.obs.addObserver(observer, "browser-search-engine-modified", false); 1.73 + 1.74 + do_print("Adding engine with multiple images"); 1.75 + Services.search.addEngine("http://localhost:4444/data/engineImages.xml", 1.76 + Ci.nsISearchEngine.DATA_XML, null, false); 1.77 + 1.78 + do_timeout(12000, function() { 1.79 + do_throw("Timeout"); 1.80 + }); 1.81 +}