Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XUL support with test #13

Merged
9 commits merged into from
Dec 24, 2010
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
pdoc
*~
29 changes: 29 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,35 @@ The remaining files should be self-explanatory; each contains a single piece of
standard library; see [the website](http://jsclass.jcoglan.com) for documentation.


Development
---

To hack on JS.Class you'll need to be able to build it and run the tests. You
need Ruby and Jake to do this:

gem install jake
cd path/to/js.class
jake

This will build the project and create files in the `build` directory. To run the
tests, run the `test/console.js` script using any JavaScript interpreter, for
example:

node test/console.js

Some interpreters will skip the tests that use asynchronous APIs, but the tests
should work using these JavaScript implementations:

* Node
* V8
* Rhino
* Narwhal
* SpiderMonkey
* Windows Script Host

To run the tests in a browser, just open the `test/browser.html` file.
To test in a XUL environment run: `xulrunner -app test/xulenv/application.ini`

License
---

Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'rubygems'
require 'httparty'
require 'nokogiri'
require 'set'
Expand Down
8 changes: 7 additions & 1 deletion source/dom/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ JS.DOM.Builder = new JS.Class('DOM.Builder', {
},

makeElement: function(name, children) {
var element = document.createElement(name), child, attribute;
var element, child, attribute;
if ( document.createElementNS ) {
// That makes possible to mix HTML within SVG or XUL.
element = document.createElementNS("http://www.w3.org/1999/xhtml", name);
} else {
element = document.createElement(name);
}
for (var i = 0, n = children.length; i < n; i++) {
child = children[i];
if (JS.isFn(child)) {
Expand Down
45 changes: 39 additions & 6 deletions source/package/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,62 @@ JS.Package.DomLoader = {
},

loadFile: function(path, fireCallbacks) {
if (window.console && console.info)
console.info('Loading ' + path);

var self = this,
tag = document.createElement('script');
tag = document.createElement('script');

tag.type = 'text/javascript';
tag.src = path;

tag.onload = tag.onreadystatechange = function() {
var state = tag.readyState, status = tag.status;
if ( !state || state === 'loaded' || state === 'complete' || (state === 4 && status === 200) ) {
if ( !state || state === 'loaded' || state === 'complete' ||
(state === 4 && status === 200) ) {
fireCallbacks();
tag.onload = tag.onreadystatechange = self._K;
tag = null;
}
};

if (window.console && console.info)
console.info('Loading ' + path);

document.getElementsByTagName('head')[0].appendChild(tag);
},

_K: function() {}
};

JS.Package.MozIJSSubScriptLoader = {
usable: function() {
try {
if ( Components &&
Components.classes &&
Components.classes["@mozilla.org/moz/jssubscript-loader;1"] &&
Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService ) {
return true;
} else {
return false;
}
} catch(e) {
return false;
}
},

setup: function() {
this.mozLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader);
},

loadFile: function(path, fireCallbacks) {
if (window.console && console.info)
console.info('Loading ' + path);

this.mozLoader.loadSubScript(path);
fireCallbacks();
}
};


JS.Package.CommonJSLoader = {
usable: function() {
return typeof require === 'function' &&
Expand Down Expand Up @@ -115,7 +147,8 @@ JS.Package.WshLoader = {
};

(function() {
var candidates = [ JS.Package.DomLoader,
var candidates = [ JS.Package.MozIJSSubScriptLoader,
JS.Package.DomLoader,
JS.Package.CommonJSLoader,
JS.Package.ServerLoader,
JS.Package.WshLoader ],
Expand Down
7 changes: 7 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
try {

if (typeof CWD === 'undefined') CWD = '.'

JS.Packages(function() { with(this) {
Expand Down Expand Up @@ -33,3 +35,8 @@ JS.require('JS.Test', 'JS.MethodChain', function() {
JS.Test.method('autorun'))
})

} catch(e) {
var info = 'ERROR while starting the test environment:\n' + e;
if (window.console && console.info) console.info(info);
else alert(info)
}
12 changes: 12 additions & 0 deletions test/xulenv/application.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[App]
Vendor=JSClass
Name=XULTestEnvironment
Version=0.1
BuildID=20101002
Copyright=Copyright (c) 2010 Aurélio A. Heckert
[email protected]

[Gecko]
MinVersion=1.8
MaxVersion=1.9.2.*

1 change: 1 addition & 0 deletions test/xulenv/chrome/chrome.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content xultestenv file:content/
1 change: 1 addition & 0 deletions test/xulenv/chrome/content/jsclass
22 changes: 22 additions & 0 deletions test/xulenv/chrome/content/main.xul
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://xultestenv/content/testui.css" type="text/css"?>

<window id="main-win" title="XUL Test Environment - JS.Class" width="600" height="500"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:html="http://www.w3.org/1999/xhtml">

<box flex="1" style="overflow:auto">
<html:body flex="1" id="htmlbody"></html:body>
</box>
<script type="text/javascript">
var JSCLASS_PATH = "chrome://xultestenv/content/jsclass/build/src/";
document.body = document.getElementById("htmlbody");
window.console = { log: function(a,b){ alert(a+"\n\n"+b) } }
</script>

<script type="text/javascript">CWD = 'chrome://xultestenv/content/jsclass/'</script>
<script type="text/javascript" src="jsclass/build/min/loader.js"></script>
<script type="text/javascript" src="chrome://xultestenv/content/jsclass/test/runner.js"></script>

</window>
133 changes: 133 additions & 0 deletions test/xulenv/chrome/content/testui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
body {
overflow: auto;
}

.test-result-container {
font: normal 15px FreeSans, Helvatica, Arial, sans-serif;
background: #fff;
color: #444;
border: 2px solid #444;
position: absolute;
right: 30px;
top: 30px;
width: 509px;
margin: auto;
overflow: hidden;
}

.test-result-container p,
.test-result-container ul,
.test-result-container li {
margin: 0;
padding: 0;
list-style: circle outside;
}

.test-result-container .report {
border-collapse: collapse;
margin: 0;
padding: 0;
}

.test-result-container .report th, .test-result-container .report td {
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
font-weight: bold;
padding: 0 8px;
text-align: right;
width: 110px;
}

.test-result-container .report th {
border-top: 1px solid #ccc;
background: #eee;
padding: 4px 8px;
}

.test-result-container .report td {
font-size: 300%;
color: #999;
}

.test-result-container .specs {
border-top: 1px solid #999;
list-style: none;
}

.test-result-container .specs .spec,
.test-result-container .specs .test {
position: relative;
}

.test-result-container .specs .spec-name,
.test-result-container .specs .test-name {
cursor: pointer;
}

.test-result-container .spec-name {
border-top: 1px solid #ddd;
font-weight: bold;
cursor: pointer;
}

.test-result-container .specs ul {
margin-left: 32px;
}

.test-result-container .specs p {
padding: 4px 12px;
}

.test-result-container .specs .fault {
font-size: 75%;
}

.test-result-container .specs .failed {
color: #e40;
}

.test-result-container .specs .closed ul.children {
display: none;
}

.test-result-container .test .stats {
display: none;
}

.test-result-container .stats {
float: right;
list-style: none;
top: 0;
right: 0;
}

.test-result-container .stats li {
list-style: none;
display: block;
float: left;
border-left: 1px solid #eee;
padding: 4px 8px;
width: 47px;
}

.test-result-container .stats .number {
font-weight: bold;
color: #666;
}

.test-result-container .stats .letter {
color: #999;
font-size: 80%;
}

.test-result-container .passed .number {
color: #6c3;
}

.test-result-container .summary {
border-top: 1px solid #999;
color: #666;
padding: 4px 8px;
margin: 0;
}

1 change: 1 addition & 0 deletions test/xulenv/defaults/preferences/prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pref("toolkit.defaultChromeURI", "chrome://xultestenv/content/main.xul");