Permalink
Browse files

moving QUnit tests to separate files

  • Loading branch information...
1 parent 338906b commit 397582c6a52898cf7a98727eab4505ed30d83050 @erikvold erikvold committed May 31, 2011
View
14 extension/content/js/aboutScriptish.js
@@ -2,18 +2,16 @@ const Cu = Components.utils;
Cu.import("resource://scriptish/constants.js");
function $(aID) document.getElementById(aID);
+function include(aSrc, aCallback) {
+ var script = document.createElement("script");
+ script.src = aSrc;
+ script.addEventListener("load", aCallback, false);
+ document.documentElement.firstChild.appendChild(script);
+ }
(function() {
// Show about:scriptish?test
if (window.location.href.split("?")[1] == "test") {
- var head = document.documentElement.firstChild;
- var include = function(aSrc, aCallback) {
- var script = document.createElement("script");
- script.src = aSrc;
- script.addEventListener("load", aCallback, false);
- head.appendChild(script);
- }
-
include("js/third-party/qunit/qunit.js", function() {
include("tests/runTests.js", function() {
$("main").style.display = "none";
View
139 extension/content/tests/runTests.js
@@ -1,138 +1,7 @@
function runTests() {
var tools = {};
-
- /**
- * MODULE: Scriptish Service
- */
- module("Scriptish Service");
-
- test("Availability", function() {
- expect(2);
- equals(typeof(Services.scriptish), "object", "Scriptish service is available");
- equals(typeof(Services.scriptish.shouldLoad), "function", "shouldLoad is available");
- });
-
- // TODO: generate fake requests to test
- test("shouldLoad", function() {
- expect(0);
- });
-
-
- /**
- * MODULE: Scriptish Utilities
- */
- module("Scriptish Utilities");
- Cu.import("resource://scriptish/utils/Scriptish_alert.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_convert2RegExp.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_createUserScriptSource.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_cryptoHash.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_ExtendedStringBundle.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_findError.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getBinaryContents.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getBrowserForContentWindow.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getContents.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getEditor.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getFirebugConsole.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getProfileFile.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getTempFile.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getTLDURL.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getUriFromFile.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getURLsForContentWindow.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getWindowIDs.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_getWriteStream.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_installUri.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_launchApplicationWithDoc.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_memoize.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_notification.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_openInEditor.js", tools);
- Cu.import("resource://scriptish/utils/Scriptish_stringBundle.js", tools);
-
- test("Availability", function() {
- expect(24);
-
- equals(typeof(tools.Scriptish_alert), "function", "has Scriptish_alert");
- equals(typeof(tools.Scriptish_convert2RegExp), "function", "has Scriptish_convert2RegExp");
- equals(typeof(tools.Scriptish_createUserScriptSource), "function", "has Scriptish_createUserScriptSource");
- equals(typeof(tools.Scriptish_cryptoHash), "function", "has Scriptish_cryptoHash");
- equals(typeof(tools.Scriptish_ExtendedStringBundle), "function", "has Scriptish_ExtendedStringBundle");
- equals(typeof(tools.Scriptish_findError), "function", "has Scriptish_findError");
- equals(typeof(tools.Scriptish_getBinaryContents), "function", "has Scriptish_getBinaryContents");
- equals(typeof(tools.Scriptish_getBrowserForContentWindow), "function", "has Scriptish_getBrowserForContentWindow");
- equals(typeof(tools.Scriptish_getContents), "function", "has Scriptish_getContents");
- equals(typeof(tools.Scriptish_getEditor), "function", "has Scriptish_getEditor");
- equals(typeof(tools.Scriptish_getFirebugConsole), "function", "has Scriptish_getFirebugConsole");
- equals(typeof(tools.Scriptish_getProfileFile), "function", "has Scriptish_getProfileFile");
- equals(typeof(tools.Scriptish_getTempFile), "function", "has Scriptish_getTempFile");
- equals(typeof(tools.Scriptish_getTLDURL), "function", "has Scriptish_getTLDURL");
- equals(typeof(tools.Scriptish_getUriFromFile), "function", "has Scriptish_getUriFromFile");
- equals(typeof(tools.Scriptish_getURLsForContentWindow), "function", "has Scriptish_getURLsForContentWindow");
- equals(typeof(tools.Scriptish_getWindowIDs), "function", "has Scriptish_getWindowIDs");
- equals(typeof(tools.Scriptish_getWriteStream), "function", "has Scriptish_getWriteStream");
- equals(typeof(tools.Scriptish_installUri), "function", "has Scriptish_installUri");
- equals(typeof(tools.Scriptish_launchApplicationWithDoc), "function", "has Scriptish_launchApplicationWithDoc");
- equals(typeof(tools.Scriptish_memoize), "function", "has Scriptish_memoize");
- equals(typeof(tools.Scriptish_notification), "function", "has Scriptish_notification");
- equals(typeof(tools.Scriptish_openInEditor), "function", "has Scriptish_openInEditor");
- equals(typeof(tools.Scriptish_stringBundle), "function", "has Scriptish_stringBundle");
- });
-
- test("Scriptish_cryptoHash", function() {
- expect(2);
-
- var str = "Hello World!";
- var str_DEF_SHA1 = tools.Scriptish_cryptoHash(str);
- var str_SHA1 = tools.Scriptish_cryptoHash(str, "SHA1");
-
- equal(str_DEF_SHA1, "2ef7bde608ce5404e97d5f042f95f89f1c232871", "Default hashing algorithm is SHA1");
- equal(str_SHA1, "2ef7bde608ce5404e97d5f042f95f89f1c232871", "Specifying an algorithm (SHA1) works");
- });
-
-
- /**
- * MODULE: Scriptish Utilities (third party)
- */
- module("Scriptish Utilities (third party)");
- Cu.import("resource://scriptish/third-party/MatchPattern.js", tools);
- Cu.import("resource://scriptish/third-party/Scriptish_openFolder.js", tools);
- Cu.import("resource://scriptish/third-party/Timer.js", tools);
-
- test("Availability", function() {
- expect(3);
-
- equals(typeof(tools.MatchPattern), "function", "has MatchPattern");
- equals(typeof(tools.MatchPattern), "function", "has Scriptish_openFolder");
- equals(typeof(tools.Timer), "function", "has Timer");
- });
-
- test("Tools Menu's 'Scriptish' Menu", function() {
- expect(3);
-
- var win = Services.wm.getMostRecentWindow("navigator:browser");
- function $(aID) win.document.getElementById(aID);
- var scriptish_menu = $("scriptish_general_menu");
- var tools_menu = $("menu_ToolsPopup");
- ok(!!scriptish_menu, "Scriptish menu exists");
- ok(!!tools_menu, "Tools menu exists");
- equal(scriptish_menu.parentNode, tools_menu, "The Scriptish menu is a child of the Tools menu");
- });
-
- test("Test timeout", function() {
- expect(1);
- stop();
-
- try {
- var success = false;
- timeout(function() {
- ok((success = true), "timeout success");
- start();
- });
- setTimeout(function() {
- ok(false, "timeout error: timeout");
- start();
- }, 500);
- } catch (e) {
- ok(false, "timeout error: " + e);
- start();
- }
- });
+ include("tests/testAvailability.js");
+ include("tests/testCryptoHash.js");
+ include("tests/testToolsMenuItem.js");
+ include("tests/testTimeout.js");
}
View
78 extension/content/tests/testAvailability.js
@@ -0,0 +1,78 @@
+
+module("Availability");
+
+var tools = {};
+
+(function(Cu) {
+Cu.import("resource://scriptish/constants.js");
+Cu.import("resource://scriptish/utils/Scriptish_alert.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_convert2RegExp.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_createUserScriptSource.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_cryptoHash.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_ExtendedStringBundle.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_findError.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getBinaryContents.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getBrowserForContentWindow.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getContents.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getEditor.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getFirebugConsole.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getProfileFile.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getTempFile.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getTLDURL.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getUriFromFile.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getURLsForContentWindow.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getWindowIDs.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_getWriteStream.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_installUri.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_launchApplicationWithDoc.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_memoize.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_notification.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_openInEditor.js", tools);
+Cu.import("resource://scriptish/utils/Scriptish_stringBundle.js", tools);
+Cu.import("resource://scriptish/third-party/MatchPattern.js", tools);
+Cu.import("resource://scriptish/third-party/Scriptish_openFolder.js", tools);
+Cu.import("resource://scriptish/third-party/Timer.js", tools);
+})(Components.utils);
+
+test("Scriptish", function() {
+ expect(2);
+ equals(typeof(Services.scriptish), "object", "Scriptish service is available");
+ equals(typeof(Services.scriptish.shouldLoad), "function", "shouldLoad is available");
+ });
+
+test("Utils", function() {
+ expect(24);
+
+ equals(typeof(tools.Scriptish_alert), "function", "has Scriptish_alert");
+ equals(typeof(tools.Scriptish_convert2RegExp), "function", "has Scriptish_convert2RegExp");
+ equals(typeof(tools.Scriptish_createUserScriptSource), "function", "has Scriptish_createUserScriptSource");
+ equals(typeof(tools.Scriptish_cryptoHash), "function", "has Scriptish_cryptoHash");
+ equals(typeof(tools.Scriptish_ExtendedStringBundle), "function", "has Scriptish_ExtendedStringBundle");
+ equals(typeof(tools.Scriptish_findError), "function", "has Scriptish_findError");
+ equals(typeof(tools.Scriptish_getBinaryContents), "function", "has Scriptish_getBinaryContents");
+ equals(typeof(tools.Scriptish_getBrowserForContentWindow), "function", "has Scriptish_getBrowserForContentWindow");
+ equals(typeof(tools.Scriptish_getContents), "function", "has Scriptish_getContents");
+ equals(typeof(tools.Scriptish_getEditor), "function", "has Scriptish_getEditor");
+ equals(typeof(tools.Scriptish_getFirebugConsole), "function", "has Scriptish_getFirebugConsole");
+ equals(typeof(tools.Scriptish_getProfileFile), "function", "has Scriptish_getProfileFile");
+ equals(typeof(tools.Scriptish_getTempFile), "function", "has Scriptish_getTempFile");
+ equals(typeof(tools.Scriptish_getTLDURL), "function", "has Scriptish_getTLDURL");
+ equals(typeof(tools.Scriptish_getUriFromFile), "function", "has Scriptish_getUriFromFile");
+ equals(typeof(tools.Scriptish_getURLsForContentWindow), "function", "has Scriptish_getURLsForContentWindow");
+ equals(typeof(tools.Scriptish_getWindowIDs), "function", "has Scriptish_getWindowIDs");
+ equals(typeof(tools.Scriptish_getWriteStream), "function", "has Scriptish_getWriteStream");
+ equals(typeof(tools.Scriptish_installUri), "function", "has Scriptish_installUri");
+ equals(typeof(tools.Scriptish_launchApplicationWithDoc), "function", "has Scriptish_launchApplicationWithDoc");
+ equals(typeof(tools.Scriptish_memoize), "function", "has Scriptish_memoize");
+ equals(typeof(tools.Scriptish_notification), "function", "has Scriptish_notification");
+ equals(typeof(tools.Scriptish_openInEditor), "function", "has Scriptish_openInEditor");
+ equals(typeof(tools.Scriptish_stringBundle), "function", "has Scriptish_stringBundle");
+});
+
+test("3rd Party", function() {
+ expect(3);
+
+ equals(typeof(tools.MatchPattern), "function", "has MatchPattern");
+ equals(typeof(tools.MatchPattern), "function", "has Scriptish_openFolder");
+ equals(typeof(tools.Timer), "function", "has Timer");
+});
View
15 extension/content/tests/testCryptoHash.js
@@ -0,0 +1,15 @@
+
+Components.utils.import("resource://scriptish/utils/Scriptish_cryptoHash.js", tools);
+
+module("Scriptish_cryptoHash");
+
+test("General", function() {
+ expect(2);
+
+ var str = "Hello World!";
+ var str_DEF_SHA1 = tools.Scriptish_cryptoHash(str);
+ var str_SHA1 = tools.Scriptish_cryptoHash(str, "SHA1");
+
+ equal(str_DEF_SHA1, "2ef7bde608ce5404e97d5f042f95f89f1c232871", "Default hashing algorithm is SHA1");
+ equal(str_SHA1, "2ef7bde608ce5404e97d5f042f95f89f1c232871", "Specifying an algorithm (SHA1) works");
+});
View
24 extension/content/tests/testTimeout.js
@@ -0,0 +1,24 @@
+
+Components.utils.import("resource://scriptish/constants.js");
+
+module("Timeout");
+
+test("Default Works", function() {
+ expect(1);
+ stop();
+
+ try {
+ var success = false;
+ timeout(function() {
+ ok((success = true), "timeout success");
+ start();
+ });
+ setTimeout(function() {
+ ok(false, "timeout error: timeout");
+ start();
+ }, 500);
+ } catch (e) {
+ ok(false, "timeout error: " + e);
+ start();
+ }
+});
View
16 extension/content/tests/testToolsMenuItem.js
@@ -0,0 +1,16 @@
+
+Components.utils.import("resource://scriptish/constants.js");
+
+module("Tools Menuitem");
+
+test("Exists", function() {
+ expect(3);
+
+ var win = Services.wm.getMostRecentWindow("navigator:browser");
+ function $(aID) win.document.getElementById(aID);
+ var scriptish_menu = $("scriptish_general_menu");
+ var tools_menu = $("menu_ToolsPopup");
+ ok(!!scriptish_menu, "Scriptish menu exists");
+ ok(!!tools_menu, "Tools menu exists");
+ equal(scriptish_menu.parentNode, tools_menu, "The Scriptish menu is a child of the Tools menu");
+});

0 comments on commit 397582c

Please sign in to comment.