Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let Cu = Components.utils; |
michael@0 | 5 | let Ci = Components.interfaces; |
michael@0 | 6 | |
michael@0 | 7 | Cu.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 8 | Cu.import("resource://gre/modules/Task.jsm"); |
michael@0 | 9 | Cu.import("resource://testing-common/httpd.js"); |
michael@0 | 10 | |
michael@0 | 11 | /* |
michael@0 | 12 | * test_nocache: Start search engine |
michael@0 | 13 | * - without search.json |
michael@0 | 14 | * |
michael@0 | 15 | * Ensure that : |
michael@0 | 16 | * - nothing explodes; |
michael@0 | 17 | * - search.json is created. |
michael@0 | 18 | */ |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | function run_test() |
michael@0 | 22 | { |
michael@0 | 23 | removeCache(); |
michael@0 | 24 | updateAppInfo(); |
michael@0 | 25 | do_load_manifest("data/chrome.manifest"); |
michael@0 | 26 | |
michael@0 | 27 | let httpServer = new HttpServer(); |
michael@0 | 28 | httpServer.start(-1); |
michael@0 | 29 | httpServer.registerDirectory("/", do_get_cwd()); |
michael@0 | 30 | |
michael@0 | 31 | let search = Services.search; |
michael@0 | 32 | |
michael@0 | 33 | do_test_pending(); |
michael@0 | 34 | |
michael@0 | 35 | // Check that cache is created at startup |
michael@0 | 36 | afterCache(function cacheCreated() { |
michael@0 | 37 | // Check that search.json has been created. |
michael@0 | 38 | let cache = gProfD.clone(); |
michael@0 | 39 | cache.append("search.json"); |
michael@0 | 40 | do_check_true(cache.exists()); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | // Perform initialization |
michael@0 | 44 | search.init(function ss_initialized(rv) { |
michael@0 | 45 | do_check_true(Components.isSuccessCode(rv)); |
michael@0 | 46 | |
michael@0 | 47 | do_print("Setting up observer"); |
michael@0 | 48 | function observer(aSubject, aTopic, aData) { |
michael@0 | 49 | do_print("Observing topic " + aTopic); |
michael@0 | 50 | if ("engine-added" == aData) { |
michael@0 | 51 | let engine = search.getEngineByName("Test search engine"); |
michael@0 | 52 | if (!engine) { |
michael@0 | 53 | return; |
michael@0 | 54 | } |
michael@0 | 55 | Services.obs.removeObserver(observer, "browser-search-engine-modified"); |
michael@0 | 56 | do_print("Engine has been added, let's wait for the cache to be built"); |
michael@0 | 57 | afterCache(function() { |
michael@0 | 58 | do_print("Success"); |
michael@0 | 59 | |
michael@0 | 60 | Task.spawn(function task() { |
michael@0 | 61 | do_print("Searching test engine in cache"); |
michael@0 | 62 | try { |
michael@0 | 63 | let path = OS.Path.join(OS.Constants.Path.profileDir, "search.json"); |
michael@0 | 64 | let data = yield OS.File.read(path); |
michael@0 | 65 | let text = new TextDecoder().decode(data); |
michael@0 | 66 | let cache = JSON.parse(text); |
michael@0 | 67 | let found = false; |
michael@0 | 68 | for (let dirName in cache.directories) { |
michael@0 | 69 | for (let engine of cache.directories[dirName].engines) { |
michael@0 | 70 | if (engine._id == "[app]/test-search-engine.xml") { |
michael@0 | 71 | found = true; |
michael@0 | 72 | break; |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | if (found) { |
michael@0 | 76 | break; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | do_check_true(found); |
michael@0 | 80 | } catch (ex) { |
michael@0 | 81 | do_throw(ex); |
michael@0 | 82 | } finally { |
michael@0 | 83 | removeCache(); |
michael@0 | 84 | httpServer.stop(function() { |
michael@0 | 85 | // httpServer doesn't seem to stop cleanly if there is no callback |
michael@0 | 86 | }); |
michael@0 | 87 | do_test_finished(); |
michael@0 | 88 | } |
michael@0 | 89 | }); |
michael@0 | 90 | }); |
michael@0 | 91 | } |
michael@0 | 92 | }; |
michael@0 | 93 | Services.obs.addObserver(observer, "browser-search-engine-modified", false); |
michael@0 | 94 | |
michael@0 | 95 | // Add an engine, check if it appears in the cache |
michael@0 | 96 | search.addEngine("http://localhost:" + httpServer.identity.primaryPort + |
michael@0 | 97 | "/data/engine.xml", |
michael@0 | 98 | Ci.nsISearchEngine.DATA_XML, |
michael@0 | 99 | null, false); |
michael@0 | 100 | }); |
michael@0 | 101 | } |