finish things up for 4.0b3
[mandelbrot.git] / tests / browser_mandelbrot_basics.js
CommitLineData
140e460f
RK
1/* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5fb4a082 5// Test some basic functionality of KaiRo.at Mandelbrot.
140e460f
RK
6
7Components.utils.import("resource://gre/modules/Services.jsm");
8
9const MBROT_LOADED = "mandelbrot-loaded";
10const TEST_DONE = "mandelbrot-test-done";
11
12function test() {
13 gBrowser.addTab();
5fb4a082 14 // Open KaiRo.at Mandelbrot, testing the menu item.
140e460f
RK
15 let menuitem = document.getElementById("tasksMenuMandelbrot") ||
16 document.getElementById("menu_openMandelbrot");
17 menuitem.click();
18
19 var testIndex = 0;
20 var win;
21
22 let testObs = {
23 observe: function(aSubject, aTopic, aData) {
24 if (aTopic == MBROT_LOADED) {
25 Services.obs.removeObserver(testObs, MBROT_LOADED);
5fb4a082 26 ok(true, "KaiRo.at Mandelbrot is loaded");
140e460f
RK
27
28 win = content.wrappedJSObject;
29 Services.obs.addObserver(testObs, TEST_DONE, false);
30 // Trigger the first test now!
31 Services.obs.notifyObservers(window, TEST_DONE, null);
32 }
33 else {
34 // TEST_DONE triggered, run next test
35 info("run test #" + (testIndex + 1) + " of " + testFuncs.length +
36 " (" + testFuncs[testIndex].name + ")");
37 setTimeout(testFuncs[testIndex++], 0, win);
38
39 if (testIndex >= testFuncs.length) {
40 // Finish this up!
41 Services.obs.removeObserver(testObs, TEST_DONE);
42 Services.cookies.removeAll();
43 gLocSvc.fhist.removeAllEntries();
44 setTimeout(finish, 0);
45 }
46 }
47 }
48 };
49 waitForExplicitFinish();
50 Services.obs.addObserver(testObs, MBROT_LOADED, false);
51}
52
53var testFuncs = [
54function test_open_state(aWin) {
55 is(aWin.document.documentElement.id, "mandelbrot-page",
5fb4a082 56 "The active tab is KaiRo.at Mandelbrot");
140e460f
RK
57 is(aWin.document.getElementById("drawButton").hidden, false,
58 "The draw button is not hidden");
59 Services.obs.notifyObservers(window, TEST_DONE, null);
60},
61
62function test_close(aWin) {
63 function dmWindowClosedListener() {
64 aWin.removeEventListener("unload", dmWindowClosedListener, false);
65 isnot(content.document.documentElement.id, "mandelbrot-page",
5fb4a082 66 "The active tab is not KaiRo.at Mandelbrot");
140e460f
RK
67 Services.obs.notifyObservers(window, TEST_DONE, null);
68 }
69 aWin.addEventListener("unload", dmWindowClosedListener, false);
70 aWin.close();
71}
72];