browser/devtools/sourceeditor/test/head.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/sourceeditor/test/head.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +"use strict";
     1.9 +
    1.10 +const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
    1.11 +const { require } = devtools;
    1.12 +const Editor  = require("devtools/sourceeditor/editor");
    1.13 +
    1.14 +gDevTools.testing = true;
    1.15 +SimpleTest.registerCleanupFunction(() => {
    1.16 +  gDevTools.testing = false;
    1.17 +});
    1.18 +
    1.19 +function setup(cb) {
    1.20 +  const opt = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";
    1.21 +  const url = "data:text/xml;charset=UTF-8,<?xml version='1.0'?>" +
    1.22 +    "<?xml-stylesheet href='chrome://global/skin/global.css'?>" +
    1.23 +    "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'" +
    1.24 +    " title='Editor' width='600' height='500'><box flex='1'/></window>";
    1.25 +
    1.26 +  let win = Services.ww.openWindow(null, url, "_blank", opt, null);
    1.27 +
    1.28 +  win.addEventListener("load", function onLoad() {
    1.29 +    win.removeEventListener("load", onLoad, false);
    1.30 +
    1.31 +    waitForFocus(function () {
    1.32 +      let box = win.document.querySelector("box");
    1.33 +      let editor = new Editor({
    1.34 +        value: "Hello.",
    1.35 +        lineNumbers: true,
    1.36 +        foldGutter: true,
    1.37 +        gutters: [ "CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter" ]
    1.38 +      });
    1.39 +
    1.40 +      editor.appendTo(box)
    1.41 +        .then(() => cb(editor, win))
    1.42 +        .then(null, (err) => ok(false, err.message));
    1.43 +    }, win);
    1.44 +  }, false);
    1.45 +}
    1.46 +
    1.47 +function ch(exp, act, label) {
    1.48 +  is(exp.line, act.line, label + " (line)");
    1.49 +  is(exp.ch, act.ch, label + " (ch)");
    1.50 +}
    1.51 +
    1.52 +function teardown(ed, win) {
    1.53 +  ed.destroy();
    1.54 +  win.close();
    1.55 +  finish();
    1.56 +}
    1.57 +
    1.58 +/**
    1.59 + * This method returns the portion of the input string `source` up to the
    1.60 + * [line, ch] location.
    1.61 + */
    1.62 +function limit(source, [line, ch]) {
    1.63 +  line++;
    1.64 +  let list = source.split("\n");
    1.65 +  if (list.length < line)
    1.66 +    return source;
    1.67 +  if (line == 1)
    1.68 +    return list[0].slice(0, ch);
    1.69 +  return [...list.slice(0, line - 1), list[line - 1].slice(0, ch)].join("\n");
    1.70 +}
    1.71 +
    1.72 +function read(url) {
    1.73 +  let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
    1.74 +    .getService(Ci.nsIScriptableInputStream);
    1.75 +
    1.76 +  let channel = Services.io.newChannel(url, null, null);
    1.77 +  let input = channel.open();
    1.78 +  scriptableStream.init(input);
    1.79 +
    1.80 +  let data = "";
    1.81 +  while (input.available()) {
    1.82 +    data = data.concat(scriptableStream.read(input.available()));
    1.83 +  }
    1.84 +  scriptableStream.close();
    1.85 +  input.close();
    1.86 +
    1.87 +  return data;
    1.88 +}
    1.89 +
    1.90 +/**
    1.91 + * This function is called by the CodeMirror test runner to report status
    1.92 + * messages from the CM tests.
    1.93 + * @see codemirror.html
    1.94 + */
    1.95 +function codeMirror_setStatus(statusMsg, type, customMsg) {
    1.96 +  switch (type) {
    1.97 +    case "expected":
    1.98 +    case "ok":
    1.99 +      ok(1, statusMsg);
   1.100 +      break;
   1.101 +    case "error":
   1.102 +    case "fail":
   1.103 +      ok(0, statusMsg);
   1.104 +      break;
   1.105 +    default:
   1.106 +      info(statusMsg);
   1.107 +      break;
   1.108 +  }
   1.109 +
   1.110 +  if (customMsg && typeof customMsg == "string" && customMsg != statusMsg) {
   1.111 +    info(customMsg);
   1.112 +  }
   1.113 +}

mercurial