TestWindowTitle.java revision 3294:9adfb22ff08f
11590Srgrimes/* 239230Sgibbs * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. 339230Sgibbs * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 439230Sgibbs * 539230Sgibbs * This code is free software; you can redistribute it and/or modify it 639230Sgibbs * under the terms of the GNU General Public License version 2 only, as 739230Sgibbs * published by the Free Software Foundation. 839230Sgibbs * 939230Sgibbs * This code is distributed in the hope that it will be useful, but WITHOUT 1039230Sgibbs * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1139230Sgibbs * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1239230Sgibbs * version 2 for more details (a copy is included in the LICENSE file that 1339230Sgibbs * accompanied this code). 1439230Sgibbs * 1539230Sgibbs * You should have received a copy of the GNU General Public License version 1639230Sgibbs * 2 along with this work; if not, write to the Free Software Foundation, 1739230Sgibbs * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1839230Sgibbs * 1939230Sgibbs * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2039230Sgibbs * or visit www.oracle.com if you need additional information or have any 2139230Sgibbs * questions. 2239230Sgibbs */ 2339230Sgibbs 2439230Sgibbs/* 2539230Sgibbs * @test 2639230Sgibbs * @bug 8016675 8026736 2739230Sgibbs * @summary Test for window title. 2839230Sgibbs * @author Bhavesh Patel 291590Srgrimes * @library ../lib 301590Srgrimes * @modules jdk.javadoc/jdk.javadoc.internal.tool 311590Srgrimes * @build JavadocTester 321590Srgrimes * @run main TestWindowTitle 331590Srgrimes */ 341590Srgrimespublic class TestWindowTitle extends JavadocTester { 351590Srgrimes 361590Srgrimes public static void main(String... args) throws Exception { 371590Srgrimes TestWindowTitle tester = new TestWindowTitle(); 381590Srgrimes tester.runTests(); 391590Srgrimes tester.printSummary(); 401590Srgrimes } 411590Srgrimes 421590Srgrimes @Test 431590Srgrimes void testJavaScriptChars() { 441590Srgrimes // Window title with JavaScript special characters. 451590Srgrimes String title = "Testing \"Window 'Title'\" with a \\ backslash and a / " 461590Srgrimes + "forward slash and a \u00e8 unicode char also a tab and also a " 471590Srgrimes + "\t special character another \u0002 unicode)"; 481590Srgrimes 491590Srgrimes javadoc("-d", "out-js-chars", 501590Srgrimes "-windowtitle", title, 511590Srgrimes "-sourcepath", testSrc, 521590Srgrimes "p1", "p2"); 531590Srgrimes checkExit(Exit.OK); 541590Srgrimes 551590Srgrimes checkOutput("overview-summary.html", true, 561590Srgrimes "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " 571590Srgrimes + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " 581590Srgrimes + "also a tab and also a \\t special character another \\u0002 unicode))\";" 591590Srgrimes ); 601590Srgrimes 6187715Smarkm checkOutput("overview-summary.html", false, 621590Srgrimes "parent.document.title=\"Overview (Testing \"Window \'Title\'\" " 6387715Smarkm + "with a \\ backslash and a / forward slash and a \u00E8 unicode char " 6487715Smarkm + "also a tab and also a \t special character another \u0002 unicode))\";" 6587715Smarkm ); 6687715Smarkm } 6787715Smarkm 6887715Smarkm @Test 691590Srgrimes void testScriptTag() { 701590Srgrimes // Window title with a script tag. 7174671Stmm String title = "Testing script tag in title </title><script>alert(\"Should not pop up\")</script>."; 721590Srgrimes 7387715Smarkm javadoc("-d", "out-script", 7487715Smarkm "-windowtitle", title, 751590Srgrimes "-sourcepath", testSrc, 761590Srgrimes "p1", "p2"); 7787715Smarkm checkExit(Exit.OK); 7887715Smarkm 7987715Smarkm checkOutput("overview-summary.html", true, 801590Srgrimes "parent.document.title=\"Overview (Testing script tag in title alert" 811590Srgrimes + "(\\\"Should not pop up\\\").)\";" 8240060Sobrien ); 831590Srgrimes 8439230Sgibbs checkOutput("p2/C2.html", true, 851590Srgrimes "parent.document.title=\"C2 (Testing script tag in title alert" 861590Srgrimes + "(\\\"Should not pop up\\\").)\";" 871590Srgrimes ); 881590Srgrimes 8939230Sgibbs checkOutput("overview-summary.html", false, 901590Srgrimes "parent.document.title=\"Overview (Testing script tag in title </title><script>" 911590Srgrimes + "alert(\\\"Should not pop up\\\")</script>.)\";" 9239230Sgibbs ); 931590Srgrimes 9439230Sgibbs checkOutput("p2/C2.html", false, 951590Srgrimes "parent.document.title=\"C2 (Testing script tag in title </title><script>" 961590Srgrimes + "alert(\\\"Should not pop up\\\")</script>.)\";" 971590Srgrimes ); 981590Srgrimes } 991590Srgrimes 1001590Srgrimes @Test 1011590Srgrimes void testHtmlTags() { 1021590Srgrimes // Window title with other HTML tags. 1031590Srgrimes String title = "Testing another <p>HTML</p> tag. Another <h1>tag</h1>. A " 1041590Srgrimes + "<span id=\"testTag\">tag with attributes</span>. <script and </p are not tags."; 1051590Srgrimes 1061590Srgrimes javadoc("-d", "out-html-tags", 1071590Srgrimes "-windowtitle", title, 1081590Srgrimes "-sourcepath", testSrc, 1091590Srgrimes "p1", "p2"); 1101590Srgrimes checkExit(Exit.OK); 1111590Srgrimes 1121590Srgrimes checkOutput("overview-summary.html", true, 1131590Srgrimes "parent.document.title=\"Overview (Testing another HTML tag. Another tag. A " 1141590Srgrimes + "tag with attributes. <script and </p are not tags.)\";" 1151590Srgrimes ); 1161590Srgrimes 11783131Sken checkOutput("overview-summary.html", false, 1181590Srgrimes "parent.document.title=\"Overview (Testing another <p>HTML</p> tag. Another " 11939230Sgibbs + "<h1>tag</h1>. A <span id=\"testTag\">tag with attributes</span>. <script and " 12039230Sgibbs + "</p are not tags.)\";" 12139230Sgibbs ); 12239230Sgibbs } 12339230Sgibbs 12439230Sgibbs @Test 12539230Sgibbs void testHtmlEntities() { 12639230Sgibbs // Window title using entities. 12739230Sgibbs String title = "Testing entities <script>alert(\"Should not pop up\")</script>."; 12839230Sgibbs 12939230Sgibbs javadoc("-d", "out-html-entities", 13039230Sgibbs "-windowtitle", title, 13139230Sgibbs "-sourcepath", testSrc, 1321590Srgrimes "p1", "p2"); 1331590Srgrimes 1341590Srgrimes checkOutput("overview-summary.html", true, 1351590Srgrimes "parent.document.title=\"Overview (Testing entities <script>alert(\\\"Should " 1361590Srgrimes + "not pop up\\\")</script>.)\";" 1371590Srgrimes ); 13839230Sgibbs 13969141Srwatson checkOutput("overview-summary.html", false, 14039230Sgibbs "parent.document.title=\"Overview (Testing entities alert(\\\"Should not pop up\\\").)\";" 14169141Srwatson ); 14287715Smarkm } 14387715Smarkm 14469141Srwatson @Test 14569141Srwatson void testEmptyTags() { 14669141Srwatson // Window title with just empty HTML tags. 14739230Sgibbs String title = "</title><script></script>"; 14839230Sgibbs 14939230Sgibbs javadoc("-d", "out-empty-tags", 15039230Sgibbs "-windowtitle", title, 15139230Sgibbs "-sourcepath", testSrc, 15239230Sgibbs "p1", "p2"); 15339230Sgibbs 15439230Sgibbs checkOutput("overview-summary.html", true, 15539230Sgibbs "parent.document.title=\"Overview\";" 15639230Sgibbs ); 15739230Sgibbs 15839230Sgibbs checkOutput("overview-summary.html", false, 15939230Sgibbs "parent.document.title=\"Overview (</title><script></script>)\";" 16083131Sken ); 16139230Sgibbs } 16239230Sgibbs 16339230Sgibbs @Test 16439230Sgibbs void testUnicode() { 16539230Sgibbs //Window title with unicode characters. 16639230Sgibbs String title = "Testing unicode \u003cscript\u003ealert(\"Should not pop up\")\u003c/script\u003e."; 16739230Sgibbs 16839230Sgibbs javadoc("-d", "out-unicode", 16939230Sgibbs "-windowtitle", title, 17039230Sgibbs "-sourcepath", testSrc, 17139230Sgibbs "p1", "p2"); 17239230Sgibbs checkExit(Exit.OK); 1731590Srgrimes 1741590Srgrimes checkOutput("overview-summary.html", true, 1751590Srgrimes "parent.document.title=\"Overview (Testing unicode alert(\\\"Should " 1761590Srgrimes + "not pop up\\\").)\";" 1771590Srgrimes ); 1781590Srgrimes 1791590Srgrimes checkOutput("overview-summary.html", false, 1801590Srgrimes "parent.document.title=\"Overview (Testing unicode <script>alert(\\\"Should not pop up\\\")" 1811590Srgrimes + "</script>.)\";" 1821590Srgrimes ); 1831590Srgrimes } 1841590Srgrimes 1851590Srgrimes @Test 1861590Srgrimes void testEmpty() { 1871590Srgrimes // An empty window title. 1881590Srgrimes String title = ""; 1894930Sbde javadoc("-d", "out-empty", 1901590Srgrimes "-windowtitle", title, 1911590Srgrimes "-sourcepath", testSrc, "p1", "p2"); 1921590Srgrimes checkExit(Exit.OK); 1931590Srgrimes 1941590Srgrimes checkOutput("overview-summary.html", true, 1951590Srgrimes "parent.document.title=\"Overview\";" 1961590Srgrimes ); 1971590Srgrimes } 1981590Srgrimes 1991590Srgrimes @Test 2001590Srgrimes void testDocTitle() { 20187715Smarkm // Window title with JavaScript special characters, specified with -doctitle 20239230Sgibbs String title = "Testing \"Window 'Title'\" with a \\ backslash and a / " 2031590Srgrimes + "forward slash and a \u00e8 unicode char also a tab and also a " 20439230Sgibbs + "\t special character another \u0002 unicode)"; 20550635Speter 20639230Sgibbs javadoc("-d", "out-doctitle", 20739230Sgibbs "-doctitle", title, 2081590Srgrimes "-sourcepath", testSrc, 2091590Srgrimes "p1", "p2"); 2101590Srgrimes checkExit(Exit.OK); 2111590Srgrimes 2121590Srgrimes checkOutput("overview-summary.html", false, 21350635Speter "parent.document.title=\"Overview (Testing \\\"Window \\\'Title\\\'\\\" " 2141590Srgrimes + "with a \\\\ backslash and a / forward slash and a \\u00E8 unicode char " 2151590Srgrimes + "also a tab and also a \\t special character another \\u0002 unicode)\";" 2161590Srgrimes ); 2171590Srgrimes } 2181590Srgrimes} 2191590Srgrimes