diff --git a/mozilla/java/webclient/build-tests.xml b/mozilla/java/webclient/build-tests.xml index f5870bae497..717f1bf9a26 100644 --- a/mozilla/java/webclient/build-tests.xml +++ b/mozilla/java/webclient/build-tests.xml @@ -166,6 +166,7 @@ + diff --git a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp index bd37031d3a4..1616c84f9b6 100644 --- a/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp +++ b/mozilla/java/webclient/src_moz/CurrentPageImpl.cpp @@ -43,8 +43,6 @@ #include "nsCRT.h" -#if 0 // convenience - JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeCopyCurrentSelectionToSystemClipboard (JNIEnv *env, jobject obj, jint nativeBCPtr) { @@ -63,8 +61,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPa } -#endif // if 0 - JNIEXPORT void JNICALL Java_org_mozilla_webclient_impl_wrapper_1native_CurrentPageImpl_nativeGetSelection (JNIEnv *env, jobject obj, jint nativeBCPtr, jobject selection) { 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 new file mode 100644 index 00000000000..bf4e30f331c --- /dev/null +++ b/mozilla/java/webclient/test/automated/src/classes/org/mozilla/webclient/CurrentPageTest.java @@ -0,0 +1,165 @@ +/* + * $Id: CurrentPageTest.java,v 1.3 2005-02-07 04:59:50 edburns%acm.org Exp $ + */ + +/* + * + * The contents of this file are subject to the Mozilla Public + * License Version 1.1 (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.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * implied. See the License for the specific language governing + * rights and limitations under the License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Sun + * Microsystems, Inc. Portions created by Sun are + * Copyright (C) 1999 Sun Microsystems, Inc. All + * Rights Reserved. + * + * Contributor(s): Ed Burns <edburns@acm.org> + */ + +package org.mozilla.webclient; + +import junit.framework.TestSuite; +import junit.framework.TestResult; +import junit.framework.Test; + +import java.util.Enumeration; + +import java.awt.Frame; +import java.awt.BorderLayout; +import java.awt.Toolkit; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.ClipboardOwner; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.DataFlavor; + +import java.io.File; +import java.io.FileInputStream; +import java.io.BufferedReader; + +// CurrentPageTest.java + +public class CurrentPageTest extends WebclientTestCase implements ClipboardOwner { + + public CurrentPageTest(String name) { + super(name); + try { + BrowserControlFactory.setAppData(getBrowserBinDir()); + } + catch (Exception e) { + fail(); + } + } + + public static Test suite() { + TestSuite result = createServerTestSuite(); + result.addTestSuite(CurrentPageTest.class); + return (result); + } + + static EventRegistration2 eventRegistration; + + static CurrentPage2 currentPage = null; + + static boolean keepWaiting; + + // + // Constants + // + + // + // ClipboardOwner + // + + + public void lostOwnership(Clipboard clipboard, + Transferable contents) { + } + + // + // Testcases + // + + public void testCopyCurrentSelectionToSystemClipboard() throws Exception { + BrowserControl firstBrowserControl = null; + DocumentLoadListenerImpl listener = null; + Selection selection = null; + firstBrowserControl = BrowserControlFactory.newBrowserControl(); + assertNotNull(firstBrowserControl); + 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); + frame.add(canvas, BorderLayout.CENTER); + frame.setVisible(true); + canvas.setVisible(true); + + Navigation2 nav = (Navigation2) + firstBrowserControl.queryInterface(BrowserControl.NAVIGATION_NAME); + assertNotNull(nav); + currentPage = (CurrentPage2) + firstBrowserControl.queryInterface(BrowserControl.CURRENT_PAGE_NAME); + + assertNotNull(currentPage); + + eventRegistration.addDocumentLoadListener(listener = new DocumentLoadListenerImpl() { + public void doEndCheck() { + CurrentPageTest.keepWaiting = false; + } + }); + + Thread.currentThread().sleep(3000); + + + // + // load four files. + // + CurrentPageTest.keepWaiting = true; + + nav.loadURL("http://localhost:5243/HistoryTest0.html"); + + // keep waiting until the previous load completes + while (CurrentPageTest.keepWaiting) { + Thread.currentThread().sleep(1000); + } + + CurrentPageTest.keepWaiting = true; + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable contents; + + Thread.currentThread().sleep(3000); + currentPage.selectAll(); + currentPage.copyCurrentSelectionToSystemClipboard(); + 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); + } + assertEquals("HistoryTest0This is page 0 of the history test.next", + buf.toString()); + + frame.setVisible(false); + BrowserControlFactory.deleteBrowserControl(firstBrowserControl); + } + + +}