browser/devtools/sourceeditor/test/head.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 8 const { require } = devtools;
michael@0 9 const Editor = require("devtools/sourceeditor/editor");
michael@0 10
michael@0 11 gDevTools.testing = true;
michael@0 12 SimpleTest.registerCleanupFunction(() => {
michael@0 13 gDevTools.testing = false;
michael@0 14 });
michael@0 15
michael@0 16 function setup(cb) {
michael@0 17 const opt = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";
michael@0 18 const url = "data:text/xml;charset=UTF-8,<?xml version='1.0'?>" +
michael@0 19 "<?xml-stylesheet href='chrome://global/skin/global.css'?>" +
michael@0 20 "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'" +
michael@0 21 " title='Editor' width='600' height='500'><box flex='1'/></window>";
michael@0 22
michael@0 23 let win = Services.ww.openWindow(null, url, "_blank", opt, null);
michael@0 24
michael@0 25 win.addEventListener("load", function onLoad() {
michael@0 26 win.removeEventListener("load", onLoad, false);
michael@0 27
michael@0 28 waitForFocus(function () {
michael@0 29 let box = win.document.querySelector("box");
michael@0 30 let editor = new Editor({
michael@0 31 value: "Hello.",
michael@0 32 lineNumbers: true,
michael@0 33 foldGutter: true,
michael@0 34 gutters: [ "CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter" ]
michael@0 35 });
michael@0 36
michael@0 37 editor.appendTo(box)
michael@0 38 .then(() => cb(editor, win))
michael@0 39 .then(null, (err) => ok(false, err.message));
michael@0 40 }, win);
michael@0 41 }, false);
michael@0 42 }
michael@0 43
michael@0 44 function ch(exp, act, label) {
michael@0 45 is(exp.line, act.line, label + " (line)");
michael@0 46 is(exp.ch, act.ch, label + " (ch)");
michael@0 47 }
michael@0 48
michael@0 49 function teardown(ed, win) {
michael@0 50 ed.destroy();
michael@0 51 win.close();
michael@0 52 finish();
michael@0 53 }
michael@0 54
michael@0 55 /**
michael@0 56 * This method returns the portion of the input string `source` up to the
michael@0 57 * [line, ch] location.
michael@0 58 */
michael@0 59 function limit(source, [line, ch]) {
michael@0 60 line++;
michael@0 61 let list = source.split("\n");
michael@0 62 if (list.length < line)
michael@0 63 return source;
michael@0 64 if (line == 1)
michael@0 65 return list[0].slice(0, ch);
michael@0 66 return [...list.slice(0, line - 1), list[line - 1].slice(0, ch)].join("\n");
michael@0 67 }
michael@0 68
michael@0 69 function read(url) {
michael@0 70 let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
michael@0 71 .getService(Ci.nsIScriptableInputStream);
michael@0 72
michael@0 73 let channel = Services.io.newChannel(url, null, null);
michael@0 74 let input = channel.open();
michael@0 75 scriptableStream.init(input);
michael@0 76
michael@0 77 let data = "";
michael@0 78 while (input.available()) {
michael@0 79 data = data.concat(scriptableStream.read(input.available()));
michael@0 80 }
michael@0 81 scriptableStream.close();
michael@0 82 input.close();
michael@0 83
michael@0 84 return data;
michael@0 85 }
michael@0 86
michael@0 87 /**
michael@0 88 * This function is called by the CodeMirror test runner to report status
michael@0 89 * messages from the CM tests.
michael@0 90 * @see codemirror.html
michael@0 91 */
michael@0 92 function codeMirror_setStatus(statusMsg, type, customMsg) {
michael@0 93 switch (type) {
michael@0 94 case "expected":
michael@0 95 case "ok":
michael@0 96 ok(1, statusMsg);
michael@0 97 break;
michael@0 98 case "error":
michael@0 99 case "fail":
michael@0 100 ok(0, statusMsg);
michael@0 101 break;
michael@0 102 default:
michael@0 103 info(statusMsg);
michael@0 104 break;
michael@0 105 }
michael@0 106
michael@0 107 if (customMsg && typeof customMsg == "string" && customMsg != statusMsg) {
michael@0 108 info(customMsg);
michael@0 109 }
michael@0 110 }

mercurial