DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (7f9f804e9dbe)

VCS Links

Line Code
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
<!DOCTYPE html>
<html>
<head>
  <title>Test for resizers appearance</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none;">

</div>

<div id="editor" contenteditable></div>
<div id="clickaway" style="width: 3px; height: 3px;"></div>
<img src="green.png"><!-- for ensuring to load the image at first test of <img> case -->
<pre id="test">

<script class="testbody" type="application/javascript">
"use strict";

SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(async function() {
  async function waitForSelectionChange() {
    return new Promise(resolve => {
      document.addEventListener("selectionchange", () => {
        resolve();
      }, {once: true});
    });
  }

  let editor = document.getElementById("editor");
  let outOfEditor = document.getElementById("clickaway");

  const kTests = [
    { description: "<img>",
      innerHTML: "<img id=\"target\" src=\"green.png\" width=\"100\" height=\"100\">",
      resizable: true,
    },
    { description: "<table>",
      innerHTML: "<table id=\"target\" border><tr><td>1-1</td><td>1-2</td></tr><tr><td>2-1</td><td>2-2</td></tr></table>",
      resizable: true,
    },
    { description: "absolute positioned <div>",
      innerHTML: "<div id=\"target\" style=\"position: absolute; top: 50px; left: 50px;\">positioned</div>",
      resizable() { return document.queryCommandState("enableAbsolutePositionEditing"); },
    },
    { description: "fixed positioned <div>",
      innerHTML: "<div id=\"target\" style=\"position: fixed; top: 50px; left: 50px;\">positioned</div>",
      resizable: false,
    },
    { description: "relative positioned <div>",
      innerHTML: "<div id=\"target\" style=\"position: relative; top: 50px; left: 50px;\">positioned</div>",
      resizable: false,
    },
  ];

  for (let kEnableAbsolutePositionEditor of [true, false]) {
    document.execCommand("enableAbsolutePositionEditing", false, kEnableAbsolutePositionEditor);
    for (const kTest of kTests) {
      const kDescription = kTest.description +
        (kEnableAbsolutePositionEditor ? " (enabled absolute position editor)" : "") + ": ";
      editor.innerHTML = kTest.innerHTML;
      let target = document.getElementById("target");

      document.execCommand("enableObjectResizing", false, false);
      ok(!document.queryCommandState("enableObjectResizing"),
         kDescription + "Object resizer should be disabled by the call of execCommand");

      synthesizeMouseAtCenter(outOfEditor, {});
      let promiseSelectionChangeEvent1 = waitForSelectionChange();
      synthesizeMouseAtCenter(target, {});
      await promiseSelectionChangeEvent1;

      ok(!target.hasAttribute("_moz_resizing"),
         kDescription + ": While enableObjectResizing is disabled, resizers shouldn't appear");

      document.execCommand("enableObjectResizing", false, true);
      ok(document.queryCommandState("enableObjectResizing"),
         kDescription + "Object resizer should be enabled by the call of execCommand");

      synthesizeMouseAtCenter(outOfEditor, {});
      let promiseSelectionChangeEvent2 = waitForSelectionChange();
      synthesizeMouseAtCenter(target, {});
      await promiseSelectionChangeEvent2;

      const kResizable = typeof kTest.resizable === "function" ? kTest.resizable() : kTest.resizable;
      is(target.hasAttribute("_moz_resizing"), kResizable,
         kDescription + (kResizable ? "While enableObjectResizing is enabled, resizers should appear" :
                                      "Even while enableObjectResizing is enabled, resizers shouldn't appear"));

      document.execCommand("enableObjectResizing", false, false);
      ok(!target.hasAttribute("_moz_resizing"),
         kDescription + "enableObjectResizing is disabled even while resizers are visible, resizers should disappear");

      document.execCommand("enableObjectResizing", false, true);
      is(target.hasAttribute("_moz_resizing"), kResizable,
         kDescription + (kResizable ? "enableObjectResizing is enabled when resizable object is selected, resizers should appear" :
                                      "Even if enableObjectResizing is enabled when non-resizable object is selected, resizers shouldn't appear"));
    }
  }

  SimpleTest.finish();
});
</script>
</pre>
</body>
</html>