From 04e78a3a4d49cd19b6a3efc7c8d5b064ff445e96 Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Thu, 14 Jun 2007 02:03:34 +0000 Subject: [PATCH] One unit test is still failing: WindowCreator. Oof. Threading problem. M webclient/build.xml - separate out "compile.binaries" target M webclient/classes_spec/org/mozilla/mcp/MCP.java - account for mac coordinate wierdness. M webclient/src_moz/AjaxListener.cpp M webclient/src_moz/CBrowserContainer.cpp M webclient/src_moz/EmbedEventListener.cpp M webclient/src_moz/ns_util.h - make sure to initialize the buffer before calling WC_ITOA M webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java M webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java M webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java - Make these tests run M webclient/test/automated/src/test/HistoryTest0.html - add an ID. M webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java - print out coordinates git-svn-id: svn://10.0.0.236/trunk@228024 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/webclient/build.xml | 4 +- .../classes_spec/org/mozilla/mcp/MCP.java | 16 ++-- .../java/webclient/src_moz/AjaxListener.cpp | 1 + .../webclient/src_moz/CBrowserContainer.cpp | 5 ++ .../webclient/src_moz/EmbedEventListener.cpp | 12 ++- mozilla/java/webclient/src_moz/ns_util.h | 3 +- .../mozilla/webclient/CurrentPageTest.java | 4 +- .../mozilla/webclient/KeyListenerTest.java | 27 ++++-- .../mozilla/webclient/MouseListenerTest.java | 84 +++++++++++++------ .../test/automated/src/test/HistoryTest0.html | 2 +- .../mozilla/webclient/test/TestBrowser.java | 11 ++- 11 files changed, 118 insertions(+), 51 deletions(-) diff --git a/mozilla/java/webclient/build.xml b/mozilla/java/webclient/build.xml index a604cb43937..ae72e2d1fc8 100644 --- a/mozilla/java/webclient/build.xml +++ b/mozilla/java/webclient/build.xml @@ -94,7 +94,9 @@ + depends="prepare,compile.classes_spec,compile.binaries,create.webclient.scripts"/> + + diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java index ed42ca2fbfd..f5f5a9f9627 100755 --- a/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java +++ b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java @@ -1,5 +1,5 @@ /* - * $Id: MCP.java,v 1.11 2007-06-13 16:57:17 edburns%acm.org Exp $ + * $Id: MCP.java,v 1.12 2007-06-14 02:03:33 edburns%acm.org Exp $ */ /* @@ -516,16 +516,16 @@ public class MCP { */ public void clickElement(Element element) { - String clientX = null, clientY = null; + String screenX = null, screenY = null; String id = element.getAttribute("id"); if (null != element) { - clientX = element.getAttribute("clientX"); - clientY = element.getAttribute("clientY"); + screenX = element.getAttribute("screenX"); + screenY = element.getAttribute("screenY"); int x,y; - if (null != clientX && null != clientY) { + if (null != screenX && null != screenY) { try { - x = Integer.valueOf(clientX).intValue(); - y = Integer.valueOf(clientY).intValue(); + x = Integer.valueOf(screenX).intValue(); + y = Integer.valueOf(screenY).intValue() - 5; Robot robot = getRobot(); robot.mouseMove(x, y); robot.mousePress(InputEvent.BUTTON1_MASK); @@ -540,7 +540,7 @@ public class MCP { } } } - if (null == element || null == clientX || null == clientY) { + if (null == element || null == screenX || null == screenY) { throw new IllegalStateException("Unable to click element " + id); } } diff --git a/mozilla/java/webclient/src_moz/AjaxListener.cpp b/mozilla/java/webclient/src_moz/AjaxListener.cpp index 0c13c8ac432..7225b77c269 100755 --- a/mozilla/java/webclient/src_moz/AjaxListener.cpp +++ b/mozilla/java/webclient/src_moz/AjaxListener.cpp @@ -227,6 +227,7 @@ AjaxListener::ObserveAjax(nsIRequest *request, PRUint32 responseStatus = 0; PRInt32 readyState = 0; char buf[20]; + memset(buf, 0, 20); jstring jStr = nsnull; nsCOMPtr domDocument; jlong documentLong = nsnull; diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index b2d637e8edb..ba30cc947da 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -1619,6 +1619,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous // PENDING(edburns): perhaps use a macro to speed this up? rv = mouseEvent->GetScreenX(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, properties, SCREEN_X_KEY, @@ -1629,6 +1630,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous rv = mouseEvent->GetScreenY(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, properties, SCREEN_Y_KEY, @@ -1639,6 +1641,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous rv = mouseEvent->GetClientX(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, properties, CLIENT_X_KEY, @@ -1649,6 +1652,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous rv = mouseEvent->GetClientY(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, properties, CLIENT_Y_KEY, @@ -1660,6 +1664,7 @@ void JNICALL CBrowserContainer::addMouseEventDataToProperties(nsIDOMEvent *aMous int16Val = 0; rv = mouseEvent->GetButton(&int16Val); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(int16Val, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, properties, BUTTON_KEY, diff --git a/mozilla/java/webclient/src_moz/EmbedEventListener.cpp b/mozilla/java/webclient/src_moz/EmbedEventListener.cpp index 534bb42b225..6e16122c0e3 100644 --- a/mozilla/java/webclient/src_moz/EmbedEventListener.cpp +++ b/mozilla/java/webclient/src_moz/EmbedEventListener.cpp @@ -372,7 +372,8 @@ nsresult EmbedEventListener::PopulatePropertiesFromEvent(nsIDOMEvent *event) } // Store a Long into the properties under the key: NODE_LONG_KEY - jlong longVal = (jlong) currentNode.get(); + PRUint32 longVal = (PRUint32) currentNode.get(); + memset(buf, 0, 20); WC_ITOA(longVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); @@ -422,6 +423,7 @@ nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtrGetScreenX(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, SCREEN_X_KEY, @@ -432,6 +434,10 @@ nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtrGetScreenY(&intVal); if (NS_SUCCEEDED(rv)) { +#if (defined(XP_MAC) || defined(XP_MACOSX)) && defined(MOZ_WIDGET_COCOA) + intVal -=5; +#endif + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, SCREEN_Y_KEY, @@ -442,6 +448,7 @@ nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtrGetClientX(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, CLIENT_X_KEY, @@ -452,6 +459,7 @@ nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtrGetClientY(&intVal); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(intVal, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, CLIENT_Y_KEY, @@ -463,6 +471,7 @@ nsresult EmbedEventListener::addMouseEventDataToProperties(nsCOMPtrGetButton(&int16Val); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(int16Val, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, BUTTON_KEY, @@ -539,6 +548,7 @@ nsresult EmbedEventListener::addKeyEventDataToProperties(nsCOMPtrGetKeyCode(&int32Val); if (NS_SUCCEEDED(rv)) { + memset(buf, 0, 20); WC_ITOA(int32Val, buf, 10); strVal = ::util_NewStringUTF(env, buf); ::util_StoreIntoPropertiesObject(env, mProperties, KEY_CODE, diff --git a/mozilla/java/webclient/src_moz/ns_util.h b/mozilla/java/webclient/src_moz/ns_util.h index 9e1dc7ee414..8a3e2d9cfee 100644 --- a/mozilla/java/webclient/src_moz/ns_util.h +++ b/mozilla/java/webclient/src_moz/ns_util.h @@ -61,8 +61,7 @@ #endif // -#if defined(XP_UNIX) || defined(XP_MAC) || defined(XP_BEOS) - +#if defined(XP_UNIX) || defined(XP_MACOSX) #define WC_ITOA(intVal, buf, radix) sprintf(buf, "%d", intVal) #else #define WC_ITOA(intVal, buf, radix) itoa(intVal, buf, radix) diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java index d75920d6288..5563932528c 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java @@ -1,5 +1,5 @@ /* - * $Id: CurrentPageTest.java,v 1.18 2007-06-12 14:21:02 edburns%acm.org Exp $ + * $Id: CurrentPageTest.java,v 1.19 2007-06-14 02:03:34 edburns%acm.org Exp $ */ /* @@ -193,7 +193,7 @@ public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner buf.append(contentLine); System.out.println(contentLine); } - assertEquals("

