0N/A/*
797N/A * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 4645058 4747738 4855054
0N/A * @summary Javascript IE load error when linked by -linkoffline
0N/A * Window title shouldn't change when loading left frames (javascript)
0N/A * @author dkramer
0N/A * @run main JavascriptWinTitle
0N/A */
0N/A
0N/A
0N/Aimport com.sun.javadoc.*;
0N/Aimport java.util.*;
0N/Aimport java.io.*;
0N/A
0N/A
0N/A/**
0N/A * Runs javadoc and runs regression tests on the resulting HTML.
0N/A * It reads each file, complete with newlines, into a string to easily
0N/A * find strings that contain newlines.
0N/A */
0N/Apublic class JavascriptWinTitle {
0N/A
0N/A private static final String BUGID = "4645058";
0N/A private static final String BUGNAME = "JavascriptWinTitle";
0N/A private static final String FS = System.getProperty("file.separator");
0N/A private static final String PS = System.getProperty("path.separator");
0N/A private static final String LS = System.getProperty("line.separator");
0N/A private static final String TMPDEST_DIR1 = "." + FS + "docs1" + FS;
0N/A private static final String TMPDEST_DIR2 = "." + FS + "docs2" + FS;
0N/A
0N/A // Subtest number. Needed because runResultsOnHTML is run twice,
0N/A // and subtestNum should increment across subtest runs.
0N/A public static int subtestNum = 0;
0N/A public static int numSubtestsPassed = 0;
0N/A
0N/A // Entry point
0N/A public static void main(String[] args) {
0N/A
0N/A // Directory that contains source files that javadoc runs on
0N/A String srcdir = System.getProperty("test.src", ".");
0N/A
0N/A // Test for all cases except the split index page
0N/A runJavadoc(new String[] {"-d", TMPDEST_DIR1,
0N/A "-doctitle", "Document Title",
0N/A "-windowtitle", "Window Title",
0N/A "-overview", (srcdir + FS + "overview.html"),
0N/A "-linkoffline",
0N/A "http://java.sun.com/j2se/1.4/docs/api", srcdir,
0N/A "-sourcepath", srcdir,
0N/A "p1", "p2"});
0N/A runTestsOnHTML(testArray);
0N/A
0N/A printSummary();
0N/A }
0N/A
0N/A /** Run javadoc */
0N/A public static void runJavadoc(String[] javadocArgs) {
0N/A if (com.sun.tools.javadoc.Main.execute(javadocArgs) != 0) {
0N/A throw new Error("Javadoc failed to execute");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Assign value for [ stringToFind, filename ]
0N/A * NOTE: The standard doclet uses the same separator "\n" for all OS's
0N/A */
0N/A private static final String[][] testArray = {
0N/A
0N/A // Test the javascript "type" attribute is present:
765N/A { "<script type=\"text/javascript\">",
0N/A TMPDEST_DIR1 + "overview-summary.html" },
0N/A
765N/A // Test onload is absent:
765N/A { "<body>",
0N/A TMPDEST_DIR1 + "overview-summary.html" },
0N/A
0N/A // Test onload is present:
765N/A { "<body>",
0N/A TMPDEST_DIR1 + FS + "p1" + FS + "package-summary.html" },
0N/A
0N/A // Test that "onload" is not present in BODY tag:
765N/A { "<body>",
0N/A TMPDEST_DIR1 + "overview-frame.html" },
0N/A
0N/A // Test that "onload" is not present in BODY tag:
765N/A { "<body>",
0N/A TMPDEST_DIR1 + "allclasses-frame.html" },
0N/A
0N/A // Test that "onload" is not present in BODY tag:
765N/A { "<body>",
0N/A TMPDEST_DIR1 + FS + "p1" + FS + "package-frame.html" },
0N/A
0N/A // Test that win title javascript is followed by NOSCRIPT code.
765N/A {"<script type=\"text/javascript\"><!--" + LS +
765N/A " if (location.href.indexOf('is-external=true') == -1) {" + LS +
765N/A " parent.document.title=\"C (Window Title)\";" + LS +
765N/A " }" + LS + "//-->" + LS + "</script>",
0N/A TMPDEST_DIR1 + FS + "p1" + FS + "C.html"
0N/A }
0N/A
0N/A };
0N/A
0N/A public static void runTestsOnHTML(String[][] testArray) {
0N/A
0N/A for (int i = 0; i < testArray.length; i++) {
0N/A
0N/A subtestNum += 1;
0N/A
0N/A // Read contents of file into a string
0N/A String fileString = readFileToString(testArray[i][1]);
0N/A
0N/A // Get string to find
0N/A String stringToFind = testArray[i][0];
0N/A
0N/A // Find string in file's contents
0N/A if (findString(fileString, stringToFind) == -1) {
0N/A System.out.println("\nSub-test " + (subtestNum)
0N/A + " for bug " + BUGID + " (" + BUGNAME + ") FAILED\n"
0N/A + "when searching for:\n"
0N/A + stringToFind);
0N/A } else {
0N/A numSubtestsPassed += 1;
0N/A System.out.println("\nSub-test " + (subtestNum) + " passed:\n" + stringToFind);
0N/A }
0N/A }
0N/A }
0N/A
0N/A public static void printSummary() {
0N/A if ( numSubtestsPassed == subtestNum ) {
0N/A System.out.println("\nAll " + numSubtestsPassed + " subtests passed");
0N/A } else {
0N/A throw new Error("\n" + (subtestNum - numSubtestsPassed) + " of " + (subtestNum)
0N/A + " subtests failed for bug " + BUGID + " (" + BUGNAME + ")\n");
0N/A }
0N/A }
0N/A
0N/A // Read the file into a String
0N/A public static String readFileToString(String filename) {
0N/A try {
0N/A File file = new File(filename);
0N/A if ( !file.exists() ) {
0N/A System.out.println("\nFILE DOES NOT EXIST: " + filename);
0N/A }
0N/A BufferedReader in = new BufferedReader(new FileReader(file));
0N/A
0N/A // Create an array of characters the size of the file
0N/A char[] allChars = new char[(int)file.length()];
0N/A
0N/A // Read the characters into the allChars array
0N/A in.read(allChars, 0, (int)file.length());
0N/A in.close();
0N/A
0N/A // Convert to a string
0N/A String allCharsString = new String(allChars);
0N/A
0N/A return allCharsString;
0N/A
0N/A } catch (FileNotFoundException e) {
0N/A System.err.println(e);
0N/A return "";
0N/A } catch (IOException e) {
0N/A System.err.println(e);
0N/A return "";
0N/A }
0N/A }
0N/A
0N/A public static int findString(String fileString, String stringToFind) {
0N/A return fileString.indexOf(stringToFind);
0N/A }
0N/A}