Author: maoziqing
Date: Tue Jun 30 13:42:13 2009
New Revision: 3549

Added:
   trunk/tests/com/google/caja/plugin/DomitaTest.java
   trunk/third_party/java/webdriver/
trunk/third_party/java/webdriver/commons-codec-1.3.jar (contents, props changed) trunk/third_party/java/webdriver/commons-collections-3.2.1.jar (contents, props changed) trunk/third_party/java/webdriver/commons-collections-3.2.jar (contents, props changed) trunk/third_party/java/webdriver/commons-httpclient-3.1.jar (contents, props changed) trunk/third_party/java/webdriver/commons-io-1.4.jar (contents, props changed) trunk/third_party/java/webdriver/commons-lang-2.4.jar (contents, props changed) trunk/third_party/java/webdriver/commons-logging-1.1.1.jar (contents, props changed) trunk/third_party/java/webdriver/cssparser-0.9.5.jar (contents, props changed) trunk/third_party/java/webdriver/hamcrest-all-1.1.jar (contents, props changed) trunk/third_party/java/webdriver/htmlunit-2.4.jar (contents, props changed) trunk/third_party/java/webdriver/htmlunit-core-js-2.4.jar (contents, props changed) trunk/third_party/java/webdriver/jmock-2.4.0.jar (contents, props changed) trunk/third_party/java/webdriver/jmock-junit3-2.4.0.jar (contents, props changed)
   trunk/third_party/java/webdriver/jna.jar   (contents, props changed)
trunk/third_party/java/webdriver/json-20080701.jar (contents, props changed) trunk/third_party/java/webdriver/junit-3.8.1.jar (contents, props changed) trunk/third_party/java/webdriver/nekohtml-1.9.11.jar (contents, props changed)
   trunk/third_party/java/webdriver/sac-1.3.jar   (contents, props changed)
trunk/third_party/java/webdriver/serializer-2.7.1.jar (contents, props changed) trunk/third_party/java/webdriver/webdriver-all.jar (contents, props changed) trunk/third_party/java/webdriver/xalan-2.7.1.jar (contents, props changed) trunk/third_party/java/webdriver/xercesImpl-2.8.1.jar (contents, props changed) trunk/third_party/java/webdriver/xml-apis-1.3.04.jar (contents, props changed)
Modified:
   trunk/build.xml
   trunk/tests/com/google/caja/plugin/domita_test.html
   trunk/tests/com/google/caja/plugin/domita_test_untrusted.html

Log:
Add an automatic test for the domita test.



Modified: trunk/build.xml
==============================================================================
--- trunk/build.xml     (original)
+++ trunk/build.xml     Tue Jun 30 13:42:13 2009
@@ -76,6 +76,28 @@
     <pathelement path="${third_party}/java/json_simple/json_simple.jar"/>
     <pathelement path="${third_party}/java/jsdk2.1/servlet.jar"/>
     <pathelement path="${third_party}/java/rhino/js.jar"/>
