aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-02 01:14:36 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-02 01:14:36 +0100
commit41ffab7b32df1756e78af92ff68ff40afb75e1d5 (patch)
tree3bcddc3dfaa9f6ad7afbd0cf31f09d6bceb8e208 /tests
parent273765aa78125b2106218ad554e6dedad7d2b381 (diff)
parent52bcf6e79eb3085b598a9ca0d21f60879a0e3706 (diff)
downloadbugzilla-triage-41ffab7b32df1756e78af92ff68ff40afb75e1d5.tar.gz
Merge branch 'pageMod' into next
Conflicts: lib/bzpage.js
Diffstat (limited to 'tests')
-rw-r--r--tests/pagemod-test-helpers.js55
-rw-r--r--tests/test-color.js10
-rw-r--r--tests/test-match-pattern.js11
-rw-r--r--tests/test-pageMod.js141
-rw-r--r--tests/test-util.js44
5 files changed, 234 insertions, 27 deletions
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-color.js b/tests/test-color.js
index 7394057..2006fd9 100644
--- a/tests/test-color.js
+++ b/tests/test-color.js
@@ -1,30 +1,30 @@
/*global exports: false, require: false */
// TODO: add some failing tests as well
"use strict";
-var util = require("color");
+//var util = require("color");
// testing Color object
-exports.ensureColorNew = function (test) {
+var ensureColorNew = function (test) {
var col = new util.Color(255, 255, 166);
test.assertEqual(col.toString(), "#ffffa6",
"creation of new RGB Color object");
};
-exports.ensureColorUpdate = function (test) {
+var ensureColorUpdate = function (test) {
var col = new util.Color(255, 255, 166);
col.update(255, 224, 176);
test.assertEqual(col.toString(), "#ffe0b0",
"updating Color object");
};
-exports.ensureColorHSL = function (test) {
+var ensureColorHSL = function (test) {
var col = new util.Color(255, 224, 176);
test.assertEqual(col.hsl().toSource(),
"[0.10126582278481013, 1, 0.8450980392156863]",
"converting to HSL model");
};
-exports.ensureColorLight = function (test) {
+var ensureColorLight = function (test) {
var col = new util.Color(255, 224, 176);
test.assertEqual(col.lightColor().toString(), "#e8dcc9",
"getting a light color");
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);
+};
diff --git a/tests/test-util.js b/tests/test-util.js
index 9acb54c..d4e4a78 100644
--- a/tests/test-util.js
+++ b/tests/test-util.js
@@ -6,7 +6,7 @@ var util = require("util");
var urlMod = require("url");
// testing util.heir
-exports.ensureHeir = function (test) {
+var ensureHeir = function (test) {
var fedlimid = {}, naoise = {};
function Father(x) {
@@ -51,28 +51,28 @@ exports.ensureHeir = function (test) {
};
// testing util.isInList
-exports.ensureIsInListTrue = function (test) {
+var ensureIsInListTrue = function (test) {
test.assert(util.isInList("a", ["a"]),
"conversion of a string to an array");
};
-exports.ensureIsInListFalse = function (test) {
+var ensureIsInListFalse = function (test) {
test.assert(!util.isInList("b", ["a"]),
"conversion of a string to an array");
};
-exports.ensureIsInListEmpty = function (test) {
+var ensureIsInListEmpty = function (test) {
test.assert(!util.isInList("b", []),
"conversion of a string to an array");
};
-exports.ensureIsInListNoMember = function (test) {
+var ensureIsInListNoMember = function (test) {
test.assert(!util.isInList("", ["x"]),
"conversion of a string to an array");
};
// testing util.filterByRegexp
-exports.ensureFilterByRegexp = function (test) {
+var ensureFilterByRegexp = function (test) {
var list = [
{
"regexp": "test(ing|ed)",
@@ -92,7 +92,7 @@ exports.ensureFilterByRegexp = function (test) {
"simple testing of filterByRegexp with non-string return value");
};
-exports.ensureFilterByRegexpEmpty = function (test) {
+var ensureFilterByRegexpEmpty = function (test) {
test.assertRaises(function () {
util.filterByRegexp(undefined, "tralala");
},
@@ -101,78 +101,78 @@ exports.ensureFilterByRegexpEmpty = function (test) {
};
// testing util.getISODate
-exports.ensureGetISODate = function (test) {
+var ensureGetISODate = function (test) {
test.assertEqual(util.getISODate("Mon May 31 2010 23:29:09 GMT+0200 (CET)"),
"2010-05-31", "conversion of a Date to ISO-formatted String");
};
// testing util.valToArray
-exports.ensureValToArrayString = function (test) {
+var ensureValToArrayString = function (test) {
test.assertEqual(JSON.stringify(util.valToArray("a")),
JSON.stringify(["a"]),
"conversion of a string to an array");
};
-exports.ensureValToArrayEmpty = function (test) {
+var ensureValToArrayEmpty = function (test) {
test.assertEqual(JSON.stringify(util.valToArray("")),
JSON.stringify([""]),
"conversion of an empty string to an array");
};
-exports.ensureValToArrayArray = function (test) {
+var ensureValToArrayArray = function (test) {
test.assertEqual(JSON.stringify(util.valToArray(["a"])),
JSON.stringify(["a"]),
"non-conversion of an array");
};
// testing util.addCSVValue
-exports.ensureCSVAddedToNull = function (test) {
+var ensureCSVAddedToNull = function (test) {
test.assertEqual(util.addCSVValue("", "b"), "b",
"adding a string to empty string");
};
-exports.ensureCSVAddedNull = function (test) {
+var ensureCSVAddedNull = function (test) {
test.assertEqual(util.addCSVValue("a", ""), "a",
"adding nothing to a string");
};
-exports.ensureCSVAddedString = function (test) {
+var ensureCSVAddedString = function (test) {
test.assertEqual(util.addCSVValue("a", "b"), "a, b",
"adding one string to another one");
};
-exports.ensureCSVAddedArray = function (test) {
+var ensureCSVAddedArray = function (test) {
test.assertEqual(util.addCSVValue("a", ["b", "c"]), "a, b, c",
"adding array to a string");
};
-exports.ensureCSVAddedArray2Array = function (test) {
+var ensureCSVAddedArray2Array = function (test) {
test.assertEqual(util.addCSVValue("a, b", ["c", "d"]), "a, b, c, d",
"adding one array to another");
};
// testing util.removeCSVValue
-exports.ensureCSVRemoveSimple = function (test) {
+var ensureCSVRemoveSimple = function (test) {
test.assertEqual(util.removeCSVValue("a, b", "b"), "a",
"removing one string from an array");
};
// also checking a tolerancy against different ways of writing arrays
-exports.ensureCSVRemoveNonMember = function (test) {
+var ensureCSVRemoveNonMember = function (test) {
test.assertEqual(util.removeCSVValue("a,b", "c"), "a, b",
"removing a string from an array of which it isn't a member");
};
-exports.ensureCSVRemoveEmpty = function (test) {
+var ensureCSVRemoveEmpty = function (test) {
test.assertEqual(util.removeCSVValue("", "c"), "",
"removing a string from an empty array");
};
// testing util.getObjectKeys
-exports.ensureGetObjectKeys = function (test) {
+var ensureGetObjectKeys = function (test) {
var testObj = {
a: 1,
b: 2
@@ -183,7 +183,7 @@ exports.ensureGetObjectKeys = function (test) {
};
// testing util.getParamsFromURL
-exports.ensureGetParamsFromURL = function (test) {
+var ensureGetParamsFromURL = function (test) {
test.assertEqual(JSON.stringify(util.getParamsFromURL("https://bugzilla.redhat.com/show_bug.cgi?id=549066")),
JSON.stringify({id:"549066"}),
"simply compare result of bugzilla show_page URL");
@@ -206,7 +206,7 @@ exports.ensureGetParamsFromURL = function (test) {
};
// testing util.getBugNo
-exports.ensureGetBugNo = function (test) {
+var ensureGetBugNo = function (test) {
var bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=597141");
test.assertEqual(bugNo, 597141, "getting bug number");
bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=serialWacom");