langtools/test/com/sun/javadoc/testWindowTitle/TestWindowTitle.java
changeset 24399 af1a0220d0fa
parent 24072 e7549dcbc4af
child 30730 d3ce7619db2c
equal deleted inserted replaced
24398:601a611d0aee 24399:af1a0220d0fa
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8016675 8026736
    26  * @bug 8016675 8026736
    27  * @summary Test for window title.
    27  * @summary Test for window title.
    28  * @author Bhavesh Patel
    28  * @author Bhavesh Patel
    29  * @library ../lib/
    29  * @library ../lib
    30  * @build JavadocTester TestWindowTitle
    30  * @build JavadocTester
    31  * @run main TestWindowTitle
    31  * @run main TestWindowTitle
    32  */
    32  */
    33 
       
    34 public class TestWindowTitle extends JavadocTester {
    33 public class TestWindowTitle extends JavadocTester {
    35 
    34 
    36     //Window title with JavaScript special characters.
    35     public static void main(String... args) throws Exception {
    37     private static final String TITLE_JS_CHARS =
    36         TestWindowTitle tester = new TestWindowTitle();
    38             "Testing \"Window 'Title'\" with a \\ backslash and a / " +
    37         tester.runTests();
    39             "forward slash and a \u00e8 unicode char also a    tab and also a " +
    38         tester.printSummary();
    40             "\t special character another \u0002 unicode)";
    39     }
    41     private static final String[] ARGS_JS_CHARS = new String[]{
    40 
    42         "-d", OUTPUT_DIR + "-1", "-windowtitle", TITLE_JS_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
    41     @Test
    43     };
    42     void testJavaScriptChars() {
    44     private static final String[][] TEST_JS_CHARS = {
    43         // Window title with JavaScript special characters.
    45         { "overview-summary.html",
    44         String title = "Testing \"Window 'Title'\" with a \\ backslash and a / "
    46             "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " +
    45                 + "forward slash and a \u00e8 unicode char also a    tab and also a "
    47             "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " +
    46                 + "\t special character another \u0002 unicode)";
    48             "also a    tab and also a \\t special character another \\u0002 unicode))\";"
    47 
    49         },
    48         javadoc("-d", "out-js-chars",
    50     };
    49                 "-windowtitle", title,
    51     private static final String[][] NEG_TEST_JS_CHARS = {
    50                 "-sourcepath", testSrc,
    52         { "overview-summary.html",
    51                 "p1", "p2");
    53             "parent.document.title=\"Overview (Testing \"Window \'Title\'\" " +
    52         checkExit(Exit.OK);
    54             "with a \\ backslash and a / forward slash and a \u00E8 unicode char " +
    53 
    55             "also a    tab and also a \t special character another \u0002 unicode))\";"
    54         checkOutput("overview-summary.html", true,
    56         }
    55                 "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" "
    57     };
    56                 + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char "
    58 
    57                 + "also a    tab and also a \\t special character another \\u0002 unicode))\";"
    59     //Window title with a script tag.
    58         );
    60     private static final String TITLE_SCRIPT_TAG =
    59 
    61             "Testing script tag in title </title><script>alert(\"Should not pop up\")</script>.";
    60         checkOutput("overview-summary.html", false,
    62     private static final String[] ARGS_SCRIPT_TAG = new String[]{
    61                 "parent.document.title=\"Overview (Testing \"Window \'Title\'\" "
    63         "-d", OUTPUT_DIR + "-2", "-windowtitle", TITLE_SCRIPT_TAG, "-sourcepath", SRC_DIR, "p1", "p2"
    62                 + "with a \\ backslash and a / forward slash and a \u00E8 unicode char "
    64     };
    63                 + "also a    tab and also a \t special character another \u0002 unicode))\";"
    65     private static final String[][] TEST_SCRIPT_TAG = {
    64         );
    66         { "overview-summary.html",
    65     }
    67             "parent.document.title=\"Overview (Testing script tag in title alert" +
    66 
    68             "(\\\"Should not pop up\\\").)\";"
    67     @Test
    69         },
    68     void testScriptTag() {
    70         { "p2/C2.html",
    69         // Window title with a script tag.
    71             "parent.document.title=\"C2 (Testing script tag in title alert" +
    70         String title = "Testing script tag in title </title><script>alert(\"Should not pop up\")</script>.";
    72             "(\\\"Should not pop up\\\").)\";"
    71 
    73         }
    72         javadoc("-d", "out-script",
    74     };
    73                 "-windowtitle", title,
    75     private static final String[][] NEG_TEST_SCRIPT_TAG = {
    74                 "-sourcepath", testSrc,
    76         { "overview-summary.html",
    75                 "p1", "p2");
    77             "parent.document.title=\"Overview (Testing script tag in title </title><script>" +
    76         checkExit(Exit.OK);
    78             "alert(\\\"Should not pop up\\\")</script>.)\";"
    77 
    79         },
    78         checkOutput("overview-summary.html", true,
    80         { "p2/C2.html",
    79                 "parent.document.title=\"Overview (Testing script tag in title alert"
    81             "parent.document.title=\"C2 (Testing script tag in title </title><script>" +
    80                 + "(\\\"Should not pop up\\\").)\";"
    82             "alert(\\\"Should not pop up\\\")</script>.)\";"
    81         );
    83         }
    82 
    84     };
    83         checkOutput("p2/C2.html", true,
    85 
    84                 "parent.document.title=\"C2 (Testing script tag in title alert"
    86     //Window title with other HTML tags.
    85                 + "(\\\"Should not pop up\\\").)\";"
    87     private static final String TITLE_HTML_TAGS =
    86         );
    88             "Testing another <p>HTML</p> tag. Another <h1>tag</h1>. A " +
    87 
    89             "<span id=\"testTag\">tag with attributes</span>. <script and </p are not tags.";
    88         checkOutput("overview-summary.html", false,
    90     private static final String[] ARGS_HTML_TAGS = new String[]{
    89                 "parent.document.title=\"Overview (Testing script tag in title </title><script>"
    91         "-d", OUTPUT_DIR + "-3", "-windowtitle", TITLE_HTML_TAGS,
    90                 + "alert(\\\"Should not pop up\\\")</script>.)\";"
    92         "-sourcepath", SRC_DIR,
    91         );
    93         "p1", "p2"
    92 
    94     };
    93         checkOutput("p2/C2.html", false,
    95     private static final String[][] TEST_HTML_TAGS = {
    94                 "parent.document.title=\"C2 (Testing script tag in title </title><script>"
    96         { "overview-summary.html",
    95                 + "alert(\\\"Should not pop up\\\")</script>.)\";"
    97             "parent.document.title=\"Overview (Testing another HTML tag. Another tag. A " +
    96         );
    98             "tag with attributes. <script and </p are not tags.)\";"
    97     }
    99         }
    98 
   100     };
    99     @Test
   101     private static final String[][] NEG_TEST_HTML_TAGS = {
   100     void testHtmlTags() {
   102         { "overview-summary.html",
   101         // Window title with other HTML tags.
   103             "parent.document.title=\"Overview (Testing another <p>HTML</p> tag. Another " +
   102         String title = "Testing another <p>HTML</p> tag. Another <h1>tag</h1>. A "
   104             "<h1>tag</h1>. A <span id=\"testTag\">tag with attributes</span>. <script and " +
   103                 + "<span id=\"testTag\">tag with attributes</span>. <script and </p are not tags.";
   105             "</p are not tags.)\";"
   104 
   106         }
   105         javadoc("-d", "out-html-tags",
   107     };
   106                 "-windowtitle", title,
   108 
   107                 "-sourcepath", testSrc,
   109     //Window title using entities.
   108                 "p1", "p2");
   110     private static final String TITLE_HTML_ENTITIES =
   109         checkExit(Exit.OK);
   111             "Testing entities &lt;script&gt;alert(\"Should not pop up\")&lt;/script&gt;.";
   110 
   112     private static final String[] ARGS_HTML_ENTITIES = new String[]{
   111         checkOutput("overview-summary.html", true,
   113         "-d", OUTPUT_DIR + "-4", "-windowtitle", TITLE_HTML_ENTITIES,
   112             "parent.document.title=\"Overview (Testing another HTML tag. Another tag. A "
   114         "-sourcepath", SRC_DIR,
   113             + "tag with attributes. <script and </p are not tags.)\";"
   115         "p1", "p2"
   114         );
   116     };
   115 
   117     private static final String[][] TEST_HTML_ENTITIES = {
   116         checkOutput("overview-summary.html", false,
   118         { "overview-summary.html",
   117             "parent.document.title=\"Overview (Testing another <p>HTML</p> tag. Another "
   119             "parent.document.title=\"Overview (Testing entities &lt;script&gt;alert(\\\"Should " +
   118             + "<h1>tag</h1>. A <span id=\"testTag\">tag with attributes</span>. <script and "
   120             "not pop up\\\")&lt;/script&gt;.)\";"
   119             + "</p are not tags.)\";"
   121         }
   120         );
   122     };
   121     }
   123     private static final String[][] NEG_TEST_HTML_ENTITIES = {
   122 
   124         { "overview-summary.html",
   123     @Test
       
   124     void testHtmlEntities() {
       
   125         // Window title using entities.
       
   126         String title = "Testing entities &lt;script&gt;alert(\"Should not pop up\")&lt;/script&gt;.";
       
   127 
       
   128         javadoc("-d", "out-html-entities",
       
   129                 "-windowtitle", title,
       
   130                 "-sourcepath", testSrc,
       
   131                 "p1", "p2");
       
   132 
       
   133         checkOutput("overview-summary.html", true,
       
   134             "parent.document.title=\"Overview (Testing entities &lt;script&gt;alert(\\\"Should "
       
   135             + "not pop up\\\")&lt;/script&gt;.)\";"
       
   136         );
       
   137 
       
   138         checkOutput("overview-summary.html", false,
   125             "parent.document.title=\"Overview (Testing entities alert(\\\"Should not pop up\\\").)\";"
   139             "parent.document.title=\"Overview (Testing entities alert(\\\"Should not pop up\\\").)\";"
   126         }
   140         );
   127     };
   141     }
   128 
   142 
   129     //Window title with just empty HTML tags.
   143     @Test
   130     private static final String TITLE_EMPTY_TAGS =
   144     void testEmptyTags() {
   131             "</title><script></script>";
   145         // Window title with just empty HTML tags.
   132     private static final String[] ARGS_EMPTY_TAGS = new String[]{
   146         String title = "</title><script></script>";
   133         "-d", OUTPUT_DIR + "-5", "-windowtitle", TITLE_EMPTY_TAGS, "-sourcepath", SRC_DIR, "p1", "p2"
   147 
   134     };
   148         javadoc("-d", "out-empty-tags",
   135     private static final String[][] TEST_EMPTY_TAGS = {
   149                 "-windowtitle", title,
   136         { "overview-summary.html",
   150                 "-sourcepath", testSrc,
       
   151                 "p1", "p2");
       
   152 
       
   153         checkOutput("overview-summary.html", true,
   137             "parent.document.title=\"Overview\";"
   154             "parent.document.title=\"Overview\";"
   138         }
   155         );
   139     };
   156 
   140     private static final String[][] NEG_TEST_EMPTY_TAGS = {
   157         checkOutput("overview-summary.html", false,
   141         { "overview-summary.html",
       
   142             "parent.document.title=\"Overview (</title><script></script>)\";"
   158             "parent.document.title=\"Overview (</title><script></script>)\";"
   143         }
   159         );
   144     };
   160     }
   145 
   161 
   146     //Window title with unicode characters.
   162     @Test
   147     private static final String TITLE_UNICODE_CHARS =
   163     void testUnicode() {
   148             "Testing unicode \u003cscript\u003ealert(\"Should not pop up\")\u003c/script\u003e.";
   164         //Window title with unicode characters.
   149     private static final String[] ARGS_UNICODE_CHARS = new String[]{
   165         String title = "Testing unicode \u003cscript\u003ealert(\"Should not pop up\")\u003c/script\u003e.";
   150         "-d", OUTPUT_DIR + "-6", "-windowtitle", TITLE_UNICODE_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
   166 
   151     };
   167         javadoc("-d", "out-unicode",
   152     private static final String[][] TEST_UNICODE_CHARS = {
   168                 "-windowtitle", title,
   153         { "overview-summary.html",
   169                 "-sourcepath", testSrc,
   154             "parent.document.title=\"Overview (Testing unicode alert(\\\"Should " +
   170                 "p1", "p2");
   155             "not pop up\\\").)\";"
   171         checkExit(Exit.OK);
   156         }
   172 
   157     };
   173         checkOutput("overview-summary.html", true,
   158     private static final String[][] NEG_TEST_UNICODE_CHARS = {
   174             "parent.document.title=\"Overview (Testing unicode alert(\\\"Should "
   159         { "overview-summary.html",
   175             + "not pop up\\\").)\";"
   160             "parent.document.title=\"Overview (Testing unicode <script>alert(\\\"Should not pop up\\\")" +
   176         );
   161             "</script>.)\";"
   177 
   162         }
   178         checkOutput("overview-summary.html", false,
   163     };
   179             "parent.document.title=\"Overview (Testing unicode <script>alert(\\\"Should not pop up\\\")"
   164 
   180             + "</script>.)\";"
   165     //An empty window title.
   181         );
   166     private static final String TITLE_EMPTY =
   182     }
   167             "";
   183 
   168     private static final String[] ARGS_EMPTY_TITLE = new String[]{
   184     @Test
   169         "-d", OUTPUT_DIR + "-7", "-windowtitle", TITLE_EMPTY, "-sourcepath", SRC_DIR, "p1", "p2"
   185     void testEmpty() {
   170     };
   186         // An empty window title.
   171     private static final String[][] TEST_EMPTY = {
   187         String title = "";
   172         { "overview-summary.html",
   188         javadoc("-d", "out-empty",
   173             "parent.document.title=\"Overview\";"
   189                 "-windowtitle", title,
   174         }
   190                 "-sourcepath", testSrc, "p1", "p2");
   175     };
   191         checkExit(Exit.OK);
   176 
   192 
   177     //Test doctitle.
   193         checkOutput("overview-summary.html", true,
   178     private static final String[] ARGS_DOCTITLE = new String[]{
   194                 "parent.document.title=\"Overview\";"
   179         "-d", OUTPUT_DIR + "-8", "-doctitle", TITLE_JS_CHARS, "-sourcepath", SRC_DIR, "p1", "p2"
   195         );
   180     };
   196     }
   181     private static final String[][] NEG_TEST_DOCTITLE = {
   197 
   182         { "overview-summary.html",
   198     @Test
   183             "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " +
   199     void testDocTitle() {
   184             "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " +
   200         // Window title with JavaScript special characters, specified with -doctitle
   185             "also a    tab and also a \\t special character another \\u0002 unicode)\";"
   201         String title = "Testing \"Window 'Title'\" with a \\ backslash and a / "
   186         },
   202                 + "forward slash and a \u00e8 unicode char also a    tab and also a "
   187     };
   203                 + "\t special character another \u0002 unicode)";
   188 
   204 
   189     /**
   205         javadoc("-d", "out-doctitle",
   190      * The entry point of the test.
   206                 "-doctitle", title,
   191      * @param args the array of command line arguments.
   207                 "-sourcepath", testSrc,
   192      */
   208                 "p1", "p2");
   193     public static void main(String[] args) {
   209         checkExit(Exit.OK);
   194         TestWindowTitle tester = new TestWindowTitle();
   210 
   195         tester.run(ARGS_JS_CHARS, TEST_JS_CHARS, NEG_TEST_JS_CHARS);
   211         checkOutput("overview-summary.html", false,
   196         tester.run(ARGS_SCRIPT_TAG, TEST_SCRIPT_TAG, NEG_TEST_SCRIPT_TAG);
   212             "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" "
   197         tester.run(ARGS_HTML_TAGS, TEST_HTML_TAGS, NEG_TEST_HTML_TAGS);
   213             + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char "
   198         tester.run(ARGS_HTML_ENTITIES, TEST_HTML_ENTITIES, NEG_TEST_HTML_ENTITIES);
   214             + "also a    tab and also a \\t special character another \\u0002 unicode)\";"
   199         tester.run(ARGS_EMPTY_TAGS, TEST_EMPTY_TAGS, NEG_TEST_EMPTY_TAGS);
   215         );
   200         tester.run(ARGS_UNICODE_CHARS, TEST_UNICODE_CHARS, NEG_TEST_UNICODE_CHARS);
       
   201         tester.run(ARGS_EMPTY_TITLE, TEST_EMPTY, NO_TEST);
       
   202         tester.run(ARGS_DOCTITLE, NO_TEST, NEG_TEST_DOCTITLE);
       
   203         tester.printSummary();
       
   204     }
   216     }
   205 }
   217 }