Bug 900137 - xpcshell tests r=yoric
authorRodrigo Silveira <rsilveira@mozilla.com>
Wed, 02 Oct 2013 17:08:34 -0700
changeset 169468 9f1168eae1b782e2a511c90c49cc3fca8742ab07
parent 169467 4ed1121bf0f4149938dd67e0ffca2372a24d24cb
child 169469 f73dd492c34c1ea7a6f7a08c78c0105fe70673cc
child 169584 fd5133a30882d420161200ff9d260a197587b00d
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyoric
bugs900137
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 900137 - xpcshell tests r=yoric
toolkit/components/search/tests/xpcshell/data/engineImages.xml
toolkit/components/search/tests/xpcshell/test_multipleIcons.js
toolkit/components/search/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data/engineImages.xml
@@ -0,0 +1,22 @@
+<!-- This Source Code Form is subject to the terms of the Mozilla Public
+   - License, v. 2.0. If a copy of the MPL was not distributed with this
+   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
+
+<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
+    <ShortName>IconsTest</ShortName>
+    <Description>IconsTest. Search by Test.</Description>
+    <InputEncoding>UTF-8</InputEncoding>
+    <Image width="16" height="16">data:image/x-icon;base64,ico16</Image>
+    <Image width="32" height="32">data:image/x-icon;base64,ico32</Image>
+    <Image width="74" height="74">data:image/png;base64,ico74</Image>
+    <Url type="application/x-suggestions+json" template="http://api.bing.com/osjson.aspx">
+        <Param name="query" value="{searchTerms}"/>
+        <Param name="form" value="MOZW"/>
+    </Url>
+    <Url type="text/html" method="GET" template="http://www.bing.com/search">
+        <Param name="q" value="{searchTerms}"/>
+        <MozParam name="pc" condition="pref" pref="ms-pc"/>
+        <Param name="form" value="MOZW"/>
+    </Url>
+    <SearchForm>http://www.bing.com/search</SearchForm>
+</SearchPlugin>
new file mode 100644
--- /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");
+  });
+}
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -2,16 +2,17 @@
 head = head_search.js
 tail =
 firefox-appdir = browser
 support-files =
   data/chrome.manifest
   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
   data/search.sqlite
   data/searchTest.jar
 
 [test_nocache.js]
 [test_645970.js]
@@ -22,12 +23,13 @@ support-files =
 [test_nodb.js]
 [test_nodb_pluschanges.js]
 [test_save_sorted_engines.js]
 [test_purpose.js]
 [test_defaultEngine.js]
 [test_prefSync.js]
 [test_notifications.js]
 [test_addEngine_callback.js]
+[test_multipleIcons.js]
 [test_async.js]
 [test_sync.js]
 [test_sync_fallback.js]
 [test_sync_delay_fallback.js]