nashorn/test/script/trusted/urlreader.js
author fparain
Fri, 26 Jul 2013 05:54:01 -0700
changeset 18986 f8699c86bb40
parent 16522 d643e3ee819c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16243
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     1
/**
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     2
 * JDK-8008305: ScriptEngine.eval should offer the ability to provide a codebase
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     3
 *
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     4
 * @test
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     5
 * @run
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     6
 */
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     7
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     8
var URLReader = Java.type("jdk.nashorn.api.scripting.URLReader");
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
     9
var URL = Java.type("java.net.URL");
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    10
var File = Java.type("java.io.File");
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    11
var JString = Java.type("java.lang.String");
16522
d643e3ee819c 8009757: Package access clean up and refactoring
sundar
parents: 16243
diff changeset
    12
var SourceHelper = Java.type("jdk.nashorn.test.models.SourceHelper");
16243
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    13
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    14
var url = new File(__FILE__).toURI().toURL();
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    15
var reader = new URLReader(url);
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    16
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    17
// check URLReader.getURL() method
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    18
//Assert.assertEquals(url, reader.getURL());
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    19
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    20
// check URL read
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    21
// read URL content by directly reading from URL
16522
d643e3ee819c 8009757: Package access clean up and refactoring
sundar
parents: 16243
diff changeset
    22
var str = SourceHelper.readFully(url);
16243
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    23
// read URL content via URLReader
16522
d643e3ee819c 8009757: Package access clean up and refactoring
sundar
parents: 16243
diff changeset
    24
var content = new JString(SourceHelper.readFully(reader));
16243
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    25
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    26
// assert that the content is same
f5fdf89e1583 8008305: ScriptEngine.eval should offer the ability to provide a codebase
sundar
parents:
diff changeset
    27
Assert.assertEquals(str, content);