| 1 | /* Any copyright is dedicated to the Public Domain. |
| 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
| 3 | */ |
| 4 | |
| 5 | // Test some basic functionality of KaiRo.at Mandelbrot. |
| 6 | |
| 7 | Components.utils.import("resource://gre/modules/Services.jsm"); |
| 8 | |
| 9 | const MBROT_LOADED = "mandelbrot-loaded"; |
| 10 | const TEST_DONE = "mandelbrot-test-done"; |
| 11 | |
| 12 | function test() { |
| 13 | gBrowser.addTab(); |
| 14 | // Open KaiRo.at Mandelbrot, testing the menu item. |
| 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); |
| 26 | ok(true, "KaiRo.at Mandelbrot is loaded"); |
| 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 | |
| 53 | var testFuncs = [ |
| 54 | function test_open_state(aWin) { |
| 55 | is(aWin.document.documentElement.id, "mandelbrot-page", |
| 56 | "The active tab is KaiRo.at Mandelbrot"); |
| 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 | |
| 62 | function test_close(aWin) { |
| 63 | function dmWindowClosedListener() { |
| 64 | aWin.removeEventListener("unload", dmWindowClosedListener, false); |
| 65 | isnot(content.document.documentElement.id, "mandelbrot-page", |
| 66 | "The active tab is not KaiRo.at Mandelbrot"); |
| 67 | Services.obs.notifyObservers(window, TEST_DONE, null); |
| 68 | } |
| 69 | aWin.addEventListener("unload", dmWindowClosedListener, false); |
| 70 | aWin.close(); |
| 71 | } |
| 72 | ]; |