[prev in list] [next in list] [prev in thread] [next in thread] 

List:       htmlunit-develop
Subject:    [HtmlUnit] SVN: [13286] trunk/htmlunit/src
From:       rbri () users ! sourceforge ! net
Date:       2016-12-28 17:51:06
Message-ID: E1cMINZ-0000Z0-QP () sfs-ml-2 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 13286
          http://sourceforge.net/p/htmlunit/code/13286
Author:   rbri
Date:     2016-12-28 17:51:06 +0000 (Wed, 28 Dec 2016)
Log Message:
-----------
Class JavasScriptPage removed. Rela browsers are handling this page as simple \
htmlpage containing only a script tag in the header. If there is no content type, the \
browser will look inside the content for a script tag.

Issue 1844

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java
  trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java

Removed Paths:
-------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/JavaScriptPage.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml	2016-12-28 10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/changes/changes.xml	2016-12-28 17:51:06 UTC (rev 13286)
@@ -8,6 +8,13 @@
 
     <body>
         <release version="2.24" date="???" description="Bugfixes">
+            <action type="update" dev="rbri">
+                Class JavasScriptPage removed. Rela browsers are handling this page \
as simple htmlpage +                containing only a script tag in the header.
+            </action>
+            <action type="fix" dev="rbri" issue="1844">
+                If there is no content type, the browser will look inside the \
content for a script tag. +            </action>
             <action type="fix" dev="rbri" issue="1845" due-to="Rob Kodey">
                 Conversion of ordered list to text has to take care of all children \
not only list items.  </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java	2016-12-28 \
                10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java	2016-12-28 \
17:51:06 UTC (rev 13286) @@ -161,7 +161,7 @@
                 return createHtmlPage(webResponse, webWindow);
 
             case JAVASCRIPT:
-                return createJavaScriptPage(webResponse, webWindow);
+                return createHtmlPage(webResponse, webWindow);
 
             case XML:
                 final SgmlPage sgmlPage = createXmlPage(webResponse, webWindow);
@@ -209,6 +209,9 @@
                     || startsWith(bytes, markerUTF16LE_)) {
                 return "text/plain";
             }
+            else if (asAsciiString.trim().startsWith("<SCRIPT>")) {
+                return "application/javascript";
+            }
             else if (isBinary(bytes)) {
                 return "application/octet-stream";
             }
@@ -283,19 +286,6 @@
     }
 
     /**
-     * Creates a JavaScriptPage for this WebResponse.
-     *
-     * @param webResponse the page's source
-     * @param webWindow the WebWindow to place the JavaScriptPage in
-     * @return the newly created JavaScriptPage
-     */
-    protected JavaScriptPage createJavaScriptPage(final WebResponse webResponse, \
                final WebWindow webWindow) {
-        final JavaScriptPage newPage = new JavaScriptPage(webResponse, webWindow);
-        webWindow.setEnclosedPage(newPage);
-        return newPage;
-    }
-
-    /**
      * Creates a TextPage for this WebResponse.
      *
      * @param webResponse the page's source

Deleted: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/JavaScriptPage.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/JavaScriptPage.java	2016-12-28 \
                10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/JavaScriptPage.java	2016-12-28 \
17:51:06 UTC (rev 13286) @@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2002-2016 Gargoyle Software Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gargoylesoftware.htmlunit;
-
-/**
- * A generic page that will be returned for JavaScript content.
- * Specifically any content types of {@code text/javascript}.
- *
- * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- * @author David K. Taylor
- * @author Ronald Brill
- * @author Ahmed Ashour
- */
-public class JavaScriptPage extends AbstractPage {
-
-    /**
-     * Creates an instance.
-     *
-     * @param webResponse the response from the server
-     * @param enclosingWindow the window that holds the page
-     */
-    public JavaScriptPage(final WebResponse webResponse, final WebWindow \
                enclosingWindow) {
-        super(webResponse, enclosingWindow);
-    }
-
-    /**
-     * Returns the content of the page.
-     *
-     * @return the content of the page
-     */
-    public String getContent() {
-        return getWebResponse().getContentAsString();
-    }
-
-}

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java	2016-12-28 \
                10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClient3Test.java	2016-12-28 \
