text-content-tests.html 5.59 KB
Newer Older
Rafael Monnerat's avatar
Rafael Monnerat committed
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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">

<!--
Copyright 2004 ThoughtWorks, Inc

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>JsUnit Utility Tests</title>
  <link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
  <script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
  <script language="JavaScript" type="text/javascript" src="../jsmock/mock.js"></script>
  <script language="JavaScript" type="text/javascript" src="../../core/scripts/htmlutils.js"></script>
  <script language="JavaScript" type="text/javascript" src="../../core/scripts/selenium-browserdetect.js"></script>
  <script language="JavaScript" type="text/javascript">
      function testEmpty()
      {
          assertText("", "empty");
      }
      function testSpaces()
      {
          assertText("1 1 1", "one_space");
          assertText("2 2  2", "two_spaces");
          assertText("3 3   3  3   3", "three_spaces");
          assertText("1 tab2 tabs", "tabs");
      }

      function testNonTextMarkup()
      {
          assertText("There is non-visible and visible markup here that doesn't change the text content", "non_text_markup");
          assertText("There is an image here and an image link", "image_in_text");
      }

      function testNonVisibleNewlinesInText()
      {
          assertText("non visible newlines", "non_visible_newlines");
      }

      function testInlineElementsForcingNewlines()
      {
          assertText("<br/>\nnewline", "br");
          // TODO we should probably always return a single (or double) newline
          assertText("<hr/>\n+newline", "hr");
      }

      function testBlockElementsForcingNewlines()
      {
          // TODO we should probably always return a single (or double) newline
          assertText("First paragraph\n+Second paragraph", "paragraphs");
          assertText("First div\n+Second div", "divs");
      }

      function testPreformattedNewlines()
      {
          // TODO What other Html tags support preformatted newlines?
          assertText("preformatted\nnewline", "preformatted");
      }

      function assertText(pattern, elementId)
      {
          var text = getText(document.getElementById(elementId));
          var re = new RegExp(pattern);

          assertTrue(text + "\n does not match pattern \n'" + pattern.replace(/\n/g, "\\n") + "'",
                  re.test(text));
      }

      function assertTextContent(expectedTextContent, elementId) {
          var actualTextContent = normalizeNewlines(getTextContent(document.getElementById(elementId)));
          assertEquals(expectedTextContent, actualTextContent);
      }

      function testTextContentOfEmptyElementIsBlankString() {
          assertTextContent("", 'empty');
      }

      function testTextContentOfSimpleElementIsContainedText() {
          assertTextContent("abc", 'simple');
      }

      function testTextContentIncludesContentOfChildElements() {
          assertTextContent("this is not simple", 'not_simple');
      }

      function testTextContentOfPreElementIncludesNewlines() {
          assertTextContent("preformatted block\n", 'pre');
      }

      function testTextContentOfElementsWithinPreElementIncludesNewlines() {
          assertTextContent("preformatted block with nested\nbold tag\n", 'pre_with_nested_tags');
      }

      function testTextContentOfBlockElementsIncludesTrailingNewline() {
          assertTextContent("this is a paragraph\n", 'p_element');
          assertTextContent("\n", 'br_element');
          assertTextContent("\n", 'hr_element');
          assertTextContent("this is a div\n", 'div_element');
      }
  </script>
</head>

<body>

<div id="one_space">1 1&nbsp;1</div>
<div id="two_spaces">2  2&nbsp;&nbsp;2</div>
<div id="three_spaces">3   3&nbsp;&nbsp;&nbsp;3  &nbsp;3 &nbsp;&nbsp;3</div>
<div id="tabs">1	tab2		tabs</div>
<div id="non_text_markup">
  There is <span>non-visible</span> and <a href="javascript:void()"><strong><em>visible</em></strong></a> markup here that <!-- comment -->doesn't change the text content
</div>
<div id="image_in_text">
  There is <img alt="alt text" src="../../core/selenium-logo.png"/>an image here and an <a href="javascript:void()"><img src="../../core/selenium-logo.png" alt="alt text"/>image link</a>
</div>
<div id="non_visible_newlines">non
<span>visible
newlines</span>
</div>
<div id="br">
  &lt;br/><br/>newline
</div>
<div id="hr">
  &lt;hr/><hr/>newline
</div>
<div id="paragraphs">
  <p>First paragraph</p><p>Second paragraph</p>
</div>
<div id="divs">
  <div>First div</div><div>Second div</div>
</div>
<div id="preformatted">
  <pre>preformatted
newline</pre>
</div>

<hr/>

<span id="empty"></span>

<span id="simple">abc</span>

<span id="not_simple">this is <b>not</b> simple</span>

<pre id="pre">
preformatted block
</pre>

<pre id="pre_with_nested_tags">
preformatted block with <b>nested
bold tag</b>
</pre>

<p id="p_element">this is a paragraph</p>

<hr id="hr_element"/>
<br id="br_element"/>
<div id="div_element">this is a div</div>



</body>
</html>