1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/search/tests/xpcshell/test_rel_searchform.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 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 that <Url rel="searchform"/> is properly recognized as a searchForm. 1.9 + */ 1.10 + 1.11 +"use strict"; 1.12 + 1.13 +const Ci = Components.interfaces; 1.14 + 1.15 +Components.utils.import("resource://testing-common/httpd.js"); 1.16 + 1.17 +let engines = [ 1.18 + "engine-rel-searchform.xml", 1.19 + "engine-rel-searchform-post.xml", 1.20 +]; 1.21 + 1.22 +function search_observer(aSubject, aTopic, aData) { 1.23 + let engine = aSubject.QueryInterface(Ci.nsISearchEngine); 1.24 + do_print("Observer: " + aData + " for " + engine.name); 1.25 + 1.26 + if (aData != "engine-added") 1.27 + return; 1.28 + 1.29 + let idx = engines.indexOf(engine.name); 1.30 + if (idx < 0) 1.31 + // The engine is some other engine unrelated to the test, so ignore it. 1.32 + return; 1.33 + 1.34 + // The final searchForm of the engine should be a URL whose domain is the 1.35 + // <ShortName> in the engine's XML and that has a ?search parameter. The 1.36 + // point of the ?search parameter is to avoid accidentally matching the value 1.37 + // returned as a last resort by Engine's searchForm getter, which is simply 1.38 + // the prePath of the engine's first HTML <Url>. 1.39 + do_check_eq(engine.searchForm, "http://" + engine.name + "/?search"); 1.40 + 1.41 + engines.splice(idx, 1); 1.42 + if (!engines.length) 1.43 + do_test_finished(); 1.44 +} 1.45 + 1.46 +function run_test() { 1.47 + removeMetadata(); 1.48 + updateAppInfo(); 1.49 + 1.50 + let httpServer = new HttpServer(); 1.51 + httpServer.start(-1); 1.52 + httpServer.registerDirectory("/", do_get_cwd()); 1.53 + 1.54 + do_register_cleanup(function cleanup() { 1.55 + httpServer.stop(function() {}); 1.56 + Services.obs.removeObserver(search_observer, "browser-search-engine-modified"); 1.57 + }); 1.58 + 1.59 + do_test_pending(); 1.60 + Services.obs.addObserver(search_observer, "browser-search-engine-modified", false); 1.61 + 1.62 + for (let basename of engines) { 1.63 + Services.search.addEngine("http://localhost:" + 1.64 + httpServer.identity.primaryPort + 1.65 + "/data/" + basename, 1.66 + Ci.nsISearchEngine.DATA_XML, 1.67 + null, false); 1.68 + } 1.69 +}