Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Add AJAX tests to Mozilla

This page is a draft, and the directions are subject to change.

Have you written an AJAX framework? Would you like to make sure we don't cause problems for your code in new releases and security updates? We have a simple format that will add your AJAX framework's code to our continuous integration infrastructure. Your tests will be executing after every checkin.

Download our test scaffolding

This is nothing too complicated. It's just a file you open from your local disk or a web server, and the tests run in JavaScript. You can use any unit test code you like, but you will have add 5 or 6 lines to communicate with our automation infrastructure. Instructions below.

Download Test Scaffolding

Open the package

It's arranged like this:

manifest.json
A list of HTML test files that need to be executed separately.
test_FooFramework.js
This is our test page; you need to rename this after your framework.
mozilla/
A directory containing our JavaScript test scaffolding.
<your files>
Fill out the rest of the package with your own files, as needed for your test.

Add our small hook script to your test pages

<!DOCTYPE HTML>
<html>
<head>
 <title>Test for Foo Framework</title>
  
 <!-- ADD THIS FILE -->
 <script type="text/javascript" src="../mozilla/hooks.js"></script>
 
 <script type="text/javascript" src="FooFramework.js"></script>
 <script>
    function doTests() {
      Foo.assert(3==3, "test eq of 3");
      Foo.assert(4==4, "test eq of 4");
      Foo.finishTests();
    }
 </script>
</head>
<body onload="doTests();">
Test for Foo Framework File 2
</body>
</html>

Add two callbacks to your test functions

We need to maintain coherent logging for every framework, so it's easiest for us to listen for common events. The download contained a fictional FooFramework, so let's look at what needs to be added to support that logging:

/* Demo FooFramework Containing Only Test Functions */
var Foo = {
  assert: function(condition, name, diagnostic) {
    var body = document.getElementsByTagName("BODY")[0];
    var para = document.createElement("P");
    para.innerHTML = condition + " | " + name + " | " + diagnostic;
    body.appendChild(para);
 
    // ADD THIS check for a test listener
    if (window.onTestAssert) {
      onTestAssert(condition, name, diagnostic);
    }
  },
  
  finishTests: function() {
    var body = document.getElementsByTagName("BODY")[0];
    var para = document.createElement("P");
    para.innerHTML = "DONE!";
    body.appendChild(para);

    // ADD THIS check for a test listener
    if (window.onTestPageFinish) {
      onTestPageFinish();
    }
  }
}

The onTestAssert() function takes three parameters:

  1. A Boolean indicating whether the assertion succeeded.
  2. An optional test name.
  3. An optional diagnostic message to print if an error occurs.

The download contains these demo files for the FooFramework. That should get you started.

File a bug

Once you've built your test, submit it to us so we can use it in the future. File a bug in Core:Testing, using Bugzilla. Use the attachment field to include a .zip or .tar.gz file containing the scaffolding and your additions.

The fine print

It's OK if you have lots of tests in one file, or a group of files, but each file should run unattended after opening, and tests that require full windows should open and close their own. Related files can refer to each other with relative URLs.

Document Tags and Contributors

 Contributors to this page: Sheppy, Riboribo, Nickolay, Sayrer
 Last updated by: Sheppy,