File: test_resizers_appearance.html

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (113 lines) | stat: -rw-r--r-- 4,656 bytes parent folder | download | duplicates (12)
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
<!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><br>
<div id="clickaway" style="width: 30px; height: 30px; border: 3px solid red;"></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";

function resizingActive(win = window) {
  let Ci = SpecialPowers.Ci;
  let editor = SpecialPowers.wrap(win).docShell.editor;
  return editor && editor.QueryInterface(Ci.nsIHTMLObjectResizer).isObjectResizingActive;
}

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(!resizingActive(),
       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(resizingActive(), 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(!resizingActive(),
         kDescription + "enableObjectResizing is disabled even while resizers are visible, resizers should disappear");

      document.execCommand("enableObjectResizing", false, true);
      is(resizingActive(), 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>