+    <pathelement path="${third_party}/java/webdriver/webdriver-all.jar"/>
+ <pathelement path="${third_party}/java/webdriver/commons-codec-1.3.jar"/>
+    <pathelement
+       path="${third_party}/java/webdriver/commons-collections-3.2.1.jar"/>
+    <pathelement
+       path="${third_party}/java/webdriver/commons-httpclient-3.1.jar"/>
+    <pathelement path="${third_party}/java/webdriver/commons-io-1.4.jar"/>
+ <pathelement path="${third_party}/java/webdriver/commons-lang-2.4.jar"/>
+    <pathelement
+       path="${third_party}/java/webdriver/commons-logging-1.1.1.jar"/>
+ <pathelement path="${third_party}/java/webdriver/css-parser-0.9.5.jar"/>
+    <pathelement path="${third_party}/java/webdriver/hamcrest.jar"/>
+    <pathelement path="${third_party}/java/webdriver/jmock-2.4.0.jar"/>
+ <pathelement path="${third_party}/java/webdriver/jmock-junit3-2.4.0.jar"/>
+    <pathelement path="${third_party}/java/webdriver/jna.jar"/>
+    <pathelement path="${third_party}/java/webdriver/json-20080701.jar"/>
+    <pathelement path="${third_party}/java/webdriver/nekohtml-1.9.11.jar"/>
+    <pathelement path="${third_party}/java/webdriver/sac-1.3.jar"/>
+ <pathelement path="${third_party}/java/webdriver/serializer-2.7.1.jar"/>
+    <pathelement path="${third_party}/java/webdriver/xalan-2.7.1.jar"/>
+    <pathelement path="${third_party}/java/jetty/lib/jetty-6.1.15.jar"/>
+ <pathelement path="${third_party}/java/jetty/lib/jetty-util-6.1.15.jar"/>
   </path>
   <path id="classpath.tests.run">
     <pathelement path="${third_party}/java/emma/emma.jar"/>
@@ -160,6 +182,9 @@
           <include name="**/${test.filter}.java"/>
         </fileset>
       </batchtest>
+      <syspropertyset>
+        <propertyref prefix="webdriver.firefox.bin"/>
+      </syspropertyset>
       <sysproperty key="emma.coverage.out.file"
        value="${reports}/coverage/coverage.ec"/>
       <sysproperty key="emma.coverage.out.merge" value="false"/>

Added: trunk/tests/com/google/caja/plugin/DomitaTest.java
==============================================================================
--- (empty file)
+++ trunk/tests/com/google/caja/plugin/DomitaTest.java Tue Jun 30 13:42:13 2009
@@ -0,0 +1,112 @@
+// Copyright (C) 2009 Google 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.google.caja.plugin;
+
+import com.google.caja.util.CajaTestCase;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.handler.DefaultHandler;
+import org.mortbay.jetty.handler.HandlerList;
+import org.mortbay.jetty.handler.ResourceHandler;
+
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.firefox.FirefoxDriver;
+
+import java.util.List;
+
+/**
+* Perform the domita test automatically.
+*
+* @author [email protected] (Ziqing Mao)
+*/
+public class DomitaTest extends CajaTestCase {
+  final int clickingRoundLimit = 10;
+
+  Server server;
+
+  /**
+   * Start a local web server on port 8000.
+   */
+  public void StartLocalServer() {
+    server = new Server(8000);
+    ResourceHandler resource_handler = new ResourceHandler();
+    resource_handler.setResourceBase(".");
+    HandlerList handlers = new HandlerList();
+ handlers.setHandlers(new Handler[]{resource_handler,new DefaultHandler()});
+    server.setHandler(handlers);
+
+    try {
+      server.start();
+    } catch (Exception e) {
+      fail("Starting the local web server failed!");
+    }
+  }
+
+  /**
+   * Stop the local web server
+   */
+  public void StopLocalServer() {
+    try {
+      server.stop();
+    } catch (Exception e) {
+      // the server will be turned down when the test exits
+    }
+  }
+
+  /**
+ * Automatically click the elements with a class name containing "clickme".
+   * Repeat until all tests are passed, or the number of rounds exceeds the
+   * threshold.
+   */
+  public void testDomita() {
+    StartLocalServer();
+
+    //System.setProperty("webdriver.firefox.bin", "/usr/bin/firefox");
+    WebDriver driver = new FirefoxDriver();
+
+    driver.get("http://localhost:8000/";
+        + "ant-lib/com/google/caja/plugin/domita_test.html");
+
+    int roundCount = 0;
+    do
+    {
+      List<WebElement> clickingList =
+ driver.findElements(By.xpath("//*[contains(@class,'clickme')]/*"));
+
+      if (clickingList.size() == 0) {
+        break;
+      }
+
+      for (WebElement e : clickingList) {
+        e.click();
+      }
+
+      roundCount++;
+    } while (roundCount <= clickingRoundLimit);
+
+ assertTrue("Too many clicking rounds.", roundCount <= clickingRoundLimit);
+
+    // check the title of the document
+    String title = driver.getTitle();
+ assertTrue("The title shows " + title.substring(title.lastIndexOf("-") + 1),
+        title.endsWith("all tests passed"));
+
+    //driver.quit();
+    StopLocalServer();
+  }
+}

