langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java
author bpatel
Fri, 03 May 2013 08:52:33 -0700
changeset 18398 1935600c6f34
parent 9067 c0b85430843d
child 18404 a5aaa0341fec
permissions -rw-r--r--
8012375: Improve Javadoc framing Reviewed-by: mduigou, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
18398
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
     2
 * Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1787
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1787
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 1787
diff changeset
    21
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
 * @test
18398
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    26
 * @bug      4665566 4855876 7025314 8012375
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
 * @summary  Verify that the output has the right javascript.
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
 * @author   jamieh
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
 * @library  ../lib/
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
 * @build    JavadocTester
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
 * @build    TestJavascript
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
 * @run main TestJavascript
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
public class TestJavascript extends JavadocTester {
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
    //Test information.
18398
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    38
    private static final String BUG_ID = "4665566-4855876-8012375";
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    //Javadoc arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    private static final String[] ARGS = new String[] {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", SRC_DIR + FS + "TestJavascript.java"
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    //Input for string search tests.
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    private static final String[][] TEST = {
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        {BUG_ID + FS + "pkg" + FS + "C.html",
9067
c0b85430843d 7025314: NLS: translatability violation on standard.properties
bpatel
parents: 7681
diff changeset
    48
            "<a href=\"../index.html?pkg/C.html\" target=\"_top\">Frames</a>"},
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
        {BUG_ID + FS + "TestJavascript.html",
9067
c0b85430843d 7025314: NLS: translatability violation on standard.properties
bpatel
parents: 7681
diff changeset
    50
            "<a href=\"index.html?TestJavascript.html\" target=\"_top\">Frames</a>"},
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
        {BUG_ID + FS + "index.html",
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    52
            "<script type=\"text/javascript\">" + NL +
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
                        "    targetPage = \"\" + window.location.search;" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
            "    if (targetPage != \"\" && targetPage != \"undefined\")" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
            "        targetPage = targetPage.substring(1);" + NL +
18398
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    56
            "    if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))" + NL +
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
            "        targetPage = \"undefined\";" + NL +
18398
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    58
            "    function validURL(url) {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    59
            "        if (!(url.indexOf(\".html\") == url.length - 5))" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    60
            "            return false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    61
            "        var allowNumber = false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    62
            "        var allowSep = false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    63
            "        var seenDot = false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    64
            "        for (var i = 0; i < url.length - 5; i++) {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    65
            "            var ch = url.charAt(i);" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    66
            "            if ('a' <= ch && ch <= 'z' ||" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    67
            "                    'A' <= ch && ch <= 'Z' ||" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    68
            "                    ch == '$' ||" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    69
            "                    ch == '_') {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    70
            "                allowNumber = true;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    71
            "                allowSep = true;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    72
            "            } else if ('0' <= ch && ch <= '9'" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    73
            "                    || ch == '-') {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    74
            "                if (!allowNumber)" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    75
            "                     return false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    76
            "            } else if (ch == '/' || ch == '.') {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    77
            "                if (!allowSep)" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    78
            "                    return false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    79
            "                allowNumber = false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    80
            "                allowSep = false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    81
            "                if (ch == '.')" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    82
            "                     seenDot = true;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    83
            "                if (ch == '/' && seenDot)" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    84
            "                     return false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    85
            "            } else {" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    86
            "                return false;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    87
            "            }" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    88
            "        }" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    89
            "        return true;" + NL +
1935600c6f34 8012375: Improve Javadoc framing
bpatel
parents: 9067
diff changeset
    90
            "    }" + NL +
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            "    function loadFrames() {" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            "        if (targetPage != \"\" && targetPage != \"undefined\")" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            "             top.classFrame.location = top.targetPage;" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
            "    }" + NL +
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
    95
            "</script>"},
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        //Make sure title javascript only runs if is-external is not true
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        {BUG_ID + FS + "pkg" + FS + "C.html",
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
                "    if (location.href.indexOf('is-external=true') == -1) {" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
                "        parent.document.title=\"C\";" + NL +
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
                        "    }"},
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private static final String[][] NEGATED_TEST = NO_TEST;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
     * The entry point of the test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
     * @param args the array of command line arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        TestJavascript tester = new TestJavascript();
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        run(tester, ARGS, TEST, NEGATED_TEST);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        tester.printSummary();
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public String getBugId() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        return BUG_ID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public String getBugName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
        return getClass().getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
}