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