aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-02-16 16:16:33 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-02-16 16:16:33 +0100
commitd448b16f969be780444190d178dad4c8b2347612 (patch)
tree70518229a92bf0e7b5cdc2497bd59356de1d47a3
parent10dcf8de5c6965832452c538451d6170b3bafb66 (diff)
downloadbugzilla-triage-d448b16f969be780444190d178dad4c8b2347612.tar.gz
Fix the password recognition.
* doh! !== instead of === * also skip attachment.cgi page
-rw-r--r--data/bzpage.js1
-rw-r--r--data/rhbzpage.js12
-rw-r--r--lib/libbugzilla.js12
-rw-r--r--lib/main.js3
-rw-r--r--package.json2
-rw-r--r--tests/pagemod-test-helpers.js55
-rw-r--r--tests/test-match-pattern.js11
-rw-r--r--tests/test-pageMod.js141
8 files changed, 215 insertions, 22 deletions
diff --git a/data/bzpage.js b/data/bzpage.js
index c71ab51..7d59f22 100644
--- a/data/bzpage.js
+++ b/data/bzpage.js
@@ -24,6 +24,7 @@ var submitHandlerInstalled = false; // for setUpLogging
* central handler processing messages from the main script.
*/
onMessage = function onMessage(msg) {
+ console.log("onMessage - incoming : msg.cmd = " + msg.cmd);
switch (msg.cmd) {
case "ReloadThePage":
document.location.reload(true);
diff --git a/data/rhbzpage.js b/data/rhbzpage.js
index f0347d7..3eaed66 100644
--- a/data/rhbzpage.js
+++ b/data/rhbzpage.js
@@ -156,6 +156,8 @@ function addAttachmentCallback(resp) {
function addAttachment(data, callback, param) {
var params = [];
+ console.log("addAttachment : constantData.passwordState.passAvailable = " +
+ constantData.passwordState.passAvailable);
if (!constantData.passwordState.passAvailable) {
console.log("addAttachment : No password, no XML-RPC calls; sorry");
return null;
@@ -343,16 +345,6 @@ function addCheckShowLink(oldAtt, snippet) {
*/
function markBadAttachments(atts) {
var badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ];
-/* FIXME
-error: An exception occurred.
-Traceback (most recent call last):
- File "/home/matej/archiv/2011/projekty/bugzilla-triage/data/bzpage.js", line 1005, in
- File "/home/matej/archiv/2011/projekty/bugzilla-triage/data/bzpage.js", line 998, in startup
- File "/home/matej/archiv/2011/projekty/bugzilla-triage/data/rhbzpage.js", line 915, in RHBZinit
- File "/home/matej/archiv/2011/projekty/bugzilla-triage/data/rhbzpage.js", line 344, in markBadAttachments
-TypeError: "use strict";constantData.passwordState is undefined
-*/
- // FIXME this should work
console.log("markBadAttachments : constantData.passwordState.toSource() = " +
constantData.passwordState.toSource());
if (!constantData.passwordState.passAvailable) {
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 41aa27a..2ec69a6 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -136,9 +136,6 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
location = new urlMod.URL(location);
}
- console.log("location = " + location);
- console.log("typeof location = " + typeof location);
-
// Collect enabled packages per hostname (plus default ones)
if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
if ("enabledPackages" in config.gJSONData.configData) {
@@ -185,19 +182,14 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
config.gJSONData.commentStrings["sentUpstreamString"];
}
- // Investigate situation about password
- /*
- passwObj = {
- password: null, // password string or null if no password provided
- withoutPass: false // whether user doesn't want to use password at all
- }; */
var locURL = new urlMod.URL(locationLoginObj.location);
var passDomain = locURL.scheme + "://" + locURL.host;
var passwObj = getPassword(locationLoginObj.login, passDomain);
// In order to avoid sending whole password to the content script,
// we are sending just these two Booleans.
+ console.log("getInstalledPackages : passwObj = " + passwObj.toSource());
config.constantData.passwordState = {
- passAvailable: (passwObj.password === null),
+ passAvailable: (passwObj.password !== null),
withoutPass: passwObj.withoutPass
};
diff --git a/lib/main.js b/lib/main.js
index 0348842..cd8f259 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -139,7 +139,8 @@ libbz.initialize(libbz.config, function () {
pageMod.PageMod({
include: [
- "https://bugzilla.redhat.com/process_bug.cgi"
+ "https://bugzilla.redhat.com/process_bug.cgi",
+ "https://bugzilla.redhat.com/attachment.cgi"
],
contentScriptWhen: 'ready',
contentScriptFile: self.data.url("skip-bug.js")
diff --git a/package.json b/package.json
index ea847cb..255ee81 100644
--- a/package.json
+++ b/package.json
@@ -7,5 +7,5 @@
"description": "Additional buttons and other function helping in the triage on bugzilla",
"author": "Matej Cepl (http://matej.ceplovi.cz)",
"license": "MIT/X11 (http://opensource.org/licenses/mit-license.php)",
- "version": "0.27"
+ "version": "0.91"
}
diff --git a/tests/pagemod-test-helpers.js b/tests/pagemod-test-helpers.js
new file mode 100644
index 0000000..b019810
--- /dev/null
+++ b/tests/pagemod-test-helpers.js
@@ -0,0 +1,55 @@
+"use strict";
+
+const {Cc,Ci} = require("chrome");
+
+/**
+ * A helper function that creates a PageMod, then opens the specified URL
+ * and checks the effect of the page mod on 'onload' event via testCallback.
+ */
+exports.testPageMod = function testPageMod(test, testURL, pageModOptions,
+ testCallback, timeout) {
+ var xulApp = require("xul-app");
+ if (!xulApp.versionInRange(xulApp.platformVersion, "1.9.3a3", "*") &&
+ !xulApp.versionInRange(xulApp.platformVersion, "1.9.2.7", "1.9.2.*")) {
+ test.pass("Note: not testing PageMod, as it doesn't work on this platform version");
+ return null;
+ }
+
+ var wm = Cc['@mozilla.org/appshell/window-mediator;1']
+ .getService(Ci.nsIWindowMediator);
+ var browserWindow = wm.getMostRecentWindow("navigator:browser");
+ if (!browserWindow) {
+ test.pass("page-mod tests: could not find the browser window, so " +
+ "will not run. Use -a firefox to run the pagemod tests.")
+ return null;
+ }
+
+ if (timeout !== undefined) {
+ test.waitUntilDone(timeout);
+ } else {
+ test.waitUntilDone();
+ }
+
+ let loader = test.makeSandboxedLoader();
+ let pageMod = loader.require("page-mod");
+
+ var pageMods = [new pageMod.PageMod(opts) for each(opts in pageModOptions)];
+
+ var tabBrowser = browserWindow.gBrowser;
+ var newTab = tabBrowser.addTab(testURL);
+ tabBrowser.selectedTab = newTab;
+ var b = tabBrowser.getBrowserForTab(newTab);
+
+ function onPageLoad() {
+ b.removeEventListener("load", onPageLoad, true);
+ testCallback(b.contentWindow.wrappedJSObject, function done() {
+ pageMods.forEach(function(mod) mod.destroy());
+ // XXX leaks reported if we don't close the tab?
+ tabBrowser.removeTab(newTab);
+ test.done();
+ });
+ }
+ b.addEventListener("load", onPageLoad, true);
+
+ return pageMods;
+}
diff --git a/tests/test-match-pattern.js b/tests/test-match-pattern.js
new file mode 100644
index 0000000..ed51b43
--- /dev/null
+++ b/tests/test-match-pattern.js
@@ -0,0 +1,11 @@
+var { MatchPattern } = require("match-pattern");
+
+exports.ensureMatchPattern = function (test) {
+ var pattern = new MatchPattern("https://bugzilla.redhat.com/attachment.cgi");
+ console.log("pattern = " + pattern);
+ test.assert(pattern.
+ test("https://bugzilla.redhat.com/attachment.cgi"), "testing match pattern");
+ test.assert(!pattern.
+ test("https://bugzilla.redhat.com/attachment.cgi?bugid=676538&action=enter"),
+ "testing failing match pattern");
+};
diff --git a/tests/test-pageMod.js b/tests/test-pageMod.js
new file mode 100644
index 0000000..8662a4c
--- /dev/null
+++ b/tests/test-pageMod.js
@@ -0,0 +1,141 @@
+/*jslint white: false, eqeqeq: false, plusplus: false, onevar: false, newcap: false */
+/*global exports: false, require: false, console: false, log: false */
+"use strict";
+var Cc = require("chrome").Cc;
+var Ci = require("chrome").Ci;
+var main = require("main");
+var utilMod = require("util");
+var testPageMod = require("pagemod-test-helpers").testPageMod;
+var self = require("self");
+
+var theURL = main.theURL;
+var testURL = self.data.url('tests/change-more-bugs01.html');
+var JSONifiedMessage = '{"cmd":"testMessage","data":{"a":"first","b":"second"}}';
+
+exports.ensureMessagesWork = function(test) {
+ var msg = new utilMod.Message("testMessage", { a: "first", b: "second" } );
+ test.assertEqual(msg.cmd, "testMessage",
+ "msg.cmd comes over well");
+ test.assertEqual(msg.data.a, "first",
+ "msg.data.a comes over well");
+ test.assertEqual(msg.data.b, "second",
+ "msg.data.b comes over well");
+ test.assertEqual(JSON.stringify(msg), JSONifiedMessage,
+ "JSONification of Message works as well");
+};
+
+/*
+
+var theURL = main.theURL;
+var testURL = self.data.url('tests/change-more-bugs01.html');
+
+var contentScriptLibraries = {
+ "bugzilla.redhat.com": [
+ self.data.url("util.js"),
+ self.data.url("color.js"),
+ self.data.url("rhbzpage.js"),
+ self.data.url("bzpage.js")
+ ]
+};
+
+libbz.initialize(libbz.config, function () {
+ pageMod.PageMod({
+ include: [
+ "https://bugzilla.redhat.com/show_bug.cgi?id=*"
+ ],
+ contentScriptWhen: 'ready',
+ contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"],
+ onAttach: function onAttach(worker, msg) {
+ console.log("worker: " + worker);
+ worker.on('message', function (msg) {
+ messageHandler(worker, msg);
+ });
+ }
+ });
+});
+
+pageMod.PageMod({
+ include: [
+ "https://bugzilla.redhat.com/process_bug.cgi"
+ ],
+ contentScriptWhen: 'ready',
+ contentScriptFile: self.data.url("skip-bug.js")
+});
+ */
+
+var ensureSimplePageLoad = function (test) {
+ console.log("testURL = " + testURL);
+ testPageMod(test, testURL, [{
+ include: ["*"],
+ contentScriptWhen: 'ready',
+ contentScriptFile: [
+ self.data.url("libPW.js"),
+ self.data.url("simplePageWorker.js")
+ ],
+ onAttach: function onAttach(worker) {
+ worker.on('message', function (msg) {
+ switch (msg.cmd) {
+ case "LogMessage":
+ log(msg.data);
+ break;
+ case "CallBack":
+ worker.postMessage(new utilMod.Message("Main", null));
+ break;
+ default:
+ console.error(msg);
+ }
+ });
+ }
+ }],
+ function (win, done) {
+ test.assertNotEqual(win.document.getElementsByTagName("form")[0],
+ null, "test of loading the page");
+ done();
+ });
+};
+
+var ensurePageLoadsWell = function (test) {
+ var wm = Cc['@mozilla.org/appshell/window-mediator;1']
+ .getService(Ci.nsIWindowMediator);
+ var browserWindow = wm.getMostRecentWindow("navigator:browser");
+ if (!browserWindow) {
+ test.fail("page-mod tests: could not find the browser window, so " +
+ "will not run. Use -a firefox to run the pagemod tests.");
+ return null;
+ }
+
+ var loader = test.makeSandboxedLoader();
+ var pageMod = loader.require("page-mod");
+ var testDoc = {}, b = {}, tabBrowser = {}, newTab = {};
+
+ pageMod.PageMod({
+ include: ["*"],
+ contentScriptWhen: 'ready',
+ contentScriptFile: [
+ self.data.url("libPW.js"),
+ self.data.url("pageWorker.js")
+ ],
+ onAttach: function onAttach(worker) {
+ worker.on('message', function (msg) {
+ switch (msg.cmd) {
+ case "testReady":
+ testDoc = b.contentWindow.wrappedJSObject.document;
+ test.assertNotEqual(testDoc.getElementById("dupeid_action"),
+ null, "test of DOM modifications of the page");
+ pageMod.destroy();
+ tabBrowser.removeTab(newTab);
+ test.done();
+ // the test itself
+ break;
+ default:
+ main.messageHandler(worker, msg);
+ }
+ });
+ }
+ });
+
+ tabBrowser = browserWindow.gBrowser;
+ newTab = tabBrowser.addTab(testURL);
+ tabBrowser.selectedTab = newTab;
+ b = tabBrowser.getBrowserForTab(newTab);
+};