xultestrunner 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/.gitignore +2 -0
  2. data/.gitmodules +3 -0
  3. data/LICENSE +21 -0
  4. data/README +17 -0
  5. data/Rakefile +50 -0
  6. data/VERSION +1 -0
  7. data/bin/xultest +13 -0
  8. data/lib/xultestrunner.rb +1 -0
  9. data/xulapp/application.ini +9 -0
  10. data/xulapp/chrome/chrome.manifest +2 -0
  11. data/xulapp/chrome/content/interface/boot.xul +20 -0
  12. data/xulapp/chrome/content/interface/testharness.html +30 -0
  13. data/xulapp/chrome/content/lib/xultestcase.js +140 -0
  14. data/xulapp/chrome/content/lib/xultestrunner.js +120 -0
  15. data/xulapp/chrome/content/vendor/prototype/LICENSE +16 -0
  16. data/xulapp/chrome/content/vendor/prototype/prototype.js +4874 -0
  17. data/xulapp/chrome/content/vendor/scriptaculous/LICENSE +20 -0
  18. data/xulapp/chrome/content/vendor/scriptaculous/test.css +90 -0
  19. data/xulapp/chrome/content/vendor/scriptaculous/unittest.js +566 -0
  20. data/xulapp/chrome/content/vendor/xpcomcore/LICENSE +21 -0
  21. data/xulapp/chrome/content/vendor/xpcomcore/README +27 -0
  22. data/xulapp/chrome/content/vendor/xpcomcore/Rakefile +83 -0
  23. data/xulapp/chrome/content/vendor/xpcomcore/VERSION.yml +5 -0
  24. data/xulapp/chrome/content/vendor/xpcomcore/bootstrapper.js +32 -0
  25. data/xulapp/chrome/content/vendor/xpcomcore/components/XPCOMCore.js +120 -0
  26. data/xulapp/chrome/content/vendor/xpcomcore/doc/files.html +241 -0
  27. data/xulapp/chrome/content/vendor/xpcomcore/doc/index.html +243 -0
  28. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/Error.html +256 -0
  29. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/Kernel.html +1030 -0
  30. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/LoadError.html +319 -0
  31. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/SelfConceptError.html +319 -0
  32. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/_global_.html +316 -0
  33. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/src/lib_file.js.html +53 -0
  34. data/xulapp/chrome/content/vendor/xpcomcore/doc/symbols/src/lib_kernel.js.html +251 -0
  35. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/README.txt +186 -0
  36. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame.js +33 -0
  37. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Chain.js +102 -0
  38. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Dumper.js +144 -0
  39. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Hash.js +84 -0
  40. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Link.js +153 -0
  41. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Namespace.js +10 -0
  42. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Opt.js +134 -0
  43. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Reflection.js +26 -0
  44. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/String.js +93 -0
  45. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/frame/Testrun.js +129 -0
  46. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/handlers/FOODOC.js +26 -0
  47. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC.js +26 -0
  48. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/DomReader.js +159 -0
  49. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/XMLDoc.js +16 -0
  50. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/handlers/XMLDOC/XMLParse.js +292 -0
  51. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC.js +104 -0
  52. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/DocComment.js +200 -0
  53. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/DocTag.js +294 -0
  54. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/JsDoc.js +126 -0
  55. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/JsPlate.js +109 -0
  56. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Lang.js +144 -0
  57. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Parser.js +145 -0
  58. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/PluginManager.js +33 -0
  59. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Symbol.js +645 -0
  60. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/SymbolSet.js +241 -0
  61. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TextStream.js +41 -0
  62. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Token.js +18 -0
  63. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TokenReader.js +332 -0
  64. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/TokenStream.js +133 -0
  65. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Util.js +32 -0
  66. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/lib/JSDOC/Walker.js +474 -0
  67. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/main.js +111 -0
  68. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/commentSrcJson.js +20 -0
  69. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/frameworkPrototype.js +16 -0
  70. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/functionCall.js +10 -0
  71. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/publishSrcHilite.js +62 -0
  72. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/symbolLink.js +10 -0
  73. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/tagParamConfig.js +31 -0
  74. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/plugins/tagSynonyms.js +43 -0
  75. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/run.js +348 -0
  76. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/t/TestDoc.js +144 -0
  77. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/t/runner.js +13 -0
  78. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test.js +325 -0
  79. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/addon.js +24 -0
  80. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/anon_inner.js +14 -0
  81. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/augments.js +31 -0
  82. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/augments2.js +26 -0
  83. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/borrows.js +46 -0
  84. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/borrows2.js +23 -0
  85. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/config.js +22 -0
  86. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/constructs.js +18 -0
  87. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/encoding.js +10 -0
  88. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/encoding_other.js +12 -0
  89. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/event.js +54 -0
  90. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/exports.js +14 -0
  91. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/functions_anon.js +39 -0
  92. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/functions_nested.js +33 -0
  93. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/global.js +13 -0
  94. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/globals.js +25 -0
  95. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/ignore.js +10 -0
  96. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/inner.js +16 -0
  97. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/jsdoc_test.js +477 -0
  98. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/lend.js +33 -0
  99. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/memberof.js +19 -0
  100. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/memberof_constructor.js +17 -0
  101. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/module.js +17 -0
  102. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/name.js +19 -0
  103. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/namespace_nested.js +23 -0
  104. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/nocode.js +13 -0
  105. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/oblit_anon.js +20 -0
  106. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/overview.js +20 -0
  107. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/param_inline.js +37 -0
  108. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/params_optional.js +8 -0
  109. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/prototype.js +17 -0
  110. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_nested.js +9 -0
  111. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_oblit.js +13 -0
  112. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/prototype_oblit_constructor.js +24 -0
  113. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/public.js +10 -0
  114. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/scripts/code.js +5 -0
  115. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/scripts/notcode.txt +5 -0
  116. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/shared.js +42 -0
  117. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/shared2.js +2 -0
  118. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/shortcuts.js +22 -0
  119. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/static_this.js +13 -0
  120. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/synonyms.js +31 -0
  121. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/tosource.js +23 -0
  122. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/app/test/variable_redefine.js +14 -0
  123. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/changes.txt +96 -0
  124. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/conf/sample.conf +31 -0
  125. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/java/build.xml +36 -0
  126. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/java/build_1.4.xml +36 -0
  127. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/java/classes/js.jar +0 -0
  128. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/java/src/JsDebugRun.java +21 -0
  129. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/java/src/JsRun.java +21 -0
  130. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/jsdebug.jar +0 -0
  131. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/jsrun.jar +0 -0
  132. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/jsrun.sh +52 -0
  133. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/allclasses.tmpl +17 -0
  134. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/allfiles.tmpl +56 -0
  135. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/class.tmpl +646 -0
  136. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/index.tmpl +39 -0
  137. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/publish.js +200 -0
  138. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/default.css +162 -0
  139. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/header.html +2 -0
  140. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/static/index.html +19 -0
  141. data/xulapp/chrome/content/vendor/xpcomcore/etc/jsdoc-toolkit/templates/jsdoc/symbol.tmpl +35 -0
  142. data/xulapp/chrome/content/vendor/xpcomcore/lib/file.js +46 -0
  143. data/xulapp/chrome/content/vendor/xpcomcore/lib/kernel.js +244 -0
  144. data/xulapp/chrome/content/vendor/xpcomcore/test/file_test.js +16 -0
  145. data/xulapp/chrome/content/vendor/xpcomcore/test/fixtures/love.js +1 -0
  146. data/xulapp/chrome/content/vendor/xpcomcore/test/fixtures/mad_love.js +1 -0
  147. data/xulapp/chrome/content/vendor/xpcomcore/test/fixtures/mad_world.js +1 -0
  148. data/xulapp/chrome/content/vendor/xpcomcore/test/fixtures/syntax_error.js +1 -0
  149. data/xulapp/chrome/content/vendor/xpcomcore/test/kernel_test.js +88 -0
  150. data/xulapp/components/bootstrap.js +93 -0
  151. data/xulapp/defaults/preferences/prefs.js +14 -0
  152. data/xultestrunner.gemspec +190 -0
  153. metadata +207 -0
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @fileoverview This file defines the implementation of our File object.
3
+ */
4
+
5
+ /**
6
+ * This will have docs when it actually does something
7
+ */
8
+ function File() {};
9
+
10
+ /**
11
+ * Joins the given string arguments together using the operating system's native path
12
+ * separator.
13
+ * @param {String} Set of strings to join together.
14
+ * @type String
15
+ */
16
+ File.join = function() {
17
+ var file = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
18
+ file.initWithPath(arguments[0]);
19
+
20
+ for(var i = 1; i < arguments.length; i++) {
21
+ file.append(arguments[i]);
22
+ }
23
+
24
+ return file.path;
25
+ };
26
+
27
+ /**
28
+ * Reads the given number of bytes (or the entire contents if the argument is ommitted)
29
+ * from the specified file
30
+ * @param {String} Path to a file.
31
+ * @param {int} Optional - number of bytes to read from the file.
32
+ * @type String
33
+ */
34
+ File.read = function(filePath, maxBytes) {
35
+ var file = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
36
+ file.initWithPath(filePath);
37
+ var fileInputStream = $Cc["@mozilla.org/network/file-input-stream;1"].createInstance($Ci.nsIFileInputStream);
38
+ var scriptableStream = $Cc["@mozilla.org/scriptableinputstream;1"].createInstance($Ci.nsIScriptableInputStream);
39
+ fileInputStream.init(file, -1, -1, 0);
40
+ scriptableStream.init(fileInputStream);
41
+ try {
42
+ return scriptableStream.read(maxBytes || scriptableStream.available());
43
+ } finally {
44
+ scriptableStream.close();
45
+ }
46
+ };
@@ -0,0 +1,244 @@
1
+ /**
2
+ * @fileoverview This file specifies a set of globally useful features/shortcuts
3
+ * and defines our "Kernel" object, which is the base for doing a lot of simple
4
+ * things with XPCOMCore such as loading in other files and printing to the
5
+ * console.
6
+ */
7
+
8
+ /**
9
+ * @class Exception representing an error loading a file.
10
+ * @extends Error
11
+ * @constructor
12
+ * @param {String} message The error message to be given for this exception.
13
+ * @type Error
14
+ */
15
+ function LoadError(message) {
16
+ var err = new Error(message);
17
+ err.name = arguments.callee.name;
18
+ return err;
19
+ };
20
+
21
+ /**
22
+ * @class Exception representing an error determining what the path to the currently executing file is.
23
+ * @extends Error
24
+ * @constructor
25
+ * @param {String} message The error message to be given for this exception.
26
+ * @type Error
27
+ */
28
+ function SelfConceptError(message) {
29
+ var err = new Error(message);
30
+ err.name = arguments.callee.name;
31
+ return err;
32
+ };
33
+
34
+ /**
35
+ * A pseudo-constructor to make JSDoc happy and actually document things in {@link Kernel}.
36
+ * If this method is called with an argument, all properties from {@link Kernel} are taken
37
+ * and defined as the return value of getter methods set on the given object.
38
+ * @class Our central 'class' containing a lot of properties and methods we need to
39
+ * build the rest of XPCOMCore on top of.
40
+ * @param {Object} mixinScope Optional argument, any object to mix {@link Kernel}'s properties
41
+ * into.
42
+ * @return The prototype object of the Kernel function.
43
+ */
44
+ function Kernel(mixinScope) {
45
+ var myPrototype = arguments.callee.prototype;
46
+ if (mixinScope) {
47
+ // FIXME - figure out a better way than this object jammed in here to special case our
48
+ // methods we really want to be calling getters when they're mixed in.
49
+ var callingGetters = {'$CURRENT_FILE': {defaultArgs: [2]}, '$CURRENT_DIRECTORY': {defaultArgs: [3] }};
50
+ var makeGetter = function(attr) { return function() { return myPrototype[attr]; } };
51
+ var makeCallingGetter = function(attr, argsArray) {
52
+ return function() {
53
+ return myPrototype[attr].apply(this, argsArray);
54
+ }
55
+ };
56
+
57
+ for (var p in myPrototype) {
58
+ if (callingGetters[p]) {
59
+ mixinScope.__defineGetter__(p, makeCallingGetter(p, callingGetters[p].defaultArgs || []));
60
+ } else {
61
+ mixinScope.__defineGetter__(p, makeGetter(p));
62
+ }
63
+ };
64
+
65
+ // Load up our standard library into the mixinScope.
66
+ var standardLibraries = ['file'];
67
+ var standardLibraryLoader = function() {
68
+ standardLibraries.forEach(function(library) { require(library); }, this);
69
+ };
70
+ standardLibraryLoader.call(mixinScope);
71
+ };
72
+ return myPrototype;
73
+ };
74
+
75
+ Kernel.prototype = {
76
+ /**
77
+ * A shortcut constant to Components.classes.
78
+ * @final
79
+ */
80
+ $Cc: Components.classes,
81
+
82
+ /**
83
+ * A shortcut constant to Components.interfaces.
84
+ * @final
85
+ */
86
+ $Ci: Components.interfaces,
87
+
88
+ /**
89
+ * A shortcut constant to Components.results.
90
+ * @final
91
+ */
92
+ $Cr: Components.results,
93
+
94
+ /**
95
+ * A shortcut constant to Components.utils.
96
+ * @final
97
+ */
98
+ $Cu: Components.utils,
99
+
100
+ /**
101
+ * Taking inspiration from Ruby, this defines the set of paths to check when
102
+ * trying to load a file via either {@link Kernel#load} or {@link Kernel#require}.
103
+ * @final
104
+ * @type Array
105
+ */
106
+ $LOAD_PATH: [XPCOMCoreConfig.getProperty('libRoot')],
107
+
108
+ /**
109
+ * Taking inspiration from Ruby, this defines the currently loaded files that
110
+ * have been loaded through {@link Kernel#require}.
111
+ * @final
112
+ * @type Array
113
+ */
114
+ $LOADED_FEATURES: ["kernel.js"],
115
+
116
+ /**
117
+ * Taking inspiration from Ruby, this method tries to determine the filesystem path to
118
+ * the caller code of this method.
119
+ * NOTE - when {@link Kernel} is mixed into an object, this function gets mixed in via
120
+ * a special case behaviour that makes it a getter that actually calls the function
121
+ * rather than returning the function object itself. This is to facilitate being able
122
+ * to call '$CURRENT_FILE' in your code rather than '$CURRENT_FILE()'. The stackTraversalDepth
123
+ * parameter is there for this reason, since we need to traverse the stack further than
124
+ * normal to find the calling scope than we normally would.
125
+ * @type String
126
+ * @param {int} stackTraversalDepth Optional argument, how far to look up the stack to
127
+ * figure out who called us. The default is usually safe.
128
+ * @throws {@link SelfConceptError} Thrown when we can't figure out what the filesystem
129
+ * path to the current file is.
130
+ */
131
+ $CURRENT_FILE: function(stackTraversalDepth) {
132
+ try {
133
+ var stackTraversalDepth = stackTraversalDepth || 1;
134
+ var ioService = $Cc["@mozilla.org/network/io-service;1"].getService($Ci.nsIIOService);
135
+ // FIXME - UGH. This is so seedy.
136
+ // Traverse up the stack as far as needed to get our caller's stack frame. Sometimes we need to
137
+ // traverse more than one level up, like when this function is actually called from a getter
138
+ // property that references it.
139
+ var callerStack = Components.stack;
140
+ for (var i = 0; i < stackTraversalDepth; i++) {
141
+ callerStack = callerStack.caller;
142
+ }
143
+ // Split based on the stupid fucking " -> " Gecko puts in the filename and get the last entry
144
+ var ostensiblyUs = callerStack.filename.split(" -> ").slice(-1);
145
+ var callerFileURI = ioService.newURI(ostensiblyUs, null, null);
146
+ // QI for an nsIFileURL which lets us get a handle on an actual file attribute and automagically does
147
+ // resource: URL resolution for us
148
+ callerFileURI.QueryInterface($Ci.nsIFileURL);
149
+ // And theoretically, we can now get a handle on an nsIFile and return the path of that.
150
+ return callerFileURI.file.path;
151
+ } catch(e) {
152
+ throw(new SelfConceptError("The filesystem location of the current file could not be determined. -- " + e));
153
+ }
154
+ },
155
+
156
+ /**
157
+ * This method tries to determine the filesystem path to parent directory of the caller
158
+ * code of this method NOTE - see the note on $CURRENT_FILE, as the same applies here.
159
+ * @type String
160
+ * @param {int} stackTraversalDepth Optional argument, how far to look up the stack to
161
+ * figure out who called us. The default is usually safe.
162
+ * @throws {@link SelfConceptError} Thrown when we can't figure out what the filesystem
163
+ * path to the parent directory of the current file is.
164
+ */
165
+ $CURRENT_DIRECTORY: function(stackTraversalDepth) {
166
+ var stackTraversalDepth = stackTraversalDepth || 2;
167
+ var currentFilePath = Kernel.prototype.$CURRENT_FILE(stackTraversalDepth);
168
+
169
+ var fileObject = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
170
+ fileObject.initWithPath(currentFilePath);
171
+
172
+ return fileObject.parent.path;
173
+ },
174
+
175
+ /**
176
+ * Prints a string to standard out, without a trailing newline.
177
+ * @param {String} str String to print to standard out.
178
+ */
179
+ print: function(str) {
180
+ dump(str);
181
+ },
182
+
183
+ /**
184
+ * Prints a string to standard out, with a trailing newline.
185
+ * @param {String} str String to print to standard out.
186
+ */
187
+ puts: function(str) {
188
+ print(str + "\n");
189
+ },
190
+
191
+ /**
192
+ * Searches {@link Kernel#$LOAD_PATH $LOAD_PATH} for files to load into the current global scope.
193
+ * Files loaded via this method will not be added to {@link Kernel#$LOADED_FEATURES} and hence
194
+ * can be repeatedly loaded and executed.
195
+ * @param {String} featurePath Full or relative path including file extension to try and load.
196
+ * @type Boolean
197
+ * @throws {@link LoadError} Thrown when we can't find the specified file in any directories specified
198
+ * in {@link Kernel#$LOAD_PATH $LOAD_PATH}.
199
+ */
200
+ load: function(featurePath) {
201
+ var loader = $Cc["@mozilla.org/moz/jssubscript-loader;1"].getService($Ci.mozIJSSubScriptLoader);
202
+ var foundFile = null;
203
+ // FIXME - so this is kinda shitty. We have an empty entry here so we default to just trying to load
204
+ // from an absolute path
205
+ var loadPath = $LOAD_PATH.concat([""]);
206
+ var loadPathLength = loadPath.length;
207
+ // FIXME - mozilla bug here. if i use foreach on array it ignores the granted security privileges
208
+ for (var i = 0; i < loadPathLength; i++) {
209
+ var potentialFile = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
210
+ potentialFile.initWithPath(loadPath[i] + "/" + featurePath);
211
+ if (potentialFile.exists()) {
212
+ foundFile = potentialFile;
213
+ break;
214
+ }
215
+ };
216
+ if (foundFile) {
217
+ foundFile.normalize();
218
+ loader.loadSubScript("file://" + encodeURI(foundFile.path));
219
+ return true;
220
+ } else {
221
+ throw(new LoadError("no such file to load -- " + featurePath));
222
+ }
223
+ },
224
+
225
+ /**
226
+ * Searches {@link Kernel#$LOAD_PATH $LOAD_PATH} for features to load into the current global scope.
227
+ * Files loaded via this method will be added to {@link Kernel#$LOADED_FEATURES} and hence two
228
+ * consecutive calls to this method will not load and execute the code twice.
229
+ * @type Boolean True if successful, false if the specified feature has already been required.
230
+ * @param {String} featurePath Full or relative path without the file extension to try and require.
231
+ * @throws {@link LoadError} Thrown when we can't find the specified feature in any directories specified
232
+ * in {@link Kernel#$LOAD_PATH $LOAD_PATH}.
233
+ */
234
+ require: function(feature) {
235
+ var jsFeature = feature + ".js";
236
+ if ($LOADED_FEATURES.indexOf(jsFeature) == -1) {
237
+ load(jsFeature);
238
+ $LOADED_FEATURES.push(jsFeature);
239
+ return true;
240
+ } else {
241
+ return false;
242
+ }
243
+ }
244
+ };
@@ -0,0 +1,16 @@
1
+ XULTestCase.create("File Test", function(setup, teardown, test) {
2
+ setup(function() {
3
+ });
4
+
5
+ test("File.join should properly put together strings", function() {
6
+ this.assertEqual($CURRENT_FILE, File.join($CURRENT_DIRECTORY, "file_test.js"));
7
+ });
8
+
9
+ test("File.read without a maxBytes argument should read the entire contents of a file if it exists", function() {
10
+ this.assertEqual("var love = true;", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "love.js")));
11
+ });
12
+
13
+ test("File.read with a maxBytes argument should read the given number of bytes from a file", function() {
14
+ this.assertEqual("var love", File.read(File.join($CURRENT_DIRECTORY, "fixtures", "love.js"), 8));
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ var love = true;
@@ -0,0 +1 @@
1
+ var mad_love = true;
@@ -0,0 +1 @@
1
+ var mad_world = true;
@@ -0,0 +1,88 @@
1
+ XULTestCase.create("Kernel Test", function(setup, teardown, test) {
2
+ setup(function() {
3
+ // FIXME: Replace with real File class.
4
+ this.File = Components.Constructor("@mozilla.org/file/local;1", $Ci.nsILocalFile, "initWithPath");
5
+ $LOAD_PATH.push(this.File($CURRENT_FILE).parent.path + "/fixtures");
6
+ });
7
+
8
+ test("Kernel() function should mix its properties into the passed in scope", function(){
9
+ var newScope = {};
10
+ this.assertNotEqual(0, Kernel.prototype.__count__);
11
+ this.assertEqual(0, newScope.__count__);
12
+ Kernel(newScope);
13
+ this.assertEqual(Kernel.prototype.__count__, newScope.__count__);
14
+ });
15
+
16
+
17
+ test("$CURRENT_FILE should be exposed as a getter that returns a value that is not a function", function(){
18
+ this.assertNotEqual("function", typeof($CURRENT_FILE));
19
+ });
20
+
21
+ test("$CURRENT_FILE should end in kernel_test.js", function(){
22
+ this.assertMatch(/kernel_test.js$/, $CURRENT_FILE);
23
+ });
24
+
25
+
26
+ test("$CURRENT_DIRECTORY should be exposed as a getter that returns a value that is not a function", function(){
27
+ this.assertNotEqual("function", typeof($CURRENT_DIRECTORY));
28
+ });
29
+
30
+ test("$CURRENT_DIRECTORY should end in test", function(){
31
+ this.assertMatch(/test$/, $CURRENT_DIRECTORY);
32
+ });
33
+
34
+
35
+ test("load should throw an exception when you give it a non-existent resource", function() {
36
+ this.assertRaise("LoadError", function() {
37
+ load("some-junk");
38
+ });
39
+ });
40
+
41
+ test("load should return true when it can load a file successfully", function() {
42
+ this.assertEqual(true, load("love.js"));
43
+ });
44
+
45
+ test("load should bubble up a syntax error if the loaded file is syntactically whack", function() {
46
+ this.assertRaise("SyntaxError", function() { load("syntax_error.js") });
47
+ });
48
+
49
+ test("load should allow loading a resource multiple times", function() {
50
+ load("love.js");
51
+ this.assertEqual(true, love);
52
+
53
+ love = false;
54
+ load("love.js");
55
+ this.assertEqual(true, love);
56
+ });
57
+
58
+ test("load works when using absolute paths", function() {
59
+ love = false;
60
+
61
+ var absolutePath = this.File($CURRENT_FILE).parent.path + "/fixtures/love.js";
62
+ // FIXME: this is unix-only and janky:
63
+ this.assertMatch(/^\//, absolutePath);
64
+
65
+ load(absolutePath);
66
+ this.assertEqual(true, love);
67
+ });
68
+
69
+
70
+ test("require should load a file the first time (just like load)", function() {
71
+ this.assertEqual(true, require("love"));
72
+ });
73
+
74
+ test("require should return false if the resource has already been loaded", function() {
75
+ require("mad_love");
76
+ this.assertEqual(false, require("mad_love"));
77
+ });
78
+
79
+ test("require should not load a resource that's already been loaded", function() {
80
+ require("mad_world");
81
+ this.assertEqual(true, mad_world);
82
+
83
+ mad_world = false;
84
+ require("mad_world");
85
+ this.assertEqual(false, mad_world);
86
+ });
87
+
88
+ });
@@ -0,0 +1,93 @@
1
+ var altXPCCoreLocation = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('XPCOMCORE');
2
+ // FIXME - this will break if the full path isnt specified in the XPCOMCORE environment var
3
+ var xpcomCoreLocation = (altXPCCoreLocation ? "file://" + altXPCCoreLocation : "resource://app/chrome/content/vendor/xpcomcore");
4
+ Components.utils.import(xpcomCoreLocation + "/bootstrapper.js");
5
+ XPCOMCore({scope: this});
6
+
7
+ // Meat and potatoes begins here.
8
+ $Cu.import("resource://gre/modules/XPCOMUtils.jsm");
9
+
10
+ // Singleton time
11
+ var xtrCommandLineHandlerInstance = null;
12
+ var xtrCommandLineHandler = function() {
13
+ if (xtrCommandLineHandlerInstance) { return xtrCommandLineHandlerInstance; }
14
+ this.wrappedJSObject = this;
15
+ xtrCommandLineHandlerInstance = this;
16
+ };
17
+
18
+ xtrCommandLineHandler.prototype = {
19
+ args: {},
20
+ classDescription: "XULTestRunner Command Line Handler",
21
+ contractID: "@conflagrationjs.org/xultestrunner/app-startup-clh;1",
22
+ classID: Components.ID("{1073bad0-9b5c-11de-8a39-0800200c9a66}"),
23
+ // FIXME - Firefox 3.5.2 has included a weird bug where getService on my
24
+ // XPCOM component fails so the helpInfo never shows up.
25
+ // http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/e505ce76e23c5289#
26
+ helpInfo: " -testDir Path to a test directory.\n -testFile Path to a single test file.\n",
27
+ QueryInterface: XPCOMUtils.generateQI([$Ci.nsIObserver, $Ci.nsICommandLineHandler]),
28
+ _xpcom_categories: [{category: "command-line-handler", entry: "m-xultestrunner"}],
29
+
30
+ handle: function(cmdLine) {
31
+ try {
32
+ var testDir = cmdLine.handleFlagWithParam("testDir", false);
33
+ var testFile = cmdLine.handleFlagWithParam("testFile", false);
34
+ // We got either flag with no params if this is thrown.
35
+ } catch (e if e.result == $Cr.NS_ERROR_ILLEGAL_VALUE) {
36
+ this._handleEmptyPaths();
37
+ }
38
+ this._handleArguments(cmdLine, testDir, testFile);
39
+ },
40
+
41
+ _handleArguments: function(cmdLine, testDir, testFile) {
42
+ if (testDir) {
43
+ this._catchMissingFile(testDir, function(){
44
+ this.args.testDir = this._normalizePath(cmdLine.workingDirectory, testDir);
45
+ });
46
+ } else if (testFile) {
47
+ this._catchMissingFile(testFile, function(){
48
+ this.args.testFile = this._normalizePath(cmdLine.workingDirectory, testFile);
49
+ });
50
+ } else {
51
+ this._handleNoArguments();
52
+ }
53
+ },
54
+
55
+ _handleEmptyPaths: function() {
56
+ puts("-testDir or -testFile were given without arguments. Please specify a path to a test file or directory.");
57
+ throw($Cr.NS_ERROR_ABORT);
58
+ },
59
+
60
+ _handleNoArguments: function() {
61
+ puts("-testDir or -testFile must be specified. Please specify a path to a test file or directory.");
62
+ throw($Cr.NS_ERROR_ABORT);
63
+ },
64
+
65
+ // FIXME - ghetto. but cmdLine.resolvePath is busted like a fox. a firefox. HAHAHAHA
66
+ _normalizePath: function(workingDirFile, path) {
67
+ if (path.match(/^\//)) {
68
+ var fullPath = $Cc["@mozilla.org/file/local;1"].createInstance($Ci.nsILocalFile);
69
+ fullPath.initWithPath(path);
70
+ } else {
71
+ var fullPath = workingDirFile.clone();
72
+ fullPath.QueryInterface($Ci.nsILocalFile);
73
+ fullPath.appendRelativePath(path);
74
+ }
75
+ fullPath.normalize();
76
+ return fullPath;
77
+ },
78
+
79
+ _catchMissingFile: function(attemptedPath, wrappedFunc) {
80
+ try {
81
+ wrappedFunc.call(this);
82
+ } catch (e if e.result == $Cr.NS_ERROR_FILE_NOT_FOUND) {
83
+ puts("Given path '" + attemptedPath + "' does not exist.");
84
+ throw($Cr.NS_ERROR_ABORT);
85
+ }
86
+ }
87
+
88
+ };
89
+
90
+
91
+ NSGetModule = function(compMgr, fileSpec) {
92
+ return XPCOMUtils.generateModule([xtrCommandLineHandler]);
93
+ };