summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug518122.html
blob: acb9d78d0a1f43afd6d66325b5d5a990ad1cc538 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=518122
-->
<head>
  <title>Test for Bug 518122</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=518122">Mozilla Bug 518122</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 518122 **/

SimpleTest.waitForExplicitFinish();
addLoadEvent(runTests);

var simple_tests = [ ["foo", "foo"],
                     ["", ""],
                     [null, ""],
                     [undefined , "undefined"],
                     ["\n", "\n"],
                     ["\r", "\n"],
                     ["\rfoo", "\nfoo"],
                     ["foo\r", "foo\n"],
                     ["foo\rbar", "foo\nbar"],
                     ["foo\rbar\r", "foo\nbar\n"],
                     ["\r\n", "\n"],
                     ["\r\nfoo", "\nfoo"],
                     ["foo\r\n", "foo\n"],
                     ["foo\r\nbar", "foo\nbar"],
                     ["foo\r\nbar\r\n", "foo\nbar\n"] ];

var value_append_tests = [ ["foo", "bar", "foobar"],
                           ["foo", "foo", "foofoo"],
                           ["foobar", "bar", "foobarbar"],
                           ["foobar", "foo", "foobarfoo"],
                           ["foo\n", "foo", "foo\nfoo"],
                           ["foo\r", "foo", "foo\nfoo"],
                           ["foo\r\n", "foo", "foo\nfoo"],
                           ["\n", "\n", "\n\n"],
                           ["\r", "\r", "\n\n"],
                           ["\r\n", "\r\n", "\n\n"],
                           ["\r", "\r\n", "\n\n"],
                           ["\r\n", "\r", "\n\n"],
                           [null, null, "null"],
                           [null, undefined, "undefined"],
                           ["", "", ""]
                           ];


var simple_tests_for_input = [ ["foo", "foo"],
                               ["", ""],
                               [null, ""],
                               [undefined , "undefined"],
                               ["\n", ""],
                               ["\r", ""],
                               ["\rfoo", "foo"],
                               ["foo\r", "foo"],
                               ["foo\rbar", "foobar"],
                               ["foo\rbar\r", "foobar"],
                               ["\r\n", ""],
                               ["\r\nfoo", "foo"],
                               ["foo\r\n", "foo"],
                               ["foo\r\nbar", "foobar"],
                               ["foo\r\nbar\r\n", "foobar"] ];

var value_append_tests_for_input = [ ["foo", "bar", "foobar"],
                                     ["foo", "foo", "foofoo"],
                                     ["foobar", "bar", "foobarbar"],
                                     ["foobar", "foo", "foobarfoo"],
                                     ["foo\n", "foo", "foofoo"],
                                     ["foo\r", "foo", "foofoo"],
                                     ["foo\r\n", "foo", "foofoo"],
                                     ["\n", "\n", ""],
                                     ["\r", "\r", ""],
                                     ["\r\n", "\r\n", ""],
                                     ["\r", "\r\n", ""],
                                     ["\r\n", "\r", ""],
                                     [null, null, "null"],
                                     [null, undefined, "undefined"],
                                     ["", "", ""]
                                     ];
function runTestsFor(el, simpleTests, appendTests) {
  for(var i = 0; i < simpleTests.length; ++i) {
    el.value = simpleTests[i][0];
    is(el.value, simpleTests[i][1], "Wrong value (wrap=" + el.getAttribute('wrap') + ", simple_test=" + i + ")");
  }
  for (var j = 0; j < appendTests.length; ++j) {
    el.value = appendTests[j][0];
    el.value += appendTests[j][1];
    is(el.value, appendTests[j][2], "Wrong value (wrap=" + el.getAttribute('wrap') + ", value_append_test=" + j + ")");
  }
}

function runTests() {
  var textareas = document.getElementsByTagName("textarea");
  for (var i = 0; i < textareas.length; ++i) {
    runTestsFor(textareas[i], simple_tests, value_append_tests);
  }
  var input = document.getElementsByTagName("input")[0];
  runTestsFor(input, simple_tests_for_input, value_append_tests_for_input);
  // initialize the editor
  input.focus();
  input.blur();
  runTestsFor(input, simple_tests_for_input, value_append_tests_for_input);
  SimpleTest.finish();
}


</script>
</pre>
<textarea cols="30" rows="7" wrap="none"></textarea>
<textarea cols="30" rows="7" wrap="off"></textarea><br>
<textarea cols="30" rows="7" wrap="soft"></textarea>
<textarea cols="30" rows="7" wrap="hard"></textarea>
<input type="text">
</body>
</html>