test_bug1358025.html (3303B)
1 <html> 2 <head> 3 <title>Test for bug 1358025</title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" type="text/css" 6 href="/tests/SimpleTest/test.css" /> 7 </head> 8 <body> 9 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1358025">Mozilla Bug 1358025</a> 10 <div id="display"> 11 <input type="text" id="edit"> 12 </div> 13 <div id="content" style="display: none"> 14 15 </div> 16 <pre id="test"> 17 <script class="testbody" type="application/javascript"> 18 SimpleTest.waitForExplicitFinish(); 19 SimpleTest.waitForFocus(() => { 20 let input = document.getElementById("edit"); 21 input.focus(); 22 23 let controller = 24 SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_undo"); 25 26 // Create undo transaction 27 SpecialPowers.wrap(input).setUserInput("XXX"); 28 SpecialPowers.wrap(input).setUserInput(""); 29 30 // Enable undo because this is user input 31 SpecialPowers.wrap(input).setUserInput(""); 32 is(input.value, "", "value is empty"); 33 ok(controller.isCommandEnabled("cmd_undo"), 34 "Undo is enabled by same empty string"); 35 36 SpecialPowers.wrap(input).setUserInput("ABC"); 37 is(input.value, "ABC", "value is ABC"); 38 ok(controller.isCommandEnabled("cmd_undo"), "Undo is enabled by a string"); 39 40 SpecialPowers.wrap(input).setUserInput("ABC"); 41 is(input.value, "ABC", "value is ABC"); 42 ok(controller.isCommandEnabled("cmd_undo"), "Undo is enabled by same string"); 43 44 SpecialPowers.wrap(input).setUserInput("DEF"); 45 is(input.value, "DEF", "value is DEF"); 46 ok(controller.isCommandEnabled("cmd_undo"), 47 "Undo is enabled by different string"); 48 49 SpecialPowers.wrap(input).setUserInput(""); 50 is(input.value, "", "value is empty"); 51 ok(controller.isCommandEnabled("cmd_undo"), 52 "Undo is enabled by empty string"); 53 54 // disable undo because this is by script 55 56 // But Edge and Chrome still turn on undo when setting empty value from 57 // empty value. So we are same behaviour for this case. 58 input.value = ""; 59 is(input.value, "", "value is empty"); 60 ok(controller.isCommandEnabled("cmd_undo"), 61 "Undo is still enabled by same empty string"); 62 63 input.value = "ABC"; 64 is(input.value, "ABC", "value is ABC"); 65 ok(!controller.isCommandEnabled("cmd_undo"), "Undo is disabled by a string"); 66 67 // When setting same value by script, all browsers (Edge, Safari and Chrome) 68 // keep undo state. 69 input.value = ""; 70 SpecialPowers.wrap(input).setUserInput("ABC"); 71 ok(controller.isCommandEnabled("cmd_undo"), "Undo is enabled"); 72 input.value = "ABC"; 73 is(input.value, "ABC", "value is ABC"); 74 ok(controller.isCommandEnabled("cmd_undo"), 75 "Undo is still enabled by same string"); 76 77 input.value = ""; 78 SpecialPowers.wrap(input).setUserInput("ABC"); 79 ok(controller.isCommandEnabled("cmd_undo"), "Undo is enabled"); 80 input.value = "DEF"; 81 is(input.value, "DEF", "value is DEF"); 82 ok(!controller.isCommandEnabled("cmd_undo"), 83 "Undo is disabled by different string"); 84 85 input.value = ""; 86 SpecialPowers.wrap(input).setUserInput("DEF"); 87 ok(controller.isCommandEnabled("cmd_undo"), "Undo is enabled"); 88 input.value = ""; 89 is(input.value, "", "value is empty"); 90 ok(!controller.isCommandEnabled("cmd_undo"), 91 "Undo is disabled by empty string"); 92 93 SimpleTest.finish(); 94 }, window); 95 </script> 96 </pre> 97 </body> 98 </html>