tor-browser

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

browser_markup_html_edit_undo-redo.js (3653B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Test that the undo and redo correctly updates the content when opening the HTML editor on a
      7 // new node. Bug 1327674.
      8 
      9 const DIV1_HTML = '<div id="d1">content1</div>';
     10 const DIV2_HTML = '<div id="d2">content2</div>';
     11 const DIV2_HTML_UPDATED = '<div id="d2">content2_updated</div>';
     12 
     13 const TEST_URL =
     14  "data:text/html," +
     15  "<!DOCTYPE html>" +
     16  "<head><meta charset='utf-8' /></head>" +
     17  "<body>" +
     18  DIV1_HTML +
     19  DIV2_HTML +
     20  "</body>" +
     21  "</html>";
     22 
     23 add_task(async function () {
     24  const { inspector } = await openInspectorForURL(TEST_URL);
     25 
     26  inspector.markup._frame.focus();
     27 
     28  await selectNode("#d1", inspector);
     29 
     30  info("Open the HTML editor on node #d1");
     31  let onHtmlEditorCreated = once(inspector.markup, "begin-editing");
     32  EventUtils.sendKey("F2", inspector.markup._frame.contentWindow);
     33  await onHtmlEditorCreated;
     34 
     35  ok(inspector.markup.htmlEditor.isVisible, "HTML Editor is visible");
     36  is(
     37    inspector.markup.htmlEditor.editor.getText(),
     38    DIV1_HTML,
     39    "The editor content for d1 is correct."
     40  );
     41 
     42  info("Hide the HTML editor for #d1");
     43  let onEditorHidden = once(inspector.markup.htmlEditor, "popuphidden");
     44  EventUtils.sendKey("ESCAPE", inspector.markup.htmlEditor.doc.defaultView);
     45  await onEditorHidden;
     46  ok(!inspector.markup.htmlEditor.isVisible, "HTML Editor is not visible");
     47 
     48  await selectNode("#d2", inspector);
     49 
     50  info("Open the HTML editor on node #d2");
     51  onHtmlEditorCreated = once(inspector.markup, "begin-editing");
     52  EventUtils.sendKey("F2", inspector.markup._frame.contentWindow);
     53  await onHtmlEditorCreated;
     54 
     55  ok(inspector.markup.htmlEditor.isVisible, "HTML Editor is visible");
     56  is(
     57    inspector.markup.htmlEditor.editor.getText(),
     58    DIV2_HTML,
     59    "The editor content for d2 is correct."
     60  );
     61 
     62  // Wait a bit so that the next change is tracked as a
     63  // seperate history change
     64  await waitForTime(1000);
     65 
     66  inspector.markup.htmlEditor.editor.focus();
     67  // Select and replace the content
     68  await EventUtils.synthesizeKey("a", { accelKey: true });
     69  await EventUtils.synthesizeKey(DIV2_HTML_UPDATED);
     70 
     71  // Wait a bit so that the next change is tracked as a
     72  // seperate history change
     73  await waitForTime(1000);
     74 
     75  is(
     76    inspector.markup.htmlEditor.editor.getText(),
     77    DIV2_HTML_UPDATED,
     78    "The editor content for d2 is updated."
     79  );
     80 
     81  await EventUtils.synthesizeKey("z", { accelKey: true });
     82  // Wait a bit for the content to update
     83  await waitForTime(1000);
     84  is(
     85    inspector.markup.htmlEditor.editor.getText(),
     86    DIV2_HTML,
     87    "The editor content for d2 is reverted."
     88  );
     89 
     90  // Undo should be at the last change in history
     91  await EventUtils.synthesizeKey("z", { accelKey: true });
     92  // Wait a bit for the content to update
     93  await waitForTime(1000);
     94  is(
     95    inspector.markup.htmlEditor.editor.getText(),
     96    DIV2_HTML,
     97    "The editor content for d2 has not been set to content1."
     98  );
     99 
    100  // TO FIX: The redo key seems to fail intermittently on Windows
    101  if (!isWindows()) {
    102    // Redo should be back to to the updated content
    103    await EventUtils.synthesizeKey("z", { shiftKey: true, accelKey: true });
    104    is(
    105      inspector.markup.htmlEditor.editor.getText(),
    106      DIV2_HTML_UPDATED,
    107      "The editor content for d2 is back to updated"
    108    );
    109  }
    110 
    111  info("Hide the HTML editor for #d2");
    112  onEditorHidden = once(inspector.markup.htmlEditor, "popuphidden");
    113  EventUtils.sendKey("ESCAPE", inspector.markup.htmlEditor.doc.defaultView);
    114  await onEditorHidden;
    115  ok(!inspector.markup.htmlEditor.isVisible, "HTML Editor is not visible");
    116 });