Issue: 369376

M classes_spec/org/mozilla/webclient/impl/wrapper_native/CurrentPageImpl.java
M test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java

- Get the test case working.


git-svn-id: svn://10.0.0.236/trunk@220409 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
edburns%acm.org
2007-02-16 13:29:15 +00:00
parent 5e31e514c3
commit 7841b5844f
2 changed files with 43 additions and 16 deletions

View File

@@ -21,20 +21,21 @@
package org.mozilla.webclient.impl.wrapper_native;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import org.mozilla.util.Assert;
import org.mozilla.util.Log;
import org.mozilla.util.ParameterCheck;
import org.mozilla.webclient.BrowserControl;
import org.mozilla.webclient.CurrentPage2;
import org.mozilla.webclient.Selection;
import org.mozilla.webclient.WindowControl;
import org.mozilla.webclient.impl.WrapperFactory;
import org.mozilla.webclient.impl.DOMTreeDumper;
import java.util.Properties;
import java.io.*;
import java.net.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@@ -43,7 +44,8 @@ import org.mozilla.webclient.UnimplementedException;
import org.mozilla.dom.DOMAccessor;
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage2
public class CurrentPageImpl extends ImplObjectNative implements CurrentPage2,
ClipboardOwner
{
//
// Protected Constants
@@ -100,7 +102,12 @@ public void copyCurrentSelectionToSystemClipboard()
NativeEventThread.instance.pushBlockingWCRunnable(new WCRunnable() {
public Object run() {
transferable = null;
nativeCopyCurrentSelectionToSystemClipboard(CurrentPageImpl.this.getNativeBrowserControl());
if (null != transferable) {
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
clip.setContents(transferable, CurrentPageImpl.this);
}
return null;
}
public String toString() {
@@ -336,10 +343,21 @@ public void printPreview(boolean pre)
});
}
private Transferable transferable = null;
void addStringToTransferable(String mimeType, String text) {
System.out.println("mimeType:" + mimeType + " text:" + text);
if (null == transferable) {
if (mimeType.equals("text/unicode")) {
transferable = new StringSelection(text);
}
}
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
//
// Native methods
//
@@ -372,4 +390,5 @@ native public void nativePrint(int webShellPtr);
native public void nativePrintPreview(int webShellPtr, boolean preview);
} // end of class CurrentPageImpl

View File

@@ -1,5 +1,5 @@
/*
* $Id: CurrentPageTest.java,v 1.13 2007-01-30 18:26:37 edburns%acm.org Exp $
* $Id: CurrentPageTest.java,v 1.14 2007-02-16 13:29:15 edburns%acm.org Exp $
*/
/*
@@ -90,7 +90,7 @@ public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner
// Testcases
//
public void NOT_testCopyCurrentSelectionToSystemClipboard() throws Exception {
public void testCopyCurrentSelectionToSystemClipboard() throws Exception {
BrowserControl firstBrowserControl = null;
DocumentLoadListenerImpl listener = null;
Selection selection = null;
@@ -145,15 +145,23 @@ public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner
contents = clipboard.getContents(this);
assertNotNull(contents);
DataFlavor bestTextFlavor = DataFlavor.getTextPlainUnicodeFlavor();
BufferedReader clipReader =
new BufferedReader(bestTextFlavor.getReaderForText(contents));
String contentLine;
StringBuffer buf = new StringBuffer();
while (null != (contentLine = clipReader.readLine())) {
buf.append(contentLine);
System.out.println(contentLine);
}
DataFlavor bestTextFlavor = DataFlavor.selectBestTextFlavor(clipboard.getAvailableDataFlavors());
BufferedReader clipReader = null;
try {
clipReader = new BufferedReader(bestTextFlavor.getReaderForText(contents));
}
catch (Throwable e) {
fail("Can't get reader for text: Throwable: " + e.toString() + " " +
e.getMessage());
}
String contentLine;
StringBuffer buf = new StringBuffer();
while (null != (contentLine = clipReader.readLine())) {
buf.append(contentLine);
System.out.println(contentLine);
}
assertEquals("HistoryTest0This is page 0 of the history test.next",
buf.toString());