17:51:06 UTC (rev 13286) @@ -456,4 +456,92 @@
             + "</head><body><script>alert(document.title)</script></body></html>";
         loadPageWithAlerts2(html);
     }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @Alerts ("executed")
+    public void javascriptContentDetectorWithoutContentType() throws Exception {
+        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<script>alert('executed')</script>", 200, "OK", \
null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @Alerts (DEFAULT = "executed",
+             IE = "")
+    @NotYetImplemented(IE)
+    public void javascriptContentDetectorWithoutContentType500() throws Exception {
+        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<script>alert('executed')</script>", 500, "OK", \
null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @Alerts ("executed")
+    public void javascriptContentDetectorWithoutContentTypeWhitespace() throws \
Exception { +        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse(" \t \r\n \n   <script>alert('executed')</script>", \
200, "OK", null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    public void javascriptContentDetectorWithoutContentTypeTextBefore() throws \
Exception { +        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("Attention<script>alert('executed')</script>", 200, \
"OK", null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @Alerts ("executed")
+    public void javascriptContentDetectorWithoutContentUppercase() throws Exception \
{ +        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<SCRIPT>alert('executed')</SCRIPT>", 200, "OK", \
null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @Alerts ("executed")
+    public void javascriptContentDetectorWithoutContentMixedCase() throws Exception \
{ +        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<scRIPt>alert('executed')</scRIPt>", 200, "OK", \
null); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    public void javascriptContentDetectorContentTypeTextPlain() throws Exception {
+        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<script>alert('executed')</script>", 200, "OK", \
"text/plain"); +        loadPageWithAlerts2(URL_FIRST);
+    }
+
+    /**
+     * @throws Exception if something goes wrong
+     */
+    @Test
+    @NotYetImplemented
+    public void javascriptContentDetectorContentTypeApplicationJavascript() throws \
Exception { +        final MockWebConnection conn = getMockWebConnection();
+        conn.setDefaultResponse("<script>alert('executed')</script>", 200, "OK", \
"application/javascript"); +        loadPageWithAlerts2(URL_FIRST);
+    }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java	2016-12-28 \
                10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java	2016-12-28 \
17:51:06 UTC (rev 13286) @@ -1550,7 +1550,7 @@
         assertTrue(TextPage.class.isInstance(client.getPage(URL_FIRST)));
 
         webConnection.setResponse(URL_FIRST, "", "Text/JavaScript");
-        assertTrue(JavaScriptPage.class.isInstance(client.getPage(URL_FIRST)));
+        assertTrue(HtmlPage.class.isInstance(client.getPage(URL_FIRST)));
     }
 
     /**

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java	2016-12-28 \
                10:20:31 UTC (rev 13285)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java	2016-12-28 \
17:51:06 UTC (rev 13286) @@ -75,6 +75,7 @@
 import com.gargoylesoftware.htmlunit.MockWebConnection.RawResponseData;
 import com.gargoylesoftware.htmlunit.html.DomElement;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
 import com.gargoylesoftware.htmlunit.html.HtmlPageTest;
 import com.gargoylesoftware.htmlunit.util.NameValuePair;
 
@@ -997,6 +998,16 @@
     @SuppressWarnings("unchecked")
     protected List<String> getCollectedAlerts(final WebDriver driver) throws \
Exception {  final List<String> collectedAlerts = new ArrayList<>();
+
+        // do not throw an exception if we ask for collected alerts for non html \
pages +        // see \
com.gargoylesoftware.htmlunit.WebClient3Test.javascriptContentDetectorContentTypeTextPlain()
 +        if (driver instanceof HtmlUnitDriver) {
+            final Page page = getWebWindowOf((HtmlUnitDriver) \
driver).getEnclosedPage(); +            if (!(page instanceof HtmlPage)) {
+                return collectedAlerts;
+            }
+        }
+
         final JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
 
         final Object result = jsExecutor.executeScript("return \
top.__huCatchedAlerts");


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
HtmlUnit-develop@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic