1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/editor/libeditor/text/tests/test_bug629172.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=629172 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 629172</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <script type="text/javascript" src="/tests/SimpleTest/WindowSnapshot.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=629172">Mozilla Bug 629172</a> 1.18 +<p id="display"></p> 1.19 +<div id="content"> 1.20 +<textarea id="ltr-ref" style="display: none">test.</textarea> 1.21 +<textarea id="rtl-ref" style="display: none; direction: rtl">test.</textarea> 1.22 +</div> 1.23 +<pre id="test"> 1.24 +<script type="application/javascript"> 1.25 + 1.26 +/** Test for Bug 629172 **/ 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 +SimpleTest.waitForFocus(function() { 1.29 + var LTRRef = document.getElementById("ltr-ref"); 1.30 + var RTLRef = document.getElementById("rtl-ref"); 1.31 + var Screenshots = {}; 1.32 + 1.33 + // generate the reference screenshots 1.34 + LTRRef.style.display = ""; 1.35 + document.body.clientWidth; 1.36 + Screenshots.ltr = snapshotWindow(window); 1.37 + LTRRef.parentNode.removeChild(LTRRef); 1.38 + RTLRef.style.display = ""; 1.39 + document.body.clientWidth; 1.40 + Screenshots.rtl = snapshotWindow(window); 1.41 + RTLRef.parentNode.removeChild(RTLRef); 1.42 + Screenshots.get = function(dir, flip) { 1.43 + if (flip) { 1.44 + return this[dir == "rtl" ? "ltr" : "rtl"]; 1.45 + } else { 1.46 + return this[dir]; 1.47 + } 1.48 + }; 1.49 + 1.50 + function testDirection(initialDir) { 1.51 + var t = document.createElement("textarea"); 1.52 + t.setAttribute("dir", initialDir); 1.53 + t.value = "test."; 1.54 + var inputEventCount = 0; 1.55 + t.oninput = function() { inputEventCount++; }; 1.56 + document.getElementById("content").appendChild(t); 1.57 + document.body.clientWidth; 1.58 + var s1 = snapshotWindow(window); 1.59 + ok(compareSnapshots(s1, Screenshots.get(initialDir, false), true)[0], 1.60 + "Textarea should appear correctly before switching the direction (" + initialDir + ")"); 1.61 + t.focus(); 1.62 + is(inputEventCount, 0, "input event count must be 0 before"); 1.63 + synthesizeKey("x", {accelKey: true, shiftKey: true}); 1.64 + is(t.getAttribute("dir"), initialDir == "ltr" ? "rtl" : "ltr", "The dir attribute must be correctly updated"); 1.65 + is(inputEventCount, 1, "input event count must be 1 after"); 1.66 + t.blur(); 1.67 + var s2 = snapshotWindow(window); 1.68 + ok(compareSnapshots(s2, Screenshots.get(initialDir, true), true)[0], 1.69 + "Textarea should appear correctly after switching the direction (" + initialDir + ")"); 1.70 + t.focus(); 1.71 + is(inputEventCount, 1, "input event count must be 1 before"); 1.72 + synthesizeKey("x", {accelKey: true, shiftKey: true}); 1.73 + is(inputEventCount, 2, "input event count must be 2 after"); 1.74 + is(t.getAttribute("dir"), initialDir == "ltr" ? "ltr" : "rtl", "The dir attribute must be correctly updated"); 1.75 + t.blur(); 1.76 + var s3 = snapshotWindow(window); 1.77 + ok(compareSnapshots(s3, Screenshots.get(initialDir, false), true)[0], 1.78 + "Textarea should appear correctly after switching back the direction (" + initialDir + ")"); 1.79 + t.parentNode.removeChild(t); 1.80 + } 1.81 + 1.82 + testDirection("ltr"); 1.83 + testDirection("rtl"); 1.84 + 1.85 + SimpleTest.finish(); 1.86 +}); 1.87 + 1.88 +</script> 1.89 +</pre> 1.90 +</body> 1.91 +</html>