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.

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

mercurial