1/* 2 * Copyright (c) 2004, 2016, 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 4665566 4855876 7025314 8012375 8015997 8016328 8024756 8151921 27 * @summary Verify that the output has the right javascript. 28 * @author jamieh 29 * @library ../lib 30 * @modules jdk.javadoc 31 * @build JavadocTester 32 * @run main TestJavascript 33 */ 34 35public class TestJavascript extends JavadocTester { 36 37 public static void main(String... args) throws Exception { 38 TestJavascript tester = new TestJavascript(); 39 tester.runTests(); 40 } 41 42 @Test 43 void test() { 44 javadoc("-d", "out", 45 "-sourcepath", testSrc, 46 "pkg", testSrc("TestJavascript.java")); 47 checkExit(Exit.OK); 48 49 checkOutput("pkg/C.html", true, 50 "<a href=\"../index.html?pkg/C.html\" target=\"_top\">Frames</a>"); 51 52 checkOutput("TestJavascript.html", true, 53 "<a href=\"index.html?TestJavascript.html\" target=\"_top\">Frames</a>"); 54 55 checkOutput("index.html", true, 56 "<script type=\"text/javascript\">\n" 57 + " tmpTargetPage = \"\" + window.location.search;\n" 58 + " if (tmpTargetPage != \"\" && tmpTargetPage != \"undefined\")\n" 59 + " tmpTargetPage = tmpTargetPage.substring(1);\n" 60 + " if (tmpTargetPage.indexOf(\":\") != -1 || (tmpTargetPage != \"\" && !validURL(tmpTargetPage)))\n" 61 + " tmpTargetPage = \"undefined\";\n" 62 + " targetPage = tmpTargetPage;\n" 63 + " function validURL(url) {\n" 64 + " try {\n" 65 + " url = decodeURIComponent(url);\n" 66 + " }\n" 67 + " catch (error) {\n" 68 + " return false;\n" 69 + " }\n" 70 + " var pos = url.indexOf(\".html\");\n" 71 + " if (pos == -1 || pos != url.length - 5)\n" 72 + " return false;\n" 73 + " var allowNumber = false;\n" 74 + " var allowSep = false;\n" 75 + " var seenDot = false;\n" 76 + " for (var i = 0; i < url.length - 5; i++) {\n" 77 + " var ch = url.charAt(i);\n" 78 + " if ('a' <= ch && ch <= 'z' ||\n" 79 + " 'A' <= ch && ch <= 'Z' ||\n" 80 + " ch == '$' ||\n" 81 + " ch == '_' ||\n" 82 + " ch.charCodeAt(0) > 127) {\n" 83 + " allowNumber = true;\n" 84 + " allowSep = true;\n" 85 + " } else if ('0' <= ch && ch <= '9'\n" 86 + " || ch == '-') {\n" 87 + " if (!allowNumber)\n" 88 + " return false;\n" 89 + " } else if (ch == '/' || ch == '.') {\n" 90 + " if (!allowSep)\n" 91 + " return false;\n" 92 + " allowNumber = false;\n" 93 + " allowSep = false;\n" 94 + " if (ch == '.')\n" 95 + " seenDot = true;\n" 96 + " if (ch == '/' && seenDot)\n" 97 + " return false;\n" 98 + " } else {\n" 99 + " return false;\n" 100 + " }\n" 101 + " }\n" 102 + " return true;\n" 103 + " }\n" 104 + " function loadFrames() {\n" 105 + " if (targetPage != \"\" && targetPage != \"undefined\")\n" 106 + " top.classFrame.location = top.targetPage;\n" 107 + " }\n" 108 + "</script>"); 109 110 checkOutput("index.html", true, 111 "<body onload=\"loadFrames()\""); 112 113 //Make sure title javascript only runs if is-external is not true 114 checkOutput("pkg/C.html", true, 115 " try {\n" 116 + " if (location.href.indexOf('is-external=true') == -1) {\n" 117 + " parent.document.title=\"C\";\n" 118 + " }\n" 119 + " }\n" 120 + " catch(err) {\n" 121 + " }"); 122 } 123} 124