[HtmlUnit] SVN: [13743] trunk/htmlunit/src

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[HtmlUnit] SVN: [13743] trunk/htmlunit/src

rbri
Revision: 13743
          http://sourceforge.net/p/htmlunit/code/13743
Author:   rbri
Date:     2017-03-15 20:03:28 +0000 (Wed, 15 Mar 2017)
Log Message:
-----------
reduce the number of temp files created when asking images for width/height

Modified Paths:
--------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java

Added Paths:
-----------
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgJavaScriptTest.java

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java 2017-03-15 20:00:05 UTC (rev 13742)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/DefaultPageCreator.java 2017-03-15 20:03:28 UTC (rev 13743)
@@ -106,27 +106,32 @@
             return PageType.UNKNOWN;
         }
 
-        if ("text/html".equals(contentType)) {
-            return PageType.HTML;
-        }
+        switch (contentType) {
+            case "text/html":
+            case "image/svg+xml":
+                return PageType.HTML;
+                
+            case "text/javascript":
+            case "application/x-javascript":
+            case "application/javascript":
+                return PageType.JAVASCRIPT;
 
-        if ("text/javascript".equals(contentType) || "application/x-javascript".equals(contentType)
-                || "application/javascript".equals(contentType)) {
-            return PageType.JAVASCRIPT;
-        }
+            case "text/xml":
+            case "application/xml":
+            case "text/vnd.wap.wml":
+                return PageType.XML;
 
-        if ("text/xml".equals(contentType)
-            || "application/xml".equals(contentType)
-            || "text/vnd.wap.wml".equals(contentType)
-            || contentType.endsWith("+xml")) {
-            return PageType.XML;
-        }
+            default:
+                if (contentType.endsWith("+xml")) {
+                    return PageType.XML;
+                }
 
-        if (contentType.startsWith("text/")) {
-            return PageType.TEXT;
+                if (contentType.startsWith("text/")) {
+                    return PageType.TEXT;
+                }
+
+                return PageType.UNKNOWN;
         }
-
-        return PageType.UNKNOWN;
     }
 
     /**

Added: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgJavaScriptTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgJavaScriptTest.java                        (rev 0)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/svg/SvgJavaScriptTest.java 2017-03-15 20:03:28 UTC (rev 13743)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2002-2017 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.svg;
+
+import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.CHROME;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+
+import com.gargoylesoftware.htmlunit.BrowserRunner;
+import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver;
+import com.gargoylesoftware.htmlunit.TextUtil;
+import com.gargoylesoftware.htmlunit.WebDriverTestCase;
+
+/**
+ * Tests for running JavaScripts in SVG elements..
+ *
+ * @author Ahmed Ashour
+ */
+@RunWith(BrowserRunner.class)
+public class SvgJavaScriptTest extends WebDriverTestCase {
+
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    @BuggyWebDriver(CHROME)
+    public void onclick() throws Exception {
+        final String html = ""
+            + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+            + "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" baseProfile=\"full\" width=\"100px\""
+            + " height=\"100px\" viewBox=\"0 0 100 100\">\n"
+            + "  <rect id=\"rect\" width=\"50\" height=\"50\" fill=\"blue\" "
+            + "onclick=\"document.getElementById('rect').setAttribute('fill', 'green')\" />\n"
+            + "</svg>";
+
+        final WebDriver driver = loadPage2(html, URL_FIRST, "image/svg+xml", TextUtil.DEFAULT_CHARSET);
+        WebElement rect = driver.findElement(By.id("rect"));
+
+        assertEquals("blue", rect.getAttribute("fill"));
+        rect.click();
+        assertEquals("green", rect.getAttribute("fill"));
+    }
+}


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop