<!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>