Bug 645970 - search service doesn't unpack jar:jar: [r=gavin]
authorVivien Nicolas <21@vingtetun.org>
Fri, 15 Apr 2011 12:40:43 +0200
changeset 68155 15b8b01a965e01526b25f989a73a642f1922e50d
parent 68152 29ea31633ac69c8d7219bb7a741bb8ae182da4d6
child 68156 ad0261d9618d85c8dfef66749679059f8dc05bdb
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs645970
milestone6.0a1
Bug 645970 - search service doesn't unpack jar:jar: [r=gavin]
toolkit/components/search/Makefile.in
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/Makefile.in
toolkit/components/search/tests/xpcshell/data/chrome.manifest
toolkit/components/search/tests/xpcshell/data/searchTest.jar
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_645970.js
--- a/toolkit/components/search/Makefile.in
+++ b/toolkit/components/search/Makefile.in
@@ -44,9 +44,13 @@ VPATH     = @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 EXTRA_COMPONENTS = toolkitsearch.manifest
 EXTRA_PP_COMPONENTS = nsSearchService.js \
 	nsSearchSuggestions.js
 
 DEFINES += -DMOZ_DISTRIBUTION_ID=$(MOZ_DISTRIBUTION_ID)
 
+ifdef ENABLE_TESTS
+DIRS += tests
+endif
+
 include $(topsrcdir)/config/rules.mk
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -2863,17 +2863,17 @@ SearchService.prototype = {
 
     rootURIs.forEach(function (root) {
       // Find the underlying JAR file for this chrome package (_loadEngines uses
       // it to determine whether it needs to invalidate the cache)
       let chromeFile;
       try {
         let chromeURI = gChromeReg.convertChromeURL(makeURI(root));
         let fileURI = chromeURI; // flat packaging
-        if (fileURI instanceof Ci.nsIJARURI)
+        while (fileURI instanceof Ci.nsIJARURI)
           fileURI = fileURI.JARFile; // JAR packaging
         fileURI.QueryInterface(Ci.nsIFileURL);
         chromeFile = fileURI.file;
       } catch (ex) {
         LOG("_findJAREngines: failed to get chromeFile for " + root + ": " + ex);
       }
 
       if (!chromeFile)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/Makefile.in
@@ -0,0 +1,49 @@
+# ***** BEGIN LICENSE BLOCK *****
+# Version: MPL 1.1/GPL 2.0/LGPL 2.1
+#
+# The contents of this file are subject to the Mozilla Public License Version
+# 1.1 (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+# http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS IS" basis,
+# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+# for the specific language governing rights and limitations under the
+# License.
+#
+# The Original Code is mozilla.org code.
+#
+# The Initial Developer of the Original Code is
+# Mozilla.org.
+# Portions created by the Initial Developer are Copyright (C) 2005
+# the Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+#
+# Alternatively, the contents of this file may be used under the terms of
+# either of the GNU General Public License Version 2 or later (the "GPL"),
+# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+# in which case the provisions of the GPL or the LGPL are applicable instead
+# of those above. If you wish to allow use of your version of this file only
+# under the terms of either the GPL or the LGPL, and not to allow others to
+# use your version of this file under the terms of the MPL, indicate your
+# decision by deleting the provisions above and replace them with the notice
+# and other provisions required by the GPL or the LGPL. If you do not delete
+# the provisions above, a recipient may use your version of this file under
+# the terms of any one of the MPL, the GPL or the LGPL.
+#
+# ***** END LICENSE BLOCK *****
+
+DEPTH		= ../../../..
+topsrcdir	= @top_srcdir@
+srcdir		= @srcdir@
+VPATH		= @srcdir@
+relativesrcdir = toolkit/components/search/tests
+
+include $(DEPTH)/config/autoconf.mk
+
+MODULE		= test_searchservice
+
+XPCSHELL_TESTS = xpcshell
+
+include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/data/chrome.manifest
@@ -0,0 +1,1 @@
+locale testsearchplugin ar jar:jar:searchTest.jar!/chrome/searchTest.jar!/
new file mode 100644
index 0000000000000000000000000000000000000000..3882ae938f1df50ea037fbc17b1be2331a5b2da2
GIT binary patch
literal 776
zc$^FHW@h1HW&ncUb9?O=kN`UnCubDp=ceih02PS<6>%_p2P&FzJ^q&x69dB`AQnX^
zDo#x-O3nyLEiTc^N-V0Kl<N}|C~^F~Xh8W<x6iq}v$k#g6)=nEY)e>RSW*71SXGma
zPrdop?N%w%FFmgAc{)yjYZfni^lFpEnROi3W9kev58Y!+p0;+a;KtUdHK~ikQl`(j
zdF(~~w>NV(|2<b<J@3DxAe(R!!<MwSccUBYw>0T3+WD|zvR8BV)EkCL$#c#wyZOcb
zO>w{R7Fm{t-<k{ud=sR%p7K>)`ZV>Z>lCT?#`c*rHJ-ics%yVyQ?_H%1AQ%C>tL?u
zqOX4b43D>+aQB??^}9Mft`CKc7cI72y!xH*jlE{;y&2!HJ*v6-!<>&IN@eraN>*n0
z^4{OCm$7<A&3eJlJ&nJb&u(`(>b)WAdnHS)$+3wMWl_Ep?*@7^N56gi?Z@x)3GYr9
zZ&g|onl7h$JzAFS{Ir)RLfDUmc}2$;_vY{V)wz>D&a>g=I+v%+I}GFX%sv!VZT_aQ
z;8^za<1C?vR#vHLi|yKN@P^}4EPv=G?i;VPZ&_s(Ki}=+=-Rl&*r?a+Y<Td)34eZh
z*8l2%*O1S#?alkbO>s8DOG9PlEUfjm#79|1^m*{7ez@c|Pe@nxaB6wVyqjiwwaoWC
z?s%Vca?h^U4)34b{<v`K?OQqXH#j;!UC$cu;quIl{U%e}k`EMlcvXFfPxra6@JnX>
zotA@-B^<>jiu^QZ;BY-KCC6>kgy}~z|7$P`-4VO5#$D^l`quo5^uPbCV!e~hH|AVn
zSIg#fjaXUO<*3iUm;K<6x8?!fj7%cTxYHg42sFHPWI#@dAWgW_A_OQjENN85l`;do
RS=m5}n1HYXNLMj|cmNsFKCu7*
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -0,0 +1,92 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is POTI Inc.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
+const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
+
+var gXULAppInfo = null;
+
+/**
+ * Creates an nsIXULAppInfo
+ * @param   id
+ *          The ID of the test application
+ * @param   name
+ *          A name for the test application
+ * @param   version
+ *          The version of the application
+ * @param   platformVersion
+ *          The gecko version of the application
+ */
+function createAppInfo(id, name, version, platformVersion)
+{
+  gXULAppInfo = {
+    vendor: "Mozilla",
+    name: name,
+    ID: id,
+    version: version,
+    appBuildID: "2007010101",
+    platformVersion: platformVersion,
+    platformBuildID: "2007010101",
+    inSafeMode: false,
+    logConsoleErrors: true,
+    OS: "XPCShell",
+    XPCOMABI: "noarch-spidermonkey",
+    invalidateCachesOnRestart: function invalidateCachesOnRestart() {},
+
+    QueryInterface: function QueryInterface(iid) {
+      if (iid.equals(Components.interfaces.nsIXULAppInfo)
+       || iid.equals(Components.interfaces.nsIXULRuntime)
+       || iid.equals(Components.interfaces.nsISupports))
+        return this;
+
+      throw Components.results.NS_ERROR_NO_INTERFACE;
+    }
+  };
+
+  var XULAppInfoFactory = {
+    createInstance: function (outer, iid) {
+      if (outer != null)
+        throw Components.results.NS_ERROR_NO_AGGREGATION;
+      return gXULAppInfo.QueryInterface(iid);
+    }
+  };
+  var registrar = Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar);
+  registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
+                            XULAPPINFO_CONTRACTID, XULAppInfoFactory);
+}
+
+// Need to create and register a profile folder.
+var gProfD = do_get_profile();
+
new file mode 100644
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_645970.js
@@ -0,0 +1,62 @@
+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is POTI Inc.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+let Cc = Components.classes;
+let Ci = Components.interfaces;
+
+var gPrefService = Cc["@mozilla.org/preferences-service;1"]
+                    .getService(Ci.nsIPrefService)
+                    .QueryInterface(Ci.nsIPrefBranch);
+/**
+ * Test nsSearchService with nested jar: uris
+ */
+function run_test() {
+  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2");
+
+  do_load_manifest("data/chrome.manifest");
+
+  let url  = "chrome://testsearchplugin/locale/searchplugins/";
+  gPrefService.setCharPref("browser.search.jarURIs", url);
+
+  gPrefService.setBoolPref("browser.search.loadFromJars", true);
+
+  // The search service needs to be started after the jarURIs pref has been
+  // set in order to initiate it correctly
+  let searchService = Cc["@mozilla.org/browser/search-service;1"]
+                       .getService(Ci.nsIBrowserSearchService);
+  let engine = searchService.getEngineByName("bug645970");
+  do_check_neq(engine, null);
+}
+