2011-12-10 17:03:57 +00:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-10-13 23:18:43 +00:00
|
|
|
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
2015-09-21 17:04:18 +00:00
|
|
|
const Editor = require("devtools/client/sourceeditor/editor");
|
2015-08-26 13:05:13 +00:00
|
|
|
const promise = require("promise");
|
2015-09-21 17:04:18 +00:00
|
|
|
const DevToolsUtils = require("devtools/shared/DevToolsUtils");
|
2011-12-10 17:03:57 +00:00
|
|
|
|
2015-06-04 22:30:23 +00:00
|
|
|
DevToolsUtils.testing = true;
|
2014-03-13 21:27:10 +00:00
|
|
|
SimpleTest.registerCleanupFunction(() => {
|
2015-06-04 22:30:23 +00:00
|
|
|
DevToolsUtils.testing = false;
|
2014-03-13 21:27:10 +00:00
|
|
|
});
|
|
|
|
|
2015-03-17 15:42:00 +00:00
|
|
|
/**
|
|
|
|
* Open a new tab at a URL and call a callback on load
|
|
|
|
*/
|
|
|
|
function addTab(aURL, aCallback) {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab();
|
|
|
|
content.location = aURL;
|
|
|
|
|
|
|
|
let tab = gBrowser.selectedTab;
|
|
|
|
let browser = gBrowser.getBrowserForTab(tab);
|
|
|
|
|
|
|
|
function onTabLoad() {
|
|
|
|
browser.removeEventListener("load", onTabLoad, true);
|
|
|
|
aCallback(browser, tab, browser.contentDocument);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser.addEventListener("load", onTabLoad, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function promiseTab(aURL) {
|
|
|
|
return new Promise(resolve =>
|
|
|
|
addTab(aURL, resolve));
|
|
|
|
}
|
|
|
|
|
2015-06-24 00:18:55 +00:00
|
|
|
function promiseWaitForFocus() {
|
|
|
|
return new Promise(resolve =>
|
|
|
|
waitForFocus(resolve));
|
|
|
|
}
|
|
|
|
|
2015-03-17 15:42:00 +00:00
|
|
|
function setup(cb, additionalOpts = {}) {
|
|
|
|
cb = cb || function() {};
|
|
|
|
let def = promise.defer();
|
2013-11-19 23:53:13 +00:00
|
|
|
const opt = "chrome,titlebar,toolbar,centerscreen,resizable,dialog=no";
|
2015-03-17 15:42:00 +00:00
|
|
|
const url = "data:application/vnd.mozilla.xul+xml;charset=UTF-8,<?xml version='1.0'?>" +
|
2013-11-19 23:53:13 +00:00
|
|
|
"<?xml-stylesheet href='chrome://global/skin/global.css'?>" +
|
2012-08-02 19:30:46 +00:00
|
|
|
"<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'" +
|
2013-11-19 23:53:13 +00:00
|
|
|
" title='Editor' width='600' height='500'><box flex='1'/></window>";
|
2012-08-02 19:30:46 +00:00
|
|
|
|
2013-11-19 23:53:13 +00:00
|
|
|
let win = Services.ww.openWindow(null, url, "_blank", opt, null);
|
2015-03-17 15:42:00 +00:00
|
|
|
let opts = {
|
|
|
|
value: "Hello.",
|
|
|
|
lineNumbers: true,
|
|
|
|
foldGutter: true,
|
|
|
|
gutters: [ "CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter" ]
|
|
|
|
}
|
|
|
|
for (let o in additionalOpts) {
|
|
|
|
opts[o] = additionalOpts[o];
|
|
|
|
}
|
2012-08-02 19:30:46 +00:00
|
|
|
|
2013-11-19 23:53:13 +00:00
|
|
|
win.addEventListener("load", function onLoad() {
|
|
|
|
win.removeEventListener("load", onLoad, false);
|
2012-08-02 19:30:46 +00:00
|
|
|
|
2013-11-19 23:53:13 +00:00
|
|
|
waitForFocus(function () {
|
|
|
|
let box = win.document.querySelector("box");
|
2015-03-17 15:42:00 +00:00
|
|
|
let editor = new Editor(opts);
|
2012-08-02 19:30:46 +00:00
|
|
|
|
2013-11-19 23:53:13 +00:00
|
|
|
editor.appendTo(box)
|
2015-03-17 15:42:00 +00:00
|
|
|
.then(() => {
|
|
|
|
def.resolve({
|
|
|
|
ed: editor,
|
|
|
|
win: win,
|
|
|
|
edWin: editor.container.contentWindow.wrappedJSObject
|
|
|
|
});
|
|
|
|
cb(editor, win);
|
|
|
|
}, err => ok(false, err.message));
|
2013-11-19 23:53:13 +00:00
|
|
|
}, win);
|
|
|
|
}, false);
|
2015-03-17 15:42:00 +00:00
|
|
|
|
|
|
|
return def.promise;
|
2012-08-02 19:30:46 +00:00
|
|
|
}
|
|
|
|
|
2013-11-19 23:53:13 +00:00
|
|
|
function ch(exp, act, label) {
|
|
|
|
is(exp.line, act.line, label + " (line)");
|
|
|
|
is(exp.ch, act.ch, label + " (ch)");
|
2012-08-02 19:30:46 +00:00
|
|
|
}
|
2013-11-19 23:53:13 +00:00
|
|
|
|
|
|
|
function teardown(ed, win) {
|
|
|
|
ed.destroy();
|
|
|
|
win.close();
|
2015-03-17 15:42:00 +00:00
|
|
|
|
|
|
|
while (gBrowser.tabs.length > 1) {
|
|
|
|
gBrowser.removeCurrentTab();
|
|
|
|
}
|
2013-11-19 23:53:13 +00:00
|
|
|
finish();
|
2014-01-28 15:10:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:01:00 +00:00
|
|
|
/**
|
|
|
|
* Some tests may need to import one or more of the test helper scripts.
|
|
|
|
* A test helper script is simply a js file that contains common test code that
|
|
|
|
* is either not common-enough to be in head.js, or that is located in a separate
|
|
|
|
* directory.
|
|
|
|
* The script will be loaded synchronously and in the test's scope.
|
|
|
|
* @param {String} filePath The file path, relative to the current directory.
|
|
|
|
* Examples:
|
|
|
|
* - "helper_attributes_test_runner.js"
|
|
|
|
* - "../../../commandline/test/helpers.js"
|
|
|
|
*/
|
|
|
|
function loadHelperScript(filePath) {
|
|
|
|
let testDir = gTestPath.substr(0, gTestPath.lastIndexOf("/"));
|
|
|
|
Services.scriptloader.loadSubScript(testDir + "/" + filePath, this);
|
|
|
|
}
|
|
|
|
|
2014-01-28 15:10:40 +00:00
|
|
|
/**
|
|
|
|
* This method returns the portion of the input string `source` up to the
|
|
|
|
* [line, ch] location.
|
|
|
|
*/
|
|
|
|
function limit(source, [line, ch]) {
|
|
|
|
line++;
|
|
|
|
let list = source.split("\n");
|
|
|
|
if (list.length < line)
|
|
|
|
return source;
|
|
|
|
if (line == 1)
|
|
|
|
return list[0].slice(0, ch);
|
|
|
|
return [...list.slice(0, line - 1), list[line - 1].slice(0, ch)].join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function read(url) {
|
|
|
|
let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"]
|
|
|
|
.getService(Ci.nsIScriptableInputStream);
|
|
|
|
|
2015-02-11 04:49:06 +00:00
|
|
|
let channel = Services.io.newChannel2(url,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null, // aLoadingNode
|
|
|
|
Services.scriptSecurityManager.getSystemPrincipal(),
|
|
|
|
null, // aTriggeringPrincipal
|
|
|
|
Ci.nsILoadInfo.SEC_NORMAL,
|
|
|
|
Ci.nsIContentPolicy.TYPE_OTHER);
|
2014-01-28 15:10:40 +00:00
|
|
|
let input = channel.open();
|
|
|
|
scriptableStream.init(input);
|
|
|
|
|
2014-03-27 15:20:16 +00:00
|
|
|
let data = "";
|
|
|
|
while (input.available()) {
|
|
|
|
data = data.concat(scriptableStream.read(input.available()));
|
|
|
|
}
|
2014-01-28 15:10:40 +00:00
|
|
|
scriptableStream.close();
|
|
|
|
input.close();
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
2014-03-24 21:06:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is called by the CodeMirror test runner to report status
|
|
|
|
* messages from the CM tests.
|
|
|
|
* @see codemirror.html
|
|
|
|
*/
|
|
|
|
function codeMirror_setStatus(statusMsg, type, customMsg) {
|
|
|
|
switch (type) {
|
|
|
|
case "expected":
|
|
|
|
case "ok":
|
|
|
|
ok(1, statusMsg);
|
|
|
|
break;
|
|
|
|
case "error":
|
|
|
|
case "fail":
|
|
|
|
ok(0, statusMsg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
info(statusMsg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (customMsg && typeof customMsg == "string" && customMsg != statusMsg) {
|
|
|
|
info(customMsg);
|
|
|
|
}
|
|
|
|
}
|