michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: const { require } = devtools; michael@0: const Editor = require("devtools/sourceeditor/editor"); michael@0: michael@0: gDevTools.testing = true; michael@0: SimpleTest.registerCleanupFunction(() => { michael@0: gDevTools.testing = false; michael@0: }); michael@0: michael@0: function setup(cb) { michael@0: const opt = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no"; michael@0: const url = "data:text/xml;charset=UTF-8," + michael@0: "" + michael@0: ""; michael@0: michael@0: let win = Services.ww.openWindow(null, url, "_blank", opt, null); michael@0: michael@0: win.addEventListener("load", function onLoad() { michael@0: win.removeEventListener("load", onLoad, false); michael@0: michael@0: waitForFocus(function () { michael@0: let box = win.document.querySelector("box"); michael@0: let editor = new Editor({ michael@0: value: "Hello.", michael@0: lineNumbers: true, michael@0: foldGutter: true, michael@0: gutters: [ "CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter" ] michael@0: }); michael@0: michael@0: editor.appendTo(box) michael@0: .then(() => cb(editor, win)) michael@0: .then(null, (err) => ok(false, err.message)); michael@0: }, win); michael@0: }, false); michael@0: } michael@0: michael@0: function ch(exp, act, label) { michael@0: is(exp.line, act.line, label + " (line)"); michael@0: is(exp.ch, act.ch, label + " (ch)"); michael@0: } michael@0: michael@0: function teardown(ed, win) { michael@0: ed.destroy(); michael@0: win.close(); michael@0: finish(); michael@0: } michael@0: michael@0: /** michael@0: * This method returns the portion of the input string `source` up to the michael@0: * [line, ch] location. michael@0: */ michael@0: function limit(source, [line, ch]) { michael@0: line++; michael@0: let list = source.split("\n"); michael@0: if (list.length < line) michael@0: return source; michael@0: if (line == 1) michael@0: return list[0].slice(0, ch); michael@0: return [...list.slice(0, line - 1), list[line - 1].slice(0, ch)].join("\n"); michael@0: } michael@0: michael@0: function read(url) { michael@0: let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"] michael@0: .getService(Ci.nsIScriptableInputStream); michael@0: michael@0: let channel = Services.io.newChannel(url, null, null); michael@0: let input = channel.open(); michael@0: scriptableStream.init(input); michael@0: michael@0: let data = ""; michael@0: while (input.available()) { michael@0: data = data.concat(scriptableStream.read(input.available())); michael@0: } michael@0: scriptableStream.close(); michael@0: input.close(); michael@0: michael@0: return data; michael@0: } michael@0: michael@0: /** michael@0: * This function is called by the CodeMirror test runner to report status michael@0: * messages from the CM tests. michael@0: * @see codemirror.html michael@0: */ michael@0: function codeMirror_setStatus(statusMsg, type, customMsg) { michael@0: switch (type) { michael@0: case "expected": michael@0: case "ok": michael@0: ok(1, statusMsg); michael@0: break; michael@0: case "error": michael@0: case "fail": michael@0: ok(0, statusMsg); michael@0: break; michael@0: default: michael@0: info(statusMsg); michael@0: break; michael@0: } michael@0: michael@0: if (customMsg && typeof customMsg == "string" && customMsg != statusMsg) { michael@0: info(customMsg); michael@0: } michael@0: }