Modified: trunk/tests/com/google/caja/plugin/domita_test.html
==============================================================================
--- trunk/tests/com/google/caja/plugin/domita_test.html (original)
+++ trunk/tests/com/google/caja/plugin/domita_test.html Tue Jun 30 13:42:13 2009
@@ -286,6 +286,10 @@
         if (!node) { console.trace(); }
         node = node.node___;
         node.appendChild(document.createTextNode('Passed ' + id));
+        if (node.className != null &&
+            node.className.substring(0, 8) === 'clickme-') {
+                  node.className = node.className.substring(8);
+            }
         node.className = (node.className || '') + ' passed';
       }, 'pass');


Modified: trunk/tests/com/google/caja/plugin/domita_test_untrusted.html
==============================================================================
--- trunk/tests/com/google/caja/plugin/domita_test_untrusted.html       
(original)
+++ trunk/tests/com/google/caja/plugin/domita_test_untrusted.html Tue Jun 30 13:42:13 2009
@@ -17,6 +17,7 @@
 <style type="text/css">
   .testcontainer { background: yellow; border: 2px solid yellow }
   .testcontainer.passed { background: #c0ffc0; border: 2px solid #c0ffc0 }
+  .clickme-testcontainer { background: yellow; border: 2px solid yellow }
   .invisible { display: none; float: left }
   .inline { display: inline }
 </style>
@@ -25,19 +26,19 @@
   Timeouts and Intervals<br>
 </p>

-<p class="testcontainer" id="test-add-event-listener">
+<p class="clickme-testcontainer" id="test-add-event-listener">
   <b id="test-add-event-listener-label">click me</b>
 </p>

-<p class="testcontainer" id="test-remove-event-listener">
+<p class="clickme-testcontainer" id="test-remove-event-listener">
   <b id="test-remove-event-listener-label">click me</b>
 </p>

-<p class="testcontainer" id="test-dom-class-hierarchy">
+<p class="clickme-testcontainer" id="test-dom-class-hierarchy">
   <b>Click me</b>
 </p>

-<div class="testcontainer" id="test-case-insensitive-attrs">
+<div class="clickme-testcontainer" id="test-case-insensitive-attrs">
   <table id="is-red">
     <tr>
       <td><strong>Click me if this is red</strong></td>
@@ -45,7 +46,7 @@
   </table>
 </div>

-<p class="testcontainer" id="test-onclick-handler">
+<p class="clickme-testcontainer" id="test-onclick-handler">
   <b id="test-onclick-handler-label"
      onclick="pass('test-onclick-handler');">click me</b>
 </p>

Added: trunk/third_party/java/webdriver/commons-codec-1.3.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-collections-3.2.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-collections-3.2.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-httpclient-3.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-io-1.4.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-lang-2.4.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/commons-logging-1.1.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/cssparser-0.9.5.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/hamcrest-all-1.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/htmlunit-2.4.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/htmlunit-core-js-2.4.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/jmock-2.4.0.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/jmock-junit3-2.4.0.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/jna.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/json-20080701.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/junit-3.8.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/nekohtml-1.9.11.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/sac-1.3.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/serializer-2.7.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/webdriver-all.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/xalan-2.7.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/xercesImpl-2.8.1.jar
==============================================================================
Binary file. No diff available.

Added: trunk/third_party/java/webdriver/xml-apis-1.3.04.jar
==============================================================================
Binary file. No diff available.

Reply via email to