View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html.serializer;
16  
17  import org.htmlunit.SimpleWebTestCase;
18  import org.htmlunit.html.DomElement;
19  import org.htmlunit.html.HtmlElement;
20  import org.htmlunit.html.HtmlNumberInput;
21  import org.htmlunit.html.HtmlPage;
22  import org.htmlunit.html.HtmlTable;
23  import org.htmlunit.html.HtmlTableCell;
24  import org.htmlunit.junit.BrowserRunner;
25  import org.htmlunit.junit.annotation.Alerts;
26  import org.junit.Test;
27  import org.junit.runner.RunWith;
28  
29  /**
30   * Tests for {@link HtmlSerializerNormalizedText}.
31   * This contains the tests for plain controls.
32   *
33   * @author Ronald Brill
34   */
35  @RunWith(BrowserRunner.class)
36  public class HtmlSerializerNormalizedText2Test extends SimpleWebTestCase {
37  
38      /**
39       * Verifies getNormalizedText().
40       * @throws Exception if the test fails
41       */
42      @Test
43      @Alerts("\n")
44      public void getNormalizedTextWhiteSpaceBreak() throws Exception {
45          getNormalizedTextWhiteSpaceBreak(null);
46      }
47  
48      /**
49       * Verifies getNormalizedText().
50       * @throws Exception if the test fails
51       */
52      @Test
53      @Alerts("\n")
54      public void getNormalizedTextWhiteSpaceBreakNormal() throws Exception {
55          getNormalizedTextWhiteSpaceBreak("normal");
56      }
57  
58      /**
59       * Verifies getNormalizedText().
60       * @throws Exception if the test fails
61       */
62      @Test
63      @Alerts("\n")
64      public void getNormalizedTextWhiteSpaceBreakNowrap() throws Exception {
65          getNormalizedTextWhiteSpaceBreak("nowrap");
66      }
67  
68      /**
69       * Verifies getNormalizedText().
70       * @throws Exception if the test fails
71       */
72      @Test
73      @Alerts("\n")
74      public void getNormalizedTextWhiteSpaceBreakPre() throws Exception {
75          getNormalizedTextWhiteSpaceBreak("pre");
76      }
77  
78      /**
79       * Verifies getNormalizedText().
80       * @throws Exception if the test fails
81       */
82      @Test
83      @Alerts("\n")
84      public void getNormalizedTextWhiteSpaceBreakPreWrap() throws Exception {
85          getNormalizedTextWhiteSpaceBreak("pre-wrap");
86      }
87  
88      /**
89       * Verifies getNormalizedText().
90       * @throws Exception if the test fails
91       */
92      @Test
93      @Alerts("\n")
94      public void getNormalizedTextWhiteSpaceBreakPreLine() throws Exception {
95          getNormalizedTextWhiteSpaceBreak("pre-line");
96      }
97  
98      private void getNormalizedTextWhiteSpaceBreak(final String whiteSpace) throws Exception {
99          final String htmlContent = DOCTYPE_HTML
100             + "<html>\n"
101             + "<head></head>\n"
102             + "<body>\n"
103             + "  <br id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
104             + "</body></html>";
105 
106         final HtmlPage page = loadPage(htmlContent);
107 
108         final String text = page.getElementById("tester").asNormalizedText();
109         assertEquals(getExpectedAlerts()[0], text);
110     }
111 
112     /**
113      * Verifies getNormalizedText().
114      * @throws Exception if the test fails
115      */
116     @Test
117     @Alerts("")
118     public void getNormalizedTextWhiteSpaceInputHidden() throws Exception {
119         getNormalizedTextWhiteSpaceInputHidden(null);
120     }
121 
122     /**
123      * Verifies getNormalizedText().
124      * @throws Exception if the test fails
125      */
126     @Test
127     @Alerts("")
128     public void getNormalizedTextWhiteSpaceInputHiddenNormal() throws Exception {
129         getNormalizedTextWhiteSpaceInputHidden("normal");
130     }
131 
132     /**
133      * Verifies getNormalizedText().
134      * @throws Exception if the test fails
135      */
136     @Test
137     @Alerts("")
138     public void getNormalizedTextWhiteSpaceInputHiddenNowrap() throws Exception {
139         getNormalizedTextWhiteSpaceInputHidden("nowrap");
140     }
141 
142     /**
143      * Verifies getNormalizedText().
144      * @throws Exception if the test fails
145      */
146     @Test
147     @Alerts("")
148     public void getNormalizedTextWhiteSpaceInputHiddenPre() throws Exception {
149         getNormalizedTextWhiteSpaceInputHidden("pre");
150     }
151 
152     /**
153      * Verifies getNormalizedText().
154      * @throws Exception if the test fails
155      */
156     @Test
157     @Alerts("")
158     public void getNormalizedTextWhiteSpaceInputHiddenPreWrap() throws Exception {
159         getNormalizedTextWhiteSpaceInputHidden("pre-wrap");
160     }
161 
162     /**
163      * Verifies getNormalizedText().
164      * @throws Exception if the test fails
165      */
166     @Test
167     @Alerts("")
168     public void getNormalizedTextWhiteSpaceInputHiddenPreLine() throws Exception {
169         getNormalizedTextWhiteSpaceInputHidden("pre-line");
170     }
171 
172     private void getNormalizedTextWhiteSpaceInputHidden(final String whiteSpace) throws Exception {
173         final String htmlContent = DOCTYPE_HTML
174             + "<html>\n"
175             + "<head></head>\n"
176             + "<body>\n"
177             + "<form id='form1'>\n"
178             + "  <input type='hidden' name='tester' id='tester' "
179                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
180                         + " value='  A B  C\t \t  D \nEF\nG \n H  <br> I  '>\n"
181             + "</form>\n"
182             + "</body></html>";
183 
184         final HtmlPage page = loadPage(htmlContent);
185 
186         final String text = page.getElementById("tester").asNormalizedText();
187         assertEquals(getExpectedAlerts()[0], text);
188     }
189 
190     /**
191      * Verifies getNormalizedText().
192      * @throws Exception if the test fails
193      */
194     @Test
195     @Alerts("")
196     public void getNormalizedTextWhiteSpaceScript() throws Exception {
197         getNormalizedTextWhiteSpaceScript(null);
198     }
199 
200     /**
201      * Verifies getNormalizedText().
202      * @throws Exception if the test fails
203      */
204     @Test
205     @Alerts("")
206     public void getNormalizedTextWhiteSpaceScriptNormal() throws Exception {
207         getNormalizedTextWhiteSpaceScript("normal");
208     }
209 
210     /**
211      * Verifies getNormalizedText().
212      * @throws Exception if the test fails
213      */
214     @Test
215     @Alerts("")
216     public void getNormalizedTextWhiteSpaceScriptNowrap() throws Exception {
217         getNormalizedTextWhiteSpaceScript("nowrap");
218     }
219 
220     /**
221      * Verifies getNormalizedText().
222      * @throws Exception if the test fails
223      */
224     @Test
225     @Alerts("")
226     public void getNormalizedTextWhiteSpaceScriptPre() throws Exception {
227         getNormalizedTextWhiteSpaceScript("pre");
228     }
229 
230     /**
231      * Verifies getNormalizedText().
232      * @throws Exception if the test fails
233      */
234     @Test
235     @Alerts("")
236     public void getNormalizedTextWhiteSpaceScriptPreWrap() throws Exception {
237         getNormalizedTextWhiteSpaceScript("pre-wrap");
238     }
239 
240     /**
241      * Verifies getNormalizedText().
242      * @throws Exception if the test fails
243      */
244     @Test
245     @Alerts("")
246     public void getNormalizedTextWhiteSpaceScriptPreLine() throws Exception {
247         getNormalizedTextWhiteSpaceScript("pre-line");
248     }
249 
250     private void getNormalizedTextWhiteSpaceScript(final String whiteSpace) throws Exception {
251         final String htmlContent = DOCTYPE_HTML
252             + "<html>\n"
253             + "<head></head>\n"
254             + "<body>\n"
255             + "  <script id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
256                 + "var x;  \n \t   \n var y;</script>\n"
257             + "</body></html>";
258 
259         final HtmlPage page = loadPage(htmlContent);
260 
261         final String text = page.getElementById("tester").asNormalizedText();
262         assertEquals(getExpectedAlerts()[0], text);
263     }
264 
265     /**
266      * Verifies getNormalizedText().
267      * @throws Exception if the test fails
268      */
269     @Test
270     @Alerts("")
271     public void getNormalizedTextWhiteSpaceStyle() throws Exception {
272         getNormalizedTextWhiteSpaceStyle(null);
273     }
274 
275     /**
276      * Verifies getNormalizedText().
277      * @throws Exception if the test fails
278      */
279     @Test
280     @Alerts("")
281     public void getNormalizedTextWhiteSpaceStyleNormal() throws Exception {
282         getNormalizedTextWhiteSpaceStyle("normal");
283     }
284 
285     /**
286      * Verifies getNormalizedText().
287      * @throws Exception if the test fails
288      */
289     @Test
290     @Alerts("")
291     public void getNormalizedTextWhiteSpaceStyleNowrap() throws Exception {
292         getNormalizedTextWhiteSpaceStyle("nowrap");
293     }
294 
295     /**
296      * Verifies getNormalizedText().
297      * @throws Exception if the test fails
298      */
299     @Test
300     @Alerts("")
301     public void getNormalizedTextWhiteSpaceStylePre() throws Exception {
302         getNormalizedTextWhiteSpaceStyle("pre");
303     }
304 
305     /**
306      * Verifies getNormalizedText().
307      * @throws Exception if the test fails
308      */
309     @Test
310     @Alerts("")
311     public void getNormalizedTextWhiteSpaceStylePreWrap() throws Exception {
312         getNormalizedTextWhiteSpaceStyle("pre-wrap");
313     }
314 
315     /**
316      * Verifies getNormalizedText().
317      * @throws Exception if the test fails
318      */
319     @Test
320     @Alerts("")
321     public void getNormalizedTextWhiteSpaceStylePreLine() throws Exception {
322         getNormalizedTextWhiteSpaceStyle("pre-line");
323     }
324 
325     private void getNormalizedTextWhiteSpaceStyle(final String whiteSpace) throws Exception {
326         final String htmlContent = DOCTYPE_HTML
327             + "<html>\n"
328             + "<head></head>\n"
329             + "<body>\n"
330             + "  <style id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
331                 + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </style>\n"
332             + "</body></html>";
333 
334         final HtmlPage page = loadPage(htmlContent);
335 
336         final String text = page.getElementById("tester").asNormalizedText();
337         assertEquals(getExpectedAlerts()[0], text);
338     }
339 
340     /**
341      * Verifies getNormalizedText().
342      * @throws Exception if the test fails
343      */
344     @Test
345     @Alerts("")
346     public void getNormalizedTextWhiteSpaceNoframes() throws Exception {
347         getNormalizedTextWhiteSpaceNoframes(null);
348     }
349 
350     /**
351      * Verifies getNormalizedText().
352      * @throws Exception if the test fails
353      */
354     @Test
355     @Alerts("")
356     public void getNormalizedTextWhiteSpaceNoframesNormal() throws Exception {
357         getNormalizedTextWhiteSpaceNoframes("normal");
358     }
359 
360     /**
361      * Verifies getNormalizedText().
362      * @throws Exception if the test fails
363      */
364     @Test
365     @Alerts("")
366     public void getNormalizedTextWhiteSpaceNoframesNowrap() throws Exception {
367         getNormalizedTextWhiteSpaceNoframes("nowrap");
368     }
369 
370     /**
371      * Verifies getNormalizedText().
372      * @throws Exception if the test fails
373      */
374     @Test
375     @Alerts("")
376     public void getNormalizedTextWhiteSpaceNoframesPre() throws Exception {
377         getNormalizedTextWhiteSpaceNoframes("pre");
378     }
379 
380     /**
381      * Verifies getNormalizedText().
382      * @throws Exception if the test fails
383      */
384     @Test
385     @Alerts("")
386     public void getNormalizedTextWhiteSpaceNoframesPreWrap() throws Exception {
387         getNormalizedTextWhiteSpaceNoframes("pre-wrap");
388     }
389 
390     /**
391      * Verifies getNormalizedText().
392      * @throws Exception if the test fails
393      */
394     @Test
395     @Alerts("")
396     public void getNormalizedTextWhiteSpaceNoframesPreLine() throws Exception {
397         getNormalizedTextWhiteSpaceNoframes("pre-line");
398     }
399 
400     private void getNormalizedTextWhiteSpaceNoframes(final String whiteSpace) throws Exception {
401         final String htmlContent = DOCTYPE_HTML
402             + "<html>\n"
403             + "<head></head>\n"
404             + "<body>\n"
405             + "  <noframes id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
406                 + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </noframes>\n"
407             + "</body></html>";
408 
409         final HtmlPage page = loadPage(htmlContent);
410 
411         final String text = page.getElementById("tester").asNormalizedText();
412         assertEquals(getExpectedAlerts()[0], text);
413     }
414 
415     /**
416      * Verifies getNormalizedText().
417      * @throws Exception if the test fails
418      */
419     @Test
420     @Alerts("A B C D EF G H \n"
421             + " I")
422     public void getNormalizedTextWhiteSpaceDiv() throws Exception {
423         getNormalizedTextWhiteSpaceDiv(null);
424     }
425 
426     /**
427      * Verifies getNormalizedText().
428      * @throws Exception if the test fails
429      */
430     @Test
431     @Alerts("A B C D EF G H \n"
432             + " I")
433     public void getNormalizedTextWhiteSpaceDivNormal() throws Exception {
434         getNormalizedTextWhiteSpaceDiv("normal");
435     }
436 
437     /**
438      * Verifies getNormalizedText().
439      * @throws Exception if the test fails
440      */
441     @Test
442     @Alerts("A B C D EF G H \n"
443             + " I")
444     public void getNormalizedTextWhiteSpaceDivNowrap() throws Exception {
445         getNormalizedTextWhiteSpaceDiv("nowrap");
446     }
447 
448     /**
449      * Verifies getNormalizedText().
450      * @throws Exception if the test fails
451      */
452     @Test
453     @Alerts("A B C D EF G H \n"
454             + " I")
455     public void getNormalizedTextWhiteSpaceDivPre() throws Exception {
456         getNormalizedTextWhiteSpaceDiv("pre");
457     }
458 
459     /**
460      * Verifies getNormalizedText().
461      * @throws Exception if the test fails
462      */
463     @Test
464     @Alerts("A B C D EF G H \n"
465             + " I")
466     public void getNormalizedTextWhiteSpaceDivPreWrap() throws Exception {
467         getNormalizedTextWhiteSpaceDiv("pre-wrap");
468     }
469 
470     /**
471      * Verifies getNormalizedText().
472      * @throws Exception if the test fails
473      */
474     @Test
475     @Alerts("A B C D EF G H \n"
476             + " I")
477     public void getNormalizedTextWhiteSpaceDivPreLine() throws Exception {
478         getNormalizedTextWhiteSpaceDiv("pre-line");
479     }
480 
481     private void getNormalizedTextWhiteSpaceDiv(final String whiteSpace) throws Exception {
482         final String htmlContent = DOCTYPE_HTML
483             + "<html>\n"
484             + "<head></head>\n"
485             + "<body>\n"
486             + "  <div id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
487                 + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </div>\n"
488             + "</body></html>";
489 
490         final HtmlPage page = loadPage(htmlContent);
491 
492         final String text = page.getElementById("tester").asNormalizedText();
493         assertEquals(getExpectedAlerts()[0], text);
494     }
495 
496     /**
497      * Verifies getNormalizedText().
498      * @throws Exception if the test fails
499      */
500     @Test
501     @Alerts("  A B  C\t \t  D \n"
502             + "EF\n"
503             + "G \n"
504             + " H   I  ")
505     public void getNormalizedTextWhiteSpacePre() throws Exception {
506         getNormalizedTextWhiteSpacePre(null);
507     }
508 
509     /**
510      * Verifies getNormalizedText().
511      * @throws Exception if the test fails
512      */
513     @Test
514     @Alerts("  A B  C\t \t  D \n"
515             + "EF\n"
516             + "G \n"
517             + " H   I  ")
518     public void getNormalizedTextWhiteSpacePreNormal() throws Exception {
519         getNormalizedTextWhiteSpacePre("normal");
520     }
521 
522     /**
523      * Verifies getNormalizedText().
524      * @throws Exception if the test fails
525      */
526     @Test
527     @Alerts("  A B  C\t \t  D \n"
528             + "EF\n"
529             + "G \n"
530             + " H   I  ")
531     public void getNormalizedTextWhiteSpacePreNowrap() throws Exception {
532         getNormalizedTextWhiteSpacePre("nowrap");
533     }
534 
535     /**
536      * Verifies getNormalizedText().
537      * @throws Exception if the test fails
538      */
539     @Test
540     @Alerts("  A B  C\t \t  D \n"
541             + "EF\n"
542             + "G \n"
543             + " H   I  ")
544     public void getNormalizedTextWhiteSpacePrePre() throws Exception {
545         getNormalizedTextWhiteSpacePre("pre");
546     }
547 
548     /**
549      * Verifies getNormalizedText().
550      * @throws Exception if the test fails
551      */
552     @Test
553     @Alerts("  A B  C\t \t  D \n"
554             + "EF\n"
555             + "G \n"
556             + " H   I  ")
557     public void getNormalizedTextWhiteSpacePrePreWrap() throws Exception {
558         getNormalizedTextWhiteSpacePre("pre-wrap");
559     }
560 
561     /**
562      * Verifies getNormalizedText().
563      * @throws Exception if the test fails
564      */
565     @Test
566     @Alerts("  A B  C\t \t  D \n"
567             + "EF\n"
568             + "G \n"
569             + " H   I  ")
570     public void getNormalizedTextWhiteSpacePrePreLine() throws Exception {
571         getNormalizedTextWhiteSpacePre("pre-line");
572     }
573 
574     private void getNormalizedTextWhiteSpacePre(final String whiteSpace) throws Exception {
575         final String htmlContent = DOCTYPE_HTML
576             + "<html>\n"
577             + "<head></head>\n"
578             + "<body>\n"
579             + "  <pre id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
580                     + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </pre>\n"
581             + "</body></html>";
582 
583         final HtmlPage page = loadPage(htmlContent);
584 
585         final String text = page.getElementById("tester").asNormalizedText();
586         assertEquals(getExpectedAlerts()[0], text);
587     }
588 
589     /**
590      * Verifies getNormalizedText().
591      * @throws Exception if the test fails
592      */
593     @Test
594     @Alerts("  A B  C     D \n"
595             + "EF\n"
596             + "G \n"
597             + " H  <br> I")
598     public void getNormalizedTextWhiteSpaceTextArea() throws Exception {
599         getNormalizedTextWhiteSpaceTextArea(null);
600     }
601 
602     /**
603      * Verifies getNormalizedText().
604      * @throws Exception if the test fails
605      */
606     @Test
607     @Alerts("  A B  C     D \n"
608             + "EF\n"
609             + "G \n"
610             + " H  <br> I")
611     public void getNormalizedTextWhiteSpaceTextAreaNormal() throws Exception {
612         getNormalizedTextWhiteSpaceTextArea("normal");
613     }
614 
615     /**
616      * Verifies getNormalizedText().
617      * @throws Exception if the test fails
618      */
619     @Test
620     @Alerts("  A B  C     D \n"
621             + "EF\n"
622             + "G \n"
623             + " H  <br> I")
624     public void getNormalizedTextWhiteSpaceTextAreaNowrap() throws Exception {
625         getNormalizedTextWhiteSpaceTextArea("nowrap");
626     }
627 
628     /**
629      * Verifies getNormalizedText().
630      * @throws Exception if the test fails
631      */
632     @Test
633     @Alerts("  A B  C     D \n"
634             + "EF\n"
635             + "G \n"
636             + " H  <br> I")
637     public void getNormalizedTextWhiteSpaceTextAreaPre() throws Exception {
638         getNormalizedTextWhiteSpaceTextArea("pre");
639     }
640 
641     /**
642      * Verifies getNormalizedText().
643      * @throws Exception if the test fails
644      */
645     @Test
646     @Alerts("  A B  C     D \n"
647             + "EF\n"
648             + "G \n"
649             + " H  <br> I")
650     public void getNormalizedTextWhiteSpaceTextAreaPreWrap() throws Exception {
651         getNormalizedTextWhiteSpaceTextArea("pre-wrap");
652     }
653 
654     /**
655      * Verifies getNormalizedText().
656      * @throws Exception if the test fails
657      */
658     @Test
659     @Alerts("  A B  C     D \n"
660             + "EF\n"
661             + "G \n"
662             + " H  <br> I")
663     public void getNormalizedTextWhiteSpaceTextAreaPreLine() throws Exception {
664         getNormalizedTextWhiteSpaceTextArea("pre-line");
665     }
666 
667     private void getNormalizedTextWhiteSpaceTextArea(final String whiteSpace) throws Exception {
668         final String htmlContent = DOCTYPE_HTML
669             + "<html>\n"
670             + "<head></head>\n"
671             + "<body>\n"
672             + "  <textarea id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
673                     + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </textarea>\n"
674             + "</body></html>";
675 
676         final HtmlPage page = loadPage(htmlContent);
677 
678         final String text = page.getElementById("tester").asNormalizedText();
679         assertEquals(getExpectedAlerts()[0], text);
680     }
681 
682     /**
683      * Verifies getNormalizedText().
684      * @throws Exception if the test fails
685      */
686     @Test
687     @Alerts("A B C D EF G H <br> I")
688     public void getNormalizedTextWhiteSpaceTitle() throws Exception {
689         getNormalizedTextWhiteSpaceTitle(null);
690     }
691 
692     /**
693      * Verifies getNormalizedText().
694      * @throws Exception if the test fails
695      */
696     @Test
697     @Alerts("A B C D EF G H <br> I")
698     public void getNormalizedTextWhiteSpaceTitleNormal() throws Exception {
699         getNormalizedTextWhiteSpaceTitle("normal");
700     }
701 
702     /**
703      * Verifies getNormalizedText().
704      * @throws Exception if the test fails
705      */
706     @Test
707     @Alerts("A B C D EF G H <br> I")
708     public void getNormalizedTextWhiteSpaceTitleNowrap() throws Exception {
709         getNormalizedTextWhiteSpaceTitle("nowrap");
710     }
711 
712     /**
713      * Verifies getNormalizedText().
714      * @throws Exception if the test fails
715      */
716     @Test
717     @Alerts("A B C D EF G H <br> I")
718     public void getNormalizedTextWhiteSpaceTitlePre() throws Exception {
719         getNormalizedTextWhiteSpaceTitle("pre");
720     }
721 
722     /**
723      * Verifies getNormalizedText().
724      * @throws Exception if the test fails
725      */
726     @Test
727     @Alerts("A B C D EF G H <br> I")
728     public void getNormalizedTextWhiteSpaceTitlePreWrap() throws Exception {
729         getNormalizedTextWhiteSpaceTitle("pre-wrap");
730     }
731 
732     /**
733      * Verifies getNormalizedText().
734      * @throws Exception if the test fails
735      */
736     @Test
737     @Alerts("A B C D EF G H <br> I")
738     public void getNormalizedTextWhiteSpaceTitlePreLine() throws Exception {
739         getNormalizedTextWhiteSpaceTitle("pre-line");
740     }
741 
742     private void getNormalizedTextWhiteSpaceTitle(final String whiteSpace) throws Exception {
743         final String htmlContent = DOCTYPE_HTML
744             + "<html>\n"
745             + "<head>\n"
746             + "<title id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">"
747             + "  A B  C\t \t  D \nEF\nG \n H  <br> I  </title>\n"
748             + "</head>\n"
749             + "<body>\n"
750             + "</body></html>";
751 
752         final HtmlPage page = loadPage(htmlContent);
753 
754         final String text = page.getElementById("tester").asNormalizedText();
755         assertEquals(getExpectedAlerts()[0], text);
756     }
757 
758     /**
759      * Verifies getNormalizedText().
760      * @throws Exception if the test fails
761      */
762     @Test
763     @Alerts("A B C D EF G H"
764             + " I")
765     public void getNormalizedTextWhiteSpaceSelect() throws Exception {
766         getNormalizedTextWhiteSpaceSelect(null);
767     }
768 
769     /**
770      * Verifies getNormalizedText().
771      * @throws Exception if the test fails
772      */
773     @Test
774     @Alerts("A B C D EF G H"
775             + " I")
776     public void getNormalizedTextWhiteSpaceSelectNormal() throws Exception {
777         getNormalizedTextWhiteSpaceSelect("normal");
778     }
779 
780     /**
781      * Verifies getNormalizedText().
782      * @throws Exception if the test fails
783      */
784     @Test
785     @Alerts("A B C D EF G H"
786             + " I")
787     public void getNormalizedTextWhiteSpaceSelectNowrap() throws Exception {
788         getNormalizedTextWhiteSpaceSelect("nowrap");
789     }
790 
791     /**
792      * Verifies getNormalizedText().
793      * @throws Exception if the test fails
794      */
795     @Test
796     @Alerts("A B C D EF G H"
797             + " I")
798     public void getNormalizedTextWhiteSpaceSelectPre() throws Exception {
799         getNormalizedTextWhiteSpaceSelect("pre");
800     }
801 
802     /**
803      * Verifies getNormalizedText().
804      * @throws Exception if the test fails
805      */
806     @Test
807     @Alerts("A B C D EF G H"
808             + " I")
809     public void getNormalizedTextWhiteSpaceSelectPreWrap() throws Exception {
810         getNormalizedTextWhiteSpaceSelect("pre-wrap");
811     }
812 
813     /**
814      * Verifies getNormalizedText().
815      * @throws Exception if the test fails
816      */
817     @Test
818     @Alerts("A B C D EF G H"
819             + " I")
820     public void getNormalizedTextWhiteSpaceSelectPreLine() throws Exception {
821         getNormalizedTextWhiteSpaceSelect("pre-line");
822     }
823 
824     private void getNormalizedTextWhiteSpaceSelect(final String whiteSpace) throws Exception {
825         final String htmlContent = DOCTYPE_HTML
826             + "<html>\n"
827             + "<head></head>\n"
828             + "<body>\n"
829             + "  <form>\n"
830             + "    <select id='tester' "
831                     + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
832             + "      <option>  A B  C\t \t  D \nEF\nG \n H  <br> I  </option>\n"
833             + "      <option>Second</option>\n"
834             + "    </select>\n"
835             + "</body></html>";
836 
837         final HtmlPage page = loadPage(htmlContent);
838 
839         final String text = page.getElementById("tester").asNormalizedText();
840         assertEquals(getExpectedAlerts()[0], text);
841     }
842 
843     /**
844      * Verifies getNormalizedText().
845      * @throws Exception if the test fails
846      */
847     @Test
848     @Alerts("A B C D EF G H <br> I")
849     public void getNormalizedTextWhiteSpaceInputSubmit() throws Exception {
850         getNormalizedTextWhiteSpaceInputSubmit(null);
851     }
852 
853     /**
854      * Verifies getNormalizedText().
855      * @throws Exception if the test fails
856      */
857     @Test
858     @Alerts("A B C D EF G H <br> I")
859     public void getNormalizedTextWhiteSpaceInputSubmitNormal() throws Exception {
860         getNormalizedTextWhiteSpaceInputSubmit("normal");
861     }
862 
863     /**
864      * Verifies getNormalizedText().
865      * @throws Exception if the test fails
866      */
867     @Test
868     @Alerts("A B C D EF G H <br> I")
869     public void getNormalizedTextWhiteSpaceInputSubmitNowrap() throws Exception {
870         getNormalizedTextWhiteSpaceInputSubmit("nowrap");
871     }
872 
873     /**
874      * Verifies getNormalizedText().
875      * @throws Exception if the test fails
876      */
877     @Test
878     @Alerts("A B C D EF G H <br> I")
879     public void getNormalizedTextWhiteSpaceInputSubmitPre() throws Exception {
880         getNormalizedTextWhiteSpaceInputSubmit("pre");
881     }
882 
883     /**
884      * Verifies getNormalizedText().
885      * @throws Exception if the test fails
886      */
887     @Test
888     @Alerts("A B C D EF G H <br> I")
889     public void getNormalizedTextWhiteSpaceInputSubmitPreWrap() throws Exception {
890         getNormalizedTextWhiteSpaceInputSubmit("pre-wrap");
891     }
892 
893     /**
894      * Verifies getNormalizedText().
895      * @throws Exception if the test fails
896      */
897     @Test
898     @Alerts("A B C D EF G H <br> I")
899     public void getNormalizedTextWhiteSpaceInputSubmitPreLine() throws Exception {
900         getNormalizedTextWhiteSpaceInputSubmit("pre-line");
901     }
902 
903     private void getNormalizedTextWhiteSpaceInputSubmit(final String whiteSpace) throws Exception {
904         final String htmlContent = DOCTYPE_HTML
905             + "<html>\n"
906             + "<head></head>\n"
907             + "<body>\n"
908             + "<form id='form1'>\n"
909             + "  <input type='submit' name='tester' id='tester' "
910                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
911                         + " value='  A B  C\t \t  D \nEF\nG \n H  <br> I  '>\n"
912             + "</form>\n"
913             + "</body></html>";
914 
915         final HtmlPage page = loadPage(htmlContent);
916 
917         final String text = page.getElementById("tester").asNormalizedText();
918         assertEquals(getExpectedAlerts()[0], text);
919     }
920 
921     /**
922      * Verifies getNormalizedText().
923      * @throws Exception if the test fails
924      */
925     @Test
926     @Alerts("Submit Query")
927     public void getNormalizedTextInputSubmitNoValue() throws Exception {
928         final String htmlContent = DOCTYPE_HTML
929             + "<html>\n"
930             + "<head></head>\n"
931             + "<body>\n"
932             + "<form id='form1'>\n"
933             + "  <input type='submit' name='tester' id='tester'>\n"
934             + "</form>\n"
935             + "</body></html>";
936 
937         final HtmlPage page = loadPage(htmlContent);
938 
939         final String text = page.getElementById("tester").asNormalizedText();
940         assertEquals(getExpectedAlerts()[0], text);
941     }
942 
943     /**
944      * Verifies getNormalizedText().
945      * @throws Exception if the test fails
946      */
947     @Test
948     @Alerts("")
949     public void getNormalizedTextInputSubmitBlankValue() throws Exception {
950         final String htmlContent = DOCTYPE_HTML
951             + "<html>\n"
952             + "<head></head>\n"
953             + "<body>\n"
954             + "<form id='form1'>\n"
955             + "  <input type='submit' name='tester' id='tester' value='  \t' >\n"
956             + "</form>\n"
957             + "</body></html>";
958 
959         final HtmlPage page = loadPage(htmlContent);
960 
961         final String text = page.getElementById("tester").asNormalizedText();
962         assertEquals(getExpectedAlerts()[0], text);
963     }
964 
965     /**
966      * Verifies getNormalizedText().
967      * @throws Exception if the test fails
968      */
969     @Test
970     @Alerts("A B C D EF G H <br> I")
971     public void getNormalizedTextWhiteSpaceInputReset() throws Exception {
972         getNormalizedTextWhiteSpaceInputReset(null);
973     }
974 
975     /**
976      * Verifies getNormalizedText().
977      * @throws Exception if the test fails
978      */
979     @Test
980     @Alerts("A B C D EF G H <br> I")
981     public void getNormalizedTextWhiteSpaceInputResetNormal() throws Exception {
982         getNormalizedTextWhiteSpaceInputReset("normal");
983     }
984 
985     /**
986      * Verifies getNormalizedText().
987      * @throws Exception if the test fails
988      */
989     @Test
990     @Alerts("A B C D EF G H <br> I")
991     public void getNormalizedTextWhiteSpaceInputResetNowrap() throws Exception {
992         getNormalizedTextWhiteSpaceInputReset("nowrap");
993     }
994 
995     /**
996      * Verifies getNormalizedText().
997      * @throws Exception if the test fails
998      */
999     @Test
1000     @Alerts("A B C D EF G H <br> I")
1001     public void getNormalizedTextWhiteSpaceInputResetPre() throws Exception {
1002         getNormalizedTextWhiteSpaceInputReset("pre");
1003     }
1004 
1005     /**
1006      * Verifies getNormalizedText().
1007      * @throws Exception if the test fails
1008      */
1009     @Test
1010     @Alerts("A B C D EF G H <br> I")
1011     public void getNormalizedTextWhiteSpaceInputResetPreWrap() throws Exception {
1012         getNormalizedTextWhiteSpaceInputReset("pre-wrap");
1013     }
1014 
1015     /**
1016      * Verifies getNormalizedText().
1017      * @throws Exception if the test fails
1018      */
1019     @Test
1020     @Alerts("A B C D EF G H <br> I")
1021     public void getNormalizedTextWhiteSpaceInputResetPreLine() throws Exception {
1022         getNormalizedTextWhiteSpaceInputReset("pre-line");
1023     }
1024 
1025     private void getNormalizedTextWhiteSpaceInputReset(final String whiteSpace) throws Exception {
1026         final String htmlContent = DOCTYPE_HTML
1027             + "<html>\n"
1028             + "<head></head>\n"
1029             + "<body>\n"
1030             + "<form id='form1'>\n"
1031             + "  <input type='reset' name='tester' id='tester' "
1032                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1033                         + " value='  A B  C\t \t  D \nEF\nG \n H  <br> I  '>\n"
1034             + "</form>\n"
1035             + "</body></html>";
1036 
1037         final HtmlPage page = loadPage(htmlContent);
1038 
1039         final String text = page.getElementById("tester").asNormalizedText();
1040         assertEquals(getExpectedAlerts()[0], text);
1041     }
1042 
1043     /**
1044      * Verifies getNormalizedText().
1045      * @throws Exception if the test fails
1046      */
1047     @Test
1048     @Alerts("Reset")
1049     public void getNormalizedTextInputResetNoValue() throws Exception {
1050         final String htmlContent = DOCTYPE_HTML
1051             + "<html>\n"
1052             + "<head></head>\n"
1053             + "<body>\n"
1054             + "<form id='form1'>\n"
1055             + "  <input type='reset' name='tester' id='tester' >\n"
1056             + "</form>\n"
1057             + "</body></html>";
1058 
1059         final HtmlPage page = loadPage(htmlContent);
1060 
1061         final String text = page.getElementById("tester").asNormalizedText();
1062         assertEquals(getExpectedAlerts()[0], text);
1063     }
1064 
1065 
1066     /**
1067      * Verifies getNormalizedText().
1068      * @throws Exception if the test fails
1069      */
1070     @Test
1071     @Alerts("")
1072     public void getNormalizedTextInputResetBlankValue() throws Exception {
1073         final String htmlContent = DOCTYPE_HTML
1074             + "<html>\n"
1075             + "<head></head>\n"
1076             + "<body>\n"
1077             + "<form id='form1'>\n"
1078             + "  <input type='reset' name='tester' id='tester' value='  \t'>\n"
1079             + "</form>\n"
1080             + "</body></html>";
1081 
1082         final HtmlPage page = loadPage(htmlContent);
1083 
1084         final String text = page.getElementById("tester").asNormalizedText();
1085         assertEquals(getExpectedAlerts()[0], text);
1086     }
1087 
1088     /**
1089      * Verifies getNormalizedText().
1090      * @throws Exception if the test fails
1091      */
1092     @Test
1093     @Alerts("unchecked")
1094     public void getNormalizedTextWhiteSpaceInputCheckbox() throws Exception {
1095         getNormalizedTextWhiteSpaceInputCheckbox(null);
1096     }
1097 
1098     /**
1099      * Verifies getNormalizedText().
1100      * @throws Exception if the test fails
1101      */
1102     @Test
1103     @Alerts("unchecked")
1104     public void getNormalizedTextWhiteSpaceInputCheckboxNormal() throws Exception {
1105         getNormalizedTextWhiteSpaceInputCheckbox("normal");
1106     }
1107 
1108     /**
1109      * Verifies getNormalizedText().
1110      * @throws Exception if the test fails
1111      */
1112     @Test
1113     @Alerts("unchecked")
1114     public void getNormalizedTextWhiteSpaceInputCheckboxNowrap() throws Exception {
1115         getNormalizedTextWhiteSpaceInputCheckbox("nowrap");
1116     }
1117 
1118     /**
1119      * Verifies getNormalizedText().
1120      * @throws Exception if the test fails
1121      */
1122     @Test
1123     @Alerts("unchecked")
1124     public void getNormalizedTextWhiteSpaceInputCheckboxPre() throws Exception {
1125         getNormalizedTextWhiteSpaceInputCheckbox("pre");
1126     }
1127 
1128     /**
1129      * Verifies getNormalizedText().
1130      * @throws Exception if the test fails
1131      */
1132     @Test
1133     @Alerts("unchecked")
1134     public void getNormalizedTextWhiteSpaceInputCheckboxPreWrap() throws Exception {
1135         getNormalizedTextWhiteSpaceInputCheckbox("pre-wrap");
1136     }
1137 
1138     /**
1139      * Verifies getNormalizedText().
1140      * @throws Exception if the test fails
1141      */
1142     @Test
1143     @Alerts("unchecked")
1144     public void getNormalizedTextWhiteSpaceInputCheckboxPreLine() throws Exception {
1145         getNormalizedTextWhiteSpaceInputCheckbox("pre-line");
1146     }
1147 
1148     private void getNormalizedTextWhiteSpaceInputCheckbox(final String whiteSpace) throws Exception {
1149         final String htmlContent = DOCTYPE_HTML
1150             + "<html>\n"
1151             + "<head></head>\n"
1152             + "<body>\n"
1153             + "<form id='form1'>\n"
1154             + "  <input type='checkbox' name='tester' id='tester' "
1155                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1156                         + " value='  A B  C\t \t  D \nEF\nG \n H  <br> I  '>\n"
1157             + "</form>\n"
1158             + "</body></html>";
1159 
1160         final HtmlPage page = loadPage(htmlContent);
1161 
1162         final String text = page.getElementById("tester").asNormalizedText();
1163         assertEquals(getExpectedAlerts()[0], text);
1164     }
1165 
1166     /**
1167      * Verifies getNormalizedText().
1168      * @throws Exception if the test fails
1169      */
1170     @Test
1171     @Alerts("unchecked")
1172     public void getNormalizedTextWhiteSpaceInputRadio() throws Exception {
1173         getNormalizedTextWhiteSpaceInputRadio(null);
1174     }
1175 
1176     /**
1177      * Verifies getNormalizedText().
1178      * @throws Exception if the test fails
1179      */
1180     @Test
1181     @Alerts("unchecked")
1182     public void getNormalizedTextWhiteSpaceInputRadioNormal() throws Exception {
1183         getNormalizedTextWhiteSpaceInputRadio("normal");
1184     }
1185 
1186     /**
1187      * Verifies getNormalizedText().
1188      * @throws Exception if the test fails
1189      */
1190     @Test
1191     @Alerts("unchecked")
1192     public void getNormalizedTextWhiteSpaceInputRadioNowrap() throws Exception {
1193         getNormalizedTextWhiteSpaceInputRadio("nowrap");
1194     }
1195 
1196     /**
1197      * Verifies getNormalizedText().
1198      * @throws Exception if the test fails
1199      */
1200     @Test
1201     @Alerts("unchecked")
1202     public void getNormalizedTextWhiteSpaceInputRadioPre() throws Exception {
1203         getNormalizedTextWhiteSpaceInputRadio("pre");
1204     }
1205 
1206     /**
1207      * Verifies getNormalizedText().
1208      * @throws Exception if the test fails
1209      */
1210     @Test
1211     @Alerts("unchecked")
1212     public void getNormalizedTextWhiteSpaceInputRadioPreWrap() throws Exception {
1213         getNormalizedTextWhiteSpaceInputRadio("pre-wrap");
1214     }
1215 
1216     /**
1217      * Verifies getNormalizedText().
1218      * @throws Exception if the test fails
1219      */
1220     @Test
1221     @Alerts("unchecked")
1222     public void getNormalizedTextWhiteSpaceInputRadioPreLine() throws Exception {
1223         getNormalizedTextWhiteSpaceInputRadio("pre-line");
1224     }
1225 
1226     private void getNormalizedTextWhiteSpaceInputRadio(final String whiteSpace) throws Exception {
1227         final String htmlContent = DOCTYPE_HTML
1228             + "<html>\n"
1229             + "<head></head>\n"
1230             + "<body>\n"
1231             + "<form id='form1'>\n"
1232             + "  <input type='radio' name='tester' id='tester' "
1233                         + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'"))
1234                         + " value='  A B  C\t \t  D \nEF\nG \n H  <br> I  '>\n"
1235             + "</form>\n"
1236             + "</body></html>";
1237 
1238         final HtmlPage page = loadPage(htmlContent);
1239 
1240         final String text = page.getElementById("tester").asNormalizedText();
1241         assertEquals(getExpectedAlerts()[0], text);
1242     }
1243 
1244     /**
1245      * Verifies getNormalizedText().
1246      * @throws Exception if the test fails
1247      */
1248     @Test
1249     @Alerts("1. first item\n"
1250             + "2. A B C D EF G H \n"
1251             + " I\n"
1252             + "3. third item\n"
1253             + "4. 4. item\n"
1254             + "some text\n"
1255             + "5. last item")
1256     public void getNormalizedTextWhiteSpaceOrderedList() throws Exception {
1257         getNormalizedTextWhiteSpaceOrderedList(null);
1258     }
1259 
1260     /**
1261      * Verifies getNormalizedText().
1262      * @throws Exception if the test fails
1263      */
1264     @Test
1265     @Alerts("1. first item\n"
1266             + "2. A B C D EF G H \n"
1267             + " I\n"
1268             + "3. third item\n"
1269             + "4. 4. item\n"
1270             + "some text\n"
1271             + "5. last item")
1272     public void getNormalizedTextWhiteSpaceOrderedListNormal() throws Exception {
1273         getNormalizedTextWhiteSpaceOrderedList("normal");
1274     }
1275 
1276     /**
1277      * Verifies getNormalizedText().
1278      * @throws Exception if the test fails
1279      */
1280     @Test
1281     @Alerts("1. first item\n"
1282             + "2. A B C D EF G H \n"
1283             + " I\n"
1284             + "3. third item\n"
1285             + "4. 4. item\n"
1286             + "some text\n"
1287             + "5. last item")
1288     public void getNormalizedTextWhiteSpaceOrderedListNowrap() throws Exception {
1289         getNormalizedTextWhiteSpaceOrderedList("nowrap");
1290     }
1291 
1292     /**
1293      * Verifies getNormalizedText().
1294      * @throws Exception if the test fails
1295      */
1296     @Test
1297     @Alerts("1. first item\n"
1298             + "2. A B C D EF G H \n"
1299             + " I\n"
1300             + "3. third item\n"
1301             + "4. 4. item\n"
1302             + "some text\n"
1303             + "5. last item")
1304     public void getNormalizedTextWhiteSpaceOrderedListPre() throws Exception {
1305         getNormalizedTextWhiteSpaceOrderedList("pre");
1306     }
1307 
1308     /**
1309      * Verifies getNormalizedText().
1310      * @throws Exception if the test fails
1311      */
1312     @Test
1313     @Alerts("1. first item\n"
1314             + "2. A B C D EF G H \n"
1315             + " I\n"
1316             + "3. third item\n"
1317             + "4. 4. item\n"
1318             + "some text\n"
1319             + "5. last item")
1320     public void getNormalizedTextWhiteSpaceOrderedListPreWrap() throws Exception {
1321         getNormalizedTextWhiteSpaceOrderedList("pre-wrap");
1322     }
1323 
1324     /**
1325      * Verifies getNormalizedText().
1326      * @throws Exception if the test fails
1327      */
1328     @Test
1329     @Alerts("1. first item\n"
1330             + "2. A B C D EF G H \n"
1331             + " I\n"
1332             + "3. third item\n"
1333             + "4. 4. item\n"
1334             + "some text\n"
1335             + "5. last item")
1336     public void getNormalizedTextWhiteSpaceOrderedListPreLine() throws Exception {
1337         getNormalizedTextWhiteSpaceOrderedList("pre-line");
1338     }
1339 
1340     private void getNormalizedTextWhiteSpaceOrderedList(final String whiteSpace) throws Exception {
1341         final String htmlContent = DOCTYPE_HTML
1342             + "<html>\n"
1343             + "<head></head>\n"
1344             + "<body>\n"
1345             + "  <ol id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1346             + "    <li>first item</li>\n"
1347             + "    <li>  A B  C\t \t  D \nEF\nG \n H  <br> I  </li>\n"
1348             + "    <li>third item</li><li>4. item</li>\n"
1349             + "    some text \n"
1350             + "    <li>last item</li>\n"
1351             + "  </ol>\n"
1352             + "</body></html>";
1353 
1354         final HtmlPage page = loadPage(htmlContent);
1355 
1356         final String text = page.getElementById("tester").asNormalizedText();
1357         assertEquals(getExpectedAlerts()[0], text);
1358     }
1359 
1360     /**
1361      * Verifies getNormalizedText().
1362      * @throws Exception if the test fails
1363      */
1364     @Test
1365     @Alerts("first item\n"
1366             + "A B C D EF G H \n"
1367             + " I\n"
1368             + "third item\n"
1369             + "4. item\n"
1370             + "some text\n"
1371             + "last item")
1372     public void getNormalizedTextWhiteSpaceUnorderedList() throws Exception {
1373         getNormalizedTextWhiteSpaceUnorderedList(null);
1374     }
1375 
1376     /**
1377      * Verifies getNormalizedText().
1378      * @throws Exception if the test fails
1379      */
1380     @Test
1381     @Alerts("first item\n"
1382             + "A B C D EF G H \n"
1383             + " I\n"
1384             + "third item\n"
1385             + "4. item\n"
1386             + "some text\n"
1387             + "last item")
1388     public void getNormalizedTextWhiteSpaceUnorderedListNormal() throws Exception {
1389         getNormalizedTextWhiteSpaceUnorderedList("normal");
1390     }
1391 
1392     /**
1393      * Verifies getNormalizedText().
1394      * @throws Exception if the test fails
1395      */
1396     @Test
1397     @Alerts("first item\n"
1398             + "A B C D EF G H \n"
1399             + " I\n"
1400             + "third item\n"
1401             + "4. item\n"
1402             + "some text\n"
1403             + "last item")
1404     public void getNormalizedTextWhiteSpaceUnorderedListNowrap() throws Exception {
1405         getNormalizedTextWhiteSpaceUnorderedList("nowrap");
1406     }
1407 
1408     /**
1409      * Verifies getNormalizedText().
1410      * @throws Exception if the test fails
1411      */
1412     @Test
1413     @Alerts("first item\n"
1414             + "A B C D EF G H \n"
1415             + " I\n"
1416             + "third item\n"
1417             + "4. item\n"
1418             + "some text\n"
1419             + "last item")
1420     public void getNormalizedTextWhiteSpaceUnorderedListPre() throws Exception {
1421         getNormalizedTextWhiteSpaceUnorderedList("pre");
1422     }
1423 
1424     /**
1425      * Verifies getNormalizedText().
1426      * @throws Exception if the test fails
1427      */
1428     @Test
1429     @Alerts("first item\n"
1430             + "A B C D EF G H \n"
1431             + " I\n"
1432             + "third item\n"
1433             + "4. item\n"
1434             + "some text\n"
1435             + "last item")
1436     public void getNormalizedTextWhiteSpaceUnorderedListPreWrap() throws Exception {
1437         getNormalizedTextWhiteSpaceUnorderedList("pre-wrap");
1438     }
1439 
1440     /**
1441      * Verifies getNormalizedText().
1442      * @throws Exception if the test fails
1443      */
1444     @Test
1445     @Alerts("first item\n"
1446             + "A B C D EF G H \n"
1447             + " I\n"
1448             + "third item\n"
1449             + "4. item\n"
1450             + "some text\n"
1451             + "last item")
1452     public void getNormalizedTextWhiteSpaceUnorderedListPreLine() throws Exception {
1453         getNormalizedTextWhiteSpaceUnorderedList("pre-line");
1454     }
1455 
1456     private void getNormalizedTextWhiteSpaceUnorderedList(final String whiteSpace) throws Exception {
1457         final String htmlContent = DOCTYPE_HTML
1458             + "<html>\n"
1459             + "<head></head>\n"
1460             + "<body>\n"
1461             + "  <ul id='tester' " + (whiteSpace == null ? "" : ("style='white-space: " + whiteSpace + "'")) + ">\n"
1462             + "    <li>first item</li>\n"
1463             + "    <li>  A B  C\t \t  D \nEF\nG \n H  <br> I  </li>\n"
1464             + "    <li>third item</li><li>4. item</li>\n"
1465             + "    some text \n"
1466             + "    <li>last item</li>\n"
1467             + "  </ul>\n"
1468             + "</body></html>";
1469 
1470         final HtmlPage page = loadPage(htmlContent);
1471 
1472         final String text = page.getElementById("tester").asNormalizedText();
1473         assertEquals(getExpectedAlerts()[0], text);
1474     }
1475 
1476     /**
1477      * Verifies getNormalizedText().
1478      * @throws Exception if the test fails
1479      */
1480     @Test
1481     @Alerts("The text to be tested")
1482     public void getNormalizedTextLabel() throws Exception {
1483         getNormalizedTextFormated("<label id='tester'>The text to be <span>tested</span></label>");
1484     }
1485 
1486     /**
1487      * Verifies getNormalizedText().
1488      * @throws Exception if the test fails
1489      */
1490     @Test
1491     @Alerts("The text to be tested")
1492     public void getNormalizedTextLabelNormal() throws Exception {
1493         getNormalizedTextFormated("<label id='tester' style='white-space: normal'>"
1494                 + "The text to be <span>tested</span></label>");
1495     }
1496 
1497     /**
1498      * Verifies getNormalizedText().
1499      * @throws Exception if the test fails
1500      */
1501     @Test
1502     @Alerts("The text to be tested")
1503     public void getNormalizedTextLabelNowrap() throws Exception {
1504         getNormalizedTextFormated("<label id='tester' style='white-space: nowrap'>"
1505                 + "The text to be <span>tested</span></label>");
1506     }
1507 
1508     /**
1509      * Verifies getNormalizedText().
1510      * @throws Exception if the test fails
1511      */
1512     @Test
1513     @Alerts("The text to be tested")
1514     public void getNormalizedTextLabelPre() throws Exception {
1515         getNormalizedTextFormated("<label id='tester' style='white-space: pre'>"
1516                 + "The text to be <span>tested</span></label>");
1517     }
1518 
1519     /**
1520      * Verifies getNormalizedText().
1521      * @throws Exception if the test fails
1522      */
1523     @Test
1524     @Alerts("The text to be tested")
1525     public void getNormalizedTextLabelPreWrap() throws Exception {
1526         getNormalizedTextFormated("<label id='tester' style='white-space: pre-wrap'>"
1527                 + "The text to be <span>tested</span></label>");
1528     }
1529 
1530     /**
1531      * Verifies getNormalizedText().
1532      * @throws Exception if the test fails
1533      */
1534     @Test
1535     @Alerts("The text to be tested")
1536     public void getNormalizedTextLabelPreLine() throws Exception {
1537         getNormalizedTextFormated("<label id='tester' style='white-space: pre-line'>"
1538                 + "The text to be <span>tested</span></label>");
1539     }
1540 
1541     /**
1542      * Verifies getNormalizedText().
1543      * @throws Exception if the test fails
1544      */
1545     @Test
1546     @Alerts("A   nbsp and spaces")
1547     public void getNormalizedTextParagraphNbsp() throws Exception {
1548         getNormalizedTextFormated("<p id='tester'>A &nbsp; nbsp and spaces</p>");
1549     }
1550 
1551     /**
1552      * Verifies getNormalizedText().
1553      * @throws Exception if the test fails
1554      */
1555     @Test
1556     @Alerts("A   nbsp and spaces")
1557     public void getNormalizedTextParagraphNbspNormal() throws Exception {
1558         getNormalizedTextFormated("<p id='tester' style='white-space: normal'>"
1559                 + "A &nbsp; nbsp and spaces</p>");
1560     }
1561 
1562     /**
1563      * Verifies getNormalizedText().
1564      * @throws Exception if the test fails
1565      */
1566     @Test
1567     @Alerts("A   nbsp and spaces")
1568     public void getNormalizedTextParagraphNbspNowrap() throws Exception {
1569         getNormalizedTextFormated("<p id='tester' style='white-space: nowrap'>"
1570                 + "A &nbsp; nbsp and spaces</p>");
1571     }
1572 
1573     /**
1574      * Verifies getNormalizedText().
1575      * @throws Exception if the test fails
1576      */
1577     @Test
1578     @Alerts("A   nbsp and spaces")
1579     public void getNormalizedTextParagraphNbspPre() throws Exception {
1580         getNormalizedTextFormated("<p id='tester' style='white-space: pre'>"
1581                 + "A &nbsp; nbsp and spaces</p>");
1582     }
1583 
1584     /**
1585      * Verifies getNormalizedText().
1586      * @throws Exception if the test fails
1587      */
1588     @Test
1589     @Alerts("A   nbsp and spaces")
1590     public void getNormalizedTextParagraphNbspPreWrap() throws Exception {
1591         getNormalizedTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1592                 + "A &nbsp; nbsp and spaces</p>");
1593     }
1594 
1595     /**
1596      * Verifies getNormalizedText().
1597      * @throws Exception if the test fails
1598      */
1599     @Test
1600     @Alerts("A   nbsp and spaces")
1601     public void getNormalizedTextParagraphNbspPreLine() throws Exception {
1602         getNormalizedTextFormated("<p id='tester' style='white-space: pre-line'>"
1603                 + "A &nbsp; nbsp and spaces</p>");
1604     }
1605 
1606     /**
1607      * Verifies getNormalizedText().
1608      * @throws Exception if the test fails
1609      */
1610     @Test
1611     @Alerts("A  \n"
1612             + "  NBSPs  ")
1613     public void getNormalizedTextParagraphMultilineNbsp() throws Exception {
1614         getNormalizedTextFormated("<p id='tester'>A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1615     }
1616 
1617     /**
1618      * Verifies getNormalizedText().
1619      * @throws Exception if the test fails
1620      */
1621     @Test
1622     @Alerts("A  \n"
1623             + "  NBSPs  ")
1624     public void getNormalizedTextParagraphMultilineNbspNormal() throws Exception {
1625         getNormalizedTextFormated("<p id='tester' style='white-space: normal'>"
1626                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1627     }
1628 
1629     /**
1630      * Verifies getNormalizedText().
1631      * @throws Exception if the test fails
1632      */
1633     @Test
1634     @Alerts("A  \n"
1635             + "  NBSPs  ")
1636     public void getNormalizedTextParagraphMultilineNbspNowrap() throws Exception {
1637         getNormalizedTextFormated("<p id='tester' style='white-space: nowrap'>"
1638                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1639     }
1640 
1641     /**
1642      * Verifies getNormalizedText().
1643      * @throws Exception if the test fails
1644      */
1645     @Test
1646     @Alerts("A  \n"
1647             + "  NBSPs  ")
1648     public void getNormalizedTextParagraphMultilineNbspPre() throws Exception {
1649         getNormalizedTextFormated("<p id='tester' style='white-space: pre'>"
1650                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1651     }
1652 
1653     /**
1654      * Verifies getNormalizedText().
1655      * @throws Exception if the test fails
1656      */
1657     @Test
1658     @Alerts("A  \n"
1659             + "  NBSPs  ")
1660     public void getNormalizedTextParagraphMultilineNbspPreWrap() throws Exception {
1661         getNormalizedTextFormated("<p id='tester' style='white-space: pre-wrap'>"
1662                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1663     }
1664 
1665     /**
1666      * Verifies getNormalizedText().
1667      * @throws Exception if the test fails
1668      */
1669     @Test
1670     @Alerts("A  \n"
1671             + "  NBSPs  ")
1672     public void getNormalizedTextParagraphMultilineNbspPreLine() throws Exception {
1673         getNormalizedTextFormated("<p id='tester' style='white-space: pre-line'>"
1674                 + "A &nbsp<br />&nbsp NBSPs&nbsp;&nbsp;</p>");
1675     }
1676 
1677     /**
1678      * Verifies getNormalizedText() for issue #128
1679      * (https://github.com/HtmlUnit/htmlunit/issues/128).
1680      * @throws Exception if the test fails
1681      */
1682     @Test
1683     @Alerts("I have 2 out of 2 stamps")
1684     public void getNormalizedTextInputInsideP() throws Exception {
1685         getNormalizedTextFormated("<p id='tester'>"
1686                 + " I have <input type='number' value='2'/> out of 2 stamps</p>");
1687     }
1688 
1689 
1690     /**
1691      * @throws Exception if the test fails
1692      */
1693     @Test
1694     @Alerts("Sum")
1695     public void getNormalizedTextDetails() throws Exception {
1696         getNormalizedTextFormated("<details id='tester'>"
1697                 + "<summary>Sum</summary>"
1698                 + "<p>detail</p>"
1699                 + "</details>");
1700     }
1701 
1702     /**
1703      * @throws Exception if the test fails
1704      */
1705     @Test
1706     @Alerts("Sum\nSum2")
1707     public void getNormalizedTextDetailsTwoSums() throws Exception {
1708         getNormalizedTextFormated("<details id='tester'>"
1709                 + "<summary>Sum</summary>"
1710                 + "<summary>Sum2</summary>"
1711                 + "<p>detail</p>"
1712                 + "</details>");
1713     }
1714 
1715     /**
1716      * @throws Exception if the test fails
1717      */
1718     @Test
1719     @Alerts("Sum\ndetail")
1720     public void getNormalizedTextDetailsOpen() throws Exception {
1721         getNormalizedTextFormated("<details id='tester' open=true>"
1722                 + "<summary>Sum</summary>"
1723                 + "<p>detail</p>"
1724                 + "</details>");
1725     }
1726 
1727     private void getNormalizedTextFormated(final String htmlTesterSnipped) throws Exception {
1728         final String htmlContent = DOCTYPE_HTML
1729             + "<html>\n"
1730             + "<head></head>\n"
1731             + "<body>\n"
1732             + "  " + htmlTesterSnipped + "\n"
1733             + "</body></html>";
1734 
1735         final HtmlPage page = loadPage(htmlContent);
1736 
1737         final String text = page.getBody().asNormalizedText();
1738         assertEquals(getExpectedAlerts()[0], text);
1739     }
1740 
1741     /**
1742      * @throws Exception if an error occurs
1743      */
1744     @Test
1745     @Alerts("01 Jan 2021")
1746     public void asTextInsideSpan() throws Exception {
1747         final String html = DOCTYPE_HTML
1748             + "<html><body><form>\n"
1749             + "<span id='test'>\n"
1750             + "  <select name='day' size='1'>"
1751                     + "<option value='1' selected>01</option>"
1752                     + "<option value='2'>02</option></select>\n"
1753             + "  <select name='month' size='1'>"
1754                     + "<option value='1' selected>Jan</option>"
1755                     + "<option value='2'>Feb</option></select>\n"
1756             + "  <select name='year' size='1'>"
1757                     + "<option value='1'>2022</option>"
1758                     + "<option value='2' selected>2021</option></select>\n"
1759             + "</span>"
1760             + "</form></body></html>";
1761         final HtmlPage page = loadPage(html);
1762         final DomElement elem = page.getElementById("test");
1763         assertEquals(getExpectedAlerts()[0], elem.asNormalizedText());
1764     }
1765 
1766     /**
1767      * Tests getTableCell(int,int).
1768      * @exception Exception If the test fails
1769      */
1770     @Test
1771     public void getCellAt() throws Exception {
1772         final String htmlContent = DOCTYPE_HTML
1773             + "<html>"
1774             + "<body>\n"
1775             + "<table id='table1' summary='Test table'>\n"
1776             + "<tr>"
1777                 + "<td><a>cell1a</a><div><span>cell1b</span></div></td>"
1778                 + "<td>cell2</td><td rowspan='2'>cell4</td>"
1779             + "</tr>\n"
1780             + "<tr>"
1781                 + "<td colspan='2'>cell3</td>"
1782             + "</tr>\n"
1783             + "</table>\n"
1784             + "</body></html>";
1785         final HtmlPage page = loadPage(htmlContent);
1786 
1787         final HtmlTable table = page.getHtmlElementById("table1");
1788 
1789         final HtmlTableCell cell1 = table.getCellAt(0, 0);
1790         // assertEquals("cell1 contents", "cell1acell1b", cell1.asNormalizedText());
1791         assertEquals("cell1 contents", "cell1a\ncell1b", cell1.asNormalizedText());
1792 
1793         final HtmlTableCell cell2 = table.getCellAt(0, 1);
1794         assertEquals("cell2 contents", "cell2", cell2.asNormalizedText());
1795 
1796         final HtmlTableCell cell3 = table.getCellAt(1, 0);
1797         assertEquals("cell3 contents", "cell3", cell3.asNormalizedText());
1798         assertSame("cells (1,0) and (1,1)", cell3, table.getCellAt(1, 1));
1799 
1800         final HtmlTableCell cell4 = table.getCellAt(0, 2);
1801         assertEquals("cell4 contents", "cell4", cell4.asNormalizedText());
1802         assertSame("cells (0,2) and (1,2)", cell4, table.getCellAt(1, 2));
1803     }
1804 
1805     /**
1806      * Tests getTableCell(int,int).
1807      * @exception Exception If the test fails
1808      */
1809     @Test
1810     public void getCellAtWithBreaks() throws Exception {
1811         final String htmlContent = DOCTYPE_HTML
1812             + "<html>"
1813             + "<body>\n"
1814             + "<table id='table1' summary='Test table'>\n"
1815             + "<tr>"
1816                 + "<td><a>cell1a</a><div><br><span>cell1b</span></div></td>"
1817                 + "<td>cell2</td><td rowspan='2'>cell4</td>"
1818             + "</tr>\n"
1819             + "<tr>"
1820                 + "<td colspan='2'>cell3</td>"
1821             + "</tr>\n"
1822             + "</table>\n"
1823             + "</body></html>";
1824         final HtmlPage page = loadPage(htmlContent);
1825 
1826         final HtmlTable table = page.getHtmlElementById("table1");
1827 
1828         final HtmlTableCell cell1 = table.getCellAt(0, 0);
1829         // assertEquals("cell1 contents", "cell1a\ncell1b", cell1.asNormalizedText());
1830         assertEquals("cell1 contents", "cell1a\n\ncell1b", cell1.asNormalizedText());
1831 
1832         final HtmlTableCell cell2 = table.getCellAt(0, 1);
1833         assertEquals("cell2 contents", "cell2", cell2.asNormalizedText());
1834 
1835         final HtmlTableCell cell3 = table.getCellAt(1, 0);
1836         assertEquals("cell3 contents", "cell3", cell3.asNormalizedText());
1837         assertSame("cells (1,0) and (1,1)", cell3, table.getCellAt(1, 1));
1838 
1839         final HtmlTableCell cell4 = table.getCellAt(0, 2);
1840         assertEquals("cell4 contents", "cell4", cell4.asNormalizedText());
1841         assertSame("cells (0,2) and (1,2)", cell4, table.getCellAt(1, 2));
1842     }
1843 
1844 
1845     /**
1846      * @throws Exception if the test fails
1847      */
1848     @Test
1849     @Alerts("x 12 y")
1850     public void getNormalizedNumberInputValidNumber() throws Exception {
1851         getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "12");
1852     }
1853 
1854     /**
1855      * @throws Exception if the test fails
1856      */
1857     @Test
1858     @Alerts(DEFAULT = "x y",
1859             FF = "x ab y",
1860             FF_ESR = "x ab y")
1861     public void getNormalizedNumberInputInvalidNumber() throws Exception {
1862         getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "ab");
1863     }
1864 
1865     /**
1866      * @throws Exception if the test fails
1867      */
1868     @Test
1869     @Alerts("x - y")
1870     public void getNormalizedNumberInputMinusOnly() throws Exception {
1871         getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "-");
1872     }
1873 
1874     /**
1875      * @throws Exception if the test fails
1876      */
1877     @Test
1878     @Alerts("x + y")
1879     public void getNormalizedNumberInputPlusOnly() throws Exception {
1880         getNormalizedTextFormatedAfterTyping("<p id='tester'>x<input id='inpt' type='number' value=''/>y</p>", "+");
1881     }
1882 
1883     /**
1884      * @throws Exception if the test fails
1885      */
1886     @Test
1887     @Alerts("demo")
1888     public void getVisibleEm() throws Exception {
1889         getNormalizedTextFormated("<em id='tester'>demo</em>");
1890     }
1891 
1892     private void getNormalizedTextFormatedAfterTyping(final String htmlTesterSnipped,
1893                         final String... typed) throws Exception {
1894         final String htmlContent = DOCTYPE_HTML
1895             + "<html>\n"
1896             + "<head></head>\n"
1897             + "<body>\n"
1898             + "  " + htmlTesterSnipped + "\n"
1899             + "</body></html>";
1900 
1901         final HtmlPage page = loadPage(htmlContent);
1902 
1903         final HtmlNumberInput input = page.getHtmlElementById("inpt");
1904         for (final String string : typed) {
1905             input.type(string);
1906         }
1907 
1908         final HtmlElement tester = page.getHtmlElementById("tester");
1909         assertEquals(getExpectedAlerts()[0], tester.asNormalizedText());
1910     }
1911 }