Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/main.js

Issue 5745141503492096: Issue 1561 - Move unit tests out of the browser`s content area (Closed)
Patch Set: Rebased patch Created Jan. 10, 2015, 12:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/locale/en-US/settings.dtd ('k') | metadata.gecko » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 let {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", null);
19 let {Services} = Cu.import("resource://gre/modules/Services.jsm", null);
20
21 let optionsObserver =
22 {
23 init: function()
24 {
25 Services.obs.addObserver(this, "addon-options-displayed", true);
26 onShutdown.add(function()
27 {
28 Services.obs.removeObserver(this, "addon-options-displayed");
29 }.bind(this));
30 },
31
32 observe: function(subject, topic, data)
33 {
34 let {addonID} = require("info")
35 if (data != addonID)
36 return;
37
38 let doc = subject.QueryInterface(Ci.nsIDOMDocument);
39
40 let testList = doc.getElementById("adblockplustests-tests");
41 for (let test of getTests())
42 testList.appendItem(test, test);
43
44 doc.getElementById("adblockplustests-run").addEventListener("command", doRun , false);
45 },
46
47 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakRefer ence])
48 };
49 optionsObserver.init();
50
51 function doRun(event)
52 {
53 let wnd = Services.wm.getMostRecentWindow("adblockplustests:harness");
54 if (wnd)
55 {
56 wnd.focus();
57 return;
58 }
59
60 let doc = event.target.ownerDocument;
61
62 let params = "";
63 let testList = doc.getElementById("adblockplustests-tests");
64 if (testList.value)
65 params = "?test=" + encodeURIComponent(testList.value);
66
67 doc.defaultView.openDialog("chrome://adblockplustests/content/harness.xul" + p arams, "_blank", "chrome,centerscreen,resizable,dialog=no");
68 }
69
70 function getTests()
71 {
72 let result = [];
73
74 let {addonRoot} = require("info");
75 let uri = Services.io.newURI(addonRoot, null, null).QueryInterface(Components. interfaces.nsIJARURI);
76 let zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZi pReader);
77 zipReader.open(uri.JARFile.QueryInterface(Ci.nsIFileURL).file);
78
79 try
80 {
81 let enumerator = zipReader.findEntries(null);
82 let prefix = "chrome/content/tests/";
83 let suffix = ".js";
84 while (enumerator.hasMore())
85 {
86 let name = enumerator.getNext();
87 if (name.indexOf(prefix) == 0 && name.lastIndexOf(suffix) == name.length - suffix.length)
88 result.push(name.substring(prefix.length, name.length - suffix.length));
89 }
90 }
91 finally
92 {
93 zipReader.close();
94 }
95 result.sort();
96 return result;
97 };
98 exports.getTests = getTests;
OLDNEW
« no previous file with comments | « chrome/locale/en-US/settings.dtd ('k') | metadata.gecko » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld