content/base/test/test_bug628938.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=628938
     5 -->
     6 <head>
     7   <title>Test for Bug 628938</title>
     8   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     9   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    10 </head>
    11 <body>
    12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=628938">Mozilla Bug 628938</a>
    13 <p id="display"></p>
    14 <foo id="content" style="display: none">
    15   <div><div>foo</div></div>
    16   <span> bar </span>
    17   <div>tulip<span>bar</span></div>
    18   <span></span>
    19   <div>foo</div>
    20   <span></span>
    21   <div>bar</div>
    22   <span></span>
    23   <div>foobar</div>
    24 </foo>
    25 <pre id="test">
    26 <script type="application/javascript">
    28 /** Test for Bug 628938 **/
    30 var gResults = [];
    31 var gIdx = 0;
    33 function walkTree(walker)
    34 {
    35   if(walker.firstChild()) {
    36     do {
    37       if (walker.currentNode.nodeType == Node.ELEMENT_NODE) {
    38         ok(gResults[gIdx][0], "current node should be an element");
    39         is(walker.currentNode.nodeName, gResults[gIdx][1],
    40            "current node name should be " + gResults[gIdx][1]);
    41       } else {
    42         ok(!gResults[gIdx][0], "current node shouldn't be an element");
    43         is(walker.currentNode.nodeValue, gResults[gIdx][1],
    44            "current node value should be " + gResults[gIdx][1]);
    45       }
    46       gIdx++;
    47       // Recursively walk the rest of the sub-tree.
    48       walkTree(walker);
    49     } while(walker.nextSibling());
    51     // don't forget to return the treewalker to it's previous state
    52     // before exiting the function
    53     walker.parentNode();
    54   }
    55 }
    57 function regularWalk()
    58 {
    59   gResults = [
    60     [ false, "\n  " ],
    61     [ true, "DIV" ],
    62     [ true, "DIV" ],
    63     [ false, "foo" ],
    64     [ false, "\n  " ],
    65     [ true, "SPAN" ],
    66     [ false, " bar " ],
    67     [ false, "\n  " ],
    68     [ true, "DIV" ],
    69     [ false, "tulip" ],
    70     [ true, "SPAN" ],
    71     [ false, "bar" ],
    72     [ false, "\n  " ],
    73     [ true, "SPAN" ],
    74     [ false, "\n  " ],
    75     [ true, "DIV" ],
    76     [ false, "foo" ],
    77     [ false, "\n  " ],
    78     [ true, "SPAN" ],
    79     [ false, "\n  " ],
    80     [ true, "DIV" ],
    81     [ false, "bar" ],
    82     [ false, "\n  " ],
    83     [ true, "SPAN" ],
    84     [ false, "\n  " ],
    85     [ true, "DIV" ],
    86     [ false, "foobar" ],
    87     [ false, "\n" ],
    88   ];
    89   var walker = document.createTreeWalker(document.getElementById('content'),
    90                                          NodeFilter.SHOW_ALL, null);
    92   walkTree(walker);
    94   gIdx = 0;
    95 }
    97 function noWhiteSpaceWalk()
    98 {
    99   gResults = [
   100     [ true, "DIV" ],
   101     [ true, "DIV" ],
   102     [ false, "foo" ],
   103     [ true, "SPAN" ],
   104     [ false, " bar " ],
   105     [ true, "DIV" ],
   106     [ false, "tulip" ],
   107     [ true, "SPAN" ],
   108     [ false, "bar" ],
   109     [ true, "SPAN" ],
   110     [ true, "DIV" ],
   111     [ false, "foo" ],
   112     [ true, "SPAN" ],
   113     [ true, "DIV" ],
   114     [ false, "bar" ],
   115     [ true, "SPAN" ],
   116     [ true, "DIV" ],
   117     [ false, "foobar" ],
   118   ];
   119   var walker = document.createTreeWalker(document.getElementById('content'),
   120                                          NodeFilter.SHOW_ALL,
   121                                          {
   122                                            acceptNode : function(node) {
   123                                              if (node.nodeType == Node.TEXT_NODE &&
   124                                                  !(/[^\t\n\r ]/.test(node.nodeValue)))
   125                                                return NodeFilter.FILTER_REJECT;
   126                                              return NodeFilter.FILTER_ACCEPT;
   127                                            }
   128                                          });
   130   walkTree(walker);
   132   gIdx = 0;
   133 }
   135 function onlyElementsWalk()
   136 {
   137   gResults = [
   138     [ true, "DIV" ],
   139     [ true, "DIV" ],
   140     [ true, "SPAN" ],
   141     [ true, "DIV" ],
   142     [ true, "SPAN" ],
   143     [ true, "SPAN" ],
   144     [ true, "DIV" ],
   145     [ true, "SPAN" ],
   146     [ true, "DIV" ],
   147     [ true, "SPAN" ],
   148     [ true, "DIV" ],
   149   ];
   150   var walker = document.createTreeWalker(document.getElementById('content'),
   151                                          NodeFilter.SHOW_ELEMENT, null);
   153   walkTree(walker);
   155   gIdx = 0;
   156 }
   158 function onlyDivSubTreeWalk()
   159 {
   160   gResults = [
   161     [ true, "DIV" ],
   162     [ true, "DIV" ],
   163     [ false, "foo" ],
   164     [ true, "DIV" ],
   165     [ false, "tulip" ],
   166     [ true, "SPAN" ],
   167     [ false, "bar" ],
   168     [ true, "DIV" ],
   169     [ false, "foo" ],
   170     [ true, "DIV" ],
   171     [ false, "bar" ],
   172     [ true, "DIV" ],
   173     [ false, "foobar" ],
   174   ];
   175   var walker = document.createTreeWalker(document.getElementById('content'),
   176                                          NodeFilter.SHOW_ALL,
   177                                          {
   178                                            acceptNode : function(node) {
   179                                              if (node.nodeType == Node.TEXT_NODE &&
   180                                                  !(/[^\t\n\r ]/.test(node.nodeValue)))
   181                                                return NodeFilter.FILTER_REJECT;
   183                                              while (node) {
   184                                                if (node.nodeName == "DIV")
   185                                                  return NodeFilter.FILTER_ACCEPT;
   186                                                node = node.parentNode;
   187                                              }
   188                                              return NodeFilter.FILTER_SKIP;
   189                                            }
   190                                          });
   192   walkTree(walker);
   194   gIdx = 0;
   195 }
   197 function onlyDivDataWalk()
   198 {
   199   gResults = [
   200     [ true, "DIV" ],
   201     [ true, "DIV" ],
   202     [ false, "foo" ],
   203     [ true, "DIV" ],
   204     [ false, "tulip" ],
   205     [ true, "SPAN" ],
   206     [ true, "DIV" ],
   207     [ false, "foo" ],
   208     [ true, "DIV" ],
   209     [ false, "bar" ],
   210     [ true, "DIV" ],
   211     [ false, "foobar" ],
   212   ];
   213   var walker = document.createTreeWalker(document.getElementById('content'),
   214                                          NodeFilter.SHOW_ALL,
   215                                          {
   216                                            acceptNode : function(node) {
   217                                              if (node.nodeName == "DIV" ||
   218                                                  (node.parentNode &&
   219                                                   node.parentNode.nodeName == "DIV"))
   220                                                return NodeFilter.FILTER_ACCEPT;
   221                                              return NodeFilter.FILTER_SKIP;
   222                                            }
   223                                          });
   225   walkTree(walker);
   227   gIdx = 0;
   228 }
   230 regularWalk();
   231 noWhiteSpaceWalk();
   232 onlyElementsWalk();
   233 onlyDivSubTreeWalk();
   234 onlyDivDataWalk();
   236 </script>
   237 </pre>
   238 </body>
   239 </html>

mercurial