*
* ***** END LICENSE BLOCK ***** */
+Components.utils.import("resource://gre/modules/Services.jsm");
+
var gColorPalette = [];
-var gPref = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService)
- .getBranch(null);
var gStartTime = 0;
var gMbrotBundle;
var gCurrentImageData;
img.addEventListener("touchcancel", imgEvHandler, false);
img.addEventListener("touchleave", imgEvHandler, false);
img.addEventListener("touchmove", imgEvHandler, false);
+
+ Services.obs.notifyObservers(window, "mandelbrot-loaded", null);
}
function getAdjustPref(prefname) {
case "image.height":
value = 0;
try {
- value = gPref.getIntPref("mandelbrot." + prefname);
+ value = Services.prefs.getIntPref("mandelbrot." + prefname);
}
catch (e) { }
if ((value < 10) || (value > 5000)) {
value = 300;
- gPref.setIntPref("mandelbrot." + prefname, value);
+ Services.prefs.setIntPref("mandelbrot." + prefname, value);
}
return value;
case "last_image.Cr_*":
let Cr_min = -2.0;
let Cr_max = 1.0;
try {
- Cr_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_min"));
- Cr_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Cr_max"));
+ Cr_min = parseFloat(Services.prefs.getCharPref("mandelbrot.last_image.Cr_min"));
+ Cr_max = parseFloat(Services.prefs.getCharPref("mandelbrot.last_image.Cr_max"));
}
catch (e) { }
if ((Cr_min < -3) || (Cr_min > 2) ||
(Cr_max < -3) || (Cr_max > 2) || (Cr_min >= Cr_max)) {
Cr_min = -2.0; Cr_max = 1.0;
}
- gPref.setCharPref("mandelbrot.last_image.Cr_min", Cr_min);
- gPref.setCharPref("mandelbrot.last_image.Cr_max", Cr_max);
+ Services.prefs.setCharPref("mandelbrot.last_image.Cr_min", Cr_min);
+ Services.prefs.setCharPref("mandelbrot.last_image.Cr_max", Cr_max);
return {Cr_min: Cr_min, Cr_max: Cr_max};
case "last_image.Ci_*":
let Ci_min = -1.5;
let Ci_max = 1.5;
try {
- Ci_min = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_min"));
- Ci_max = parseFloat(gPref.getCharPref("mandelbrot.last_image.Ci_max"));
+ Ci_min = parseFloat(Services.prefs.getCharPref("mandelbrot.last_image.Ci_min"));
+ Ci_max = parseFloat(Services.prefs.getCharPref("mandelbrot.last_image.Ci_max"));
}
catch (e) { }
if ((Ci_min < -2.5) || (Ci_min > 2.5) ||
(Ci_max < -2.5) || (Ci_max > 2.5) || (Ci_min >= Ci_max)) {
Ci_min = -1.5; Ci_max = 1.5;
}
- gPref.setCharPref("mandelbrot.last_image.Ci_min", Ci_min);
- gPref.setCharPref("mandelbrot.last_image.Ci_max", Ci_max);
+ Services.prefs.setCharPref("mandelbrot.last_image.Ci_min", Ci_min);
+ Services.prefs.setCharPref("mandelbrot.last_image.Ci_max", Ci_max);
return {Ci_min: Ci_min, Ci_max: Ci_max};
case "iteration_max":
value = 500;
try {
- value = gPref.getIntPref("mandelbrot." + prefname);
+ value = Services.prefs.getIntPref("mandelbrot." + prefname);
}
catch (e) {
setIter(value);
case "use_algorithm":
value = "numeric";
try {
- value = gPref.getCharPref("mandelbrot." + prefname);
+ value = Services.prefs.getCharPref("mandelbrot." + prefname);
}
catch (e) {
setAlgorithm(value);
case "color_palette":
value = "kairo";
try {
- value = gPref.getCharPref("mandelbrot." + prefname);
+ value = Services.prefs.getCharPref("mandelbrot." + prefname);
}
catch(e) {
setPalette(value);
case "syncProportions":
value = true;
try {
- value = gPref.getBoolPref("mandelbrot." + prefname);
+ value = Services.prefs.getBoolPref("mandelbrot." + prefname);
}
catch(e) {
- gPref.setBoolPref("mandelbrot." + prefname, value);
+ Services.prefs.setBoolPref("mandelbrot." + prefname, value);
}
return value;
default:
let CRatio = Math.max(CWidth / iWidth, CHeight / iHeight);
- gPref.setCharPref("mandelbrot.last_image.Cr_min", C_mid.r - iWidth * CRatio / 2);
- gPref.setCharPref("mandelbrot.last_image.Cr_max", C_mid.r + iWidth * CRatio / 2);
- gPref.setCharPref("mandelbrot.last_image.Ci_min", C_mid.i - iHeight * CRatio / 2);
- gPref.setCharPref("mandelbrot.last_image.Ci_max", C_mid.i + iHeight * CRatio / 2);
+ Services.prefs.setCharPref("mandelbrot.last_image.Cr_min", C_mid.r - iWidth * CRatio / 2);
+ Services.prefs.setCharPref("mandelbrot.last_image.Cr_max", C_mid.r + iWidth * CRatio / 2);
+ Services.prefs.setCharPref("mandelbrot.last_image.Ci_min", C_mid.i - iHeight * CRatio / 2);
+ Services.prefs.setCharPref("mandelbrot.last_image.Ci_max", C_mid.i + iHeight * CRatio / 2);
drawImage();
}
connection.close();
if (iterMax && C_min && C_max) {
- gPref.setIntPref("mandelbrot.iteration_max", iterMax);
+ Services.prefs.setIntPref("mandelbrot.iteration_max", iterMax);
adjustCoordsAndDraw(C_min, C_max);
}
}
}
function setIter(aIter) {
- gPref.setIntPref("mandelbrot.iteration_max", aIter);
+ Services.prefs.setIntPref("mandelbrot.iteration_max", aIter);
}
function updatePaletteMenu() {
}
function setPalette(aPaletteID) {
- gPref.setCharPref("mandelbrot.color_palette", aPaletteID);
+ Services.prefs.setCharPref("mandelbrot.color_palette", aPaletteID);
gColorPalette = getColorPalette(aPaletteID);
}
let scope = (document.getElementById("mandelbrotWindow").nodeName == "page") ? "content" : "chrome";
try {
// This throws in versions that don't have JaegerMonkey yet --> catch block
- gPref.getBoolPref("javascript.options.methodjit." + scope);
+ Services.prefs.getBoolPref("javascript.options.methodjit." + scope);
// We have JaegerMonkey, i.e. two prefs for trace/method JIT
for each (let type in ["tracejit", "methodjit"]) {
let jitMenuItem = document.getElementById(type + "Enabled");
- jitMenuItem.setAttribute("checked", gPref.getBoolPref("javascript.options." + type + "." + scope));
+ jitMenuItem.setAttribute("checked", Services.prefs.getBoolPref("javascript.options." + type + "." + scope));
}
}
catch (e) {
document.getElementById(type + "Enabled").hidden = true;
let jitMenuItem = document.getElementById("jitEnabled");
jitMenuItem.hidden = false;
- jitMenuItem.setAttribute("checked", gPref.getBoolPref("javascript.options.jit." + scope));
+ jitMenuItem.setAttribute("checked", Services.prefs.getBoolPref("javascript.options.jit." + scope));
}
}
function toggleJITState(jitMenuItem, jittype) {
let scope = (document.getElementById("mandelbrotWindow").nodeName == "page") ? "content" : "chrome";
let jitpref = "javascript.options." + jittype + "jit." + scope;
- let jitEnabled = !gPref.getBoolPref(jitpref);
- gPref.setBoolPref(jitpref, jitEnabled)
+ let jitEnabled = !Services.prefs.getBoolPref(jitpref);
+ Services.prefs.setBoolPref(jitpref, jitEnabled)
jitMenuItem.setAttribute("checked", jitEnabled ? "true" : "false");
}
}
function setAlgorithm(algoID) {
- gPref.setCharPref("mandelbrot.use_algorithm", algoID);
+ Services.prefs.setCharPref("mandelbrot.use_algorithm", algoID);
}
function initImgSettings() {
function saveImgSettings() {
// Get values to prefs.
for each (let coord in ["Cr_min", "Cr_max", "Ci_min", "Ci_max"]) {
- gPref.setCharPref("mandelbrot.last_image." + coord,
- document.getElementById("is_" + coord).value);
+ Services.prefs.setCharPref("mandelbrot.last_image." + coord,
+ document.getElementById("is_" + coord).value);
}
for each (let dim in ["width", "height"]) {
- gPref.setIntPref("mandelbrot.image." + dim,
- document.getElementById("is_img_" + dim).value);
+ Services.prefs.setIntPref("mandelbrot.image." + dim,
+ document.getElementById("is_img_" + dim).value);
}
- gPref.setBoolPref("mandelbrot.syncProportions",
- document.getElementById("is_syncProp").checked);
+ Services.prefs.setBoolPref("mandelbrot.syncProportions",
+ document.getElementById("is_syncProp").checked);
}
function checkISValue(textbox, type) {
--- /dev/null
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Test some basic functionality of KaiRo-Mandelbrot.
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+const MBROT_LOADED = "mandelbrot-loaded";
+const TEST_DONE = "mandelbrot-test-done";
+
+function test() {
+ gBrowser.addTab();
+ // Open KaiRo-Mandelbrot, testing the menu item.
+ let menuitem = document.getElementById("tasksMenuMandelbrot") ||
+ document.getElementById("menu_openMandelbrot");
+ menuitem.click();
+
+ var testIndex = 0;
+ var win;
+
+ let testObs = {
+ observe: function(aSubject, aTopic, aData) {
+ if (aTopic == MBROT_LOADED) {
+ Services.obs.removeObserver(testObs, MBROT_LOADED);
+ ok(true, "KaiRo-Mandelbrot is loaded");
+
+ win = content.wrappedJSObject;
+ Services.obs.addObserver(testObs, TEST_DONE, false);
+ // Trigger the first test now!
+ Services.obs.notifyObservers(window, TEST_DONE, null);
+ }
+ else {
+ // TEST_DONE triggered, run next test
+ info("run test #" + (testIndex + 1) + " of " + testFuncs.length +
+ " (" + testFuncs[testIndex].name + ")");
+ setTimeout(testFuncs[testIndex++], 0, win);
+
+ if (testIndex >= testFuncs.length) {
+ // Finish this up!
+ Services.obs.removeObserver(testObs, TEST_DONE);
+ Services.cookies.removeAll();
+ gLocSvc.fhist.removeAllEntries();
+ setTimeout(finish, 0);
+ }
+ }
+ }
+ };
+ waitForExplicitFinish();
+ Services.obs.addObserver(testObs, MBROT_LOADED, false);
+}
+
+var testFuncs = [
+function test_open_state(aWin) {
+ is(aWin.document.documentElement.id, "mandelbrot-page",
+ "The active tab is KaiRo-Mandelbrot");
+ is(aWin.document.getElementById("drawButton").hidden, false,
+ "The draw button is not hidden");
+ Services.obs.notifyObservers(window, TEST_DONE, null);
+},
+
+function test_close(aWin) {
+ function dmWindowClosedListener() {
+ aWin.removeEventListener("unload", dmWindowClosedListener, false);
+ isnot(content.document.documentElement.id, "mandelbrot-page",
+ "The active tab is not KaiRo-Mandelbrot");
+ Services.obs.notifyObservers(window, TEST_DONE, null);
+ }
+ aWin.addEventListener("unload", dmWindowClosedListener, false);
+ aWin.close();
+}
+];