Revision: 867
          http://jwebunit.svn.sourceforge.net/jwebunit/?rev=867&view=rev
Author:   henryju
Date:     2010-10-20 09:16:23 +0000 (Wed, 20 Oct 2010)

Log Message:
-----------
[2970512] Fixed issue with absolute image path.

Modified Paths:
--------------
    
branches/2.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ImageTest.java
    
branches/2.x/jwebunit-commons-tests/src/main/resources/testcases/ImageTest/PageWithImages.html
    
branches/2.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
    branches/2.x/src/changes/changes.xml

Modified: 
branches/2.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ImageTest.java
===================================================================
--- 
branches/2.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ImageTest.java
     2010-10-19 15:21:52 UTC (rev 866)
+++ 
branches/2.x/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ImageTest.java
     2010-10-20 09:16:23 UTC (rev 867)
@@ -94,4 +94,9 @@
         assertImageValid("images/Image5.png", "image 5 - subdir");
         assertImageValid("../images/photos/Image3.jpg", "image 3 again - 
topdir");
     }
+       
+       public void testAbsolutePath() {
+        assertImagePresent("/jwebunit/ImageTest/images/Image1.gif", "absolute 
image 1");
+        assertImageValid("/jwebunit/ImageTest/images/Image1.gif", "absolute 
image 1");        
+    }
 }

Modified: 
branches/2.x/jwebunit-commons-tests/src/main/resources/testcases/ImageTest/PageWithImages.html
===================================================================
--- 
branches/2.x/jwebunit-commons-tests/src/main/resources/testcases/ImageTest/PageWithImages.html
      2010-10-19 15:21:52 UTC (rev 866)
+++ 
branches/2.x/jwebunit-commons-tests/src/main/resources/testcases/ImageTest/PageWithImages.html
      2010-10-20 09:16:23 UTC (rev 867)
@@ -28,6 +28,7 @@
 <body>
 <div id="test">
   <img src="images/Image1.gif" alt="image 1" />
+  <img src="/jwebunit/ImageTest/images/Image1.gif" alt="absolute image 1" />
   <img src="images/Image2.png" alt="image 2" />
   <img src="images/photos/Image3.jpg" alt="image 3" />
   <img src="somedir/Image4.gif" />

Modified: 
branches/2.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
===================================================================
--- 
branches/2.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2010-10-19 15:21:52 UTC (rev 866)
+++ 
branches/2.x/jwebunit-core/src/main/java/net/sourceforge/jwebunit/junit/WebTester.java
      2010-10-20 09:16:23 UTC (rev 867)
@@ -232,6 +232,15 @@
 
     }
 
+    /**
+     * This way of creating URL is not standard as absolute path are not 
correctly handled. We have to keep this
+     * non standard method for {...@link #beginAt(String)} that advertise a 
bad usage for a long time.
+     * @param url Absolute or relative URL. If start with '/', then it is 
incorrectly appended to baseURL.
+     * @param baseURL Base URL of the page
+     * @return Final absolute URL.
+     * @throws MalformedURLException
+     */
+    @Deprecated
     private URL createUrl(String url, URL baseURL) throws 
MalformedURLException {
         if (url.startsWith("http://";) || url.startsWith("https://";)
                 || url.startsWith("file://")) {
@@ -244,6 +253,24 @@
         }
     }
 
+       /**
+     * 
+     * @param url Absolute or relative URL
+     * @param baseURL Base URL of the page
+     * @return Final absolute URL.
+     * @throws MalformedURLException
+     */
+    private URL createUrlFixed(String url, URL baseURL) throws 
MalformedURLException {
+        if (url.startsWith("http://";) || url.startsWith("https://";) //Absolute 
URL
+                || url.startsWith("file://")) {
+            return new URL(url);
+        } else if (url.startsWith("www.")) { //Absolute URL with missing 
scheme (accepted by some browsers)
+            return new URL("http://"; + url);
+        } else { //Relative path
+            return new URL(baseURL, url);
+        }
+    }
+
     /**
      * Return the value of a web resource based on its key. This translates to 
a property file lookup with the locale
      * based on the current TestContext.
@@ -3427,7 +3454,7 @@
         assertImagePresent(imageSrc, imageAlt);
         URL imageUrl = null;
         try {
-            imageUrl = createUrl(imageSrc, getTestingEngine().getPageURL());
+            imageUrl = createUrlFixed(imageSrc, 
getTestingEngine().getPageURL());
         } catch (MalformedURLException e1) {
             Assert.fail(e1.getLocalizedMessage());
         }

Modified: branches/2.x/src/changes/changes.xml
===================================================================
--- branches/2.x/src/changes/changes.xml        2010-10-19 15:21:52 UTC (rev 
866)
+++ branches/2.x/src/changes/changes.xml        2010-10-20 09:16:23 UTC (rev 
867)
@@ -32,6 +32,9 @@
     </properties>
     <body>
         <release version="2.5" date="October 18, 2010" description="Small 
fixes and dependency updates">
+            <action type="fix" dev="henryju" issue="2970512" due-to="Todd 
Owen">
+                Fixed handling of absolute image path (when src attribute 
start with a /).
+            </action>
             <action type="update" dev="henryju">
                 Updated to slf4j 1.6.1.
             </action>


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
JWebUnit-development mailing list
JWebUnit-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jwebunit-development

Reply via email to