From 38884c477a8d9c34fc266ad51fcbae1096f7d81e Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Sat, 3 Mar 2007 20:35:14 +0000 Subject: [PATCH] M dist/netbeans/build.xml - Add ability to debug a singe junit test M webclient/build.xml A webclient/classes_spec/org/mozilla/mcp/MCP.java A webclient/classes_spec/org/mozilla/mcp/MCPLogStrings.properties - add mcp package M webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java - add getter for outputFileRoot. git-svn-id: svn://10.0.0.236/trunk@221270 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/java/dist/netbeans/build.xml | 33 +++ mozilla/java/webclient/build.xml | 7 + .../classes_spec/org/mozilla/mcp/MCP.java | 194 ++++++++++++++++++ .../org/mozilla/mcp/MCPLogStrings.properties | 1 + .../mozilla/webclient/WebclientTestCase.java | 9 +- 5 files changed, 242 insertions(+), 2 deletions(-) create mode 100755 mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java create mode 100755 mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCPLogStrings.properties diff --git a/mozilla/java/dist/netbeans/build.xml b/mozilla/java/dist/netbeans/build.xml index 912d304dea6..e26fc1ae8df 100755 --- a/mozilla/java/dist/netbeans/build.xml +++ b/mozilla/java/dist/netbeans/build.xml @@ -268,6 +268,7 @@ ${so.prefix}xul.${so.extension}. + @@ -295,6 +296,38 @@ ${so.prefix}xul.${so.extension}. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mozilla/java/webclient/build.xml b/mozilla/java/webclient/build.xml index 8c45c478bd1..30d1f61c0bc 100644 --- a/mozilla/java/webclient/build.xml +++ b/mozilla/java/webclient/build.xml @@ -124,11 +124,18 @@ HotJava, etc --> + + + + + + + org.mozilla.webclient.impl.WebclientFactoryImpl org.mozilla.webclient.impl.wrapper_native.WrapperFactoryImpl diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java new file mode 100755 index 00000000000..bc632f42770 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCP.java @@ -0,0 +1,194 @@ +/* + * MCP.java + * + * Created on February 27, 2007, 10:24 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package org.mozilla.mcp; + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.io.FileNotFoundException; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.mozilla.webclient.BrowserControl; +import org.mozilla.webclient.BrowserControlCanvas; +import org.mozilla.webclient.BrowserControlFactory; +import org.mozilla.webclient.DocumentLoadEvent; +import org.mozilla.webclient.EventRegistration2; +import org.mozilla.webclient.Navigation2; +import org.mozilla.webclient.PageInfoListener; +import org.mozilla.webclient.WebclientEvent; + +/** + * + * @author edburns + */ +public class MCP { + + /** Creates a new instance of MCP */ + public MCP() { + } + + public static final String MCP_LOG = "org.mozilla.mcp"; + public static final String MCP_LOG_STRINGS = "org.mozilla.mcp.MCPLogStrings"; + + public static final Logger LOGGER = getLogger(MCP_LOG); + + public static Logger getLogger( String loggerName ) { + return Logger.getLogger(loggerName, MCP_LOG_STRINGS ); + } + + private BrowserControl browserControl = null; + private Navigation2 navigation = null; + private EventRegistration2 eventRegistration = null; + private PageInfoListener pageInfoListener = null; + private Frame frame = null; + private int x = 0; + private int y = 0; + private int width = 1280; + private int height = 960; + private boolean initialized = false; + + public void setAppData(String absolutePathToNativeBrowserBinDir) + throws FileNotFoundException, + ClassNotFoundException { + BrowserControlFactory.setAppData(absolutePathToNativeBrowserBinDir); + initialized = true; + } + + void setBounds(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + private Navigation2 getNavigation() { + if (null == navigation) { + try { + navigation = (Navigation2) + getBrowserControl().queryInterface(BrowserControl.NAVIGATION_NAME); + } + catch (Throwable th) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getNavigation", + th); + LOGGER.severe("Unable to obtain Navigation2 reference from BrowserControl"); + } + } + } + return navigation; + } + + private EventRegistration2 getEventRegistration() { + if (null == eventRegistration) { + try { + eventRegistration = (EventRegistration2) + getBrowserControl().queryInterface(BrowserControl.EVENT_REGISTRATION_NAME); + } + catch (Throwable th) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getEventRegistration", + th); + LOGGER.severe("Unable to obtain EventRegistration2 reference from BrowserControl"); + } + } + + } + return eventRegistration; + } + + private PageInfoListener getPageInfoListener() { + if (null == pageInfoListener) { + pageInfoListener = new PageInfoListenerImpl(this); + } + return pageInfoListener; + } + + public BrowserControl getBrowserControl() { + if (!initialized) { + IllegalStateException ise = new IllegalStateException("Not initialized. Call setAppData()"); + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getBrowserControl", ise); + } + throw ise; + } + if (null == browserControl) { + try { + browserControl = BrowserControlFactory.newBrowserControl(); + } catch (IllegalStateException ex) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getBrowserControl", ex); + } + } catch (InstantiationException ex) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getBrowserControl", ex); + } + } catch (IllegalAccessException ex) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "getBrowserControl", ex); + } + } + } + return browserControl; + } + + public Frame getRealizedVisibleBrowserWindow() { + if (null == frame) { + BrowserControlCanvas canvas = null; + try { + canvas = (BrowserControlCanvas) getBrowserControl().queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME); + } catch (ClassNotFoundException ex) { + if (LOGGER.isLoggable(Level.SEVERE)) { + LOGGER.throwing(this.getClass().getName(), "createRealizedVisibleBrowserWindow", ex); + } + } + if (null != canvas) { + frame = new Frame(); + frame.setUndecorated(true); + frame.setBounds(x, y, width, height); + frame.add(canvas, BorderLayout.CENTER); + frame.setVisible(true); + canvas.setVisible(true); + + getEventRegistration().addDocumentLoadListener(getPageInfoListener()); + } + } + return frame; + } + + public void blockingLoad(String url) { + Navigation2 nav = getNavigation(); + synchronized (this) { + nav.loadURL(url); + } + } + + private class PageInfoListenerImpl implements PageInfoListener { + private MCP owner = null; + PageInfoListenerImpl(MCP owner) { + this.owner = owner; + } + + public void eventDispatched(WebclientEvent webclientEvent) { + Map eventData = + (Map) webclientEvent.getEventData(); + long type = webclientEvent.getType(); + + switch ((int)type) { + case ((int) DocumentLoadEvent.END_DOCUMENT_LOAD_EVENT_MASK): + owner.notifyAll(); + break; + default: + break; + } + } + + } + +} diff --git a/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCPLogStrings.properties b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCPLogStrings.properties new file mode 100755 index 00000000000..13e936fed65 --- /dev/null +++ b/mozilla/java/webclient/classes_spec/org/mozilla/mcp/MCPLogStrings.properties @@ -0,0 +1 @@ +# Sample ResourceBundle properties file diff --git a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java index 4c397d95287..97477feed06 100644 --- a/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/WebclientTestCase.java @@ -1,5 +1,5 @@ /* - * $Id: WebclientTestCase.java,v 1.14 2007-02-23 14:38:55 edburns%acm.org Exp $ + * $Id: WebclientTestCase.java,v 1.15 2007-03-03 20:35:14 edburns%acm.org Exp $ */ /* @@ -47,7 +47,7 @@ import org.mozilla.util.THTTPD; * * Lifetime And Scope

* - * @version $Id: WebclientTestCase.java,v 1.14 2007-02-23 14:38:55 edburns%acm.org Exp $ + * @version $Id: WebclientTestCase.java,v 1.15 2007-03-03 20:35:14 edburns%acm.org Exp $ * * @see Blah * @see Bloo @@ -189,6 +189,11 @@ protected static String getBrowserBinDir() { return System.getProperty("BROWSER_BIN_DIR"); } +protected static String getOutputFileRoot() { + return OUTPUT_FILE_ROOT; +} + + /** * assertTrue that NSPR_LOG_FILE is set.