tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_editor_prefs.js (4923B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test to make sure that the editor reacts to preference changes
      7 
      8 const TAB_SIZE = "devtools.editor.tabsize";
      9 const ENABLE_CODE_FOLDING = "devtools.editor.enableCodeFolding";
     10 const EXPAND_TAB = "devtools.editor.expandtab";
     11 const KEYMAP = "devtools.editor.keymap";
     12 const AUTO_CLOSE = "devtools.editor.autoclosebrackets";
     13 const AUTOCOMPLETE = "devtools.editor.autocomplete";
     14 const DETECT_INDENT = "devtools.editor.detectindentation";
     15 
     16 async function test() {
     17  waitForExplicitFinish();
     18  const { ed, win } = await setup();
     19  Assert.deepEqual(
     20    ed.getOption("gutters"),
     21    ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
     22    "gutters is correct"
     23  );
     24 
     25  ed.setText("Checking preferences.");
     26 
     27  info("Turning prefs off");
     28 
     29  ed.setOption("autocomplete", true);
     30 
     31  Services.prefs.setIntPref(TAB_SIZE, 2);
     32  Services.prefs.setBoolPref(ENABLE_CODE_FOLDING, false);
     33  Services.prefs.setBoolPref(EXPAND_TAB, false);
     34  Services.prefs.setCharPref(KEYMAP, "default");
     35  Services.prefs.setBoolPref(AUTO_CLOSE, false);
     36  Services.prefs.setBoolPref(AUTOCOMPLETE, false);
     37  Services.prefs.setBoolPref(DETECT_INDENT, false);
     38 
     39  Assert.deepEqual(
     40    ed.getOption("gutters"),
     41    ["CodeMirror-linenumbers", "breakpoints"],
     42    "gutters is correct"
     43  );
     44 
     45  is(ed.getOption("tabSize"), 2, "tabSize is correct");
     46  is(ed.getOption("indentUnit"), 2, "indentUnit is correct");
     47  is(ed.getOption("foldGutter"), false, "foldGutter is correct");
     48  is(
     49    ed.getOption("enableCodeFolding"),
     50    undefined,
     51    "enableCodeFolding is correct"
     52  );
     53  is(ed.getOption("indentWithTabs"), true, "indentWithTabs is correct");
     54  is(ed.getOption("keyMap"), "default", "keyMap is correct");
     55  is(ed.getOption("autoCloseBrackets"), false, "autoCloseBrackets is correct");
     56  is(ed.getOption("autocomplete"), true, "autocomplete is correct");
     57  ok(!ed.isAutocompletionEnabled(), "Autocompletion is not enabled");
     58 
     59  info("Turning prefs on");
     60 
     61  Services.prefs.setIntPref(TAB_SIZE, 4);
     62  Services.prefs.setBoolPref(ENABLE_CODE_FOLDING, true);
     63  Services.prefs.setBoolPref(EXPAND_TAB, true);
     64  Services.prefs.setCharPref(KEYMAP, "sublime");
     65  Services.prefs.setBoolPref(AUTO_CLOSE, true);
     66  Services.prefs.setBoolPref(AUTOCOMPLETE, true);
     67 
     68  Assert.deepEqual(
     69    ed.getOption("gutters"),
     70    ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
     71    "gutters is correct"
     72  );
     73 
     74  is(ed.getOption("tabSize"), 4, "tabSize is correct");
     75  is(ed.getOption("indentUnit"), 4, "indentUnit is correct");
     76  is(ed.getOption("foldGutter"), true, "foldGutter is correct");
     77  is(
     78    ed.getOption("enableCodeFolding"),
     79    undefined,
     80    "enableCodeFolding is correct"
     81  );
     82  is(ed.getOption("indentWithTabs"), false, "indentWithTabs is correct");
     83  is(
     84    ed.getOption("autoCloseBrackets"),
     85    "()[]{}''\"\"``",
     86    "autoCloseBrackets is correct"
     87  );
     88  is(ed.getOption("autocomplete"), true, "autocomplete is correct");
     89  ok(ed.isAutocompletionEnabled(), "Autocompletion is enabled");
     90 
     91  // Since the keyMap files are lazily loaded, this can take some time. We need to wait
     92  // until the option has the expected value.
     93  info("Wait for the keyMap option to be updated");
     94  await waitUntil(() => ed.getOption("keyMap") === "sublime");
     95  is(ed.getOption("keyMap"), "sublime", "keyMap is correct");
     96 
     97  info("Forcing foldGutter off using enableCodeFolding");
     98  ed.setOption("enableCodeFolding", false);
     99 
    100  is(ed.getOption("foldGutter"), false, "foldGutter is correct");
    101  is(ed.getOption("enableCodeFolding"), false, "enableCodeFolding is correct");
    102  Assert.deepEqual(
    103    ed.getOption("gutters"),
    104    ["CodeMirror-linenumbers", "breakpoints"],
    105    "gutters is correct"
    106  );
    107 
    108  info("Forcing foldGutter on using enableCodeFolding");
    109  ed.setOption("enableCodeFolding", true);
    110 
    111  is(ed.getOption("foldGutter"), true, "foldGutter is correct");
    112  is(ed.getOption("enableCodeFolding"), true, "enableCodeFolding is correct");
    113  Assert.deepEqual(
    114    ed.getOption("gutters"),
    115    ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
    116    "gutters is correct"
    117  );
    118 
    119  info("Checking indentation detection");
    120 
    121  Services.prefs.setBoolPref(DETECT_INDENT, true);
    122 
    123  ed.setText("Detecting\n\tTabs");
    124  is(ed.getOption("indentWithTabs"), true, "indentWithTabs is correct");
    125  is(ed.getOption("indentUnit"), 4, "indentUnit is correct");
    126 
    127  ed.setText("body {\n  color:red;\n  a:b;\n}");
    128  is(ed.getOption("indentWithTabs"), false, "indentWithTabs is correct");
    129  is(ed.getOption("indentUnit"), 2, "indentUnit is correct");
    130 
    131  Services.prefs.clearUserPref(TAB_SIZE);
    132  Services.prefs.clearUserPref(EXPAND_TAB);
    133  Services.prefs.clearUserPref(KEYMAP);
    134  Services.prefs.clearUserPref(AUTO_CLOSE);
    135  Services.prefs.clearUserPref(AUTOCOMPLETE);
    136  Services.prefs.clearUserPref(DETECT_INDENT);
    137 
    138  teardown(ed, win);
    139 }