|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /* |
|
5 * Tests getIcons() and getIconURLBySize() on engine with multiple icons. |
|
6 */ |
|
7 |
|
8 "use strict"; |
|
9 |
|
10 const Ci = Components.interfaces; |
|
11 const Cu = Components.utils; |
|
12 |
|
13 Cu.import("resource://testing-common/httpd.js"); |
|
14 |
|
15 function test_multiIcon() { |
|
16 let engine = Services.search.getEngineByName("IconsTest"); |
|
17 do_check_neq(engine, null); |
|
18 |
|
19 do_print("Running tests on IconsTest engine"); |
|
20 |
|
21 do_print("The default should be the 16x16 icon"); |
|
22 do_check_true(engine.iconURI.spec.contains("ico16")); |
|
23 |
|
24 do_check_true(engine.getIconURLBySize(32,32).contains("ico32")); |
|
25 do_check_true(engine.getIconURLBySize(74,74).contains("ico74")); |
|
26 |
|
27 do_print("Invalid dimensions should return null."); |
|
28 do_check_null(engine.getIconURLBySize(50,50)); |
|
29 |
|
30 let allIcons = engine.getIcons(); |
|
31 |
|
32 do_print("Check that allIcons contains expected icon sizes"); |
|
33 do_check_eq(allIcons.length, 3); |
|
34 let expectedWidths = [16, 32, 74]; |
|
35 do_check_true(allIcons.every((item) => { |
|
36 let width = item.width; |
|
37 do_check_neq(expectedWidths.indexOf(width), -1); |
|
38 do_check_eq(width, item.height); |
|
39 |
|
40 let icon = item.url.split(",").pop(); |
|
41 do_check_eq(icon, "ico" + width); |
|
42 |
|
43 return true; |
|
44 })); |
|
45 |
|
46 do_test_finished(); |
|
47 } |
|
48 |
|
49 function run_test() { |
|
50 removeMetadata(); |
|
51 updateAppInfo(); |
|
52 |
|
53 let httpServer = new HttpServer(); |
|
54 httpServer.start(4444); |
|
55 httpServer.registerDirectory("/", do_get_cwd()); |
|
56 |
|
57 do_register_cleanup(function cleanup() { |
|
58 httpServer.stop(function() {}); |
|
59 }); |
|
60 |
|
61 do_test_pending(); |
|
62 |
|
63 let observer = function(aSubject, aTopic, aData) { |
|
64 if (aData == "engine-loaded") { |
|
65 test_multiIcon(); |
|
66 } |
|
67 }; |
|
68 |
|
69 Services.obs.addObserver(observer, "browser-search-engine-modified", false); |
|
70 |
|
71 do_print("Adding engine with multiple images"); |
|
72 Services.search.addEngine("http://localhost:4444/data/engineImages.xml", |
|
73 Ci.nsISearchEngine.DATA_XML, null, false); |
|
74 |
|
75 do_timeout(12000, function() { |
|
76 do_throw("Timeout"); |
|
77 }); |
|
78 } |