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