test/com/sun/javadoc/testWindowTitle/TestWindowTitle.java

Mon, 23 Jan 2017 17:03:12 -0800

author
asaha
date
Mon, 23 Jan 2017 17:03:12 -0800
changeset 3376
26c9abc6c440
parent 2319
bd5898d93742
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Merge

     1 /*
     2  * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 8016675 8026736
    27  * @summary Test for window title.
    28  * @author Bhavesh Patel
    29  * @library ../lib/
    30  * @build JavadocTester TestWindowTitle
    31  * @run main TestWindowTitle
    32  */
    34 public class TestWindowTitle extends JavadocTester {
    36     private static final String BUG_ID = "8016675";
    37     //Window title with JavaScript special characters.
    38     private static final String TITLE_JS_CHARS =
    39             "Testing \"Window 'Title'\" with a \\ backslash and a / " +
    40             "forward slash and a \u00e8 unicode char also a    tab and also a " +
    41             "\t special character another \u0002 unicode)";
    42     private static final String[] ARGS_JS_CHARS = new String[]{
    43         "-d", BUG_ID + "-1", "-windowtitle", TITLE_JS_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
    44     };
    45     private static final String[][] TEST_JS_CHARS = {
    46         {BUG_ID + "-1" + FS + "overview-summary.html",
    47             "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " +
    48             "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " +
    49             "also a    tab and also a \\t special character another \\u0002 unicode))\";"
    50         },
    51     };
    52     private static final String[][] NEG_TEST_JS_CHARS = {
    53         {BUG_ID + "-1" + FS + "overview-summary.html",
    54             "parent.document.title=\"Overview (Testing \"Window \'Title\'\" " +
    55             "with a \\ backslash and a / forward slash and a \u00E8 unicode char " +
    56             "also a    tab and also a \t special character another \u0002 unicode))\";"
    57         }
    58     };
    60     //Window title with a script tag.
    61     private static final String TITLE_SCRIPT_TAG =
    62             "Testing script tag in title </title><script>alert(\"Should not pop up\")</script>.";
    63     private static final String[] ARGS_SCRIPT_TAG = new String[]{
    64         "-d", BUG_ID + "-2", "-windowtitle", TITLE_SCRIPT_TAG, "-sourcepath", SRC_DIR, "p1", "p2"
    65     };
    66     private static final String[][] TEST_SCRIPT_TAG = {
    67         {BUG_ID + "-2" + FS + "overview-summary.html",
    68             "parent.document.title=\"Overview (Testing script tag in title alert" +
    69             "(\\\"Should not pop up\\\").)\";"
    70         },
    71         {BUG_ID + "-2" + FS + "p2" + FS + "C2.html",
    72             "parent.document.title=\"C2 (Testing script tag in title alert" +
    73             "(\\\"Should not pop up\\\").)\";"
    74         }
    75     };
    76     private static final String[][] NEG_TEST_SCRIPT_TAG = {
    77         {BUG_ID + "-2" + FS + "overview-summary.html",
    78             "parent.document.title=\"Overview (Testing script tag in title </title><script>" +
    79             "alert(\\\"Should not pop up\\\")</script>.)\";"
    80         },
    81         {BUG_ID + "-2" + FS + "p2" + FS + "C2.html",
    82             "parent.document.title=\"C2 (Testing script tag in title </title><script>" +
    83             "alert(\\\"Should not pop up\\\")</script>.)\";"
    84         }
    85     };
    87     //Window title with other HTML tags.
    88     private static final String TITLE_HTML_TAGS =
    89             "Testing another <p>HTML</p> tag. Another <h1>tag</h1>. A " +
    90             "<span id=\"testTag\">tag with attributes</span>. <script and </p are not tags.";
    91     private static final String[] ARGS_HTML_TAGS = new String[]{
    92         "-d", BUG_ID + "-3", "-windowtitle", TITLE_HTML_TAGS, "-sourcepath", SRC_DIR, "p1", "p2"
    93     };
    94     private static final String[][] TEST_HTML_TAGS = {
    95         {BUG_ID + "-3" + FS + "overview-summary.html",
    96             "parent.document.title=\"Overview (Testing another HTML tag. Another tag. A " +
    97             "tag with attributes. <script and </p are not tags.)\";"
    98         }
    99     };
   100     private static final String[][] NEG_TEST_HTML_TAGS = {
   101         {BUG_ID + "-3" + FS + "overview-summary.html",
   102             "parent.document.title=\"Overview (Testing another <p>HTML</p> tag. Another " +
   103             "<h1>tag</h1>. A <span id=\"testTag\">tag with attributes</span>. <script and " +
   104             "</p are not tags.)\";"
   105         }
   106     };
   108     //Window title using entities.
   109     private static final String TITLE_HTML_ENTITIES =
   110             "Testing entities &lt;script&gt;alert(\"Should not pop up\")&lt;/script&gt;.";
   111     private static final String[] ARGS_HTML_ENTITIES = new String[]{
   112         "-d", BUG_ID + "-4", "-windowtitle", TITLE_HTML_ENTITIES, "-sourcepath", SRC_DIR, "p1", "p2"
   113     };
   114     private static final String[][] TEST_HTML_ENTITIES = {
   115         {BUG_ID + "-4" + FS + "overview-summary.html",
   116             "parent.document.title=\"Overview (Testing entities &lt;script&gt;alert(\\\"Should " +
   117             "not pop up\\\")&lt;/script&gt;.)\";"
   118         }
   119     };
   120     private static final String[][] NEG_TEST_HTML_ENTITIES = {
   121         {BUG_ID + "-4" + FS  + "overview-summary.html",
   122             "parent.document.title=\"Overview (Testing entities alert(\\\"Should not pop up\\\").)\";"
   123         }
   124     };
   126     //Window title with just empty HTML tags.
   127     private static final String TITLE_EMPTY_TAGS =
   128             "</title><script></script>";
   129     private static final String[] ARGS_EMPTY_TAGS = new String[]{
   130         "-d", BUG_ID + "-5", "-windowtitle", TITLE_EMPTY_TAGS, "-sourcepath", SRC_DIR, "p1", "p2"
   131     };
   132     private static final String[][] TEST_EMPTY_TAGS = {
   133         {BUG_ID + "-5" + FS + "overview-summary.html",
   134             "parent.document.title=\"Overview\";"
   135         }
   136     };
   137     private static final String[][] NEG_TEST_EMPTY_TAGS = {
   138         {BUG_ID + "-5" + FS + "overview-summary.html",
   139             "parent.document.title=\"Overview (</title><script></script>)\";"
   140         }
   141     };
   143     //Window title with unicode characters.
   144     private static final String TITLE_UNICODE_CHARS =
   145             "Testing unicode \u003cscript\u003ealert(\"Should not pop up\")\u003c/script\u003e.";
   146     private static final String[] ARGS_UNICODE_CHARS = new String[]{
   147         "-d", BUG_ID + "-6", "-windowtitle", TITLE_UNICODE_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
   148     };
   149     private static final String[][] TEST_UNICODE_CHARS = {
   150         {BUG_ID + "-6" + FS + "overview-summary.html",
   151             "parent.document.title=\"Overview (Testing unicode alert(\\\"Should " +
   152             "not pop up\\\").)\";"
   153         }
   154     };
   155     private static final String[][] NEG_TEST_UNICODE_CHARS = {
   156         {BUG_ID + "-6" + FS + "overview-summary.html",
   157             "parent.document.title=\"Overview (Testing unicode <script>alert(\\\"Should not pop up\\\")" +
   158             "</script>.)\";"
   159         }
   160     };
   162     //An empty window title.
   163     private static final String TITLE_EMPTY =
   164             "";
   165     private static final String[] ARGS_EMPTY_TITLE = new String[]{
   166         "-d", BUG_ID + "-7", "-windowtitle", TITLE_EMPTY, "-sourcepath", SRC_DIR, "p1", "p2"
   167     };
   168     private static final String[][] TEST_EMPTY = {
   169         {BUG_ID + "-7" + FS + "overview-summary.html",
   170             "parent.document.title=\"Overview\";"
   171         }
   172     };
   174     //Test doctitle.
   175     private static final String[] ARGS_DOCTITLE = new String[]{
   176         "-d", BUG_ID + "-8", "-doctitle", TITLE_JS_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
   177     };
   178     private static final String[][] NEG_TEST_DOCTITLE = {
   179         {BUG_ID + "-8" + FS + "overview-summary.html",
   180             "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " +
   181             "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " +
   182             "also a    tab and also a \\t special character another \\u0002 unicode)\";"
   183         },
   184     };
   186     /**
   187      * The entry point of the test.
   188      * @param args the array of command line arguments.
   189      */
   190     public static void main(String[] args) {
   191         TestWindowTitle tester = new TestWindowTitle();
   192         run(tester, ARGS_JS_CHARS, TEST_JS_CHARS, NEG_TEST_JS_CHARS);
   193         run(tester, ARGS_SCRIPT_TAG, TEST_SCRIPT_TAG, NEG_TEST_SCRIPT_TAG);
   194         run(tester, ARGS_HTML_TAGS, TEST_HTML_TAGS, NEG_TEST_HTML_TAGS);
   195         run(tester, ARGS_HTML_ENTITIES, TEST_HTML_ENTITIES, NEG_TEST_HTML_ENTITIES);
   196         run(tester, ARGS_EMPTY_TAGS, TEST_EMPTY_TAGS, NEG_TEST_EMPTY_TAGS);
   197         run(tester, ARGS_UNICODE_CHARS, TEST_UNICODE_CHARS, NEG_TEST_UNICODE_CHARS);
   198         run(tester, ARGS_EMPTY_TITLE, TEST_EMPTY, NO_TEST);
   199         run(tester, ARGS_DOCTITLE, NO_TEST, NEG_TEST_DOCTITLE);
   200         tester.printSummary();
   201     }
   203     /**
   204      * {@inheritDoc}
   205      */
   206     public String getBugId() {
   207         return BUG_ID;
   208     }
   210     /**
   211      * {@inheritDoc}
   212      */
   213     public String getBugName() {
   214         return getClass().getName();
   215     }
   216 }

mercurial