tor-browser

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

browser_inplace-editor-02.js (2166B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 /* import-globals-from helper_inplace_editor.js */
      4 
      5 "use strict";
      6 
      7 loadHelperScript("helper_inplace_editor.js");
      8 
      9 // Test that the trimOutput option for the inplace editor works correctly.
     10 
     11 add_task(async function () {
     12  await addTab("data:text/html;charset=utf-8,inline editor tests");
     13  const { host, doc } = await createHost();
     14 
     15  await testNonTrimmed(doc);
     16  await testTrimmed(doc);
     17 
     18  host.destroy();
     19  gBrowser.removeCurrentTab();
     20 });
     21 
     22 function testNonTrimmed(doc) {
     23  info("Testing the trimOutput=false option");
     24  return new Promise(resolve => {
     25    const initial = "\nMultiple\nLines\n";
     26    const changed = " \nMultiple\nLines\n with more whitespace ";
     27    createInplaceEditorAndClick(
     28      {
     29        trimOutput: false,
     30        multiline: true,
     31        initial,
     32        start(editor) {
     33          is(
     34            editor.input.value,
     35            initial,
     36            "Explicit initial value should be used."
     37          );
     38          editor.input.value = changed;
     39          EventUtils.sendKey("return");
     40        },
     41        done: onDone(changed, true, resolve),
     42      },
     43      doc
     44    );
     45  });
     46 }
     47 
     48 function testTrimmed(doc) {
     49  info("Testing the trimOutput=true option (default value)");
     50  return new Promise(resolve => {
     51    const initial = "\nMultiple\nLines\n";
     52    const changed = " \nMultiple\nLines\n with more whitespace ";
     53    createInplaceEditorAndClick(
     54      {
     55        initial,
     56        multiline: true,
     57        start(editor) {
     58          is(
     59            editor.input.value,
     60            initial,
     61            "Explicit initial value should be used."
     62          );
     63          editor.input.value = changed;
     64          EventUtils.sendKey("return");
     65        },
     66        done: onDone(changed.trim(), true, resolve),
     67      },
     68      doc
     69    );
     70  });
     71 }
     72 
     73 function onDone(value, isCommit, resolve) {
     74  return function (actualValue, actualCommit) {
     75    info("Inplace-editor's done callback executed, checking its state");
     76    is(actualValue, value, "The value is correct");
     77    is(actualCommit, isCommit, "The commit boolean is correct");
     78    resolve();
     79  };
     80 }