langtools/test/com/sun/javadoc/testJavascript/TestJavascript.java
author jjg
Wed, 16 Apr 2014 16:17:09 -0700
changeset 23971 f5ff1f5a8dee
parent 20614 994200acf1e4
child 24065 fc4022e50129
permissions -rw-r--r--
8031649: Clean up javadoc tests Reviewed-by: jjg Contributed-by: neil.toda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
     2
 * Copyright (c) 2004, 2014, 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
20614
994200acf1e4 8024756: method grouping tabs are not selectable
bpatel
parents: 20257
diff changeset
    26
 * @bug      4665566 4855876 7025314 8012375 8015997 8016328 8024756
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[] {
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    42
        "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg", SRC_DIR +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    43
        "/TestJavascript.java"
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    //Input for string search tests.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
    private static final String[][] TEST = {
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    48
        {BUG_ID + "/pkg/C.html",
9067
c0b85430843d 7025314: NLS: translatability violation on standard.properties
bpatel
parents: 7681
diff changeset
    49
            "<a href=\"../index.html?pkg/C.html\" target=\"_top\">Frames</a>"},
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    50
        {BUG_ID + "/TestJavascript.html",
9067
c0b85430843d 7025314: NLS: translatability violation on standard.properties
bpatel
parents: 7681
diff changeset
    51
            "<a href=\"index.html?TestJavascript.html\" target=\"_top\">Frames</a>"},
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    52
        {BUG_ID + "/index.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    53
            "<script type=\"text/javascript\">\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    54
                        "    targetPage = \"\" + window.location.search;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    55
            "    if (targetPage != \"\" && targetPage != \"undefined\")\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    56
            "        targetPage = targetPage.substring(1);\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    57
            "    if (targetPage.indexOf(\":\") != -1 || (targetPage != \"\" && !validURL(targetPage)))\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    58
            "        targetPage = \"undefined\";\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    59
            "    function validURL(url) {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    60
            "        try {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    61
            "            url = decodeURIComponent(url);\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    62
            "        }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    63
            "        catch (error) {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    64
            "            return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    65
            "        }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    66
            "        var pos = url.indexOf(\".html\");\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    67
            "        if (pos == -1 || pos != url.length - 5)\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    68
            "            return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    69
            "        var allowNumber = false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    70
            "        var allowSep = false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    71
            "        var seenDot = false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    72
            "        for (var i = 0; i < url.length - 5; i++) {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    73
            "            var ch = url.charAt(i);\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    74
            "            if ('a' <= ch && ch <= 'z' ||\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    75
            "                    'A' <= ch && ch <= 'Z' ||\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    76
            "                    ch == '$' ||\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    77
            "                    ch == '_' ||\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    78
            "                    ch.charCodeAt(0) > 127) {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    79
            "                allowNumber = true;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    80
            "                allowSep = true;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    81
            "            } else if ('0' <= ch && ch <= '9'\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    82
            "                    || ch == '-') {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    83
            "                if (!allowNumber)\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    84
            "                     return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    85
            "            } else if (ch == '/' || ch == '.') {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    86
            "                if (!allowSep)\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    87
            "                    return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    88
            "                allowNumber = false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    89
            "                allowSep = false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    90
            "                if (ch == '.')\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    91
            "                     seenDot = true;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    92
            "                if (ch == '/' && seenDot)\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    93
            "                     return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    94
            "            } else {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    95
            "                return false;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    96
            "            }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    97
            "        }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    98
            "        return true;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
    99
            "    }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   100
            "    function loadFrames() {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   101
            "        if (targetPage != \"\" && targetPage != \"undefined\")\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   102
            "             top.classFrame.location = top.targetPage;\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   103
            "    }\n" +
7614
cfadc977ca75 6851834: Javadoc doclet needs a structured approach to generate the output HTML.
bpatel
parents: 5520
diff changeset
   104
            "</script>"},
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        //Make sure title javascript only runs if is-external is not true
23971
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   107
        {BUG_ID + "/pkg/C.html",
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   108
            "    try {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   109
            "        if (location.href.indexOf('is-external=true') == -1) {\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   110
            "            parent.document.title=\"C\";\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   111
            "        }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   112
            "    }\n" +
f5ff1f5a8dee 8031649: Clean up javadoc tests
jjg
parents: 20614
diff changeset
   113
            "    catch(err) {\n" +
20614
994200acf1e4 8024756: method grouping tabs are not selectable
bpatel
parents: 20257
diff changeset
   114
            "    }"},
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    };
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    private static final String[][] NEGATED_TEST = NO_TEST;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     * The entry point of the test.
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
     * @param args the array of command line arguments.
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    public static void main(String[] args) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        TestJavascript tester = new TestJavascript();
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        run(tester, ARGS, TEST, NEGATED_TEST);
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
        tester.printSummary();
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    public String getBugId() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
        return BUG_ID;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    /**
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
     * {@inheritDoc}
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    public String getBugName() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        return getClass().getName();
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
}