JDK-8153681 : WebView needs to resolve resources relative to "jrt:" URLs
  • Type: Bug
  • Component: javafx
  • Sub-Component: web
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-04-06
  • Updated: 2018-08-21
  • Resolved: 2016-08-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Fixed
Related Reports
Relates :  
Relates :  
Description
WebView has special code to recognize URLs like "file:", "http:", "https:", and "jar:". With JDK 9 modularity, we will need to also recognize "jrt:" URLs which are used for resources that are compiled into the JRE runtime image.

They are of the following format:

jrt:/module.name/dir/dir/resource.html

Comments
Changeset: aec2986a8c3a Author: ghb Date: 2016-08-12 23:21 +0530 URL: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/aec2986a8c3a
12-08-2016

Version .04 looks good. +1
12-08-2016

Increased timeout to 30 sec (Considering other similar test cases), Correct indentation and nit. Not redundent i.e there are two test case, One which tests for main resource and another for sub-resource. Updated webrev : http://cr.openjdk.java.net/~ghb/8153681/webrev.04/
12-08-2016

+ // Load single resource and check for image is being rendered + // Check the natural width of rendered image + load(jrtResources[0]); + assertEquals("Failed to load " + jrtResources[0], + 1, executeScript("document.getElementsByTagName('img').length")); + + assertEquals("Failed to Render " + jrtResources[0], + 16, executeScript("document.getElementsByTagName('img')[0].naturalWidth")); Is it redundant? Because the same case is tested below as well(using new WebEngine). + JSObject window = (JSObject)webEngine.executeScript("window"); Space should be added after typecasting. e.g. (JSObject) webEngine.executeScript("window"); Also make it as final. + @Test(timeout = 5000) public void loadJrtResource() throws Exception { Give some more time, it will become flaky when test machine heavily loaded. May be 20sec will be a good number.
12-08-2016

updated webrev : http://cr.openjdk.java.net/~ghb/8153681/webrev.03/ Instead of checking rendered width, Implemented "img" event call back onload & onerror.
11-08-2016

+ // If images naturalwidth == 0 means failure to Render images + executeScript("function testImgWidth(){for(var e=0;e<document.getElementsByTagName('img').length;++e) " + + "return 0===document.getElementsByTagName('img')[e].naturalWidth?-1:0}"); + It will return in the first iteration itself. + "return 0===document.getElementsByTagName('img')[e].naturalWidth?-1:0}"); Do you want to return boolean? + assertEquals("Failed to load jrt images resources'", + 0, executeScript("testImgWidth()")); There is one extra single quote at the end(')
11-08-2016

Note that this has '8-na' so should not be backported to 8u-dev.
04-08-2016

Looks good. +1
04-08-2016

Thanks Kevin, please find updated webrev : http://cr.openjdk.java.net/~ghb/8153681/webrev.01/ 1. Follow on JDK-8163183 to fix assertEquals in LoadTest.loadJarFile(..) 2. added "isJigsawMode" in TestBase instead of adding in LoadTest considering its future usage is all other derived class. 3 & 4 are incorporated. "loadJrtResource" will be ignored in Non jigsaw mode. (Tested on Jigsaw and Non-Jigsaw mode in Linux and Windows).
04-08-2016

1. The assertEquals calls have the expected and actual values backwards (expected should be first). Related to this, I see that the existing loadJarFile test also has this same bug, which I missed when reviewing them earlier, so it might be good to file a new (P4) bug to fix that. 2. The test fails (not surprisingly) when run in non-Jigsaw mode, with the following assertion failure: test.javafx.scene.web.LoadTest > loadJrtResource FAILED java.lang.AssertionError: Failed to load jrt:/javafx.web/javafx/scene/web/AlignCenter_16x16_JFX.png' expected:<0> but was:<1> at org.junit.Assert.fail(Assert.java:91) at org.junit.Assert.failNotEquals(Assert.java:645) at org.junit.Assert.assertEquals(Assert.java:126) at test.javafx.scene.web.LoadTest.loadJrtResource(LoadTest.java:309) You will need to skip this test in non-Jigsaw mode, doing something like the following at the beginning of the test: @Test public void loadJrtResource() throws Exception { assumeTrue (isJigsawMode()); Probably the easiest way to implement isJigsawMode() is to check, via reflection, whether the java.lang.reflect.Module class is present. Something like the following should work: boolean isJigsawMode() { Class clazz = null; try { clazz = Class.forName("java.lang.reflect.Module", LoadTest.class.getClassLoader(), false); } catch (Exception) {} return class != null; } 3. You might consider storing the path names to the images in a variable so as not to duplicate them. Just a suggestion, though. For example, the following string occurs three times in the test: "jrt:/javafx.web/javafx/scene/web/AlignCenter_16x16_JFX.png" 4. The error string in the first two calls to assertEquals has a mismatched single-quote char in the string (not harmful, but it looks odd). assertEquals("Failed to load jrt:/javafx.web/javafx/scene/web/AlignCenter_16x16_JFX.png'"
03-08-2016

Its not redundant. I am loading resource two times 1st time : Only one image , Even if the target image is not reachable getElementsByTagName will return a valid object. To make sure the Image is rendered and not the alt text, Testing its naturalWidth will give images width. Testing 0th elements (i.e 1st img tag) and its natural width will give the image width. 2nd : Loading Multiple images (set of 5 images) with negative resource resolving , where in here i am not checking for each and individual elements for its naturalWidth. In a for loop (Testing all the elements and its naturalWidth == 0 means there is no image rendered) if any of 1 image fails, The return value of "testImgWidth" will return -1.
29-07-2016

One minor comment: Regarding below line, is [0] redundant? executeScript("document.getElementsByTagName('img')[0].naturalWidth"), 16);
29-07-2016

Webrev : http://cr.openjdk.java.net/~ghb/8153681/webrev.00/ Current implementation check's for URL schema followed by / is treated as hierarchical and no modification required in the native implmentation in URL handler to support jrt URL schema, i.e for jrt - "jrt:/". Added Unit test which reads image (As currently there is no html resource are exported from javafx.web) resource from 'javafx.web.jmod'. Test added to check for naviation ./ or ../ which will be handled in URL handler (on native). To Fully test the html resource along with relative resource. 1. Add resource to "9-dev/rt/modules/web/src/main/resources/path/to/res/test.html". 2. compile openjfx . 3. build jdk or create custom image with compiled openjfx modules (with generates javafx.web.jmod). 4. load resource using 'jrt:/javafx.web/path/to/res/test.html'. 'jrt:/modulename/pathtoyourclassfileorresource' ref :http://openjdk.java.net/jeps/220 Tried creating modular jar and reading the resource via jrt, But this will be treated as jar resource instead of jrt. as jrt is a filesystem which is created when we launch java (based on the current jmods built).
29-07-2016