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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | var gSS = Services.search; |
michael@0 | 5 | |
michael@0 | 6 | function observer(aSubject, aTopic, aData) { |
michael@0 | 7 | if (!gCurrentTest) { |
michael@0 | 8 | info("Observer called with no test active"); |
michael@0 | 9 | return; |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | let engine = aSubject.QueryInterface(Ci.nsISearchEngine); |
michael@0 | 13 | info("Observer: " + aData + " for " + engine.name); |
michael@0 | 14 | let method; |
michael@0 | 15 | switch (aData) { |
michael@0 | 16 | case "engine-added": |
michael@0 | 17 | if (gCurrentTest.added) |
michael@0 | 18 | method = "added" |
michael@0 | 19 | break; |
michael@0 | 20 | case "engine-current": |
michael@0 | 21 | if (gCurrentTest.current) |
michael@0 | 22 | method = "current"; |
michael@0 | 23 | break; |
michael@0 | 24 | case "engine-removed": |
michael@0 | 25 | if (gCurrentTest.removed) |
michael@0 | 26 | method = "removed"; |
michael@0 | 27 | break; |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | if (method) |
michael@0 | 31 | gCurrentTest[method](engine); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function checkEngine(checkObj, engineObj) { |
michael@0 | 35 | info("Checking engine"); |
michael@0 | 36 | for (var prop in checkObj) |
michael@0 | 37 | is(checkObj[prop], engineObj[prop], prop + " is correct"); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | var gTests = [ |
michael@0 | 41 | { |
michael@0 | 42 | name: "opensearch install", |
michael@0 | 43 | engine: { |
michael@0 | 44 | name: "Foo", |
michael@0 | 45 | alias: null, |
michael@0 | 46 | description: "Foo Search", |
michael@0 | 47 | searchForm: "http://mochi.test:8888/browser/browser/components/search/test/", |
michael@0 | 48 | type: Ci.nsISearchEngine.TYPE_OPENSEARCH |
michael@0 | 49 | }, |
michael@0 | 50 | run: function () { |
michael@0 | 51 | gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.xml", |
michael@0 | 52 | Ci.nsISearchEngine.DATA_XML, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC", |
michael@0 | 53 | false); |
michael@0 | 54 | }, |
michael@0 | 55 | added: function (engine) { |
michael@0 | 56 | ok(engine, "engine was added."); |
michael@0 | 57 | |
michael@0 | 58 | checkEngine(this.engine, engine); |
michael@0 | 59 | |
michael@0 | 60 | let engineFromSS = gSS.getEngineByName(this.engine.name); |
michael@0 | 61 | is(engine, engineFromSS, "engine is obtainable via getEngineByName"); |
michael@0 | 62 | |
michael@0 | 63 | let aEngine = gSS.getEngineByAlias("fooalias"); |
michael@0 | 64 | ok(!aEngine, "Alias was not parsed from engine description"); |
michael@0 | 65 | |
michael@0 | 66 | gSS.currentEngine = engine; |
michael@0 | 67 | }, |
michael@0 | 68 | current: function (engine) { |
michael@0 | 69 | let currentEngine = gSS.currentEngine; |
michael@0 | 70 | is(engine, currentEngine, "engine is current"); |
michael@0 | 71 | is(engine.name, this.engine.name, "current engine was changed successfully"); |
michael@0 | 72 | |
michael@0 | 73 | gSS.removeEngine(engine); |
michael@0 | 74 | }, |
michael@0 | 75 | removed: function (engine) { |
michael@0 | 76 | let currentEngine = gSS.currentEngine; |
michael@0 | 77 | ok(currentEngine, "An engine is present."); |
michael@0 | 78 | isnot(currentEngine.name, this.engine.name, "Current engine reset after removal"); |
michael@0 | 79 | |
michael@0 | 80 | nextTest(); |
michael@0 | 81 | } |
michael@0 | 82 | }, |
michael@0 | 83 | { |
michael@0 | 84 | name: "sherlock install", |
michael@0 | 85 | engine: { |
michael@0 | 86 | name: "Test Sherlock", |
michael@0 | 87 | alias: null, |
michael@0 | 88 | description: "Test Description", |
michael@0 | 89 | searchForm: "http://example.com/searchform", |
michael@0 | 90 | type: Ci.nsISearchEngine.TYPE_SHERLOCK |
michael@0 | 91 | }, |
michael@0 | 92 | run: function () { |
michael@0 | 93 | gSS.addEngine("http://mochi.test:8888/browser/browser/components/search/test/testEngine.src", |
michael@0 | 94 | Ci.nsISearchEngine.DATA_TEXT, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC", |
michael@0 | 95 | false); |
michael@0 | 96 | }, |
michael@0 | 97 | added: function (engine) { |
michael@0 | 98 | ok(engine, "engine was added."); |
michael@0 | 99 | checkEngine(this.engine, engine); |
michael@0 | 100 | |
michael@0 | 101 | let engineFromSS = gSS.getEngineByName(this.engine.name); |
michael@0 | 102 | is(engineFromSS, engine, "engine is obtainable via getEngineByName"); |
michael@0 | 103 | |
michael@0 | 104 | gSS.removeEngine(engine); |
michael@0 | 105 | }, |
michael@0 | 106 | removed: function (engine) { |
michael@0 | 107 | let currentEngine = gSS.currentEngine; |
michael@0 | 108 | ok(currentEngine, "An engine is present."); |
michael@0 | 109 | isnot(currentEngine.name, this.engine.name, "Current engine reset after removal"); |
michael@0 | 110 | |
michael@0 | 111 | nextTest(); |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | ]; |
michael@0 | 115 | |
michael@0 | 116 | var gCurrentTest = null; |
michael@0 | 117 | function nextTest() { |
michael@0 | 118 | if (gTests.length) { |
michael@0 | 119 | gCurrentTest = gTests.shift(); |
michael@0 | 120 | info("Running " + gCurrentTest.name); |
michael@0 | 121 | gCurrentTest.run(); |
michael@0 | 122 | } else |
michael@0 | 123 | executeSoon(finish); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function test() { |
michael@0 | 127 | waitForExplicitFinish(); |
michael@0 | 128 | Services.obs.addObserver(observer, "browser-search-engine-modified", false); |
michael@0 | 129 | registerCleanupFunction(cleanup); |
michael@0 | 130 | |
michael@0 | 131 | nextTest(); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function cleanup() { |
michael@0 | 135 | Services.obs.removeObserver(observer, "browser-search-engine-modified"); |
michael@0 | 136 | } |