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