summaryrefslogtreecommitdiffstats
path: root/devtools/client/sourceeditor/test/browser_editor_prefs.js
blob: 0c8c7782fcc42d011865e5bef4916a99118333a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* 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";

// Test to make sure that the editor reacts to preference changes

const TAB_SIZE = "devtools.editor.tabsize";
const ENABLE_CODE_FOLDING = "devtools.editor.enableCodeFolding";
const EXPAND_TAB = "devtools.editor.expandtab";
const KEYMAP = "devtools.editor.keymap";
const AUTO_CLOSE = "devtools.editor.autoclosebrackets";
const AUTOCOMPLETE = "devtools.editor.autocomplete";
const DETECT_INDENT = "devtools.editor.detectindentation";

function test() {
  waitForExplicitFinish();
  setup((ed, win) => {
    Assert.deepEqual(ed.getOption("gutters"), [
      "CodeMirror-linenumbers",
      "breakpoints",
      "CodeMirror-foldgutter"], "gutters is correct");

    ed.setText("Checking preferences.");

    info("Turning prefs off");

    ed.setOption("autocomplete", true);

    Services.prefs.setIntPref(TAB_SIZE, 2);
    Services.prefs.setBoolPref(ENABLE_CODE_FOLDING, false);
    Services.prefs.setBoolPref(EXPAND_TAB, false);
    Services.prefs.setCharPref(KEYMAP, "default");
    Services.prefs.setBoolPref(AUTO_CLOSE, false);
    Services.prefs.setBoolPref(AUTOCOMPLETE, false);
    Services.prefs.setBoolPref(DETECT_INDENT, false);

    Assert.deepEqual(ed.getOption("gutters"), [
      "CodeMirror-linenumbers",
      "breakpoints"], "gutters is correct");

    is(ed.getOption("tabSize"), 2, "tabSize is correct");
    is(ed.getOption("indentUnit"), 2, "indentUnit is correct");
    is(ed.getOption("foldGutter"), false, "foldGutter is correct");
    is(ed.getOption("enableCodeFolding"), undefined,
      "enableCodeFolding is correct");
    is(ed.getOption("indentWithTabs"), true, "indentWithTabs is correct");
    is(ed.getOption("keyMap"), "default", "keyMap is correct");
    is(ed.getOption("autoCloseBrackets"), "", "autoCloseBrackets is correct");
    is(ed.getOption("autocomplete"), true, "autocomplete is correct");
    ok(!ed.isAutocompletionEnabled(), "Autocompletion is not enabled");

    info("Turning prefs on");

    Services.prefs.setIntPref(TAB_SIZE, 4);
    Services.prefs.setBoolPref(ENABLE_CODE_FOLDING, true);
    Services.prefs.setBoolPref(EXPAND_TAB, true);
    Services.prefs.setCharPref(KEYMAP, "sublime");
    Services.prefs.setBoolPref(AUTO_CLOSE, true);
    Services.prefs.setBoolPref(AUTOCOMPLETE, true);

    Assert.deepEqual(ed.getOption("gutters"), [
      "CodeMirror-linenumbers",
      "breakpoints",
      "CodeMirror-foldgutter"], "gutters is correct");

    is(ed.getOption("tabSize"), 4, "tabSize is correct");
    is(ed.getOption("indentUnit"), 4, "indentUnit is correct");
    is(ed.getOption("foldGutter"), true, "foldGutter is correct");
    is(ed.getOption("enableCodeFolding"), undefined,
      "enableCodeFolding is correct");
    is(ed.getOption("indentWithTabs"), false, "indentWithTabs is correct");
    is(ed.getOption("keyMap"), "sublime", "keyMap is correct");
    is(ed.getOption("autoCloseBrackets"), "()[]{}''\"\"``",
      "autoCloseBrackets is correct");
    is(ed.getOption("autocomplete"), true, "autocomplete is correct");
    ok(ed.isAutocompletionEnabled(), "Autocompletion is enabled");

    info("Forcing foldGutter off using enableCodeFolding");
    ed.setOption("enableCodeFolding", false);

    is(ed.getOption("foldGutter"), false, "foldGutter is correct");
    is(ed.getOption("enableCodeFolding"), false,
      "enableCodeFolding is correct");
    Assert.deepEqual(ed.getOption("gutters"), [
      "CodeMirror-linenumbers",
      "breakpoints"], "gutters is correct");

    info("Forcing foldGutter on using enableCodeFolding");
    ed.setOption("enableCodeFolding", true);

    is(ed.getOption("foldGutter"), true, "foldGutter is correct");
    is(ed.getOption("enableCodeFolding"), true, "enableCodeFolding is correct");
    Assert.deepEqual(ed.getOption("gutters"), [
      "CodeMirror-linenumbers",
      "breakpoints",
      "CodeMirror-foldgutter"], "gutters is correct");

    info("Checking indentation detection");

    Services.prefs.setBoolPref(DETECT_INDENT, true);

    ed.setText("Detecting\n\tTabs");
    is(ed.getOption("indentWithTabs"), true, "indentWithTabs is correct");
    is(ed.getOption("indentUnit"), 4, "indentUnit is correct");

    ed.setText("body {\n  color:red;\n  a:b;\n}");
    is(ed.getOption("indentWithTabs"), false, "indentWithTabs is correct");
    is(ed.getOption("indentUnit"), 2, "indentUnit is correct");

    Services.prefs.clearUserPref(TAB_SIZE);
    Services.prefs.clearUserPref(EXPAND_TAB);
    Services.prefs.clearUserPref(KEYMAP);
    Services.prefs.clearUserPref(AUTO_CLOSE);
    Services.prefs.clearUserPref(AUTOCOMPLETE);
    Services.prefs.clearUserPref(DETECT_INDENT);

    teardown(ed, win);
  });
}