test/com/sun/javadoc/JavascriptWinTitle/JavascriptWinTitle.java

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

Initial load

duke@1 1 /*
duke@1 2 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
duke@1 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@1 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@1 21 * have any questions.
duke@1 22 */
duke@1 23
duke@1 24 /*
duke@1 25 * @test
duke@1 26 * @bug 4645058 4747738 4855054
duke@1 27 * @summary Javascript IE load error when linked by -linkoffline
duke@1 28 * Window title shouldn't change when loading left frames (javascript)
duke@1 29 * @author dkramer
duke@1 30 * @run main JavascriptWinTitle
duke@1 31 */
duke@1 32
duke@1 33
duke@1 34 import com.sun.javadoc.*;
duke@1 35 import java.util.*;
duke@1 36 import java.io.*;
duke@1 37
duke@1 38
duke@1 39 /**
duke@1 40 * Runs javadoc and runs regression tests on the resulting HTML.
duke@1 41 * It reads each file, complete with newlines, into a string to easily
duke@1 42 * find strings that contain newlines.
duke@1 43 */
duke@1 44 public class JavascriptWinTitle {
duke@1 45
duke@1 46 private static final String BUGID = "4645058";
duke@1 47 private static final String BUGNAME = "JavascriptWinTitle";
duke@1 48 private static final String FS = System.getProperty("file.separator");
duke@1 49 private static final String PS = System.getProperty("path.separator");
duke@1 50 private static final String LS = System.getProperty("line.separator");
duke@1 51 private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
duke@1 52 private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
duke@1 53
duke@1 54 // Subtest number. Needed because runResultsOnHTML is run twice,
duke@1 55 // and subtestNum should increment across subtest runs.
duke@1 56 public static int subtestNum = 0;
duke@1 57 public static int numSubtestsPassed = 0;
duke@1 58
duke@1 59 // Entry point
duke@1 60 public static void main(String[] args) {
duke@1 61
duke@1 62 // Directory that contains source files that javadoc runs on
duke@1 63 String srcdir = System.getProperty("test.src", ".");
duke@1 64
duke@1 65 // Test for all cases except the split index page
duke@1 66 runJavadoc(new String[] {"-d", TMPDEST_DIR1,
duke@1 67 "-doctitle", "Document Title",
duke@1 68 "-windowtitle", "Window Title",
duke@1 69 "-overview", (srcdir + FS + "overview.html"),
duke@1 70 "-linkoffline",
duke@1 71 "http://java.sun.com/j2se/1.4/docs/api", srcdir,
duke@1 72 "-sourcepath", srcdir,
duke@1 73 "p1", "p2"});
duke@1 74 runTestsOnHTML(testArray);
duke@1 75
duke@1 76 printSummary();
duke@1 77 }
duke@1 78
duke@1 79 /** Run javadoc */
duke@1 80 public static void runJavadoc(String[] javadocArgs) {
duke@1 81 if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
duke@1 82 throw new Error("Javadoc failed to execute");
duke@1 83 }
duke@1 84 }
duke@1 85
duke@1 86 /**
duke@1 87 * Assign value for [ stringToFind, filename ]
duke@1 88 * NOTE: The standard doclet uses the same separator "\n" for all OS's
duke@1 89 */
duke@1 90 private static final String[][] testArray = {
duke@1 91
duke@1 92 // Test the javascript "type" attribute is present:
duke@1 93 { "<SCRIPT type=\"text/javascript\">",
duke@1 94 TMPDEST_DIR1 + "overview-summary.html" },
duke@1 95
duke@1 96 // Test onload is present:
duke@1 97 { "onload=\"windowTitle();\"",
duke@1 98 TMPDEST_DIR1 + "overview-summary.html" },
duke@1 99
duke@1 100 // Test onload is present:
duke@1 101 { "onload=\"windowTitle();\"",
duke@1 102 TMPDEST_DIR1 + FS + "p1" + FS + "package-summary.html" },
duke@1 103
duke@1 104 // Test onload is present:
duke@1 105 { "onload=\"windowTitle();\"",
duke@1 106 TMPDEST_DIR1 + FS + "p1" + FS + "C.html" },
duke@1 107
duke@1 108 // Test that "onload" is not present in BODY tag:
duke@1 109 { "<BODY BGCOLOR=\"white\">",
duke@1 110 TMPDEST_DIR1 + "overview-frame.html" },
duke@1 111
duke@1 112 // Test that "onload" is not present in BODY tag:
duke@1 113 { "<BODY BGCOLOR=\"white\">",
duke@1 114 TMPDEST_DIR1 + "allclasses-frame.html" },
duke@1 115
duke@1 116 // Test that "onload" is not present in BODY tag:
duke@1 117 { "<BODY BGCOLOR=\"white\">",
duke@1 118 TMPDEST_DIR1 + FS + "p1" + FS + "package-frame.html" },
duke@1 119
duke@1 120 // Test that win title javascript is followed by NOSCRIPT code.
duke@1 121 {"<SCRIPT type=\"text/javascript\">" + LS +
duke@1 122 "function windowTitle()" + LS +
duke@1 123 "{" + LS +
duke@1 124 " if (location.href.indexOf('is-external=true') == -1) {" + LS +
duke@1 125 " parent.document.title=\"C (Window Title)\";" + LS +
duke@1 126 " }" + LS +
duke@1 127 "}" + LS +
duke@1 128 "</SCRIPT>" + LS +
duke@1 129 "<NOSCRIPT>" + LS +
duke@1 130 "</NOSCRIPT>",
duke@1 131 TMPDEST_DIR1 + FS + "p1" + FS + "C.html"
duke@1 132 }
duke@1 133
duke@1 134 };
duke@1 135
duke@1 136 public static void runTestsOnHTML(String[][] testArray) {
duke@1 137
duke@1 138 for (int i = 0; i < testArray.length; i++) {
duke@1 139
duke@1 140 subtestNum += 1;
duke@1 141
duke@1 142 // Read contents of file into a string
duke@1 143 String fileString = readFileToString(testArray[i][1]);
duke@1 144
duke@1 145 // Get string to find
duke@1 146 String stringToFind = testArray[i][0];
duke@1 147
duke@1 148 // Find string in file's contents
duke@1 149 if (findString(fileString, stringToFind) == -1) {
duke@1 150 System.out.println("\nSub-test " + (subtestNum)
duke@1 151 + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
duke@1 152 + "when searching for:\n"
duke@1 153 + stringToFind);
duke@1 154 } else {
duke@1 155 numSubtestsPassed += 1;
duke@1 156 System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
duke@1 157 }
duke@1 158 }
duke@1 159 }
duke@1 160
duke@1 161 public static void printSummary() {
duke@1 162 if ( numSubtestsPassed == subtestNum ) {
duke@1 163 System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
duke@1 164 } else {
duke@1 165 throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
duke@1 166 + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
duke@1 167 }
duke@1 168 }
duke@1 169
duke@1 170 // Read the file into a String
duke@1 171 public static String readFileToString(String filename) {
duke@1 172 try {
duke@1 173 File file = new File(filename);
duke@1 174 if ( !file.exists() ) {
duke@1 175 System.out.println("\nFILE DOES NOT EXIST: " + filename);
duke@1 176 }
duke@1 177 BufferedReader in = new BufferedReader(new FileReader(file));
duke@1 178
duke@1 179 // Create an array of characters the size of the file
duke@1 180 char[] allChars = new char[(int)file.length()];
duke@1 181
duke@1 182 // Read the characters into the allChars array
duke@1 183 in.read(allChars, 0, (int)file.length());
duke@1 184 in.close();
duke@1 185
duke@1 186 // Convert to a string
duke@1 187 String allCharsString = new String(allChars);
duke@1 188
duke@1 189 return allCharsString;
duke@1 190
duke@1 191 } catch (FileNotFoundException e) {
duke@1 192 System.err.println(e);
duke@1 193 return "";
duke@1 194 } catch (IOException e) {
duke@1 195 System.err.println(e);
duke@1 196 return "";
duke@1 197 }
duke@1 198 }
duke@1 199
duke@1 200 public static int findString(String fileString, String stringToFind) {
duke@1 201 return fileString.indexOf(stringToFind);
duke@1 202 }
duke@1 203 }

mercurial