File: test_bug1330796.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 (95 lines) | stat: -rw-r--r-- 3,615 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1330796
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 772796</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"/>
  <style> .pre { white-space: pre } </style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=772796">Mozilla Bug 1330796</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>

<div id="editable" contenteditable></div>

<pre id="test">

<script type="application/javascript">
// We want to test what happens when the user splits a mail cite by clicking
// at the start, the middle and the end of the cite and hitting the enter key.
// Mail cites are spans, and since bug 1288911 they are displayed as blocks.
// The _moz_quote attribute is used to give the cite a blue color via CSS.
// As an internal attribute, it's not returned from the innerHTML.
// To the user the tests look like:
// > mailcite
// This text is 10 characters long, so we position at 0, 5 and 10.
// Althought since bug 1288911 those cites are displayed as block,
// the tests are repeated also for inline display.
// Each entry of the 'tests' array has the original HTML, the offset to click
// at and the expected result HTML.
var tests = [
  // With style="display: block;".
  [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 0,
    "x<span style=\"display: block;\">&gt; mailcite<br></span>" ],
  [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 5,
    "<span style=\"display: block;\">&gt; mai<br></span>x<span style=\"display: block;\">lcite<br></span>"],
  [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite<br></span>", 10,
    "<span style=\"display: block;\">&gt; mailcite<br></span>x" ],
  // No <br> at the end to simulate prior deletion to the end of the quote.
  [ "<span _moz_quote=true style=\"display: block;\">&gt; mailcite</span>", 10,
    "<span style=\"display: block;\">&gt; mailcite<br></span>x" ],

  // Without style="display: block;".
  [ "<span _moz_quote=true>&gt; mailcite<br></span>", 0,
    "x<br><span>&gt; mailcite<br></span>" ],
  [ "<span _moz_quote=true>&gt; mailcite<br></span>", 5,
    "<span>&gt; mai</span><br>x<br><span>lcite<br></span>" ],
  [ "<span _moz_quote=true>&gt; mailcite<br></span>", 10,
    "<span>&gt; mailcite<br></span>x" ],
  // No <br> at the end to simulate prior deletion to the end of the quote.
  [ "<span _moz_quote=true>&gt; mailcite</span>", 10,
    "<span>&gt; mailcite</span><br>x" ],
];

/** Test for Bug 1330796 */

SimpleTest.waitForExplicitFinish();

SimpleTest.waitForFocus(function() {
  var sel = window.getSelection();
  var theEdit = document.getElementById("editable");
  makeMailEditor();

  for (let i = 0; i < tests.length; i++) {
    theEdit.innerHTML = tests[i][0];
    theEdit.focus();
    var theText = theEdit.firstChild.firstChild;
    // Position set at the beginning , middle and end of the text.
    sel.collapse(theText, tests[i][1]);

    synthesizeKey("KEY_Enter");
    sendString("x");
    is(theEdit.innerHTML, tests[i][2], "unexpected HTML for test " + i.toString());
  }

  SimpleTest.finish();
});

function makeMailEditor() {
  var Ci = SpecialPowers.Ci;
  var editingSession = SpecialPowers.wrap(window).docShell.editingSession;
  var editor = editingSession.getEditorForWindow(window);
  editor.flags |= Ci.nsIEditor.eEditorMailMask;
}
</script>

</pre>
</body>
</html>