HistoryTest0

This is page 0 of the history test.

next


", + assertEquals("

HistoryTest0

This is page 0 of the history test.

next


", buf.toString()); diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java index f7d599c69c5..8fe74b9a1ce 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/KeyListenerTest.java @@ -1,5 +1,5 @@ /* - * $Id: KeyListenerTest.java,v 1.5 2007-05-04 17:10:35 edburns%acm.org Exp $ + * $Id: KeyListenerTest.java,v 1.6 2007-06-14 02:03:34 edburns%acm.org Exp $ */ /* @@ -37,6 +37,7 @@ import java.awt.event.KeyEvent; import java.awt.event.InputEvent; import java.awt.BorderLayout; import org.mozilla.mcp.junit.WebclientTestCase; +import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -96,7 +97,6 @@ public class KeyListenerTest extends WebclientTestCase { assertNotNull(canvas); Frame frame = new Frame(); - frame.setUndecorated(true); frame.setBounds(0, 0, 640, 480); frame.add(canvas, BorderLayout.CENTER); frame.setVisible(true); @@ -154,8 +154,7 @@ public class KeyListenerTest extends WebclientTestCase { id = element.getAttribute("id"), name = element.getAttribute("name"), nodeName = domNode.getNodeName(), - value = domNode.getNodeValue(); - assertEquals("field1", id); + value = domNode.getNodeValue(); assertEquals("field1", id); assertEquals("field1", name); assertEquals("INPUT", nodeName); assertEquals("", value); @@ -182,23 +181,33 @@ public class KeyListenerTest extends WebclientTestCase { while (KeyListenerTest.keepWaiting) { Thread.currentThread().sleep(1000); } + + Document dom = currentPage.getDOM(); + assertNotNull(dom); + Element textField = dom.getElementById("field1"); + assertNotNull(textField); + + String screenX = textField.getAttribute("screenX"); + String screenY = textField.getAttribute("screenY"); + assertNotNull(screenX); + assertNotNull(screenY); + int x = Integer.valueOf(screenX).intValue(); + int y = Integer.valueOf(screenY).intValue() - 5; Robot robot = new Robot(); - - robot.mouseMove(IN_X, IN_Y); + robot.mouseMove(x, y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); - + /**** // uncomment to enable manual testing - /************* KeyListenerTest.keepWaiting = true; // keep waiting until the previous load completes while (KeyListenerTest.keepWaiting) { Thread.currentThread().sleep(1000); } - ******************/ + ****/ robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java index 5dccdb36335..f6e9662ef98 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/MouseListenerTest.java @@ -1,5 +1,5 @@ /* - * $Id: MouseListenerTest.java,v 1.4 2007-05-04 17:10:35 edburns%acm.org Exp $ + * $Id: MouseListenerTest.java,v 1.5 2007-06-14 02:03:34 edburns%acm.org Exp $ */ /* @@ -26,6 +26,7 @@ package org.mozilla.webclient; +import java.awt.Rectangle; import junit.framework.TestSuite; import junit.framework.Test; import java.util.Map; @@ -38,6 +39,7 @@ import java.awt.event.MouseEvent; import java.awt.event.InputEvent; import java.awt.BorderLayout; import org.mozilla.mcp.junit.WebclientTestCase; +import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -61,17 +63,15 @@ public class MouseListenerTest extends WebclientTestCase { return (result); } - static final int IN_X = 20; - static final int IN_Y = 117; - - static final int OUT_X = 700; - static final int OUT_Y = 500; - static EventRegistration2 eventRegistration; static CurrentPage2 currentPage = null; static boolean keepWaiting; + + int x; + + int y; // // Constants @@ -96,15 +96,14 @@ public class MouseListenerTest extends WebclientTestCase { assertNotNull(firstBrowserControl); History history = (History) firstBrowserControl.queryInterface(BrowserControl.HISTORY_NAME); - BrowserControlCanvas canvas = (BrowserControlCanvas) + final BrowserControlCanvas canvas = (BrowserControlCanvas) firstBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); eventRegistration = (EventRegistration2) firstBrowserControl.queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); assertNotNull(canvas); - Frame frame = new Frame(); - frame.setUndecorated(true); - frame.setBounds(0, 0, 640, 480); + final Frame frame = new Frame(); + frame.setBounds(0, 30, 640, 480); frame.add(canvas, BorderLayout.CENTER); frame.setVisible(true); canvas.setVisible(true); @@ -127,8 +126,13 @@ public class MouseListenerTest extends WebclientTestCase { // PENDING(edburns): flesh this out with more content MouseListener mouseListener = new MouseListener() { public void mouseEntered(MouseEvent e) { - assertEquals(IN_X, e.getX()); - assertEquals(IN_Y, e.getY()); + Rectangle + frameBounds = frame.getBounds(), + canvasBounds = canvas.getBounds(); + assertEquals(MouseListenerTest.this.x, e.getX() + + frameBounds.x + canvasBounds.x); + assertEquals(MouseListenerTest.this.y, e.getY() + + frameBounds.y + canvasBounds.y); assertTrue(e instanceof WCMouseEvent); WCMouseEvent wcMouseEvent = (WCMouseEvent) e; @@ -175,15 +179,6 @@ public class MouseListenerTest extends WebclientTestCase { } }; - if (addToCanvas) { - canvas.addMouseListener(mouseListener); - } - else { - eventRegistration.addMouseListener(mouseListener); - } - - Thread.currentThread().sleep(3000); - // // load four files. @@ -198,18 +193,57 @@ public class MouseListenerTest extends WebclientTestCase { } Robot robot = new Robot(); - - robot.mouseMove(IN_X, IN_Y); + + Document dom = currentPage.getDOM(); + assertNotNull(dom); + Element toClick = dom.getElementById("HistoryTest0"); + assertNotNull(toClick); + String + screenX = toClick.getAttribute("screenX"), + screenY = toClick.getAttribute("screenY"); + assertNotNull(screenX); + assertNotNull(screenY); + + x = Integer.valueOf(screenX).intValue(); + y = Integer.valueOf(screenY).intValue() - 5; + + // Click the H1 just to ensure the window has focus. + robot.mouseMove(x,y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); + + // Now, add our test listener + if (addToCanvas) { + canvas.addMouseListener(mouseListener); + } + else { + eventRegistration.addMouseListener(mouseListener); + } + + Thread.currentThread().sleep(3000); + + toClick = dom.getElementById("HistoryTest1.html"); + assertNotNull(toClick); + screenX = toClick.getAttribute("screenX"); + screenY = toClick.getAttribute("screenY"); + assertNotNull(screenX); + assertNotNull(screenY); + + x = Integer.valueOf(screenX).intValue(); + y = Integer.valueOf(screenY).intValue() - 5; MouseListenerTest.keepWaiting = true; + + robot.mouseMove(x, y); + robot.mousePress(InputEvent.BUTTON1_MASK); + robot.mouseRelease(InputEvent.BUTTON1_MASK); + while (MouseListenerTest.keepWaiting) { Thread.currentThread().sleep(1000); } - robot.mouseMove(OUT_X, OUT_Y); + robot.mouseMove(x + 50, y + 50); Thread.currentThread().sleep(3000); diff --git a/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html b/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html index 6671c17fa93..e58d9b09415 100644 --- a/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html +++ b/mozilla/java/webclient/test/automated/src/test/HistoryTest0.html @@ -5,7 +5,7 @@ -

HistoryTest0

+

HistoryTest0

This is page 0 of the history test.

diff --git a/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java b/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java index f031d675e75..2bff6af3784 100644 --- a/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java +++ b/mozilla/java/webclient/test/manual/src/classes/org/mozilla/webclient/test/TestBrowser.java @@ -383,7 +383,11 @@ public class TestBrowser extends JPanel { name = element.getAttribute("name"), nodeName = domNode.getNodeName(), value = domNode.getNodeValue(), - status = ""; + status = "", + clientX = element.getAttribute("clientX"), + clientY = element.getAttribute("clientY"), + screenX = element.getAttribute("screenX"), + screenY = element.getAttribute("screenY"); if (null != href) { // PENDING(edburns): take care of relative URL status = href; @@ -391,7 +395,10 @@ public class TestBrowser extends JPanel { if (null != id || null != name || null != nodeName || null != value) { status = status + " domNode: " + nodeName + " id: " + id - + " name: " + name + " value: " + value; + + " name: " + name + " value: " + + value + "client(" + clientX + "," + + clientY + ") screen(" + screenX + "," + + screenY + ")"; updateStatusInfo(status); } }