author Myk Melez <myk@mozilla.org>
Tue, 14 Aug 2012 15:27:26 -0700
changeset 102403 07b53bdc212ac3876cea6c2c7906e3106985043e
parent 1 9b2a99adc05e53cd4010de512f50118594756650
child 156421 fbadb971da8374793708dcaaccfc74037fd8c495
permissions -rw-r--r--
bug 770770: refactor webapp runtime test harness to reduce complexity/special-casing; r=adw

 mochitest README

Steps to get started:

 1.) Run the runtests.pl script to start the server.
     Currently, the test script automatically determines the location
     of *Firefox*.

 2.) gen_template.pl will generate test templates for HTML, XUL, and XHTML.
     Read the comment at the top of the file for usage instructions.

 3.) Write a test.

Example test:

  <title>Test for Bug 345656</title>
  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>        
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<p id="display"></p>
<div id="content" style="display: none">
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 345656 **/
//add information to show on the test page
$("display").innerHTML = "doing stuff...";

// The '$' is function is shorthand for getElementById. This is the same thing:
document.getElementById("display").innerHTML = "doing stuff...";

// you can add content that you don't want to clutter 
// the display to the content div.
// You can write directly, or you can use MochiKit functions
// to do it in JS like this:
                 DIV({class: "qux"},
                     SPAN({id: "span42"}, "content"))

// the ok() function is like assert
ok(true, "checking to see if true is true);

// this will fail
ok(1==2, "1 equals 2?");

// this will be marked as a todo.
// When we fix 1 so it equals 2, we'll need to change this 
// function to ok() or is().
todo(1==2, "1 equals 2?");

// is() takes two args
myVar = "foo";
is(myVar, "foo", "checking to see if myVar is 'foo'");

// Tests can run in event handlers.
// Call this to tell SimpleTest to wait for SimpleTest.finish() 

// event handler:
function event_fired(ev) {
  is(ev.newValue, "width: auto;", "DOMAttrModified event reports correct newValue");
  SimpleTest.finish(); // trigger the end of our test sequence

// Hook up the event. Mochikit.Signal has many conveniences for this, if you want.
$("content").addEventListener("DOMAttrModified", event_fired, false);

// Fire the event.
$("content").style.width = "auto";