10
|
1 |
/*
|
5520
|
2 |
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
|
10
|
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 |
*
|
5520
|
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.
|
10
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* @test
|
|
26 |
* @bug 4645058 4747738 4855054
|
|
27 |
* @summary Javascript IE load error when linked by -linkoffline
|
|
28 |
* Window title shouldn't change when loading left frames (javascript)
|
|
29 |
* @author dkramer
|
|
30 |
* @run main JavascriptWinTitle
|
|
31 |
*/
|
|
32 |
|
|
33 |
|
|
34 |
import com.sun.javadoc.*;
|
|
35 |
import java.util.*;
|
|
36 |
import java.io.*;
|
|
37 |
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Runs javadoc and runs regression tests on the resulting HTML.
|
|
41 |
* It reads each file, complete with newlines, into a string to easily
|
|
42 |
* find strings that contain newlines.
|
|
43 |
*/
|
|
44 |
public class JavascriptWinTitle {
|
|
45 |
|
|
46 |
private static final String BUGID = "4645058";
|
|
47 |
private static final String BUGNAME = "JavascriptWinTitle";
|
|
48 |
private static final String FS = System.getProperty("file.separator");
|
|
49 |
private static final String PS = System.getProperty("path.separator");
|
|
50 |
private static final String LS = System.getProperty("line.separator");
|
|
51 |
private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
|
|
52 |
private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
|
|
53 |
|
|
54 |
// Subtest number. Needed because runResultsOnHTML is run twice,
|
|
55 |
// and subtestNum should increment across subtest runs.
|
|
56 |
public static int subtestNum = 0;
|
|
57 |
public static int numSubtestsPassed = 0;
|
|
58 |
|
|
59 |
// Entry point
|
|
60 |
public static void main(String[] args) {
|
|
61 |
|
|
62 |
// Directory that contains source files that javadoc runs on
|
|
63 |
String srcdir = System.getProperty("test.src", ".");
|
|
64 |
|
|
65 |
// Test for all cases except the split index page
|
|
66 |
runJavadoc(new String[] {"-d", TMPDEST_DIR1,
|
|
67 |
"-doctitle", "Document Title",
|
|
68 |
"-windowtitle", "Window Title",
|
|
69 |
"-overview", (srcdir + FS + "overview.html"),
|
|
70 |
"-linkoffline",
|
|
71 |
"http://java.sun.com/j2se/1.4/docs/api", srcdir,
|
|
72 |
"-sourcepath", srcdir,
|
|
73 |
"p1", "p2"});
|
|
74 |
runTestsOnHTML(testArray);
|
|
75 |
|
|
76 |
printSummary();
|
|
77 |
}
|
|
78 |
|
|
79 |
/** Run javadoc */
|
|
80 |
public static void runJavadoc(String[] javadocArgs) {
|
|
81 |
if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
|
|
82 |
throw new Error("Javadoc failed to execute");
|
|
83 |
}
|
|
84 |
}
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Assign value for [ stringToFind, filename ]
|
|
88 |
* NOTE: The standard doclet uses the same separator "\n" for all OS's
|
|
89 |
*/
|
|
90 |
private static final String[][] testArray = {
|
|
91 |
|
|
92 |
// Test the javascript "type" attribute is present:
|
|
93 |
{ "<SCRIPT type=\"text/javascript\">",
|
|
94 |
TMPDEST_DIR1 + "overview-summary.html" },
|
|
95 |
|
|
96 |
// Test onload is present:
|
|
97 |
{ "onload=\"windowTitle();\"",
|
|
98 |
TMPDEST_DIR1 + "overview-summary.html" },
|
|
99 |
|
|
100 |
// Test onload is present:
|
|
101 |
{ "onload=\"windowTitle();\"",
|
|
102 |
TMPDEST_DIR1 + FS + "p1" + FS + "package-summary.html" },
|
|
103 |
|
|
104 |
// Test onload is present:
|
|
105 |
{ "onload=\"windowTitle();\"",
|
|
106 |
TMPDEST_DIR1 + FS + "p1" + FS + "C.html" },
|
|
107 |
|
|
108 |
// Test that "onload" is not present in BODY tag:
|
|
109 |
{ "<BODY BGCOLOR=\"white\">",
|
|
110 |
TMPDEST_DIR1 + "overview-frame.html" },
|
|
111 |
|
|
112 |
// Test that "onload" is not present in BODY tag:
|
|
113 |
{ "<BODY BGCOLOR=\"white\">",
|
|
114 |
TMPDEST_DIR1 + "allclasses-frame.html" },
|
|
115 |
|
|
116 |
// Test that "onload" is not present in BODY tag:
|
|
117 |
{ "<BODY BGCOLOR=\"white\">",
|
|
118 |
TMPDEST_DIR1 + FS + "p1" + FS + "package-frame.html" },
|
|
119 |
|
|
120 |
// Test that win title javascript is followed by NOSCRIPT code.
|
|
121 |
{"<SCRIPT type=\"text/javascript\">" + LS +
|
|
122 |
"function windowTitle()" + LS +
|
|
123 |
"{" + LS +
|
|
124 |
" if (location.href.indexOf('is-external=true') == -1) {" + LS +
|
|
125 |
" parent.document.title=\"C (Window Title)\";" + LS +
|
|
126 |
" }" + LS +
|
|
127 |
"}" + LS +
|
|
128 |
"</SCRIPT>" + LS +
|
|
129 |
"<NOSCRIPT>" + LS +
|
|
130 |
"</NOSCRIPT>",
|
|
131 |
TMPDEST_DIR1 + FS + "p1" + FS + "C.html"
|
|
132 |
}
|
|
133 |
|
|
134 |
};
|
|
135 |
|
|
136 |
public static void runTestsOnHTML(String[][] testArray) {
|
|
137 |
|
|
138 |
for (int i = 0; i < testArray.length; i++) {
|
|
139 |
|
|
140 |
subtestNum += 1;
|
|
141 |
|
|
142 |
// Read contents of file into a string
|
|
143 |
String fileString = readFileToString(testArray[i][1]);
|
|
144 |
|
|
145 |
// Get string to find
|
|
146 |
String stringToFind = testArray[i][0];
|
|
147 |
|
|
148 |
// Find string in file's contents
|
|
149 |
if (findString(fileString, stringToFind) == -1) {
|
|
150 |
System.out.println("\nSub-test " + (subtestNum)
|
|
151 |
+ " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
|
|
152 |
+ "when searching for:\n"
|
|
153 |
+ stringToFind);
|
|
154 |
} else {
|
|
155 |
numSubtestsPassed += 1;
|
|
156 |
System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
public static void printSummary() {
|
|
162 |
if ( numSubtestsPassed == subtestNum ) {
|
|
163 |
System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
|
|
164 |
} else {
|
|
165 |
throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
|
|
166 |
+ " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
// Read the file into a String
|
|
171 |
public static String readFileToString(String filename) {
|
|
172 |
try {
|
|
173 |
File file = new File(filename);
|
|
174 |
if ( !file.exists() ) {
|
|
175 |
System.out.println("\nFILE DOES NOT EXIST: " + filename);
|
|
176 |
}
|
|
177 |
BufferedReader in = new BufferedReader(new FileReader(file));
|
|
178 |
|
|
179 |
// Create an array of characters the size of the file
|
|
180 |
char[] allChars = new char[(int)file.length()];
|
|
181 |
|
|
182 |
// Read the characters into the allChars array
|
|
183 |
in.read(allChars, 0, (int)file.length());
|
|
184 |
in.close();
|
|
185 |
|
|
186 |
// Convert to a string
|
|
187 |
String allCharsString = new String(allChars);
|
|
188 |
|
|
189 |
return allCharsString;
|
|
190 |
|
|
191 |
} catch (FileNotFoundException e) {
|
|
192 |
System.err.println(e);
|
|
193 |
return "";
|
|
194 |
} catch (IOException e) {
|
|
195 |
System.err.println(e);
|
|
196 |
return "";
|
|
197 |
}
|
|
198 |
}
|
|
199 |
|
|
200 |
public static int findString(String fileString, String stringToFind) {
|
|
201 |
return fileString.indexOf(stringToFind);
|
|
202 |
}
|
|
203 |
}
|