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

List:       htmlunit-develop
Subject:    [HtmlUnit] SF.net SVN: htmlunit:[5621] trunk/htmlunit/src
From:       asashour () users ! sourceforge ! net
Date:       2010-03-26 20:09:16
Message-ID: E1NvFqG-0001xz-ON () sfp-svn-5 ! v30 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 5621
          http://htmlunit.svn.sourceforge.net/htmlunit/?rev=5621&view=rev
Author:   asashour
Date:     2010-03-26 20:09:16 +0000 (Fri, 26 Mar 2010)

Log Message:
-----------
- Add HtmlPage.isQuirksMode()
- Fix the change of 'Remove redundant HTMLCollection.getDefaultValue()'

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java
  trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java
  trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java


Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml	2010-03-26 19:36:21 UTC (rev 5620)
+++ trunk/htmlunit/src/changes/changes.xml	2010-03-26 20:09:16 UTC (rev 5621)
@@ -6,6 +6,9 @@
 
     <body>
         <release version="2.8" date="?" description="Bugfixes, large file download, \
single thread for JavaScript background tasks"> +            <action type="add" \
dev="asashour"> +                Add HtmlPage.isQuirksMode()
+            </action>
             <action type="remove" dev="asashour">
                 Remove StringScriptPreProcessor.
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java	2010-03-26 \
                19:36:21 UTC (rev 5620)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java	2010-03-26 \
20:09:16 UTC (rev 5621) @@ -2240,5 +2240,35 @@
         return (document instanceof HtmlPage)
             && ("name".equals(attributeName) || "id".equals(attributeName));
     }
+
+    /**
+     * Returns whether the current page mode is in quirks mode or in standards mode.
+     * @return true for quirks mode, false for standards mode
+     */
+    public boolean isQuirksMode() {
+        boolean quirks = true;
+        final DocumentType docType = getDoctype();
+        if (docType != null) {
+            final String publicId = docType.getPublicId();
+            final String systemId = docType.getSystemId();
+            if (systemId != null) {
+                if (systemId.equals("http://www.w3.org/TR/html4/strict.dtd")) {
+                    quirks = false;
+                }
+                else if (systemId.equals("http://www.w3.org/TR/html4/loose.dtd")) {
+                    if (publicId.equals("-//W3C//DTD HTML 4.01 Transitional//EN")
+                        || (publicId.equals("-//W3C//DTD HTML 4.0 Transitional//EN")
+                                && getWebClient().getBrowserVersion().isIE())) {
+                        quirks = false;
+                    }
+                }
+                else if \
(systemId.equals("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd") +               \
|| systemId.equals("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")) { +    \
quirks = false; +                }
+            }
+        }
+       return quirks;
+    }
 }
 

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java	2010-03-26 \
                19:36:21 UTC (rev 5620)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLCollection.java	2010-03-26 \
20:09:16 UTC (rev 5621) @@ -684,4 +684,12 @@
         }
         return getScriptableFor(object);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getClassName() {
+        return "HTMLCollection";
+    }
 }

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java
 ===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java	2010-03-26 \
                19:36:21 UTC (rev 5620)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java	2010-03-26 \
20:09:16 UTC (rev 5621) @@ -666,32 +666,7 @@
      * @return the "compatMode" attribute
      */
     public String jsxGet_compatMode() {
-        boolean strict = false;
-        final org.w3c.dom.DocumentType docType = getPage().getDoctype();
-        if (docType != null) {
-            final String publicId = docType.getPublicId();
-            final String systemId = docType.getSystemId();
-            if (systemId != null) {
-                if (systemId.equals("http://www.w3.org/TR/html4/strict.dtd")) {
-                    strict = true;
-                }
-                else if (systemId.equals("http://www.w3.org/TR/html4/loose.dtd")) {
-                    if (publicId.equals("-//W3C//DTD HTML 4.01 Transitional//EN")
-                        || publicId.equals("-//W3C//DTD HTML 4.0 Transitional//EN") \
                && getBrowserVersion().isIE()) {
-                        strict = true;
-                    }
-                }
-                else if \
                (systemId.equals("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")
-                    || \
                systemId.equals("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd")) \
                {
-                    strict = true;
-                }
-            }
-        }
-
-        if (strict) {
-            return "CSS1Compat";
-        }
-        return "BackCompat";
+        return getHtmlPage().isQuirksMode() ? "BackCompat" : "CSS1Compat";
     }
 
     /**

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java
 ===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java	2010-03-26 \
                19:36:21 UTC (rev 5620)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java	2010-03-26 \
20:09:16 UTC (rev 5621) @@ -16,6 +16,7 @@
 
 import static org.junit.Assert.fail;
 
+import java.lang.reflect.Field;
 import java.net.URL;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
@@ -26,10 +27,12 @@
 import org.junit.runner.RunWith;
 import org.openqa.selenium.By;
 import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.htmlunit.HtmlUnitDriver;
 
 import com.gargoylesoftware.htmlunit.BrowserRunner;
 import com.gargoylesoftware.htmlunit.ScriptException;
 import com.gargoylesoftware.htmlunit.WebDriverTestCase;
+import com.gargoylesoftware.htmlunit.WebWindow;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Browser;
 import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers;
@@ -203,7 +206,15 @@
             + "</body>\n"
             + "</html>";
 
-        loadPageWithAlerts2(html);
+        final WebDriver driver = loadPageWithAlerts2(html);
+        if (driver instanceof HtmlUnitDriver) {
+            final HtmlUnitDriver huDriver = (HtmlUnitDriver) driver;
+            final Field field = \
HtmlUnitDriver.class.getDeclaredField("currentWindow"); +            \
field.setAccessible(true); +            final WebWindow webWindow = (WebWindow) \
field.get(huDriver); +            final HtmlPage page = (HtmlPage) \
webWindow.getEnclosedPage(); +            \
assertEquals(getExpectedAlerts()[0].equals("BackCompat"), page.isQuirksMode()); +     \
}  }
 
     /**


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

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
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