TestWindowTitle.java revision 3233:b5d08bc0d224
1/* 2 * Copyright (c) 2013, 2015, 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 */ 23 24/* 25 * @test 26 * @bug 8016675 8026736 27 * @summary Test for window title. 28 * @author Bhavesh Patel 29 * @library ../lib 30 * @modules jdk.javadoc 31 * @build JavadocTester 32 * @run main TestWindowTitle 33 */ 34public class TestWindowTitle extends JavadocTester { 35 36 public static void main(String... args) throws Exception { 37 TestWindowTitle tester = new TestWindowTitle(); 38 tester.runTests(); 39 tester.printSummary(); 40 } 41 42 @Test 43 void testJavaScriptChars() { 44 // Window title with JavaScript special characters. 45 String title = "Testing \"Window 'Title'\" with a \\ backslash and a / " 46 + "forward slash and a \u00e8 unicode char also a tab and also a " 47 + "\t special character another \u0002 unicode)"; 48 49 javadoc("-d", "out-js-chars", 50 "-windowtitle", title, 51 "-sourcepath", testSrc, 52 "p1", "p2"); 53 checkExit(Exit.OK); 54 55 checkOutput("overview-summary.html", true, 56 "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " 57 + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " 58 + "also a tab and also a \\t special character another \\u0002 unicode))\";" 59 ); 60 61 checkOutput("overview-summary.html", false, 62 "parent.document.title=\"Overview (Testing \"Window \'Title\'\" " 63 + "with a \\ backslash and a / forward slash and a \u00E8 unicode char " 64 + "also a tab and also a \t special character another \u0002 unicode))\";" 65 ); 66 } 67 68 @Test 69 void testScriptTag() { 70 // Window title with a script tag. 71 String title = "Testing script tag in title </title><script>alert(\"Should not pop up\")</script>."; 72 73 javadoc("-d", "out-script", 74 "-windowtitle", title, 75 "-sourcepath", testSrc, 76 "p1", "p2"); 77 checkExit(Exit.OK); 78 79 checkOutput("overview-summary.html", true, 80 "parent.document.title=\"Overview (Testing script tag in title alert" 81 + "(\\\"Should not pop up\\\").)\";" 82 ); 83 84 checkOutput("p2/C2.html", true, 85 "parent.document.title=\"C2 (Testing script tag in title alert" 86 + "(\\\"Should not pop up\\\").)\";" 87 ); 88 89 checkOutput("overview-summary.html", false, 90 "parent.document.title=\"Overview (Testing script tag in title </title><script>" 91 + "alert(\\\"Should not pop up\\\")</script>.)\";" 92 ); 93 94 checkOutput("p2/C2.html", false, 95 "parent.document.title=\"C2 (Testing script tag in title </title><script>" 96 + "alert(\\\"Should not pop up\\\")</script>.)\";" 97 ); 98 } 99 100 @Test 101 void testHtmlTags() { 102 // Window title with other HTML tags. 103 String title = "Testing another <p>HTML</p> tag. Another <h1>tag</h1>. A " 104 + "<span id=\"testTag\">tag with attributes</span>. <script and </p are not tags."; 105 106 javadoc("-d", "out-html-tags", 107 "-windowtitle", title, 108 "-sourcepath", testSrc, 109 "p1", "p2"); 110 checkExit(Exit.OK); 111 112 checkOutput("overview-summary.html", true, 113 "parent.document.title=\"Overview (Testing another HTML tag. Another tag. A " 114 + "tag with attributes. <script and </p are not tags.)\";" 115 ); 116 117 checkOutput("overview-summary.html", false, 118 "parent.document.title=\"Overview (Testing another <p>HTML</p> tag. Another " 119 + "<h1>tag</h1>. A <span id=\"testTag\">tag with attributes</span>. <script and " 120 + "</p are not tags.)\";" 121 ); 122 } 123 124 @Test 125 void testHtmlEntities() { 126 // Window title using entities. 127 String title = "Testing entities <script>alert(\"Should not pop up\")</script>."; 128 129 javadoc("-d", "out-html-entities", 130 "-windowtitle", title, 131 "-sourcepath", testSrc, 132 "p1", "p2"); 133 134 checkOutput("overview-summary.html", true, 135 "parent.document.title=\"Overview (Testing entities <script>alert(\\\"Should " 136 + "not pop up\\\")</script>.)\";" 137 ); 138 139 checkOutput("overview-summary.html", false, 140 "parent.document.title=\"Overview (Testing entities alert(\\\"Should not pop up\\\").)\";" 141 ); 142 } 143 144 @Test 145 void testEmptyTags() { 146 // Window title with just empty HTML tags. 147 String title = "</title><script></script>"; 148 149 javadoc("-d", "out-empty-tags", 150 "-windowtitle", title, 151 "-sourcepath", testSrc, 152 "p1", "p2"); 153 154 checkOutput("overview-summary.html", true, 155 "parent.document.title=\"Overview\";" 156 ); 157 158 checkOutput("overview-summary.html", false, 159 "parent.document.title=\"Overview (</title><script></script>)\";" 160 ); 161 } 162 163 @Test 164 void testUnicode() { 165 //Window title with unicode characters. 166 String title = "Testing unicode \u003cscript\u003ealert(\"Should not pop up\")\u003c/script\u003e."; 167 168 javadoc("-d", "out-unicode", 169 "-windowtitle", title, 170 "-sourcepath", testSrc, 171 "p1", "p2"); 172 checkExit(Exit.OK); 173 174 checkOutput("overview-summary.html", true, 175 "parent.document.title=\"Overview (Testing unicode alert(\\\"Should " 176 + "not pop up\\\").)\";" 177 ); 178 179 checkOutput("overview-summary.html", false, 180 "parent.document.title=\"Overview (Testing unicode <script>alert(\\\"Should not pop up\\\")" 181 + "</script>.)\";" 182 ); 183 } 184 185 @Test 186 void testEmpty() { 187 // An empty window title. 188 String title = ""; 189 javadoc("-d", "out-empty", 190 "-windowtitle", title, 191 "-sourcepath", testSrc, "p1", "p2"); 192 checkExit(Exit.OK); 193 194 checkOutput("overview-summary.html", true, 195 "parent.document.title=\"Overview\";" 196 ); 197 } 198 199 @Test 200 void testDocTitle() { 201 // Window title with JavaScript special characters, specified with -doctitle 202 String title = "Testing \"Window 'Title'\" with a \\ backslash and a / " 203 + "forward slash and a \u00e8 unicode char also a tab and also a " 204 + "\t special character another \u0002 unicode)"; 205 206 javadoc("-d", "out-doctitle", 207 "-doctitle", title, 208 "-sourcepath", testSrc, 209 "p1", "p2"); 210 checkExit(Exit.OK); 211 212 checkOutput("overview-summary.html", false, 213 "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " 214 + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " 215 + "also a tab and also a \\t special character another \\u0002 unicode)\";" 216 ); 217 } 218} 219