editor/libeditor/base/tests/test_bug773262.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/editor/libeditor/base/tests/test_bug773262.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +<!doctype html>
     1.5 +<!--
     1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=773262
     1.7 +-->
     1.8 +<title>Test for Bug 773262</title>
     1.9 +<script src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +<link rel="stylesheet" href="/tests/SimpleTest/test.css">
    1.11 +<p><a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=773262">Mozilla Bug 773262</a></p>
    1.12 +<iframe></iframe>
    1.13 +<script>
    1.14 +function runTest(doc, desc) {
    1.15 +  is(doc.queryCommandEnabled("undo"), false,
    1.16 +     desc + ": Undo shouldn't be enabled yet");
    1.17 +  is(doc.queryCommandEnabled("redo"), false,
    1.18 +     desc + ": Redo shouldn't be enabled yet");
    1.19 +  is(doc.body.innerHTML, "<p>Hello</p>", desc + ": Wrong initial innerHTML");
    1.20 +
    1.21 +  doc.getSelection().selectAllChildren(doc.body.firstChild);
    1.22 +  doc.execCommand("bold");
    1.23 +  is(doc.queryCommandEnabled("undo"), true,
    1.24 +     desc + ": Undo should be enabled after bold");
    1.25 +  is(doc.queryCommandEnabled("redo"), false,
    1.26 +     desc + ": Redo still shouldn't be enabled");
    1.27 +  is(doc.body.innerHTML, "<p><b>Hello</b></p>",
    1.28 +     desc + ": Wrong innerHTML after bold");
    1.29 +
    1.30 +  doc.execCommand("undo");
    1.31 +  is(doc.queryCommandEnabled("undo"), false,
    1.32 +     desc + ": Undo should be disabled again");
    1.33 +  is(doc.queryCommandEnabled("redo"), true,
    1.34 +     desc + ": Redo should be enabled now");
    1.35 +  is(doc.body.innerHTML, "<p>Hello</p>",
    1.36 +     desc + ": Wrong innerHTML after undo");
    1.37 +
    1.38 +  doc.execCommand("redo");
    1.39 +  is(doc.queryCommandEnabled("undo"), true,
    1.40 +     desc + ": Undo should be enabled after redo");
    1.41 +  is(doc.queryCommandEnabled("redo"), false,
    1.42 +     desc + ": Redo should be disabled again");
    1.43 +  is(doc.body.innerHTML, "<p><b>Hello</b></p>",
    1.44 +     desc + ": Wrong innerHTML after redo");
    1.45 +}
    1.46 +
    1.47 +SimpleTest.waitForExplicitFinish();
    1.48 +addLoadEvent(function() {
    1.49 +  var doc = document.querySelector("iframe").contentDocument;
    1.50 +
    1.51 +  // First turn on designMode and run the test like that, as a sanity check.
    1.52 +  doc.body.innerHTML = "<p>Hello</p>";
    1.53 +  doc.designMode = "on";
    1.54 +  runTest(doc, "1");
    1.55 +
    1.56 +  // Now to test the actual bug: repeat all the above, but with designMode
    1.57 +  // toggled.  This should clear the undo history, so everything should be
    1.58 +  // exactly as before.
    1.59 +  doc.designMode = "off";
    1.60 +  doc.body.innerHTML = "<p>Hello</p>";
    1.61 +  doc.designMode = "on";
    1.62 +  runTest(doc, "2");
    1.63 +
    1.64 +  SimpleTest.finish();
    1.65 +});
    1.66 +</script>

mercurial