1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/sourceeditor/test/browser_editor_basic.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,62 @@ 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 +function test() { 1.11 + waitForExplicitFinish(); 1.12 + setup((ed, win) => { 1.13 + // appendTo 1.14 + let src = win.document.querySelector("iframe").getAttribute("src"); 1.15 + ok(~src.indexOf(".CodeMirror"), "correct iframe is there"); 1.16 + 1.17 + // getOption/setOption 1.18 + ok(ed.getOption("styleActiveLine"), "getOption works"); 1.19 + ed.setOption("styleActiveLine", false); 1.20 + ok(!ed.getOption("styleActiveLine"), "setOption works"); 1.21 + 1.22 + // Language modes 1.23 + is(ed.getMode(), Editor.modes.text, "getMode"); 1.24 + ed.setMode(Editor.modes.js); 1.25 + is(ed.getMode(), Editor.modes.js, "setMode"); 1.26 + 1.27 + // Content 1.28 + is(ed.getText(), "Hello.", "getText"); 1.29 + ed.setText("Hi.\nHow are you?"); 1.30 + is(ed.getText(), "Hi.\nHow are you?", "setText"); 1.31 + is(ed.getText(1), "How are you?", "getText(num)"); 1.32 + is(ed.getText(5), "", "getText(num) when num is out of scope"); 1.33 + 1.34 + ed.replaceText("YOU", { line: 1, ch: 8 }, { line: 1, ch: 11 }); 1.35 + is(ed.getText(1), "How are YOU?", "replaceText(str, from, to)"); 1.36 + ed.replaceText("you?", { line: 1, ch: 8 }); 1.37 + is(ed.getText(1), "How are you?", "replaceText(str, from)"); 1.38 + ed.replaceText("Hello."); 1.39 + is(ed.getText(), "Hello.", "replaceText(str)"); 1.40 + 1.41 + ed.insertText(", sir/madam", { line: 0, ch: 5}); 1.42 + is(ed.getText(), "Hello, sir/madam.", "insertText"); 1.43 + 1.44 + // Add-ons 1.45 + ed.extend({ whoami: () => "Anton", whereami: () => "Mozilla" }); 1.46 + is(ed.whoami(), "Anton", "extend/1"); 1.47 + is(ed.whereami(), "Mozilla", "extend/2"); 1.48 + 1.49 + // Line classes 1.50 + ed.setText("Hello!\nHow are you?"); 1.51 + ok(!ed.hasLineClass(0, "test"), "no test line class"); 1.52 + ed.addLineClass(0, "test"); 1.53 + ok(ed.hasLineClass(0, "test"), "test line class is there"); 1.54 + ed.removeLineClass(0, "test"); 1.55 + ok(!ed.hasLineClass(0, "test"), "test line class is gone"); 1.56 + 1.57 + // Font size 1.58 + let size = ed.getFontSize(); 1.59 + is("number", typeof size, "we have the default font size"); 1.60 + ed.setFontSize(ed.getFontSize() + 1); 1.61 + is(ed.getFontSize(), size + 1, "new font size was set"); 1.62 + 1.63 + teardown(ed, win); 1.64 + }); 1.65 +}